@brimveyn/aimux 1.20.1 → 1.20.3
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/README.md +9 -1
- package/package.json +1 -1
- package/skills/aimux-orchestrator/SKILL.md +39 -5
- package/skills/aimux-orchestrator/references/prompts.md +11 -0
- package/src/auto-rename/coordinator.ts +206 -32
- package/src/auto-rename/heuristic-title.ts +57 -0
- package/src/auto-rename/prompt-capture.ts +19 -0
- package/src/auto-rename/prompt-gate.ts +82 -0
- package/src/auto-rename/title-format.ts +38 -0
- package/src/auto-rename/title-runner.ts +32 -21
- package/src/cli/client/workspace-resolver.ts +61 -8
- package/src/cli/commands/tab/await.ts +1 -1
- package/src/cli/commands/tab/close.ts +1 -1
- package/src/cli/commands/tab/create.ts +27 -3
- package/src/cli/commands/tab/focus.ts +1 -1
- package/src/cli/commands/tab/prompt-io.ts +6 -1
- package/src/cli/commands/tab/run.ts +10 -2
- package/src/cli/commands/tab/send.ts +12 -7
- package/src/cli/commands/tab/snapshot.ts +2 -1
- package/src/cli/commands/tab/tail.ts +1 -1
- package/src/cli/commands/tab/wait.ts +2 -1
- package/src/cli/commands/worker/await.ts +5 -4
- package/src/cli/commands/worker/doctor.ts +25 -1
- package/src/cli/commands/worker/list.ts +50 -8
- package/src/cli/commands/worker/prompt.ts +31 -6
- package/src/cli/commands/worker/run.ts +56 -10
- package/src/cli/commands/worker/shared.ts +312 -52
- package/src/cli/commands/worker/stop.ts +39 -10
- package/src/cli/commands/worker/submit.ts +40 -0
- package/src/cli/commands/workspace/close.ts +1 -1
- package/src/cli/commands/workspace/create.ts +2 -1
- package/src/cli/commands/workspace/switch.ts +1 -1
- package/src/cli/commands/worktree/create-core.ts +27 -7
- package/src/cli/commands/worktree/create.ts +18 -3
- package/src/cli/commands/worktree/remove.ts +3 -1
- package/src/cli/completion/entry.ts +181 -0
- package/src/cli/completion/install.ts +222 -0
- package/src/cli/completion/plan.ts +216 -0
- package/src/cli/completion/scripts.ts +147 -0
- package/src/cli/completion/sources.ts +74 -0
- package/src/cli/context.ts +15 -0
- package/src/cli/flags.ts +45 -2
- package/src/cli/index.ts +20 -10
- package/src/cli/output.ts +3 -0
- package/src/cli/registry.ts +2 -0
- package/src/daemon/daemon.ts +11 -0
- package/src/doctor.ts +4 -0
- package/src/git/worktree.ts +15 -1
- package/src/index.tsx +35 -11
- package/src/platform/worktree-paths.ts +21 -1
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { buildHeadlessInvocation, type HeadlessInvocation } from '../auto-commit/headless-commands'
|
|
2
|
+
import { clampTitle } from './title-format'
|
|
2
3
|
|
|
3
4
|
export type TitleSpawnFn = (
|
|
4
5
|
invocation: HeadlessInvocation,
|
|
5
6
|
signal: AbortSignal
|
|
6
7
|
) => Promise<{ stdout: string; exitCode: number } | null>
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* `failed` is retryable — a later prompt may well produce a usable title.
|
|
11
|
+
* `unavailable` is not: the provider has no headless mode or its binary is not
|
|
12
|
+
* installed, so the coordinator should stop burning attempts and fall back.
|
|
13
|
+
*/
|
|
14
|
+
export type TitleResult =
|
|
15
|
+
| { status: 'ok'; title: string }
|
|
16
|
+
| { status: 'failed' }
|
|
17
|
+
| { status: 'unavailable' }
|
|
18
|
+
|
|
8
19
|
export function buildTitlePrompt(firstPrompt: string): string {
|
|
9
20
|
return [
|
|
10
21
|
'Create a concise tab title for the user request below.',
|
|
@@ -23,24 +34,16 @@ export function sanitizeGeneratedTitle(raw: string): string | null {
|
|
|
23
34
|
if (first == null || first === '') return null
|
|
24
35
|
|
|
25
36
|
const unlabelled = first.replace(/^TITLE\s*:\s*/iu, '').replaceAll(/^["'“”‘’]+|["'“”‘’]+$/gu, '')
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.replace(/[.!?,;:…]+$/u, '')
|
|
29
|
-
.trim()
|
|
30
|
-
const words = clean.split(' ').filter(Boolean)
|
|
31
|
-
const usesUnspacedScript = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(clean)
|
|
32
|
-
if (words.length < 2 && !usesUnspacedScript) return null
|
|
37
|
+
return clampTitle(unlabelled)
|
|
38
|
+
}
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
function executableOnPath(executable: string): boolean {
|
|
41
|
+
try {
|
|
42
|
+
return typeof Bun !== 'undefined' && Bun.which(executable) != null
|
|
43
|
+
} catch {
|
|
44
|
+
// Never let a lookup failure mask a provider that would have worked.
|
|
45
|
+
return true
|
|
40
46
|
}
|
|
41
|
-
return title === '' || (title.split(' ').filter(Boolean).length < 2 && !usesUnspacedScript)
|
|
42
|
-
? null
|
|
43
|
-
: title
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
export async function generateTabTitle(options: {
|
|
@@ -50,21 +53,29 @@ export async function generateTabTitle(options: {
|
|
|
50
53
|
timeoutMs: number
|
|
51
54
|
signal: AbortSignal
|
|
52
55
|
spawn?: TitleSpawnFn
|
|
53
|
-
|
|
56
|
+
isExecutableAvailable?: (executable: string) => boolean
|
|
57
|
+
}): Promise<TitleResult> {
|
|
54
58
|
const invocation = buildHeadlessInvocation(
|
|
55
59
|
options.provider,
|
|
56
60
|
buildTitlePrompt(options.firstPrompt),
|
|
57
61
|
options.model
|
|
58
62
|
)
|
|
59
|
-
if (!invocation) return
|
|
63
|
+
if (!invocation) return { status: 'unavailable' }
|
|
64
|
+
|
|
65
|
+
// A caller-supplied spawn does not go through PATH, so only probe it for the
|
|
66
|
+
// real one. Probing lets a missing CLI fail instantly instead of after the
|
|
67
|
+
// full timeout, once per tab instead of once per attempt.
|
|
68
|
+
const available = options.isExecutableAvailable ?? (options.spawn ? null : executableOnPath)
|
|
69
|
+
if (available && !available(invocation.executable)) return { status: 'unavailable' }
|
|
60
70
|
|
|
61
71
|
const signal = AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs)])
|
|
62
72
|
try {
|
|
63
73
|
const result = await (options.spawn ?? defaultSpawn)(invocation, signal)
|
|
64
|
-
if (!result || result.exitCode !== 0 || signal.aborted) return
|
|
65
|
-
|
|
74
|
+
if (!result || result.exitCode !== 0 || signal.aborted) return { status: 'failed' }
|
|
75
|
+
const title = sanitizeGeneratedTitle(result.stdout)
|
|
76
|
+
return title == null ? { status: 'failed' } : { status: 'ok', title }
|
|
66
77
|
} catch {
|
|
67
|
-
return
|
|
78
|
+
return { status: 'failed' }
|
|
68
79
|
}
|
|
69
80
|
}
|
|
70
81
|
|
|
@@ -1,17 +1,55 @@
|
|
|
1
|
-
import type { SessionRecord } from '../../state/types'
|
|
1
|
+
import type { SessionRecord, WorktreeRecord } from '../../state/types'
|
|
2
2
|
|
|
3
3
|
import { findMostRecentSession, loadSessionCatalog } from '../../state/session-catalog'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
6
|
+
* Where a command's target workspace came from. An orchestrator needs this to
|
|
7
|
+
* tell "I asked for pragma-once" from "aimux guessed, and the UI had moved on":
|
|
8
|
+
* `active` is the only origin that can silently follow the UI to another repo.
|
|
9
|
+
*/
|
|
10
|
+
export type WorkspaceOrigin = 'flag' | 'env' | 'active'
|
|
11
|
+
|
|
12
|
+
export interface ResolvedWorkspace {
|
|
13
|
+
origin: WorkspaceOrigin
|
|
14
|
+
record: SessionRecord
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Env pin for headless orchestrators — `--workspace` still wins over it. */
|
|
18
|
+
export const WORKSPACE_ENV_VAR = 'AIMUX_WORKSPACE'
|
|
19
|
+
|
|
20
|
+
/** The workspace's primary (root) worktree, i.e. the repository it is about. */
|
|
21
|
+
export function findPrimaryWorktree(session: SessionRecord): WorktreeRecord | undefined {
|
|
22
|
+
return session.worktrees?.find((worktree) => worktree.source === 'primary')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The repo every fresh worktree for this workspace is cut from. Surfaced in
|
|
27
|
+
* every worker envelope so an agent can see *which project* it just acted on
|
|
28
|
+
* instead of inferring it from a worktree path hash.
|
|
29
|
+
*/
|
|
30
|
+
export function workspaceRepoRoot(session: SessionRecord): string | null {
|
|
31
|
+
return findPrimaryWorktree(session)?.repoRoot ?? session.projectPath ?? null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Stable workspace identity block embedded in command output. */
|
|
35
|
+
export function workspaceIdentity(session: SessionRecord): {
|
|
36
|
+
id: string
|
|
37
|
+
name: string
|
|
38
|
+
repoRoot: string | null
|
|
39
|
+
} {
|
|
40
|
+
return { id: session.id, name: session.name, repoRoot: workspaceRepoRoot(session) }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolve `--workspace W` to a session record from the catalog, reporting where
|
|
45
|
+
* the choice came from. Precedence: the explicit flag, then `AIMUX_WORKSPACE`,
|
|
46
|
+
* then the most recently opened session. Throws when the catalog is empty (no
|
|
47
|
+
* session has ever been created) or when the explicit name/id doesn't match.
|
|
10
48
|
*
|
|
11
49
|
* Matching: exact id wins; otherwise exact name (case-sensitive); otherwise
|
|
12
50
|
* unique case-insensitive name match.
|
|
13
51
|
*/
|
|
14
|
-
export function
|
|
52
|
+
export function resolveWorkspaceWithOrigin(name: string | undefined): ResolvedWorkspace {
|
|
15
53
|
const sessions = loadSessionCatalog()
|
|
16
54
|
if (sessions.length === 0) {
|
|
17
55
|
throw new Error(
|
|
@@ -19,14 +57,29 @@ export function resolveWorkspace(name: string | undefined): SessionRecord {
|
|
|
19
57
|
)
|
|
20
58
|
}
|
|
21
59
|
|
|
22
|
-
|
|
60
|
+
const flag = name !== undefined && name !== '' ? name : undefined
|
|
61
|
+
const env = process.env[WORKSPACE_ENV_VAR]
|
|
62
|
+
const fromEnv = env != null && env !== '' ? env : undefined
|
|
63
|
+
const selector = flag ?? fromEnv
|
|
64
|
+
if (selector === undefined) {
|
|
23
65
|
const active = findMostRecentSession(sessions)
|
|
24
66
|
if (!active) {
|
|
25
67
|
throw new Error('no active workspace and the catalog is empty')
|
|
26
68
|
}
|
|
27
|
-
return active
|
|
69
|
+
return { origin: 'active', record: active }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
origin: flag !== undefined ? 'flag' : 'env',
|
|
74
|
+
record: matchWorkspace(sessions, selector),
|
|
28
75
|
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function resolveWorkspace(name: string | undefined): SessionRecord {
|
|
79
|
+
return resolveWorkspaceWithOrigin(name).record
|
|
80
|
+
}
|
|
29
81
|
|
|
82
|
+
function matchWorkspace(sessions: SessionRecord[], name: string): SessionRecord {
|
|
30
83
|
const byId = sessions.find((session) => session.id === name)
|
|
31
84
|
if (byId) return byId
|
|
32
85
|
|
|
@@ -27,7 +27,7 @@ import { awaitTurn, DEFAULT_TIMEOUT_MS, type TurnOutcome, turnOutcomeExitCode }
|
|
|
27
27
|
const QUESTION_TAIL_LINES = 25
|
|
28
28
|
|
|
29
29
|
export const tabAwait: CliCommand = {
|
|
30
|
-
args: [{ name: 'tabId', required: true }],
|
|
30
|
+
args: [{ complete: { kind: 'dynamic', source: 'tab' }, name: 'tabId', required: true }],
|
|
31
31
|
flags: [
|
|
32
32
|
...SHARED_FLAGS,
|
|
33
33
|
{
|
|
@@ -5,7 +5,7 @@ import { SHARED_FLAGS } from '../../flags'
|
|
|
5
5
|
import { EXIT_OK, writeJson } from '../../output'
|
|
6
6
|
|
|
7
7
|
export const tabClose: CliCommand = {
|
|
8
|
-
args: [{ name: 'tabId', required: true }],
|
|
8
|
+
args: [{ complete: { kind: 'dynamic', source: 'tab' }, name: 'tabId', required: true }],
|
|
9
9
|
flags: SHARED_FLAGS,
|
|
10
10
|
group: 'tab',
|
|
11
11
|
run: async (ctx) => {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
IPC_CAPABILITY_WORKER_METADATA,
|
|
14
14
|
} from '../../../ipc/protocol'
|
|
15
15
|
import { createPrefixedId } from '../../../platform/id'
|
|
16
|
+
import { pruneEmptyWorktreeParent } from '../../../platform/worktree-paths'
|
|
16
17
|
import {
|
|
17
18
|
type AssistantOption,
|
|
18
19
|
buildAssistantModelArgs,
|
|
@@ -98,6 +99,7 @@ async function rollbackCreatedWorktree(
|
|
|
98
99
|
repoPath: record.repoRoot,
|
|
99
100
|
targetPath: record.path,
|
|
100
101
|
})
|
|
102
|
+
await pruneEmptyWorktreeParent(record.path)
|
|
101
103
|
await daemon.expectOk('removeWorktreeRecord', {
|
|
102
104
|
sessionId: workspace.id,
|
|
103
105
|
worktreeId: record.id,
|
|
@@ -272,39 +274,61 @@ export const tabCreate: CliCommand = {
|
|
|
272
274
|
flags: [
|
|
273
275
|
...SHARED_FLAGS,
|
|
274
276
|
{
|
|
277
|
+
complete: { kind: 'dynamic', source: 'assistant' },
|
|
275
278
|
description: 'assistant id (claude, codex, opencode, grok, kimi, terminal, ...)',
|
|
276
279
|
kind: 'string',
|
|
277
280
|
name: 'assistant',
|
|
278
281
|
},
|
|
279
|
-
{ description: 'tab title (defaults to assistant label)', kind: 'string', name: 'title' },
|
|
280
|
-
{ description: 'cwd for the spawned PTY', kind: 'string', name: 'cwd' },
|
|
281
282
|
{
|
|
283
|
+
complete: { kind: 'none' },
|
|
284
|
+
description: 'tab title (defaults to assistant label)',
|
|
285
|
+
kind: 'string',
|
|
286
|
+
name: 'title',
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
complete: { kind: 'file' },
|
|
290
|
+
description: 'cwd for the spawned PTY',
|
|
291
|
+
kind: 'string',
|
|
292
|
+
name: 'cwd',
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
complete: { kind: 'none' },
|
|
282
296
|
description: 'explicit command (overrides the assistant default)',
|
|
283
297
|
kind: 'string',
|
|
284
298
|
name: 'command',
|
|
285
299
|
},
|
|
286
300
|
{
|
|
301
|
+
complete: { kind: 'none' },
|
|
287
302
|
description: 'model for the worker (maps to the assistant’s model flag)',
|
|
288
303
|
kind: 'string',
|
|
289
304
|
name: 'model',
|
|
290
305
|
},
|
|
291
306
|
{
|
|
307
|
+
complete: { kind: 'none' },
|
|
292
308
|
description: 'reasoning-effort level (maps to the assistant’s effort flag)',
|
|
293
309
|
kind: 'string',
|
|
294
310
|
name: 'effort',
|
|
295
311
|
},
|
|
296
312
|
{
|
|
313
|
+
complete: { kind: 'dynamic', source: 'worktree' },
|
|
297
314
|
description: 'worktree id the tab belongs to (defaults to the workspace’s active worktree)',
|
|
298
315
|
kind: 'string',
|
|
299
316
|
name: 'worktree',
|
|
300
317
|
},
|
|
301
318
|
{
|
|
319
|
+
complete: { kind: 'none' },
|
|
302
320
|
description: 'create a fresh worktree for this tab (optionally named: --new-worktree=<name>)',
|
|
303
321
|
kind: 'optional-string',
|
|
304
322
|
name: 'new-worktree',
|
|
305
323
|
},
|
|
306
|
-
{ description: 'base ref for --new-worktree (default HEAD)', kind: 'string', name: 'base' },
|
|
307
324
|
{
|
|
325
|
+
complete: { kind: 'dynamic', source: 'git-ref' },
|
|
326
|
+
description: 'base ref for --new-worktree (default HEAD)',
|
|
327
|
+
kind: 'string',
|
|
328
|
+
name: 'base',
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
complete: { kind: 'none' },
|
|
308
332
|
description: 'branch for --new-worktree (default aimux/<name>)',
|
|
309
333
|
kind: 'string',
|
|
310
334
|
name: 'branch',
|
|
@@ -5,7 +5,7 @@ import { SHARED_FLAGS } from '../../flags'
|
|
|
5
5
|
import { EXIT_OK, writeJson } from '../../output'
|
|
6
6
|
|
|
7
7
|
export const tabFocus: CliCommand = {
|
|
8
|
-
args: [{ name: 'tabId', required: true }],
|
|
8
|
+
args: [{ complete: { kind: 'dynamic', source: 'tab' }, name: 'tabId', required: true }],
|
|
9
9
|
flags: SHARED_FLAGS,
|
|
10
10
|
group: 'tab',
|
|
11
11
|
run: async (ctx) => {
|
|
@@ -92,7 +92,12 @@ export async function writePromptPayload(
|
|
|
92
92
|
payload: PromptPayload,
|
|
93
93
|
appendEnter: boolean
|
|
94
94
|
): Promise<number> {
|
|
95
|
-
|
|
95
|
+
// Skip a zero-length write: "submit only" (empty payload + --enter) is a
|
|
96
|
+
// legitimate operation, but a 0-byte write reaches the pty as an empty
|
|
97
|
+
// ArrayBufferView and surfaces a raw Bun ERR_INVALID_ARG_TYPE to the user.
|
|
98
|
+
if (payload.data !== '') {
|
|
99
|
+
await daemon.expectOk('write', { data: payload.data, tabId })
|
|
100
|
+
}
|
|
96
101
|
let bytesWritten = Buffer.byteLength(payload.data, 'utf8')
|
|
97
102
|
if (appendEnter) {
|
|
98
103
|
// A bracketed paste swallows a same-burst `\r`, so settle first, then
|
|
@@ -20,10 +20,18 @@ import { awaitTurn, DEFAULT_TIMEOUT_MS, turnOutcomeExitCode } from './await-turn
|
|
|
20
20
|
import { buildPromptPayload, resolvePromptText, writePromptPayload } from './prompt-io'
|
|
21
21
|
|
|
22
22
|
export const tabRun: CliCommand = {
|
|
23
|
-
args: [
|
|
23
|
+
args: [
|
|
24
|
+
{ complete: { kind: 'dynamic', source: 'tab' }, name: 'tabId', required: true },
|
|
25
|
+
{ complete: { kind: 'none' }, name: 'text' },
|
|
26
|
+
],
|
|
24
27
|
flags: [
|
|
25
28
|
...SHARED_FLAGS,
|
|
26
|
-
{
|
|
29
|
+
{
|
|
30
|
+
complete: { kind: 'file' },
|
|
31
|
+
description: 'read the prompt from this file',
|
|
32
|
+
kind: 'string',
|
|
33
|
+
name: 'prompt-file',
|
|
34
|
+
},
|
|
27
35
|
{ description: 'read the prompt from stdin', kind: 'boolean', name: 'stdin' },
|
|
28
36
|
{
|
|
29
37
|
description: 'overall turn cap in milliseconds (default 900000 = 15 min)',
|
|
@@ -9,7 +9,10 @@ import { buildPromptPayload, writePromptPayload } from './prompt-io'
|
|
|
9
9
|
const DEFAULT_AWAIT_TIMEOUT_MS = 15_000
|
|
10
10
|
|
|
11
11
|
export const tabSend: CliCommand = {
|
|
12
|
-
args: [
|
|
12
|
+
args: [
|
|
13
|
+
{ complete: { kind: 'dynamic', source: 'tab' }, name: 'tabId', required: true },
|
|
14
|
+
{ complete: { kind: 'none' }, name: 'text' },
|
|
15
|
+
],
|
|
13
16
|
flags: [
|
|
14
17
|
...SHARED_FLAGS,
|
|
15
18
|
{ description: 'append \\r so the receiving CLI submits', kind: 'boolean', name: 'enter' },
|
|
@@ -24,6 +27,7 @@ export const tabSend: CliCommand = {
|
|
|
24
27
|
name: 'stdin',
|
|
25
28
|
},
|
|
26
29
|
{
|
|
30
|
+
complete: { kind: 'file' },
|
|
27
31
|
description: 'read the payload from this file instead of <text>',
|
|
28
32
|
kind: 'string',
|
|
29
33
|
name: 'prompt-file',
|
|
@@ -59,12 +63,13 @@ export const tabSend: CliCommand = {
|
|
|
59
63
|
? ctx.args.flags['await-timeout']
|
|
60
64
|
: DEFAULT_AWAIT_TIMEOUT_MS
|
|
61
65
|
|
|
62
|
-
// Uptake only means something once
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// Uptake only means something once something submits: either the appended
|
|
67
|
+
// `\r` (--enter) or a chord that carries its own submit (--keys "<CR>",
|
|
68
|
+
// which is the recovery path for a prompt already sitting in a composer).
|
|
69
|
+
// Without one of those there is nothing to confirm, so fail loudly rather
|
|
70
|
+
// than block forever on a transition that can't come.
|
|
71
|
+
if (awaitSubmit && !appendEnter && !asKeys) {
|
|
72
|
+
throw new Error('--await-submit requires --enter or --keys (the chord carries the submit)')
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
// At most one payload source. Unlike `tab run`, zero sources is valid here
|
|
@@ -9,11 +9,12 @@ import { snapshotTailLines, snapshotToLines } from '../../snapshot-render'
|
|
|
9
9
|
const RENDER_WAIT_MS = 500
|
|
10
10
|
|
|
11
11
|
export const tabSnapshot: CliCommand = {
|
|
12
|
-
args: [{ name: 'tabId', required: true }],
|
|
12
|
+
args: [{ complete: { kind: 'dynamic', source: 'tab' }, name: 'tabId', required: true }],
|
|
13
13
|
flags: [
|
|
14
14
|
...SHARED_FLAGS,
|
|
15
15
|
{ description: 'return only the last N non-blank lines', kind: 'number', name: 'tail' },
|
|
16
16
|
{
|
|
17
|
+
complete: { kind: 'values', values: ['json', 'text'] },
|
|
17
18
|
description: 'output format: json (default) or text (raw screen dump)',
|
|
18
19
|
kind: 'string',
|
|
19
20
|
name: 'format',
|
|
@@ -21,7 +21,7 @@ function toCursor(snapshot: TerminalSnapshot): Cursor {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export const tabTail: CliCommand = {
|
|
24
|
-
args: [{ name: 'tabId', required: true }],
|
|
24
|
+
args: [{ complete: { kind: 'dynamic', source: 'tab' }, name: 'tabId', required: true }],
|
|
25
25
|
flags: [
|
|
26
26
|
...SHARED_FLAGS,
|
|
27
27
|
{
|
|
@@ -12,10 +12,11 @@ function isTabActivity(value: string): value is TabActivity {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const tabWait: CliCommand = {
|
|
15
|
-
args: [{ name: 'tabId', required: true }],
|
|
15
|
+
args: [{ complete: { kind: 'dynamic', source: 'tab' }, name: 'tabId', required: true }],
|
|
16
16
|
flags: [
|
|
17
17
|
...SHARED_FLAGS,
|
|
18
18
|
{
|
|
19
|
+
complete: { kind: 'values', values: ['idle', 'waiting-input', 'working'] },
|
|
19
20
|
description: 'target activity (idle | working | waiting-input)',
|
|
20
21
|
kind: 'string',
|
|
21
22
|
name: 'status',
|
|
@@ -5,27 +5,28 @@ import { writeJson } from '../../output'
|
|
|
5
5
|
import { DEFAULT_TIMEOUT_MS } from '../tab/await-turn'
|
|
6
6
|
import {
|
|
7
7
|
awaitExistingWorker,
|
|
8
|
-
|
|
8
|
+
resolveWorkerTarget,
|
|
9
9
|
workerEnvelope,
|
|
10
10
|
workerOutcomeExitCode,
|
|
11
11
|
workerView,
|
|
12
12
|
} from './shared'
|
|
13
13
|
|
|
14
14
|
export const workerAwait: CliCommand = {
|
|
15
|
-
args: [{ name: 'worker', required: true }],
|
|
15
|
+
args: [{ complete: { kind: 'dynamic', source: 'worker' }, name: 'worker', required: true }],
|
|
16
16
|
flags: [
|
|
17
17
|
...SHARED_FLAGS,
|
|
18
18
|
{ description: 'overall turn cap in milliseconds', kind: 'number', name: 'timeout' },
|
|
19
19
|
],
|
|
20
20
|
group: 'worker',
|
|
21
21
|
run: async (ctx) => {
|
|
22
|
-
const tab = await
|
|
22
|
+
const { tab, workspace } = await resolveWorkerTarget(ctx, ctx.args.positionals[0] ?? '')
|
|
23
23
|
const outcome = await awaitExistingWorker(
|
|
24
24
|
ctx,
|
|
25
|
+
workspace,
|
|
25
26
|
tab.id,
|
|
26
27
|
typeof ctx.args.flags.timeout === 'number' ? ctx.args.flags.timeout : DEFAULT_TIMEOUT_MS
|
|
27
28
|
)
|
|
28
|
-
writeJson(workerEnvelope(workerView(
|
|
29
|
+
writeJson(workerEnvelope(workspace, workerView(workspace, tab), outcome))
|
|
29
30
|
return workerOutcomeExitCode(outcome)
|
|
30
31
|
},
|
|
31
32
|
summary: "Await an existing worker's in-flight turn",
|
|
@@ -18,6 +18,11 @@ import {
|
|
|
18
18
|
isCommandAvailable,
|
|
19
19
|
parseCommand,
|
|
20
20
|
} from '../../../pty/command-registry'
|
|
21
|
+
import {
|
|
22
|
+
findPrimaryWorktree,
|
|
23
|
+
WORKSPACE_ENV_VAR,
|
|
24
|
+
workspaceRepoRoot,
|
|
25
|
+
} from '../../client/workspace-resolver'
|
|
21
26
|
import { SHARED_FLAGS } from '../../flags'
|
|
22
27
|
import { EXIT_OK, EXIT_RUNTIME, writeJson } from '../../output'
|
|
23
28
|
import { WORKER_SCHEMA_VERSION } from './shared'
|
|
@@ -56,7 +61,8 @@ export const workerDoctor: CliCommand = {
|
|
|
56
61
|
const missingManagerCapabilities = [MANAGER_CAPABILITY_WORKER_METADATA].filter(
|
|
57
62
|
(capability) => !managerCapabilities.includes(capability)
|
|
58
63
|
)
|
|
59
|
-
const primaryWorktree = workspace
|
|
64
|
+
const primaryWorktree = findPrimaryWorktree(workspace)
|
|
65
|
+
const workspaceOrigin = ctx.getWorkspaceOrigin?.() ?? 'active'
|
|
60
66
|
const availableAssistants = assistants.filter((assistant) => assistant.available)
|
|
61
67
|
const skillPath = fileURLToPath(
|
|
62
68
|
new URL('../../../../skills/aimux-orchestrator/', import.meta.url)
|
|
@@ -81,6 +87,16 @@ export const workerDoctor: CliCommand = {
|
|
|
81
87
|
if (!existsSync(skillPath)) {
|
|
82
88
|
issues.push(`packaged orchestrator skill is missing: ${skillPath}`)
|
|
83
89
|
}
|
|
90
|
+
// Not an issue — an inferred workspace is the normal interactive case — but
|
|
91
|
+
// it IS the one resolution mode that can follow the UI to another project
|
|
92
|
+
// between two calls. An orchestrator dispatching a multi-hour fleet wants to
|
|
93
|
+
// see this before it starts, not after it reviews diffs from the wrong repo.
|
|
94
|
+
const warnings: string[] = []
|
|
95
|
+
if (workspaceOrigin === 'active') {
|
|
96
|
+
warnings.push(
|
|
97
|
+
`workspace "${workspace.name}" was inferred from the most recently opened session and follows the UI; pin it with --workspace or ${WORKSPACE_ENV_VAR}`
|
|
98
|
+
)
|
|
99
|
+
}
|
|
84
100
|
const ready = issues.length === 0
|
|
85
101
|
writeJson({
|
|
86
102
|
assistants,
|
|
@@ -100,7 +116,12 @@ export const workerDoctor: CliCommand = {
|
|
|
100
116
|
skill: { ok: existsSync(skillPath), path: skillPath },
|
|
101
117
|
workspace: {
|
|
102
118
|
hasPrimaryWorktree: primaryWorktree !== undefined,
|
|
119
|
+
name: workspace.name,
|
|
103
120
|
ok: primaryWorktree !== undefined,
|
|
121
|
+
/** Repo every fresh worker worktree is cut from — confirm before dispatching. */
|
|
122
|
+
repoRoot: workspaceRepoRoot(workspace),
|
|
123
|
+
/** 'flag' | 'env' | 'active'; only 'active' can follow the UI. */
|
|
124
|
+
source: workspaceOrigin,
|
|
104
125
|
},
|
|
105
126
|
},
|
|
106
127
|
cliVersion: version,
|
|
@@ -116,10 +137,13 @@ export const workerDoctor: CliCommand = {
|
|
|
116
137
|
ready,
|
|
117
138
|
schemaVersion: WORKER_SCHEMA_VERSION,
|
|
118
139
|
skillPath,
|
|
140
|
+
warnings,
|
|
119
141
|
workspace: {
|
|
120
142
|
id: workspace.id,
|
|
121
143
|
name: workspace.name,
|
|
122
144
|
projectPath: workspace.projectPath ?? null,
|
|
145
|
+
repoRoot: workspaceRepoRoot(workspace),
|
|
146
|
+
source: workspaceOrigin,
|
|
123
147
|
},
|
|
124
148
|
})
|
|
125
149
|
return ready ? EXIT_OK : EXIT_RUNTIME
|
|
@@ -1,22 +1,64 @@
|
|
|
1
1
|
import type { CliCommand } from '../../registry'
|
|
2
2
|
|
|
3
|
+
import { workspaceIdentity } from '../../client/workspace-resolver'
|
|
3
4
|
import { SHARED_FLAGS } from '../../flags'
|
|
4
5
|
import { EXIT_OK, writeJson } from '../../output'
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
listNamedWorkerTabs,
|
|
8
|
+
listWorkerTargets,
|
|
9
|
+
resolveWorkerTarget,
|
|
10
|
+
WORKER_SCHEMA_VERSION,
|
|
11
|
+
workerView,
|
|
12
|
+
} from './shared'
|
|
6
13
|
|
|
7
14
|
export const workerList: CliCommand = {
|
|
8
|
-
args: [{ name: 'worker' }],
|
|
9
|
-
flags:
|
|
15
|
+
args: [{ complete: { kind: 'dynamic', source: 'worker' }, name: 'worker' }],
|
|
16
|
+
flags: [
|
|
17
|
+
...SHARED_FLAGS,
|
|
18
|
+
{
|
|
19
|
+
description: 'list workers in every catalogued workspace, not just the target one',
|
|
20
|
+
kind: 'boolean',
|
|
21
|
+
name: 'all-workspaces',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
10
24
|
group: 'worker',
|
|
11
25
|
run: async (ctx) => {
|
|
12
26
|
const selector = ctx.args.positionals[0]
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
|
|
28
|
+
// `{"workers":[]}` alone is indistinguishable from "every worker died", and
|
|
29
|
+
// the natural recovery from that reading is a destructive re-dispatch. Name
|
|
30
|
+
// the workspace that was queried so an empty fleet is legible as "not here"
|
|
31
|
+
// rather than "gone", and offer one call that answers "are they really gone?"
|
|
32
|
+
if (ctx.args.flags['all-workspaces'] === true) {
|
|
33
|
+
const targets = await listWorkerTargets(ctx)
|
|
34
|
+
writeJson({
|
|
35
|
+
schemaVersion: WORKER_SCHEMA_VERSION,
|
|
36
|
+
workers: targets
|
|
37
|
+
.filter((target) => selector === undefined || target.tab.workerName === selector)
|
|
38
|
+
.map((target) => ({
|
|
39
|
+
...workerView(target.workspace, target.tab),
|
|
40
|
+
workspace: workspaceIdentity(target.workspace),
|
|
41
|
+
})),
|
|
42
|
+
})
|
|
43
|
+
return EXIT_OK
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (selector !== undefined) {
|
|
47
|
+
const { tab, workspace } = await resolveWorkerTarget(ctx, selector)
|
|
48
|
+
writeJson({
|
|
49
|
+
schemaVersion: WORKER_SCHEMA_VERSION,
|
|
50
|
+
workers: [workerView(workspace, tab)],
|
|
51
|
+
workspace: workspaceIdentity(workspace),
|
|
52
|
+
})
|
|
53
|
+
return EXIT_OK
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const workspace = ctx.getWorkspace()
|
|
57
|
+
const tabs = await listNamedWorkerTabs(ctx, workspace)
|
|
17
58
|
writeJson({
|
|
18
59
|
schemaVersion: WORKER_SCHEMA_VERSION,
|
|
19
|
-
workers: tabs.map((tab) => workerView(
|
|
60
|
+
workers: tabs.map((tab) => workerView(workspace, tab)),
|
|
61
|
+
workspace: workspaceIdentity(workspace),
|
|
20
62
|
})
|
|
21
63
|
return EXIT_OK
|
|
22
64
|
},
|
|
@@ -6,17 +6,25 @@ import { DEFAULT_TIMEOUT_MS } from '../tab/await-turn'
|
|
|
6
6
|
import { resolvePromptText } from '../tab/prompt-io'
|
|
7
7
|
import {
|
|
8
8
|
dispatchWorkerPrompt,
|
|
9
|
-
|
|
9
|
+
resolveWorkerTarget,
|
|
10
10
|
workerEnvelope,
|
|
11
11
|
workerOutcomeExitCode,
|
|
12
12
|
workerView,
|
|
13
13
|
} from './shared'
|
|
14
14
|
|
|
15
15
|
export const workerPrompt: CliCommand = {
|
|
16
|
-
args: [
|
|
16
|
+
args: [
|
|
17
|
+
{ complete: { kind: 'dynamic', source: 'worker' }, name: 'worker', required: true },
|
|
18
|
+
{ complete: { kind: 'none' }, name: 'text' },
|
|
19
|
+
],
|
|
17
20
|
flags: [
|
|
18
21
|
...SHARED_FLAGS,
|
|
19
|
-
{
|
|
22
|
+
{
|
|
23
|
+
complete: { kind: 'file' },
|
|
24
|
+
description: 'read the prompt from this file',
|
|
25
|
+
kind: 'string',
|
|
26
|
+
name: 'prompt-file',
|
|
27
|
+
},
|
|
20
28
|
{ description: 'read the prompt from stdin', kind: 'boolean', name: 'stdin' },
|
|
21
29
|
{
|
|
22
30
|
description: 'return after prompt uptake instead of turn completion',
|
|
@@ -24,11 +32,23 @@ export const workerPrompt: CliCommand = {
|
|
|
24
32
|
name: 'detach',
|
|
25
33
|
},
|
|
26
34
|
{ description: 'overall turn cap in milliseconds', kind: 'number', name: 'timeout' },
|
|
35
|
+
{
|
|
36
|
+
description:
|
|
37
|
+
'milliseconds to wait for the detached submit→working confirmation (default 15000)',
|
|
38
|
+
kind: 'number',
|
|
39
|
+
name: 'uptake-timeout',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
description:
|
|
43
|
+
'clear the composer (<C-u>) before writing, so text typed by a human in the UI cannot be concatenated onto this prompt',
|
|
44
|
+
kind: 'boolean',
|
|
45
|
+
name: 'replace',
|
|
46
|
+
},
|
|
27
47
|
],
|
|
28
48
|
group: 'worker',
|
|
29
49
|
run: async (ctx) => {
|
|
30
50
|
const selector = ctx.args.positionals[0] ?? ''
|
|
31
|
-
const tab = await
|
|
51
|
+
const { tab, workspace } = await resolveWorkerTarget(ctx, selector)
|
|
32
52
|
const promptFile =
|
|
33
53
|
typeof ctx.args.flags['prompt-file'] === 'string' ? ctx.args.flags['prompt-file'] : undefined
|
|
34
54
|
const text = await resolvePromptText(
|
|
@@ -36,12 +56,17 @@ export const workerPrompt: CliCommand = {
|
|
|
36
56
|
ctx.args.flags.stdin === true,
|
|
37
57
|
ctx.args.positionals[1]
|
|
38
58
|
)
|
|
39
|
-
const outcome = await dispatchWorkerPrompt(ctx, tab.id, text, {
|
|
59
|
+
const outcome = await dispatchWorkerPrompt(ctx, workspace, tab.id, text, {
|
|
40
60
|
detach: ctx.args.flags.detach === true,
|
|
61
|
+
replace: ctx.args.flags.replace === true,
|
|
41
62
|
timeoutMs:
|
|
42
63
|
typeof ctx.args.flags.timeout === 'number' ? ctx.args.flags.timeout : DEFAULT_TIMEOUT_MS,
|
|
64
|
+
uptakeTimeoutMs:
|
|
65
|
+
typeof ctx.args.flags['uptake-timeout'] === 'number'
|
|
66
|
+
? ctx.args.flags['uptake-timeout']
|
|
67
|
+
: undefined,
|
|
43
68
|
})
|
|
44
|
-
writeJson(workerEnvelope(workerView(
|
|
69
|
+
writeJson(workerEnvelope(workspace, workerView(workspace, tab), outcome))
|
|
45
70
|
return workerOutcomeExitCode(outcome)
|
|
46
71
|
},
|
|
47
72
|
summary: 'Prompt an existing named worker and await its outcome',
|