@yanauto/broco 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +209 -0
- package/LICENSE +202 -0
- package/README.md +188 -2
- package/README.zh-CN.md +187 -0
- package/assets/broco-board-icon-128.png +0 -0
- package/assets/broco-favicon-192.png +0 -0
- package/assets/broco-favicon-32.png +0 -0
- package/assets/broco-favicon-64.png +0 -0
- package/assets/broco-foreman-256.png +0 -0
- package/assets/broco-hero-1024.png +0 -0
- package/assets/broco-icon-512.png +0 -0
- package/assets/broco-readme-logo-dark.png +0 -0
- package/assets/broco-readme-logo-light.png +0 -0
- package/assets/broco-social-preview-1280x640.png +0 -0
- package/assets/favicon.ico +0 -0
- package/bin/broco +1077 -0
- package/bundle/board/assets/index-Bue0HpFh.css +1 -0
- package/bundle/board/assets/index-DTqMQtD9.js +16 -0
- package/bundle/board/broco-board-icon-128.png +0 -0
- package/bundle/board/broco-favicon-32.png +0 -0
- package/bundle/board/broco-favicon-64.png +0 -0
- package/bundle/board/broco-foreman-256.png +0 -0
- package/bundle/board/favicon.ico +0 -0
- package/bundle/board/fonts/instrument-sans-latin.woff2 +0 -0
- package/bundle/board/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/bundle/board/index.html +18 -0
- package/lib/attachments.mjs +104 -0
- package/lib/claude-md.mjs +132 -0
- package/lib/cli-args.mjs +292 -0
- package/lib/cli-process.mjs +75 -0
- package/lib/client.mjs +198 -0
- package/lib/credential-proxy.mjs +165 -0
- package/lib/credential-source.mjs +23 -0
- package/lib/crew.mjs +947 -0
- package/lib/detect.mjs +279 -0
- package/lib/directories.mjs +32 -0
- package/lib/map.mjs +336 -0
- package/lib/model-catalog.json +864 -0
- package/lib/model-catalog.mjs +138 -0
- package/lib/model-env.mjs +11 -0
- package/lib/native.mjs +228 -0
- package/lib/paths.mjs +63 -0
- package/lib/pi-profile.mjs +29 -0
- package/lib/pi-secrets.mjs +48 -0
- package/lib/pi.mjs +232 -0
- package/lib/platform/index.mjs +13 -0
- package/lib/platform/launchd.mjs +138 -0
- package/lib/platform/linux.mjs +168 -0
- package/lib/platform/macos.mjs +29 -0
- package/lib/platform/processes.mjs +102 -0
- package/lib/problems.mjs +50 -0
- package/lib/projects.mjs +530 -0
- package/lib/quota.mjs +132 -0
- package/lib/roster-output.mjs +136 -0
- package/lib/roster.mjs +913 -0
- package/lib/runner.mjs +403 -0
- package/lib/settings-audit.mjs +104 -0
- package/lib/setup.mjs +416 -0
- package/lib/slots.mjs +177 -0
- package/lib/stats.mjs +92 -0
- package/lib/store.mjs +737 -0
- package/lib/stream-workers.mjs +464 -0
- package/lib/templates.mjs +173 -0
- package/lib/time.mjs +25 -0
- package/lib/web.mjs +260 -0
- package/lib/worker-policy.mjs +17 -0
- package/lib/worktree.mjs +269 -0
- package/package.json +50 -4
- package/scripts/package-board.mjs +53 -0
- package/skills/broco/SKILL.md +59 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { basename, join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
export const START_MARKER = '<!-- broco:start -->'
|
|
5
|
+
export const END_MARKER = '<!-- broco:end -->'
|
|
6
|
+
export const SUPPORTED_HOSTS = ['auto', 'agents', 'claude', 'codex', 'cursor', 'agy', 'opencode', 'pi']
|
|
7
|
+
|
|
8
|
+
function normalizeHost(host) {
|
|
9
|
+
if (host === undefined || host === null || host === '') return 'auto'
|
|
10
|
+
const clean = String(host).trim().toLowerCase()
|
|
11
|
+
if (!SUPPORTED_HOSTS.includes(clean)) {
|
|
12
|
+
throw new Error('Invalid --host value: ' + host + ' (expected ' + SUPPORTED_HOSTS.join(', ') + ')')
|
|
13
|
+
}
|
|
14
|
+
return clean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function resolveAgentsDocPath(repoPath, { host } = {}) {
|
|
18
|
+
const mode = normalizeHost(host)
|
|
19
|
+
const agentsPath = join(repoPath, 'AGENTS.md')
|
|
20
|
+
const claudePath = join(repoPath, 'CLAUDE.md')
|
|
21
|
+
if (mode === 'claude') return claudePath
|
|
22
|
+
if (mode !== 'auto') return agentsPath
|
|
23
|
+
if (existsSync(agentsPath)) return agentsPath
|
|
24
|
+
if (existsSync(claudePath)) return claudePath
|
|
25
|
+
return agentsPath
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function agentsMdBlock({ managerMode = false } = {}) {
|
|
29
|
+
if (managerMode) {
|
|
30
|
+
return [
|
|
31
|
+
START_MARKER,
|
|
32
|
+
'## broco Manager Mode',
|
|
33
|
+
'',
|
|
34
|
+
'In this repository you operate as the **manager** coordinating worker agents through `broco` rather than doing heavy implementation yourself:',
|
|
35
|
+
'',
|
|
36
|
+
'- **Check status, roster & quota before dispatching**: Run `broco status --json` and `broco roster --json` (or `broco roster`) to see active work, allowed workers, available models, capabilities, and live quota.',
|
|
37
|
+
'- **Delegate implementation, research & reviews**:',
|
|
38
|
+
' - Single task or follow-up: `broco say <name> "<prompt>"` or multi-line via file/stdin `broco say <name> --file <path|-> [--worker <id>] [--model <id>] [--effort <level>] [--worktree] [--bg] [--json]`',
|
|
39
|
+
' - Bulk / sharded tasks: `broco map <prefix> --brief <text-or-file> --inputs <item>... [--worker <id>] [--bg] [--json]`',
|
|
40
|
+
' - Cross-vendor review: `broco review <name> [--by <other-worker>] [--bg] [--json]`',
|
|
41
|
+
' - Inspect, retry & collect: `broco ls --active`, `broco show <name>`, `broco diff <name>`, `broco wait <name> [turn]`, `broco retry <name-or-prefix>`',
|
|
42
|
+
'- **Adjust configuration directly**: Tune project settings via `broco` config commands (`broco set concurrency <n>`, `broco allow ...`, `broco defaults <worker> --model <id> --effort <level>`, `broco rules ...`, `broco note <worker> "<note>"`, `broco undo` to revert).',
|
|
43
|
+
'- **Verify, close & clean worktrees**: Inspect `broco diff <name>` and run checks before closing with `broco done <name> --result pass|rework|fail|blocked [--why "<reason>"]`, then prune finished worktrees with `broco clean`.',
|
|
44
|
+
END_MARKER
|
|
45
|
+
].join('\n')
|
|
46
|
+
}
|
|
47
|
+
return [
|
|
48
|
+
START_MARKER,
|
|
49
|
+
'## broco On-Demand Crew',
|
|
50
|
+
'',
|
|
51
|
+
'In this repository you can summon other logged-in coding CLIs through `broco` when it genuinely helps. Handle quick edits and same-vendor questions yourself; reach for `broco` when your quota is tight, you want an independent cross-vendor worktree review, you need a modality you lack (image/audio/video/PDF), or you have sharded `map` batch work:',
|
|
52
|
+
'',
|
|
53
|
+
'- **Check status, roster & quota**: Run `broco status --json` and `broco roster --json` (or `broco roster`) to see active work, allowed workers, available models, capabilities, and live quota.',
|
|
54
|
+
'- **Summon a worker when needed**:',
|
|
55
|
+
' - Single task or follow-up: `broco say <name> "<prompt>"` or multi-line via file/stdin `broco say <name> --file <path|-> [--worker <id>] [--model <id>] [--effort <level>] [--worktree] [--bg] [--json]`',
|
|
56
|
+
' - Bulk / sharded tasks: `broco map <prefix> --brief <text-or-file> --inputs <item>... [--worker <id>] [--bg] [--json]`',
|
|
57
|
+
' - Cross-vendor review (omitting `--by` auto-picks another vendor): `broco review <name> [--by <other-worker>] [--bg] [--json]`',
|
|
58
|
+
' - Inspect, retry & collect: `broco ls --active`, `broco show <name>`, `broco diff <name>`, `broco wait <name> [turn]`, `broco retry <name-or-prefix>`',
|
|
59
|
+
'- **Verify, close & clean**: Inspect `broco diff <name>`, record `broco done <name> --result pass|rework|fail|blocked [--why "<reason>"]`, and prune finished worktrees with `broco clean`.',
|
|
60
|
+
END_MARKER
|
|
61
|
+
].join('\n')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function claudeMdBlock(opts) {
|
|
65
|
+
return agentsMdBlock(opts)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function ensureAgentsMd(repoPath, opts = {}) {
|
|
69
|
+
const managerMode = Boolean(opts?.managerMode)
|
|
70
|
+
const path = resolveAgentsDocPath(repoPath, opts)
|
|
71
|
+
const file = basename(path)
|
|
72
|
+
const mode = managerMode ? 'manager' : 'on-demand'
|
|
73
|
+
const block = agentsMdBlock({ managerMode })
|
|
74
|
+
if (!existsSync(path)) {
|
|
75
|
+
writeFileSync(path, block + '\n')
|
|
76
|
+
return { path, file, mode, action: 'created' }
|
|
77
|
+
}
|
|
78
|
+
const existing = readFileSync(path, 'utf8')
|
|
79
|
+
const start = existing.indexOf(START_MARKER)
|
|
80
|
+
const end = start >= 0 ? existing.indexOf(END_MARKER, start + START_MARKER.length) : -1
|
|
81
|
+
if (start === -1 || end === -1) {
|
|
82
|
+
const prefix = !existing ? '' : existing.endsWith('\n\n') ? existing : existing.endsWith('\n') ? existing + '\n' : existing + '\n\n'
|
|
83
|
+
writeFileSync(path, prefix + block + '\n')
|
|
84
|
+
return { path, file, mode, action: 'appended' }
|
|
85
|
+
}
|
|
86
|
+
const afterPos = end + END_MARKER.length
|
|
87
|
+
if (existing.slice(start, afterPos) === block) return { path, file, mode, action: 'unchanged' }
|
|
88
|
+
writeFileSync(path, existing.slice(0, start) + block + existing.slice(afterPos))
|
|
89
|
+
return { path, file, mode, action: 'updated' }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function ensureClaudeMd(repoPath, opts) {
|
|
93
|
+
return ensureAgentsMd(repoPath, opts)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function stripMarkerFile(path) {
|
|
97
|
+
const file = basename(path)
|
|
98
|
+
if (!existsSync(path)) return { path, file, action: 'absent', removed: false }
|
|
99
|
+
const existing = readFileSync(path, 'utf8')
|
|
100
|
+
const start = existing.indexOf(START_MARKER)
|
|
101
|
+
const end = start >= 0 ? existing.indexOf(END_MARKER, start + START_MARKER.length) : -1
|
|
102
|
+
if (start === -1 || end === -1) return { path, file, action: 'unchanged', removed: false }
|
|
103
|
+
const before = existing.slice(0, start)
|
|
104
|
+
const after = existing.slice(end + END_MARKER.length)
|
|
105
|
+
if (!(before + after).trim()) {
|
|
106
|
+
rmSync(path, { force: true })
|
|
107
|
+
return { path, file, action: 'deleted', removed: true }
|
|
108
|
+
}
|
|
109
|
+
const cleaned = !before.trim()
|
|
110
|
+
? after.replace(/^\r?\n+/, '')
|
|
111
|
+
: !after.trim()
|
|
112
|
+
? before.replace(/(?:\r?\n){2,}$/, '\n')
|
|
113
|
+
: before.replace(/(?:\r?\n)+$/, '') + '\n\n' + after.replace(/^\r?\n+/, '')
|
|
114
|
+
writeFileSync(path, cleaned)
|
|
115
|
+
return { path, file, action: 'stripped', removed: true }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function removeAgentsMd(repoPath, opts = {}) {
|
|
119
|
+
const mode = normalizeHost(opts?.host)
|
|
120
|
+
if (mode === 'claude') return stripMarkerFile(join(repoPath, 'CLAUDE.md'))
|
|
121
|
+
if (mode !== 'auto') return stripMarkerFile(join(repoPath, 'AGENTS.md'))
|
|
122
|
+
const candidates = [join(repoPath, 'AGENTS.md'), join(repoPath, 'CLAUDE.md')]
|
|
123
|
+
const results = candidates.map(stripMarkerFile)
|
|
124
|
+
const removed = results.filter(r => r.removed)
|
|
125
|
+
if (removed.length === 1) return removed[0]
|
|
126
|
+
if (removed.length > 1) return { ...removed[0], alsoRemoved: removed.slice(1) }
|
|
127
|
+
return results.find(r => r.action === 'unchanged') ?? results[0]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function removeClaudeMd(repoPath, opts) {
|
|
131
|
+
return removeAgentsMd(repoPath, opts)
|
|
132
|
+
}
|
package/lib/cli-args.mjs
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util'
|
|
2
|
+
|
|
3
|
+
const MULTI_FLAGS = new Set(['attach', 'path', 'add', 'rm', 'input', 'inputs'])
|
|
4
|
+
|
|
5
|
+
const flags = {
|
|
6
|
+
"cwd": ["dir", "Worker working directory for a new session; conflicts with --worktree"],
|
|
7
|
+
"project": ["path", "Project root or subdirectory (works with or without broco init); defaults to the current directory"],
|
|
8
|
+
"upstream": ["origin", "HTTP(S) upstream origin; no credentials, path or query"],
|
|
9
|
+
"path": ["prefix", "Allowed path prefix on segment boundaries; repeatable"],
|
|
10
|
+
"header": ["name", "Header to replace with the credential"],
|
|
11
|
+
"value-env": ["name", "Read the credential from this environment variable; exclusive with --value-command"],
|
|
12
|
+
"value-command": ["command", "Read credential from command stdout (10s timeout); never put a secret literal in the command"],
|
|
13
|
+
"value-prefix": ["text", "Non-secret header prefix, for example 'Bearer '"],
|
|
14
|
+
"max-requests": ["count", "Maximum forwarded requests, including upstream failures"],
|
|
15
|
+
"ttl": ["seconds", "Lifetime in seconds (1–2147483); closes active streams at expiry"],
|
|
16
|
+
"allow": ["worker,worker", "Allowed workers, separated by commas"],
|
|
17
|
+
"default-worker": ["worker", "Default worker for this scope"],
|
|
18
|
+
"concurrency": ["count", "Maximum concurrent active turns for this scope (1–64 or inherit)"],
|
|
19
|
+
"host": ["name", "Target instructions file host for init/uninit (auto|agents|claude|codex|cursor|agy|opencode|pi)"],
|
|
20
|
+
"manager-mode": [null, "Write heavy manager-mode instructions instead of lightweight on-demand crew guidance"],
|
|
21
|
+
"no-agents-md": [null, "Skip creating, updating, or stripping AGENTS.md / CLAUDE.md"],
|
|
22
|
+
"no-claude-md": [null, "Alias for --no-agents-md"],
|
|
23
|
+
"migrate-cc-bro": [null, "Safely copy legacy ~/.cc-bro settings and SQLite data into ~/.broco without deleting ~/.cc-bro"],
|
|
24
|
+
"yes": [null, "Confirm detected logged-in workers for the global allowlist without prompting"],
|
|
25
|
+
"allow-nested": [null, "Allow dispatching from inside a broco worker session (disables recursion guard)"],
|
|
26
|
+
"clear": [null, "Clear existing overrides in this scope"],
|
|
27
|
+
"global": [null, "Target global defaults instead of a project"],
|
|
28
|
+
"add": ["text", "Rule text to add; repeatable"],
|
|
29
|
+
"rm": ["text", "Rule text to remove; repeatable"],
|
|
30
|
+
"override": [null, "Override global rules instead of appending to them"],
|
|
31
|
+
"limit": ["count", "Maximum entries to show"],
|
|
32
|
+
"refresh": [null, "Bypass detection cache and re-probe allowed CLIs"],
|
|
33
|
+
"file": ["path", "Read prompt text from a UTF-8 file (or '-' for stdin)"],
|
|
34
|
+
"brief": ["text", "Batch prompt text or path to a .md/.txt/.prompt file"],
|
|
35
|
+
"brief-file": ["path", "Read prompt text from a UTF-8 file (or '-' for stdin)"],
|
|
36
|
+
"inputs": ["list", "Shard inputs (comma-separated or shell-expanded paths); repeatable"],
|
|
37
|
+
"input": ["item", "Single shard input; repeatable"],
|
|
38
|
+
"inputs-file": ["path", "Read shard inputs (non-empty lines or JSON array) from a file or '-'"],
|
|
39
|
+
"active": [null, "Exclude closed (done) tickets"],
|
|
40
|
+
"status": ["list", "Filter by comma-separated status values"],
|
|
41
|
+
"flag": ["flag", "Filter by flag (error|stopped)"],
|
|
42
|
+
"batch": ["prefix", "Filter tickets belonging to a batch prefix"],
|
|
43
|
+
"compact": [null, "Omit full event timeline from show output"],
|
|
44
|
+
"turn": ["number", "Inspect a specific turn number"],
|
|
45
|
+
"stat": [null, "Show diffstat summary without full patch"],
|
|
46
|
+
"dry-run": [null, "Preview worktrees and attachments that would be cleaned"],
|
|
47
|
+
"delete-branch": [null, "Also delete the ticket branch after removing its worktree"],
|
|
48
|
+
"force": [null, "Force cleanup of dirty, unclosed, or unmerged worktrees"],
|
|
49
|
+
"json": [null, "Print JSON output"],
|
|
50
|
+
"no-open": [null, "Print the board URL without opening a browser"],
|
|
51
|
+
"worker": ["id", "Worker ID"],
|
|
52
|
+
"full": [null, "Show full model metadata, variants, or full shard replies"],
|
|
53
|
+
"new-task": [null, "Start an independent task after recording the current outcome; otherwise continue or rework the current task"],
|
|
54
|
+
"task": ["number", "Task number from show; defaults to the current task"],
|
|
55
|
+
"result": ["pass|rework|fail|blocked", "Outcome to record; inferred when omitted"],
|
|
56
|
+
"why": ["text", "Reason for the outcome"],
|
|
57
|
+
"by": ["worker", "Worker to perform the review; omit to auto-pick another vendor"],
|
|
58
|
+
"model": ["id", "Exact model ID (or compact family ID) from the roster"],
|
|
59
|
+
"effort": ["level", "Model effort level"],
|
|
60
|
+
"bg": [null, "Return the dispatch receipt without waiting"],
|
|
61
|
+
"attach": ["file", "Attach a file; may be repeated"],
|
|
62
|
+
"worktree": [null, "Start the first message in an independent worktree"],
|
|
63
|
+
"title": ["title", "Ticket or batch title"],
|
|
64
|
+
"from": ["name", "Start a new name with an inactive session's title and latest completed reply, followed by your message"],
|
|
65
|
+
"all": [null, "Show full message history, all projects in status, or all scopes in audit"]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const commands = {
|
|
69
|
+
"version": {
|
|
70
|
+
"description": "Print the broco version and git commit",
|
|
71
|
+
"positionals": [],
|
|
72
|
+
"options": ["json"]
|
|
73
|
+
},
|
|
74
|
+
"status": {
|
|
75
|
+
"description": "Show runner health, active/queued work, concurrency, and active proxies without starting an offline runner",
|
|
76
|
+
"positionals": [],
|
|
77
|
+
"options": ["project", "all", "json"]
|
|
78
|
+
},
|
|
79
|
+
"proxy-open": {
|
|
80
|
+
"description": "Open a loopback credential proxy; requires upstream, path, header, one value source, max-requests and ttl",
|
|
81
|
+
"positionals": [],
|
|
82
|
+
"options": ["upstream", "path", "header", "value-env", "value-command", "value-prefix", "max-requests", "ttl", "json"]
|
|
83
|
+
},
|
|
84
|
+
"proxy-list": {
|
|
85
|
+
"description": "List active credential proxies on this runner without credentials or source commands",
|
|
86
|
+
"positionals": [],
|
|
87
|
+
"options": ["json"]
|
|
88
|
+
},
|
|
89
|
+
"proxy-close": {
|
|
90
|
+
"description": "Close a credential proxy and abort its active requests",
|
|
91
|
+
"positionals": [["id", "Proxy ID from proxy-open or proxy-list"]],
|
|
92
|
+
"options": ["json"]
|
|
93
|
+
},
|
|
94
|
+
"setup": {
|
|
95
|
+
"description": "Install skills across detected hosts, inspect roster & quota, confirm global allowlist, or migrate ~/.cc-bro",
|
|
96
|
+
"positionals": [],
|
|
97
|
+
"options": ["allow", "default-worker", "yes", "migrate-cc-bro", "json"]
|
|
98
|
+
},
|
|
99
|
+
"init": {
|
|
100
|
+
"description": "Register this project (L1), configure project policy, and update AGENTS.md (or CLAUDE.md)",
|
|
101
|
+
"positionals": [],
|
|
102
|
+
"options": ["project", "allow", "default-worker", "concurrency", "host", "manager-mode", "no-agents-md", "no-claude-md", "json"]
|
|
103
|
+
},
|
|
104
|
+
"uninit": {
|
|
105
|
+
"description": "Unregister this project and remove .broco and the broco AGENTS.md / CLAUDE.md section",
|
|
106
|
+
"positionals": [],
|
|
107
|
+
"options": ["project", "host", "no-agents-md", "no-claude-md", "json"]
|
|
108
|
+
},
|
|
109
|
+
"ui": {
|
|
110
|
+
"description": "Open the local board",
|
|
111
|
+
"positionals": [],
|
|
112
|
+
"options": ["no-open", "json"]
|
|
113
|
+
},
|
|
114
|
+
"roster": {
|
|
115
|
+
"description": "Show models and project or global permissions",
|
|
116
|
+
"positionals": [],
|
|
117
|
+
"options": ["project", "global", "worker", "full", "refresh", "json"]
|
|
118
|
+
},
|
|
119
|
+
"defaults": {
|
|
120
|
+
"description": "Set worker default model and/or effort immediately",
|
|
121
|
+
"positionals": [["worker", "Worker ID"]],
|
|
122
|
+
"options": ["model", "effort", "clear", "global", "project", "json"]
|
|
123
|
+
},
|
|
124
|
+
"note": {
|
|
125
|
+
"description": "Set or clear a worker note immediately",
|
|
126
|
+
"positionals": [["worker", "Worker ID"], ["text", "Worker note; omit when passing --clear", "optional"]],
|
|
127
|
+
"options": ["clear", "global", "project", "json"]
|
|
128
|
+
},
|
|
129
|
+
"set": {
|
|
130
|
+
"description": "Set concurrency or default-worker immediately",
|
|
131
|
+
"positionals": [["key", "Setting key (concurrency|default-worker)"], ["value", "Setting value"]],
|
|
132
|
+
"options": ["global", "project", "json"]
|
|
133
|
+
},
|
|
134
|
+
"allow": {
|
|
135
|
+
"description": "Allow one or more comma-separated workers immediately",
|
|
136
|
+
"positionals": [["workers", "Comma-separated worker IDs"]],
|
|
137
|
+
"options": ["default-worker", "global", "project", "json"]
|
|
138
|
+
},
|
|
139
|
+
"deny": {
|
|
140
|
+
"description": "Disallow one or more comma-separated workers immediately",
|
|
141
|
+
"positionals": [["workers", "Comma-separated worker IDs"]],
|
|
142
|
+
"options": ["global", "project", "json"]
|
|
143
|
+
},
|
|
144
|
+
"rules": {
|
|
145
|
+
"description": "Show or update project, global, or per-worker rules",
|
|
146
|
+
"positionals": [],
|
|
147
|
+
"options": ["add", "rm", "clear", "worker", "override", "global", "project", "json"]
|
|
148
|
+
},
|
|
149
|
+
"hide": {
|
|
150
|
+
"description": "Hide comma-separated model IDs or families for a worker",
|
|
151
|
+
"positionals": [["worker", "Worker ID"], ["models", "Comma-separated model IDs or families"]],
|
|
152
|
+
"options": ["global", "project", "json"]
|
|
153
|
+
},
|
|
154
|
+
"unhide": {
|
|
155
|
+
"description": "Unhide comma-separated model IDs or families for a worker",
|
|
156
|
+
"positionals": [["worker", "Worker ID"], ["models", "Comma-separated model IDs or families"]],
|
|
157
|
+
"options": ["global", "project", "json"]
|
|
158
|
+
},
|
|
159
|
+
"audit": {
|
|
160
|
+
"description": "List recent settings audit entries",
|
|
161
|
+
"positionals": [],
|
|
162
|
+
"options": ["global", "all", "project", "limit", "json"]
|
|
163
|
+
},
|
|
164
|
+
"undo": {
|
|
165
|
+
"description": "Revert a settings change by audit ID (or the latest undoable change)",
|
|
166
|
+
"positionals": [["id", "Audit ID to revert; defaults to latest undoable change", "optional"]],
|
|
167
|
+
"options": ["global", "project", "json"]
|
|
168
|
+
},
|
|
169
|
+
"done": {
|
|
170
|
+
"description": "Record a task outcome (or close ready shards in a batch); defaults to the current task",
|
|
171
|
+
"positionals": [["name", "Session name or batch prefix"]],
|
|
172
|
+
"options": ["task", "project", "result", "why", "json"]
|
|
173
|
+
},
|
|
174
|
+
"stats": {
|
|
175
|
+
"description": "Show your per-task record grouped by bro and model across projects (or one project)",
|
|
176
|
+
"positionals": [],
|
|
177
|
+
"options": ["project", "json"]
|
|
178
|
+
},
|
|
179
|
+
"review": {
|
|
180
|
+
"description": "Ask another worker to review a session (auto-picks another vendor when --by is omitted)",
|
|
181
|
+
"positionals": [["name", "Session to review"]],
|
|
182
|
+
"options": ["project", "by", "model", "effort", "bg", "allow-nested", "json"]
|
|
183
|
+
},
|
|
184
|
+
"say": {
|
|
185
|
+
"description": "Send a message to a named worker session (inline, --file, or stdin)",
|
|
186
|
+
"positionals": [["name", "Session name"], ["message", "Message text, or '-' for stdin; omit with --file or piped stdin", "optional"]],
|
|
187
|
+
"options": ["file", "brief-file", "new-task", "project", "cwd", "attach", "worktree", "title", "from", "model", "effort", "worker", "bg", "allow-nested", "json"]
|
|
188
|
+
},
|
|
189
|
+
"retry": {
|
|
190
|
+
"description": "Retry a failed or stopped session's last prompt (or failed/stopped shards in a batch)",
|
|
191
|
+
"positionals": [["name", "Session name or batch prefix"]],
|
|
192
|
+
"options": ["project", "model", "effort", "worker", "bg", "allow-nested", "json"]
|
|
193
|
+
},
|
|
194
|
+
"map": {
|
|
195
|
+
"description": "Dispatch one brief across multiple shard inputs (<prefix>-1 .. <prefix>-N)",
|
|
196
|
+
"positionals": [["prefix", "Batch prefix"], ["inputs", "Shard inputs or file paths", "variadic"]],
|
|
197
|
+
"options": ["brief", "brief-file", "inputs", "input", "inputs-file", "project", "cwd", "worktree", "title", "model", "effort", "worker", "bg", "allow-nested", "json"]
|
|
198
|
+
},
|
|
199
|
+
"ls": {
|
|
200
|
+
"description": "List tickets",
|
|
201
|
+
"positionals": [],
|
|
202
|
+
"options": ["active", "status", "flag", "batch", "limit", "project", "json"]
|
|
203
|
+
},
|
|
204
|
+
"show": {
|
|
205
|
+
"description": "Show a session (or batch) and its result",
|
|
206
|
+
"positionals": [["name", "Session name or batch prefix"]],
|
|
207
|
+
"options": ["turn", "compact", "full", "status", "project", "all", "json"]
|
|
208
|
+
},
|
|
209
|
+
"diff": {
|
|
210
|
+
"description": "Show tracked and untracked changes for a session relative to its base commit",
|
|
211
|
+
"positionals": [["name", "Session name"]],
|
|
212
|
+
"options": ["stat", "project", "json"]
|
|
213
|
+
},
|
|
214
|
+
"clean": {
|
|
215
|
+
"description": "Remove retained git worktrees (and orphaned attachment snapshots) for finished tickets",
|
|
216
|
+
"positionals": [["name", "Session name or batch prefix; omit to clean all done worktrees", "optional"]],
|
|
217
|
+
"options": ["dry-run", "delete-branch", "force", "project", "json"]
|
|
218
|
+
},
|
|
219
|
+
"watch": {
|
|
220
|
+
"description": "Watch session activity",
|
|
221
|
+
"positionals": [],
|
|
222
|
+
"options": ["project"]
|
|
223
|
+
},
|
|
224
|
+
"wait": {
|
|
225
|
+
"description": "Wait for a session turn (defaults to latest) or a batch to finish",
|
|
226
|
+
"positionals": [["name", "Session name or batch prefix"], ["turn", "Positive turn number; omit for latest turn or batch", "optional"]],
|
|
227
|
+
"options": ["project", "json"]
|
|
228
|
+
},
|
|
229
|
+
"stop": {
|
|
230
|
+
"description": "Stop a session (or batch) and verify its processes stopped",
|
|
231
|
+
"positionals": [["name", "Session name or batch prefix"]],
|
|
232
|
+
"options": ["project", "json"]
|
|
233
|
+
},
|
|
234
|
+
"shutdown": {
|
|
235
|
+
"description": "Stop the runner, including running and queued work",
|
|
236
|
+
"positionals": [],
|
|
237
|
+
"options": ["json"]
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function formatPositional([key, , mode]) {
|
|
242
|
+
if (mode === 'variadic') return '[' + key + '...]'
|
|
243
|
+
if (mode === 'optional') return '[' + key + ']'
|
|
244
|
+
return '<' + key + '>'
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function usage(name) {
|
|
248
|
+
const command = commands[name]
|
|
249
|
+
return ['broco', name, ...command.positionals.map(formatPositional),
|
|
250
|
+
...command.options.map(key => '[--' + key + (flags[key][0] ? ' ' + flags[key][0] : '') + ']')].join(' ')
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function commandHelp(name) {
|
|
254
|
+
const command = commands[name]
|
|
255
|
+
return [usage(name), command.description, '',
|
|
256
|
+
...command.positionals.map(p => ' ' + formatPositional(p) + ' ' + p[1]),
|
|
257
|
+
...command.options.map(key => ' --' + key + (flags[key][0] ? ' ' + flags[key][0] : '') + ' ' + flags[key][1]),
|
|
258
|
+
' -h, --help Show this command help'].join('\n')
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function helpText() {
|
|
262
|
+
return Object.keys(commands).map(commandHelp).join('\n\n')
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function parseCommand(argv) {
|
|
266
|
+
const [cmd, ...args] = argv
|
|
267
|
+
if (!cmd || ['help', '--help', '-h'].includes(cmd)) return { help: helpText() }
|
|
268
|
+
if (cmd === '--version' || cmd === '-v') {
|
|
269
|
+
const { values: opt, positionals } = parseArgs({
|
|
270
|
+
args,
|
|
271
|
+
options: { json: { type: 'boolean' }, help: { type: 'boolean', short: 'h' } },
|
|
272
|
+
allowPositionals: true
|
|
273
|
+
})
|
|
274
|
+
if (opt.help) return { help: commandHelp('version') }
|
|
275
|
+
if (positionals.length) throw new Error(commandHelp('version'))
|
|
276
|
+
return { cmd: 'version', opt, positionals: [] }
|
|
277
|
+
}
|
|
278
|
+
if (!Object.hasOwn(commands, cmd)) {
|
|
279
|
+
throw new Error('Unknown command "' + cmd + '"; available: ' + Object.keys(commands).join(', ') + ' (run broco --help)')
|
|
280
|
+
}
|
|
281
|
+
const command = commands[cmd]
|
|
282
|
+
const options = Object.fromEntries(command.options.map(key => [key, {
|
|
283
|
+
type: flags[key][0] ? 'string' : 'boolean', ...(MULTI_FLAGS.has(key) ? { multiple: true } : {})
|
|
284
|
+
}]))
|
|
285
|
+
options.help = { type: 'boolean', short: 'h' }
|
|
286
|
+
const { values: opt, positionals } = parseArgs({ args, options, allowPositionals: true })
|
|
287
|
+
if (opt.help) return { help: commandHelp(cmd) }
|
|
288
|
+
const min = command.positionals.filter(([, , mode]) => !mode).length
|
|
289
|
+
const max = command.positionals.some(([, , mode]) => mode === 'variadic') ? Infinity : command.positionals.length
|
|
290
|
+
if (positionals.length < min || positionals.length > max) throw new Error(commandHelp(cmd))
|
|
291
|
+
return { cmd, opt, positionals }
|
|
292
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { execFile, spawn } from 'node:child_process'
|
|
2
|
+
import { accessSync, constants, statSync } from 'node:fs'
|
|
3
|
+
import { delimiter, join } from 'node:path'
|
|
4
|
+
import { createInterface } from 'node:readline'
|
|
5
|
+
import { promisify } from 'node:util'
|
|
6
|
+
import { toolsPath } from './paths.mjs'
|
|
7
|
+
|
|
8
|
+
const exec = promisify(execFile)
|
|
9
|
+
export function executable(name) {
|
|
10
|
+
for (const file of name.includes('/') ? [name] : toolsPath.split(delimiter).map(p => join(p, name))) {
|
|
11
|
+
try { accessSync(file, constants.X_OK); if (statSync(file).isFile()) return file } catch {}
|
|
12
|
+
}
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const HOST_VARS = ['CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT', 'CLAUDE_CODE_SSE_PORT', 'CLAUDE_CODE_SESSION_ID', 'CLAUDE_CODE_PARENT_SESSION_ID', 'CLAUDE_CODE_AGENT_ID']
|
|
17
|
+
|
|
18
|
+
function probeEnv(extra = {}) {
|
|
19
|
+
const env = { ...process.env, PATH: toolsPath, PI_OFFLINE: '1', ...extra }
|
|
20
|
+
for (const key of HOST_VARS) delete env[key]
|
|
21
|
+
return env
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function inspectCommand(file, args, cwd, signal) {
|
|
25
|
+
try {
|
|
26
|
+
const r = await exec(file, args, { cwd, env: probeEnv({ NO_COLOR: '1' }), timeout: 20000, maxBuffer: 4 * 1024 * 1024, ...(signal ? { signal } : {}) })
|
|
27
|
+
const clean = (r.stdout + r.stderr).replace(/\x1b\[[0-9;]*m/g, '')
|
|
28
|
+
return { ok: true, text: clean, output: clean }
|
|
29
|
+
} catch (err) {
|
|
30
|
+
const output = (String(err?.stdout ?? '') + String(err?.stderr ?? '')).replace(/\x1b\[[0-9;]*m/g, '')
|
|
31
|
+
return { ok: false, text: '', output }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function inspectRpc(file, args, cwd, run, kind = 'jsonrpc') {
|
|
36
|
+
const child = spawn(file, args, { cwd, env: probeEnv(), stdio: ['pipe', 'pipe', 'ignore'] })
|
|
37
|
+
const pending = new Map()
|
|
38
|
+
let next = 0
|
|
39
|
+
const fail = () => { for (const p of pending.values()) p.reject(new Error('CLI inspection unavailable')); pending.clear() }
|
|
40
|
+
child.on('error', fail)
|
|
41
|
+
child.stdin.on('error', fail)
|
|
42
|
+
child.once('close', fail)
|
|
43
|
+
const closed = new Promise(ok => child.once('close', ok))
|
|
44
|
+
const rl = createInterface({ input: child.stdout, crlfDelay: Infinity })
|
|
45
|
+
rl.on('line', line => {
|
|
46
|
+
try {
|
|
47
|
+
const r = JSON.parse(line), p = pending.get(r.id)
|
|
48
|
+
if (!p) return
|
|
49
|
+
pending.delete(r.id)
|
|
50
|
+
if (r.error || r.success === false) p.reject(new Error('CLI inspection unavailable'))
|
|
51
|
+
else p.resolve(kind === 'pi' ? r.data : r.result)
|
|
52
|
+
} catch {}
|
|
53
|
+
})
|
|
54
|
+
const send = obj => child.stdin.write(JSON.stringify(obj) + '\n')
|
|
55
|
+
const request = (method, params = {}) => {
|
|
56
|
+
const id = String(++next)
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
pending.set(id, { resolve, reject })
|
|
59
|
+
send(kind === 'pi' ? { id, type: method, ...params } : { id, method, params })
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
const timer = setTimeout(() => { fail(); child.kill('SIGKILL') }, 20000)
|
|
63
|
+
timer.unref?.()
|
|
64
|
+
try { return await run(request, send) }
|
|
65
|
+
finally {
|
|
66
|
+
clearTimeout(timer)
|
|
67
|
+
rl.close()
|
|
68
|
+
child.stdin.end()
|
|
69
|
+
child.kill()
|
|
70
|
+
const kill = setTimeout(() => child.kill('SIGKILL'), 1000)
|
|
71
|
+
kill.unref?.()
|
|
72
|
+
await closed
|
|
73
|
+
clearTimeout(kill)
|
|
74
|
+
}
|
|
75
|
+
}
|