Update src/ai-repo-commander.user.js

New Command Delimiters

^%$bridge → @bridge@ (easier to type/remember)
--- → @end@ (won't conflict with markdown horizontal rules!)


Updated All Regex Patterns

Command detection
Block extraction
Completion checking
Fingerprinting


Updated Test Commands

All examples now use @bridge@ / @end@
Added example showing --- working inside content blocks



New Command Format:
yaml@bridge@
action: update_file
repo: test-repo
path: docs/README.md
content: |
  # My Markdown
  
  This has a horizontal rule:
  ---
  
  No problem! The @end@ terminator is distinctive.
body: Optional description
@end@
This commit is contained in:
rob 2025-10-09 17:44:30 +00:00
parent d037173671
commit 9270695403
1 changed files with 30 additions and 27 deletions

View File

@ -1,8 +1,8 @@
// ==UserScript== // ==UserScript==
// @name AI Repo Commander // @name AI Repo Commander
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 1.4.1 // @version 1.5.0
// @description Execute ^%$bridge YAML commands from AI assistants (safe & robust): complete-block detection, streaming-settle, persistent dedupe, paste+autosubmit, debug console with Tools/Settings, draggable/collapsible panel // @description Execute @bridge@ YAML commands from AI assistants (safe & robust): complete-block detection, streaming-settle, persistent dedupe, paste+autosubmit, debug console with Tools/Settings, draggable/collapsible panel
// @author Your Name // @author Your Name
// @match https://chat.openai.com/* // @match https://chat.openai.com/*
// @match https://chatgpt.com/* // @match https://chatgpt.com/*
@ -36,7 +36,7 @@
// Timing & API // Timing & API
DEBOUNCE_DELAY: 3000, DEBOUNCE_DELAY: 3000,
MAX_RETRIES: 2, MAX_RETRIES: 2,
VERSION: '1.4.1', VERSION: '1.5.0',
API_TIMEOUT_MS: 60000, API_TIMEOUT_MS: 60000,
PROCESS_EXISTING: false, PROCESS_EXISTING: false,
@ -583,11 +583,11 @@
// Extract the *command block* if present; else fall back to element text // Extract the *command block* if present; else fall back to element text
function _commandishText(el) { function _commandishText(el) {
// Mirror parser's detector: require header, action, and '---' // Mirror parser's detector: require header, action, and '@end@'
const blocks = el.querySelectorAll('pre code, pre, code'); const blocks = el.querySelectorAll('pre code, pre, code');
for (const b of blocks) { for (const b of blocks) {
const t = _norm(b.textContent || ''); const t = _norm(b.textContent || '');
if (/\n---\s*$/.test(t) && /(^|\n)\s*\^%\$bridge\b/m.test(t) && /(^|\n)\s*action\s*:/m.test(t)) { if (/@end@\s*$/m.test(t) && /(^|\n)\s*@bridge@\b/m.test(t) && /(^|\n)\s*action\s*:/m.test(t)) {
return t; return t;
} }
} }
@ -1145,11 +1145,11 @@
return true; return true;
} }
// ---------------------- Parser (strict, require ---) ---------------------- // ---------------------- Parser (strict, require @end@) ----------------------
class CommandParser { class CommandParser {
static parseYAMLCommand(codeBlockText) { static parseYAMLCommand(codeBlockText) {
const block = this.extractCompleteBlock(codeBlockText); const block = this.extractCompleteBlock(codeBlockText);
if (!block) throw new Error('No complete ^%$bridge command found (missing --- terminator).'); if (!block) throw new Error('No complete @bridge@ command found (missing @end@ terminator).');
const parsed = this.parseKeyValuePairs(block); const parsed = this.parseKeyValuePairs(block);
// Defaults // Defaults
@ -1171,7 +1171,8 @@
} }
static extractCompleteBlock(text) { static extractCompleteBlock(text) {
const pattern = /^\s*\^%\$bridge[ \t]*\n([\s\S]*?)\n---[ \t]*(?:\n|$)/m; // Require terminator @end@ (clearer than --- which appears in markdown)
const pattern = /^\s*@bridge@[ \t]*\n([\s\S]*?)\n@end@[ \t]*(?:\n|$)/m;
const m = text.match(pattern); const m = text.match(pattern);
if (!m) return null; if (!m) return null;
const inner = m[1]?.trimEnd(); const inner = m[1]?.trimEnd();
@ -1603,10 +1604,10 @@
} }
isCompleteCommandText(txt) { isCompleteCommandText(txt) {
if (!CONFIG.REQUIRE_TERMINATOR) return /(^|\n)\s*\^%\$bridge\b/m.test(txt) && /(^|\n)\s*action\s*:/m.test(txt); if (!CONFIG.REQUIRE_TERMINATOR) return /(^|\n)\s*@bridge@\b/m.test(txt) && /(^|\n)\s*action\s*:/m.test(txt);
return /(^|\n)\s*\^%\$bridge\b/m.test(txt) return /(^|\n)\s*@bridge@\b/m.test(txt)
&& /(^|\n)\s*action\s*:/m.test(txt) && /(^|\n)\s*action\s*:/m.test(txt)
&& /(^|\n)---\s*$/.test(txt); && /@end@\s*$/m.test(txt);
} }
findCommandInCodeBlock(el) { findCommandInCodeBlock(el) {
@ -2009,51 +2010,53 @@
validUpdate: validUpdate:
`\ `\
\`\`\`yaml \`\`\`yaml
^%$bridge @bridge@
action: update_file action: update_file
repo: test-repo repo: test-repo
path: TEST.md path: TEST.md
content: | content: |
Test content Test content
Multiple lines Multiple lines
--- ---
Even markdown horizontal rules work!
@end@
\`\`\` \`\`\`
`, `,
getFile: getFile:
`\ `\
\`\`\`yaml \`\`\`yaml
^%$bridge @bridge@
action: get_file action: get_file
repo: test-repo repo: test-repo
path: README.md path: README.md
--- @end@
\`\`\` \`\`\`
`, `,
listFiles: listFiles:
`\ `\
\`\`\`yaml \`\`\`yaml
^%$bridge @bridge@
action: list_files action: list_files
repo: test-repo repo: test-repo
path: . path: .
--- @end@
\`\`\` \`\`\`
`, `,
createBranch: createBranch:
`\ `\
\`\`\`yaml \`\`\`yaml
^%$bridge @bridge@
action: create_branch action: create_branch
repo: test-repo repo: test-repo
branch: feature/new-feature branch: feature/new-feature
source_branch: main source_branch: main
--- @end@
\`\`\` \`\`\`
`, `,
createPR: createPR:
`\ `\
\`\`\`yaml \`\`\`yaml
^%$bridge @bridge@
action: create_pr action: create_pr
repo: test-repo repo: test-repo
title: Add new feature title: Add new feature
@ -2063,13 +2066,13 @@ body: |
This PR adds a new feature This PR adds a new feature
- Item 1 - Item 1
- Item 2 - Item 2
--- @end@
\`\`\` \`\`\`
`, `,
createIssue: createIssue:
`\ `\
\`\`\`yaml \`\`\`yaml
^%$bridge @bridge@
action: create_issue action: create_issue
repo: test-repo repo: test-repo
title: Bug report title: Bug report
@ -2078,25 +2081,25 @@ body: |
Steps to reproduce: Steps to reproduce:
1. Step one 1. Step one
2. Step two 2. Step two
--- @end@
\`\`\` \`\`\`
`, `,
createTag: createTag:
`\ `\
\`\`\`yaml \`\`\`yaml
^%$bridge @bridge@
action: create_tag action: create_tag
repo: test-repo repo: test-repo
tag: v1.0.0 tag: v1.0.0
target: main target: main
message: Release version 1.0.0 message: Release version 1.0.0
--- @end@
\`\`\` \`\`\`
`, `,
createRelease: createRelease:
`\ `\
\`\`\`yaml \`\`\`yaml
^%$bridge @bridge@
action: create_release action: create_release
repo: test-repo repo: test-repo
tag_name: v1.0.0 tag_name: v1.0.0
@ -2109,7 +2112,7 @@ body: |
## Bug Fixes ## Bug Fixes
- Fix X - Fix X
- Fix Y - Fix Y
--- @end@
\`\`\` \`\`\`
` `
}; };