@cortex-agent/server 2026.9.21 → 2026.9.25
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/defaults/config/thread-templates/agents/creative.json +17 -0
- package/defaults/prompts/systemPrompts/creative.md +13 -0
- package/defaults/prompts/systemPrompts/direct.md +1 -1
- package/dist/agent-adapter/claude/adapter.d.ts +12 -0
- package/dist/agent-adapter/claude/adapter.js +19 -1
- package/dist/agent-adapter/claude/spawn-args.d.ts +7 -0
- package/dist/agent-adapter/claude/spawn-args.js +10 -0
- package/dist/agent-adapter/pi/child-runner.d.ts +4 -2
- package/dist/agent-adapter/pi/child-runner.js +5 -1
- package/dist/agent-adapter/pi/event-parser.d.ts +3 -2
- package/dist/agent-adapter/pi/event-parser.js +46 -2
- package/dist/agent-adapter/pi/extensions.d.ts +7 -1
- package/dist/agent-adapter/pi/extensions.js +10 -3
- package/dist/agent-adapter/pi/mcp-bridge.js +8 -8
- package/dist/agent-adapter/pi/pi-session.js +5 -0
- package/dist/agent-adapter/pi/runtime.js +3 -0
- package/dist/agent-adapter/pi/session-options.js +5 -1
- package/dist/agent-adapter/pi/subagent.d.ts +15 -3
- package/dist/agent-adapter/pi/subagent.js +18 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +6 -1
- package/dist/agent-adapter/pi/tool-shims.js +34 -1
- package/dist/agent-adapter/types.d.ts +5 -0
- package/dist/core/agents/subagent/types.d.ts +3 -0
- package/dist/core/config-generator.js +17 -2
- package/dist/core/debug-mode.d.ts +11 -10
- package/dist/core/debug-mode.js +12 -18
- package/dist/core/exec-async.d.ts +26 -0
- package/dist/core/exec-async.js +47 -0
- package/dist/core/locales/en.d.ts +14 -1
- package/dist/core/locales/slices/commands.d.ts +12 -1
- package/dist/core/locales/slices/commands.js +24 -2
- package/dist/core/locales/slices/startup.d.ts +2 -0
- package/dist/core/locales/slices/startup.js +4 -0
- package/dist/core/rebuild-progress.d.ts +58 -0
- package/dist/core/rebuild-progress.js +103 -0
- package/dist/core/resilient-watch.js +5 -3
- package/dist/core/run-registry.d.ts +7 -0
- package/dist/core/run-registry.js +6 -0
- package/dist/core/types/thread-types.d.ts +23 -4
- package/dist/domain/agents/agent-state.d.ts +7 -0
- package/dist/domain/agents/agent-state.js +9 -1
- package/dist/domain/agents/agent-switch.d.ts +38 -0
- package/dist/domain/agents/agent-switch.js +106 -0
- package/dist/domain/agents/config.d.ts +20 -2
- package/dist/domain/agents/config.js +58 -4
- package/dist/domain/agents/index.d.ts +1 -0
- package/dist/domain/agents/index.js +1 -0
- package/dist/domain/agents/profile-manager.d.ts +6 -0
- package/dist/domain/agents/profile-manager.js +14 -1
- package/dist/domain/executions/registry.d.ts +2 -0
- package/dist/domain/executions/registry.js +84 -7
- package/dist/domain/plugins/runtime.js +1 -1
- package/dist/domain/plugins/skill-projection.d.ts +8 -2
- package/dist/domain/plugins/skill-projection.js +76 -19
- package/dist/domain/remote/client-bootstrap.js +1 -1
- package/dist/domain/remote/client-hot-reload.d.ts +1 -1
- package/dist/domain/remote/client-hot-reload.js +27 -23
- package/dist/domain/runs/engine-spec.js +4 -0
- package/dist/domain/runs/request.d.ts +6 -0
- package/dist/domain/runs/run.js +1 -0
- package/dist/domain/runs/spec-loader.d.ts +4 -3
- package/dist/domain/runs/spec-loader.js +4 -3
- package/dist/domain/scheduling/jobs/sync-public.js +6 -6
- package/dist/domain/scheduling/scheduler.js +14 -12
- package/dist/domain/sessions/session-lifecycle.d.ts +5 -0
- package/dist/domain/sessions/session-lifecycle.js +13 -1
- package/dist/domain/system/rebuild-hold.d.ts +44 -0
- package/dist/domain/system/rebuild-hold.js +91 -0
- package/dist/domain/system/server-update-check.d.ts +2 -1
- package/dist/domain/system/server-update-check.js +15 -13
- package/dist/domain/tasks/archiver.js +21 -13
- package/dist/domain/tasks/mutator.js +60 -59
- package/dist/domain/tasks/system/task-completion.d.ts +7 -2
- package/dist/domain/tasks/system/task-completion.js +69 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -1
- package/dist/domain/tasks/system/task-lifecycle-edit.js +21 -2
- package/dist/domain/tasks/system/task-lock.d.ts +23 -0
- package/dist/domain/tasks/system/task-lock.js +29 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +14 -1
- package/dist/domain/tasks/system/task-mutations.js +25 -2
- package/dist/domain/tasks/system/task-state.d.ts +12 -1
- package/dist/domain/tasks/system/task-state.js +19 -2
- package/dist/domain/threads/prompt-builder.d.ts +9 -6
- package/dist/domain/threads/prompt-builder.js +28 -10
- package/dist/domain/threads/runner.js +7 -3
- package/dist/domain/threads/state-machine.js +15 -11
- package/dist/domain/threads/template-loader.js +6 -4
- package/dist/domain/threads/template-validate.d.ts +43 -6
- package/dist/domain/threads/template-validate.js +12 -0
- package/dist/domain/ui-service/app-router.d.ts +10 -0
- package/dist/domain/ui-service/app-router.js +2 -1
- package/dist/domain/ui-service/input-schemas.d.ts +11 -0
- package/dist/domain/ui-service/input-schemas.js +11 -0
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
- package/dist/domain/ui-service/mutate/sessions.js +40 -0
- package/dist/domain/ui-service/mutate/tasks.js +4 -3
- package/dist/domain/ui-service/query/config.js +19 -1
- package/dist/domain/ui-service/query/memory.js +28 -34
- package/dist/domain/ui-service/query/sessions.js +89 -12
- package/dist/domain/ui-service/query/system.js +19 -0
- package/dist/domain/ui-service/query-input-schemas.d.ts +1 -0
- package/dist/domain/ui-service/query-input-schemas.js +2 -0
- package/dist/domain/ui-service/types.d.ts +97 -3
- package/dist/domain/ui-service/ui-service.js +2 -1
- package/dist/entry/app.js +23 -4
- package/dist/entry/daemon-notice.d.ts +10 -1
- package/dist/entry/daemon-notice.js +16 -1
- package/dist/entry/daemon.d.ts +43 -2
- package/dist/entry/daemon.js +163 -9
- package/dist/orchestration/agent-runner.js +16 -0
- package/dist/orchestration/conversation-request.d.ts +33 -0
- package/dist/orchestration/conversation-request.js +78 -16
- package/dist/orchestration/mid-turn-inject.d.ts +3 -0
- package/dist/orchestration/mid-turn-inject.js +9 -4
- package/dist/orchestration/resume-dispatcher.js +4 -2
- package/dist/orchestration/routing/commands/mode.js +114 -63
- package/dist/orchestration/thread-executor.js +13 -0
- package/dist/orchestration/turn/turn.js +1 -0
- package/dist/store/conversation-display-projection.d.ts +9 -1
- package/dist/store/conversation-display-projection.js +13 -6
- package/dist/store/conversation-history-reader.d.ts +19 -0
- package/dist/store/conversation-history-reader.js +163 -44
- package/dist/store/conversation-history-repo.d.ts +37 -10
- package/dist/store/conversation-history-repo.js +161 -139
- package/dist/store/session-registry-journal.d.ts +4 -0
- package/dist/store/session-registry-journal.js +4 -0
- package/dist/store/session-registry-repo.d.ts +2 -1
- package/dist/store/session-registry-repo.js +2 -0
- package/dist/store/task-repo.d.ts +6 -3
- package/dist/store/task-repo.js +26 -10
- package/package.json +2 -1
- package/web/dist/AGENTS.md +10 -0
- package/web/dist/assets/index-B1dBi8Za.css +1 -0
- package/web/dist/assets/{index-DZTuqUO4.js → index-BAeLybF0.js} +1 -1
- package/web/dist/assets/index-BcQI8Fh5.js +445 -0
- package/web/dist/index.html +12 -4
- package/web/dist/theme.css +211 -40
- package/web/dist/assets/index-CwwQNMpP.css +0 -1
- package/web/dist/assets/index-DLSfgq3o.js +0 -444
|
@@ -99,8 +99,13 @@ export interface EngineSpec {
|
|
|
99
99
|
gatewayBaseUrl?: string;
|
|
100
100
|
gatewayPath?: string;
|
|
101
101
|
};
|
|
102
|
+
/** `disableSkills` covers the whole skill layer, including the user-level plugins and skills
|
|
103
|
+
* Cortex never passed in (`--plugin-dir` only ever added its own); `settingSources` narrows
|
|
104
|
+
* which setting files the backend may read at all. */
|
|
102
105
|
flags: {
|
|
103
106
|
disableHooks?: boolean;
|
|
107
|
+
disableSkills?: boolean;
|
|
108
|
+
settingSources?: string[];
|
|
104
109
|
streamDeltas?: boolean;
|
|
105
110
|
captureTranscripts?: boolean;
|
|
106
111
|
preserveUnreportedAccounting?: boolean;
|
|
@@ -28,6 +28,8 @@ export interface SubagentResult {
|
|
|
28
28
|
output: string;
|
|
29
29
|
usage: SubagentUsage;
|
|
30
30
|
model?: string;
|
|
31
|
+
/** The provider that answered, as the child's own messages reported it (pi children only). */
|
|
32
|
+
provider?: string;
|
|
31
33
|
/** Which backend actually ran the child; absent on results built before dispatch. */
|
|
32
34
|
backend?: Backend;
|
|
33
35
|
stopReason?: string;
|
|
@@ -47,6 +49,7 @@ export interface ChildAccumulator {
|
|
|
47
49
|
output: string;
|
|
48
50
|
usage: SubagentUsage;
|
|
49
51
|
model?: string;
|
|
52
|
+
provider?: string;
|
|
50
53
|
stopReason?: string;
|
|
51
54
|
errorMessage?: string;
|
|
52
55
|
}
|
|
@@ -100,15 +100,30 @@ function materializedConfigPath(outputDir, configPaths, documents, encodedAllowl
|
|
|
100
100
|
.digest('hex').slice(0, 16);
|
|
101
101
|
return path.join(outputDir, `mcp-composition-${digest}.json`);
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* An allowlist is an UPPER BOUND on this spawn's MCP surface, not a list of tools the spawn must
|
|
105
|
+
* have. The two failure modes it has to tell apart:
|
|
106
|
+
*
|
|
107
|
+
* - a name that exists NOWHERE in {@link MCP_TOOLS_BY_SERVER} is a typo, and typos are worth
|
|
108
|
+
* failing on — nothing would ever register under that name, on any surface.
|
|
109
|
+
* - a name that exists globally but belongs to a bundle this spawn does not compose is simply
|
|
110
|
+
* absent HERE. `send_file` lives in `cortex-web`, so an agent that names it runs with it on a
|
|
111
|
+
* web session and without it on Slack; that is what a surface means. Dropping the name is the
|
|
112
|
+
* whole behaviour — throwing would make an agent definition a statement about which surfaces it
|
|
113
|
+
* may be used on, which is not what an allowlist is for.
|
|
114
|
+
*/
|
|
115
|
+
function narrowAllowlistToSurface(canonical, selectedTools) {
|
|
116
|
+
validateMcpToolAllowlist(canonical);
|
|
117
|
+
return canonical.filter(name => selectedTools.has(name));
|
|
118
|
+
}
|
|
103
119
|
export function materializeMcpToolAllowlistConfigs(configPaths, allowlist, outputDir = path.join(CONFIG_DIR, 'mcp-tool-gates'), selectedBundles) {
|
|
104
120
|
if (allowlist === undefined)
|
|
105
121
|
return [...configPaths];
|
|
106
122
|
const documents = configPaths.map(readMcpConfig);
|
|
107
|
-
const canonical = canonicalizeMcpToolAllowlist(allowlist);
|
|
108
123
|
const selectedTools = selectedBundles
|
|
109
124
|
? new Set(selectedBundles.flatMap(bundle => MCP_TOOLS_BY_SERVER[bundle] ?? []))
|
|
110
125
|
: knownToolsIn(documents);
|
|
111
|
-
|
|
126
|
+
const canonical = narrowAllowlistToSurface(canonicalizeMcpToolAllowlist(allowlist), selectedTools);
|
|
112
127
|
const encoded = JSON.stringify(canonical);
|
|
113
128
|
const materialized = mergedMcpConfig(documents, encoded, selectedBundles);
|
|
114
129
|
mkdirSync(outputDir, { recursive: true, mode: 0o700 });
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export declare const DEFAULT_DEBUG_TOOL_WARNING_CHARS = 10000;
|
|
2
|
-
interface DebugToolDetails {
|
|
3
|
-
toolInput?: unknown;
|
|
4
|
-
toolResult?: {
|
|
5
|
-
content: string;
|
|
6
|
-
isError: boolean;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
2
|
/** Preserve Cortex's established DEBUG semantics: every non-empty value enables the mode. */
|
|
10
3
|
export declare function isDebugMode(env?: NodeJS.ProcessEnv): boolean;
|
|
11
4
|
export declare function debugToolWarningChars(env?: NodeJS.ProcessEnv): number;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The large-payload warning is a hint on a UI chip — "opening this will be slow" — so it is
|
|
7
|
+
* measured on the serialized JSON line the row was read from, which every caller already holds.
|
|
8
|
+
*
|
|
9
|
+
* It used to re-serialize the parsed input with `JSON.stringify(value, null, 2)` and split the
|
|
10
|
+
* result into an array of code points, once per tool row per parse, only to compare a number
|
|
11
|
+
* against this threshold. That was 4.65% of the server's CPU, and it put one array slot plus one
|
|
12
|
+
* string object per character straight into the GC's path. A serialized row is within a small
|
|
13
|
+
* constant factor of what the modal renders, which is all a warning chip ever needed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isOverDebugToolWarningChars(chars: number, env?: NodeJS.ProcessEnv): boolean;
|
package/dist/core/debug-mode.js
CHANGED
|
@@ -7,22 +7,16 @@ export function debugToolWarningChars(env = process.env) {
|
|
|
7
7
|
const value = Number(env.CORTEX_DEBUG_TOOL_WARNING_CHARS);
|
|
8
8
|
return Number.isSafeInteger(value) && value > 0 ? value : DEFAULT_DEBUG_TOOL_WARNING_CHARS;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const inputChars = Array.from(formatDebugValue(details.toolInput)).length;
|
|
23
|
-
const resultChars = details.toolResult ? Array.from(details.toolResult.content).length : 0;
|
|
24
|
-
return inputChars + resultChars;
|
|
25
|
-
}
|
|
26
|
-
export function isDebugToolOverWarningThreshold(details, env = process.env) {
|
|
27
|
-
return debugToolCharacterCount(details) > debugToolWarningChars(env);
|
|
10
|
+
/**
|
|
11
|
+
* The large-payload warning is a hint on a UI chip — "opening this will be slow" — so it is
|
|
12
|
+
* measured on the serialized JSON line the row was read from, which every caller already holds.
|
|
13
|
+
*
|
|
14
|
+
* It used to re-serialize the parsed input with `JSON.stringify(value, null, 2)` and split the
|
|
15
|
+
* result into an array of code points, once per tool row per parse, only to compare a number
|
|
16
|
+
* against this threshold. That was 4.65% of the server's CPU, and it put one array slot plus one
|
|
17
|
+
* string object per character straight into the GC's path. A serialized row is within a small
|
|
18
|
+
* constant factor of what the modal renders, which is all a warning chip ever needed.
|
|
19
|
+
*/
|
|
20
|
+
export function isOverDebugToolWarningChars(chars, env = process.env) {
|
|
21
|
+
return chars > debugToolWarningChars(env);
|
|
28
22
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Normalized outcome of a child process run. Non-zero exits and timeouts are values, not throws. */
|
|
2
|
+
export interface ExecResult {
|
|
3
|
+
/** Exit code 0 — the only case callers should treat as success. */
|
|
4
|
+
ok: boolean;
|
|
5
|
+
/** Exit code, or null when the process was killed (timeout/signal) or failed to spawn. */
|
|
6
|
+
code: number | null;
|
|
7
|
+
signal: NodeJS.Signals | null;
|
|
8
|
+
/** True when the shared timeout elapsed and the child was killed. */
|
|
9
|
+
timedOut: boolean;
|
|
10
|
+
stdout: string;
|
|
11
|
+
stderr: string;
|
|
12
|
+
/** Spawn-level failure (ENOENT, EACCES, …). Absent for ordinary non-zero exits. */
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ExecOptions {
|
|
16
|
+
cwd?: string;
|
|
17
|
+
env?: NodeJS.ProcessEnv;
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
maxBuffer?: number;
|
|
20
|
+
/** Text piped to the child's stdin, which is then closed. Omitted → stdin is closed empty. */
|
|
21
|
+
stdin?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Run a binary with an argument array — no shell, so no quoting surface. */
|
|
24
|
+
export declare function runFile(file: string, args?: readonly string[], opts?: ExecOptions): Promise<ExecResult>;
|
|
25
|
+
/** Run a command line through the platform shell — the async equivalent of `execSync(command)`. */
|
|
26
|
+
export declare function runShell(command: string, opts?: ExecOptions): Promise<ExecResult>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
/** execFile's own default; kept explicit so a caller can raise it for git blame-sized output. */
|
|
3
|
+
const DEFAULT_MAX_BUFFER = 1024 * 1024;
|
|
4
|
+
function finish(resolve, error, stdout, stderr, timeoutMs) {
|
|
5
|
+
const code = error && typeof error.code === 'number' ? error.code : error ? null : 0;
|
|
6
|
+
const signal = error?.signal ?? null;
|
|
7
|
+
// Node reports a timed-out child as killed with a SIGTERM signal; a missing binary arrives
|
|
8
|
+
// as a string errno code with no signal at all. Both land here as code=null.
|
|
9
|
+
const timedOut = Boolean(error) && (error?.killed === true || signal === 'SIGTERM') && timeoutMs !== undefined;
|
|
10
|
+
resolve({
|
|
11
|
+
ok: code === 0,
|
|
12
|
+
code,
|
|
13
|
+
signal,
|
|
14
|
+
timedOut,
|
|
15
|
+
stdout,
|
|
16
|
+
stderr,
|
|
17
|
+
...(error && typeof error.code === 'string' ? { error: error.message } : {}),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** Run a binary with an argument array — no shell, so no quoting surface. */
|
|
21
|
+
export function runFile(file, args = [], opts = {}) {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
const child = execFile(file, [...args], {
|
|
24
|
+
cwd: opts.cwd,
|
|
25
|
+
env: opts.env ?? process.env,
|
|
26
|
+
timeout: opts.timeoutMs,
|
|
27
|
+
killSignal: 'SIGTERM',
|
|
28
|
+
maxBuffer: opts.maxBuffer ?? DEFAULT_MAX_BUFFER,
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
windowsHide: true,
|
|
31
|
+
}, (error, stdout, stderr) => finish(resolve, error, stdout, stderr, opts.timeoutMs));
|
|
32
|
+
// Always close stdin: a child that reads it (e.g. `git cat-file --batch-check`) must not wait
|
|
33
|
+
// on a pipe nobody writes to.
|
|
34
|
+
if (opts.stdin !== undefined)
|
|
35
|
+
child.stdin?.end(opts.stdin);
|
|
36
|
+
else
|
|
37
|
+
child.stdin?.end();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Run a command line through the platform shell — the async equivalent of `execSync(command)`. */
|
|
41
|
+
export function runShell(command, opts = {}) {
|
|
42
|
+
const shell = process.platform === 'win32'
|
|
43
|
+
? (process.env.ComSpec ?? 'cmd.exe')
|
|
44
|
+
: '/bin/sh';
|
|
45
|
+
const flag = process.platform === 'win32' ? '/c' : '-c';
|
|
46
|
+
return runFile(shell, [flag, command], opts);
|
|
47
|
+
}
|
|
@@ -207,6 +207,8 @@ export declare const en: {
|
|
|
207
207
|
'startup.started': "Cortex agent v${version} started on ${machine}.";
|
|
208
208
|
'startup.restarted': "Cortex agent v${version} restarted on ${machine}.";
|
|
209
209
|
'startup.reason': " Reason: ${reason}.";
|
|
210
|
+
'startup.rebuildHold': "Cortex is rebuilding itself (${phase}) and is about to restart, so this message was not processed. Send it again in a moment.";
|
|
211
|
+
'startup.rebuildHoldDropped': "A message for ${channel} arrived during the rebuild (${phase}) and was not processed: ${preview}";
|
|
210
212
|
'interaction.askExpired': "This AskUserQuestion prompt has expired. Please ask again if you still need it.";
|
|
211
213
|
'interaction.askInactive': "This AskUserQuestion prompt is no longer active.";
|
|
212
214
|
'interaction.selectOrType': "Please select an option or type a custom answer.";
|
|
@@ -343,10 +345,21 @@ export declare const en: {
|
|
|
343
345
|
'cmd.skills.localGroup': ".claude/skills";
|
|
344
346
|
'cmd.agent.defaultSet': "Default agent set to *${name}* (${detail})";
|
|
345
347
|
'cmd.agent.disabled': "Default agent disabled.";
|
|
346
|
-
'cmd.agent.disableButton': "Disable";
|
|
347
348
|
'cmd.agent.current': "Default agent: *${name}* (${detail})";
|
|
348
349
|
'cmd.agent.none': "No default agent set.\nAvailable: ${agents}";
|
|
349
350
|
'cmd.agent.unknown': "Unknown agent: `${name}`\nAvailable: ${available}";
|
|
351
|
+
'cmd.agent.channelSet': "Agent for this conversation set to *${name}* (${detail}). Takes effect on the next message.";
|
|
352
|
+
'cmd.agent.crossBackendBlocked': "Can't switch to *${name}* — it pins a profile on the `${target}` backend but this conversation is on `${current}`. Backends can't be swapped mid-conversation. Start a new session (`!new`) to switch backend.";
|
|
353
|
+
'cmd.agent.channelHeader': "Agent for this conversation: *${name}* (${detail})";
|
|
354
|
+
'cmd.agent.followingGlobal': "This conversation follows the global default: *${name}*";
|
|
355
|
+
'cmd.agent.followingGlobalNone': "This conversation follows the global default, which is unset (running `main`).";
|
|
356
|
+
'cmd.agent.globalLine': "Global default: *${name}*";
|
|
357
|
+
'cmd.agent.globalNone': "Global default: none";
|
|
358
|
+
'cmd.agent.available': "Available: ${agents}";
|
|
359
|
+
'cmd.agent.cleared': "Agent cleared for this conversation — following the global default: *${name}*";
|
|
360
|
+
'cmd.agent.clearedNoGlobal': "Agent cleared for this conversation — no global default, running `main`.";
|
|
361
|
+
'cmd.agent.globalUsage': "Usage: `!agent global <name>` · `!agent global off`";
|
|
362
|
+
'cmd.agent.followGlobalButton': "Follow global";
|
|
350
363
|
'cmd.channel.noProjects': "No projects found.";
|
|
351
364
|
'cmd.channel.projectsHeader': "*Projects*\n${list}";
|
|
352
365
|
'cmd.channel.registeredNotification': "Registered for `${project}` task notifications.";
|
|
@@ -52,10 +52,21 @@ export declare const commandsEn: {
|
|
|
52
52
|
readonly 'cmd.skills.localGroup': ".claude/skills";
|
|
53
53
|
readonly 'cmd.agent.defaultSet': "Default agent set to *${name}* (${detail})";
|
|
54
54
|
readonly 'cmd.agent.disabled': "Default agent disabled.";
|
|
55
|
-
readonly 'cmd.agent.disableButton': "Disable";
|
|
56
55
|
readonly 'cmd.agent.current': "Default agent: *${name}* (${detail})";
|
|
57
56
|
readonly 'cmd.agent.none': "No default agent set.\nAvailable: ${agents}";
|
|
58
57
|
readonly 'cmd.agent.unknown': "Unknown agent: `${name}`\nAvailable: ${available}";
|
|
58
|
+
readonly 'cmd.agent.channelSet': "Agent for this conversation set to *${name}* (${detail}). Takes effect on the next message.";
|
|
59
|
+
readonly 'cmd.agent.crossBackendBlocked': "Can't switch to *${name}* — it pins a profile on the `${target}` backend but this conversation is on `${current}`. Backends can't be swapped mid-conversation. Start a new session (`!new`) to switch backend.";
|
|
60
|
+
readonly 'cmd.agent.channelHeader': "Agent for this conversation: *${name}* (${detail})";
|
|
61
|
+
readonly 'cmd.agent.followingGlobal': "This conversation follows the global default: *${name}*";
|
|
62
|
+
readonly 'cmd.agent.followingGlobalNone': "This conversation follows the global default, which is unset (running `main`).";
|
|
63
|
+
readonly 'cmd.agent.globalLine': "Global default: *${name}*";
|
|
64
|
+
readonly 'cmd.agent.globalNone': "Global default: none";
|
|
65
|
+
readonly 'cmd.agent.available': "Available: ${agents}";
|
|
66
|
+
readonly 'cmd.agent.cleared': "Agent cleared for this conversation — following the global default: *${name}*";
|
|
67
|
+
readonly 'cmd.agent.clearedNoGlobal': "Agent cleared for this conversation — no global default, running `main`.";
|
|
68
|
+
readonly 'cmd.agent.globalUsage': "Usage: `!agent global <name>` · `!agent global off`";
|
|
69
|
+
readonly 'cmd.agent.followGlobalButton': "Follow global";
|
|
59
70
|
readonly 'cmd.channel.noProjects': "No projects found.";
|
|
60
71
|
readonly 'cmd.channel.projectsHeader': "*Projects*\n${list}";
|
|
61
72
|
readonly 'cmd.channel.registeredNotification': "Registered for `${project}` task notifications.";
|
|
@@ -55,10 +55,21 @@ export const commandsEn = {
|
|
|
55
55
|
'cmd.skills.localGroup': '.claude/skills',
|
|
56
56
|
'cmd.agent.defaultSet': 'Default agent set to *${name}* (${detail})',
|
|
57
57
|
'cmd.agent.disabled': 'Default agent disabled.',
|
|
58
|
-
'cmd.agent.disableButton': 'Disable',
|
|
59
58
|
'cmd.agent.current': 'Default agent: *${name}* (${detail})',
|
|
60
59
|
'cmd.agent.none': 'No default agent set.\nAvailable: ${agents}',
|
|
61
60
|
'cmd.agent.unknown': 'Unknown agent: `${name}`\nAvailable: ${available}',
|
|
61
|
+
'cmd.agent.channelSet': 'Agent for this conversation set to *${name}* (${detail}). Takes effect on the next message.',
|
|
62
|
+
'cmd.agent.crossBackendBlocked': 'Can\'t switch to *${name}* — it pins a profile on the `${target}` backend but this conversation is on `${current}`. Backends can\'t be swapped mid-conversation. Start a new session (`!new`) to switch backend.',
|
|
63
|
+
'cmd.agent.channelHeader': 'Agent for this conversation: *${name}* (${detail})',
|
|
64
|
+
'cmd.agent.followingGlobal': 'This conversation follows the global default: *${name}*',
|
|
65
|
+
'cmd.agent.followingGlobalNone': 'This conversation follows the global default, which is unset (running `main`).',
|
|
66
|
+
'cmd.agent.globalLine': 'Global default: *${name}*',
|
|
67
|
+
'cmd.agent.globalNone': 'Global default: none',
|
|
68
|
+
'cmd.agent.available': 'Available: ${agents}',
|
|
69
|
+
'cmd.agent.cleared': 'Agent cleared for this conversation — following the global default: *${name}*',
|
|
70
|
+
'cmd.agent.clearedNoGlobal': 'Agent cleared for this conversation — no global default, running `main`.',
|
|
71
|
+
'cmd.agent.globalUsage': 'Usage: `!agent global <name>` · `!agent global off`',
|
|
72
|
+
'cmd.agent.followGlobalButton': 'Follow global',
|
|
62
73
|
// --- channel (projects/register/unregister/project-dir) ---
|
|
63
74
|
'cmd.channel.noProjects': 'No projects found.',
|
|
64
75
|
'cmd.channel.projectsHeader': '*Projects*\n${list}',
|
|
@@ -422,10 +433,21 @@ export const commandsZh = {
|
|
|
422
433
|
'cmd.skills.localGroup': '.claude/skills',
|
|
423
434
|
'cmd.agent.defaultSet': '默认 agent 已设为 *${name}*(${detail})',
|
|
424
435
|
'cmd.agent.disabled': '默认 agent 已禁用。',
|
|
425
|
-
'cmd.agent.disableButton': '禁用',
|
|
426
436
|
'cmd.agent.current': '默认 agent:*${name}*(${detail})',
|
|
427
437
|
'cmd.agent.none': '未设置默认 agent。\n可用:${agents}',
|
|
428
438
|
'cmd.agent.unknown': '未知 agent:`${name}`\n可用:${available}',
|
|
439
|
+
'cmd.agent.channelSet': '本对话的 agent 已设为 *${name}*(${detail}),下一条消息生效。',
|
|
440
|
+
'cmd.agent.crossBackendBlocked': '无法切换到 *${name}* —— 它钉死的配置使用 `${target}` backend,而当前对话在 `${current}` 上。对话进行中不能切换 backend。请开启新会话(`!new`)后再切换。',
|
|
441
|
+
'cmd.agent.channelHeader': '本对话的 agent:*${name}*(${detail})',
|
|
442
|
+
'cmd.agent.followingGlobal': '本对话跟随全局默认:*${name}*',
|
|
443
|
+
'cmd.agent.followingGlobalNone': '本对话跟随全局默认,而全局未设置(使用 `main`)。',
|
|
444
|
+
'cmd.agent.globalLine': '全局默认:*${name}*',
|
|
445
|
+
'cmd.agent.globalNone': '全局默认:无',
|
|
446
|
+
'cmd.agent.available': '可用:${agents}',
|
|
447
|
+
'cmd.agent.cleared': '已清除本对话的 agent —— 跟随全局默认:*${name}*',
|
|
448
|
+
'cmd.agent.clearedNoGlobal': '已清除本对话的 agent —— 全局未设置默认,使用 `main`。',
|
|
449
|
+
'cmd.agent.globalUsage': '用法:`!agent global <name>` · `!agent global off`',
|
|
450
|
+
'cmd.agent.followGlobalButton': '跟随全局',
|
|
429
451
|
// --- channel ---
|
|
430
452
|
'cmd.channel.noProjects': '未找到项目。',
|
|
431
453
|
'cmd.channel.projectsHeader': '*项目*\n${list}',
|
|
@@ -2,5 +2,7 @@ export declare const startupEn: {
|
|
|
2
2
|
readonly 'startup.started': "Cortex agent v${version} started on ${machine}.";
|
|
3
3
|
readonly 'startup.restarted': "Cortex agent v${version} restarted on ${machine}.";
|
|
4
4
|
readonly 'startup.reason': " Reason: ${reason}.";
|
|
5
|
+
readonly 'startup.rebuildHold': "Cortex is rebuilding itself (${phase}) and is about to restart, so this message was not processed. Send it again in a moment.";
|
|
6
|
+
readonly 'startup.rebuildHoldDropped': "A message for ${channel} arrived during the rebuild (${phase}) and was not processed: ${preview}";
|
|
5
7
|
};
|
|
6
8
|
export declare const startupZh: Record<keyof typeof startupEn, string>;
|
|
@@ -6,9 +6,13 @@ export const startupEn = {
|
|
|
6
6
|
'startup.started': 'Cortex agent v${version} started on ${machine}.',
|
|
7
7
|
'startup.restarted': 'Cortex agent v${version} restarted on ${machine}.',
|
|
8
8
|
'startup.reason': ' Reason: ${reason}.',
|
|
9
|
+
'startup.rebuildHold': 'Cortex is rebuilding itself (${phase}) and is about to restart, so this message was not processed. Send it again in a moment.',
|
|
10
|
+
'startup.rebuildHoldDropped': 'A message for ${channel} arrived during the rebuild (${phase}) and was not processed: ${preview}',
|
|
9
11
|
};
|
|
10
12
|
export const startupZh = {
|
|
11
13
|
'startup.started': 'Cortex 代理 v${version} 已在 ${machine} 上启动。',
|
|
12
14
|
'startup.restarted': 'Cortex 代理 v${version} 已在 ${machine} 上重启。',
|
|
13
15
|
'startup.reason': ' 原因:${reason}。',
|
|
16
|
+
'startup.rebuildHold': 'Cortex 正在热重建(${phase})并即将重启,这条消息没有被处理。请稍后重发。',
|
|
17
|
+
'startup.rebuildHoldDropped': '重建期间(${phase})收到一条发往 ${channel} 的消息,未被处理:${preview}',
|
|
14
18
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Where the supervisor publishes its pipeline state. */
|
|
2
|
+
export declare const REBUILD_PROGRESS_FILE: string;
|
|
3
|
+
/** The pipeline's fixed step vocabulary. `install` covers both install paths (fast sync vs
|
|
4
|
+
* pack + `npm install -g`); which one ran is in the step's `detail`. */
|
|
5
|
+
export type RebuildStepName = 'server' | 'ui-contract' | 'web' | 'install' | 'restart';
|
|
6
|
+
export type RebuildStepStatus = 'pending' | 'running' | 'done' | 'failed' | 'skipped';
|
|
7
|
+
export interface RebuildStepState {
|
|
8
|
+
name: RebuildStepName;
|
|
9
|
+
status: RebuildStepStatus;
|
|
10
|
+
/** Free-text qualifier for a finished step ('fast', 'pack + install -g', 'exit 1'). */
|
|
11
|
+
detail: string | null;
|
|
12
|
+
startedAt: string | null;
|
|
13
|
+
endedAt: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** `deferred` is a pipeline that built successfully and then stopped short of touching the running
|
|
16
|
+
* process because app.ts was mid-turn: the install replaces the files that process loaded and the
|
|
17
|
+
* restart kills it, so both wait for idle. The whole pipeline runs again from the top then. */
|
|
18
|
+
export type RebuildStatus = 'running' | 'succeeded' | 'aborted' | 'deferred';
|
|
19
|
+
export interface RebuildProgress {
|
|
20
|
+
status: RebuildStatus;
|
|
21
|
+
/** What triggered the pipeline, verbatim from the watcher ('src change: core/foo.ts'). */
|
|
22
|
+
reason: string;
|
|
23
|
+
/** The step in flight, or null once terminal. */
|
|
24
|
+
current: RebuildStepName | null;
|
|
25
|
+
steps: RebuildStepState[];
|
|
26
|
+
startedAt: string;
|
|
27
|
+
updatedAt: string;
|
|
28
|
+
endedAt: string | null;
|
|
29
|
+
/** Why it ended the way it did — the operator notice's words for an abort, what is still owed for
|
|
30
|
+
* a deferral. Null while running and for a plain success. */
|
|
31
|
+
detail: string | null;
|
|
32
|
+
/** The supervisor that owns this record. Lets a reader discard a record left `running` by a
|
|
33
|
+
* daemon that is no longer alive. */
|
|
34
|
+
daemonPid: number;
|
|
35
|
+
}
|
|
36
|
+
/** A step list in pipeline order. `names` comes from the caller because which packages exist is
|
|
37
|
+
* a property of the checkout, not of this module. */
|
|
38
|
+
export declare function planRebuildProgress(p: {
|
|
39
|
+
reason: string;
|
|
40
|
+
names: RebuildStepName[];
|
|
41
|
+
daemonPid: number;
|
|
42
|
+
now?: () => Date;
|
|
43
|
+
}): RebuildProgress;
|
|
44
|
+
/** Mark a step as in flight. A step that is not in the plan is ignored rather than invented —
|
|
45
|
+
* the plan is what the reader renders a total from. */
|
|
46
|
+
export declare function startRebuildStep(progress: RebuildProgress, name: RebuildStepName, now?: () => Date): RebuildProgress;
|
|
47
|
+
/** Close a step. `status` is the step's own outcome; the pipeline's outcome is set separately,
|
|
48
|
+
* because a failed step and an aborted pipeline are recorded by different callers. */
|
|
49
|
+
export declare function finishRebuildStep(progress: RebuildProgress, name: RebuildStepName, status: Extract<RebuildStepStatus, 'done' | 'failed' | 'skipped'>, detail?: string | null, now?: () => Date): RebuildProgress;
|
|
50
|
+
/** Terminal state. Any step still `pending` becomes `skipped`, so a reader never shows a step as
|
|
51
|
+
* "waiting" for a pipeline that has stopped. */
|
|
52
|
+
export declare function settleRebuildProgress(progress: RebuildProgress, status: Extract<RebuildStatus, 'succeeded' | 'aborted' | 'deferred'>, detail?: string | null, now?: () => Date): RebuildProgress;
|
|
53
|
+
/** Read the published record, or null when there is none / it is unreadable. Never throws: a
|
|
54
|
+
* missing or corrupt progress file must not take the daemon-status query down with it. */
|
|
55
|
+
export declare function readRebuildProgress(file?: string): RebuildProgress | null;
|
|
56
|
+
/** Publish the record. Best-effort by design: losing a progress write must never abort a rebuild
|
|
57
|
+
* that is otherwise fine, so the caller gets a boolean instead of an exception. */
|
|
58
|
+
export declare function writeRebuildProgress(progress: RebuildProgress, file?: string): boolean;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Hot-rebuild progress: the supervisor's view of its own pipeline, written where the app can read it.
|
|
3
|
+
//
|
|
4
|
+
// The daemon runs build → install → restart in its own process, and the last step kills the app
|
|
5
|
+
// that would otherwise hold this state in memory. So the record lives in a file: the daemon is the
|
|
6
|
+
// only writer, `system.daemonStatus` is the only reader, and a freshly restarted app can still say
|
|
7
|
+
// what the rebuild it was born from did. The same phases go down the fork IPC channel
|
|
8
|
+
// (`entry/daemon-notice.ts`) because the turn gate needs them without waiting for a poll.
|
|
9
|
+
//
|
|
10
|
+
// Steps are planned up front and flipped in place, so the reader always knows the total and never
|
|
11
|
+
// has to guess whether a missing step is pending or skipped.
|
|
12
|
+
//
|
|
13
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
14
|
+
import * as path from 'node:path';
|
|
15
|
+
import { STORE_DIR } from './paths.js';
|
|
16
|
+
import { atomicWriteSync } from './atomic-write.js';
|
|
17
|
+
/** Where the supervisor publishes its pipeline state. */
|
|
18
|
+
export const REBUILD_PROGRESS_FILE = path.join(STORE_DIR, 'daemon-rebuild.json');
|
|
19
|
+
/** A step list in pipeline order. `names` comes from the caller because which packages exist is
|
|
20
|
+
* a property of the checkout, not of this module. */
|
|
21
|
+
export function planRebuildProgress(p) {
|
|
22
|
+
const ts = (p.now ?? (() => new Date()))().toISOString();
|
|
23
|
+
return {
|
|
24
|
+
status: 'running',
|
|
25
|
+
reason: p.reason,
|
|
26
|
+
current: null,
|
|
27
|
+
steps: p.names.map((name) => ({ name, status: 'pending', detail: null, startedAt: null, endedAt: null })),
|
|
28
|
+
startedAt: ts,
|
|
29
|
+
updatedAt: ts,
|
|
30
|
+
endedAt: null,
|
|
31
|
+
detail: null,
|
|
32
|
+
daemonPid: p.daemonPid,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function patchStep(progress, name, patch, ts) {
|
|
36
|
+
return {
|
|
37
|
+
...progress,
|
|
38
|
+
updatedAt: ts,
|
|
39
|
+
steps: progress.steps.map((step) => (step.name === name ? { ...step, ...patch } : step)),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Mark a step as in flight. A step that is not in the plan is ignored rather than invented —
|
|
43
|
+
* the plan is what the reader renders a total from. */
|
|
44
|
+
export function startRebuildStep(progress, name, now = () => new Date()) {
|
|
45
|
+
const ts = now().toISOString();
|
|
46
|
+
return { ...patchStep(progress, name, { status: 'running', startedAt: ts, endedAt: null }, ts), current: name };
|
|
47
|
+
}
|
|
48
|
+
/** Close a step. `status` is the step's own outcome; the pipeline's outcome is set separately,
|
|
49
|
+
* because a failed step and an aborted pipeline are recorded by different callers. */
|
|
50
|
+
export function finishRebuildStep(progress, name, status, detail = null, now = () => new Date()) {
|
|
51
|
+
const ts = now().toISOString();
|
|
52
|
+
const next = patchStep(progress, name, { status, detail, endedAt: ts }, ts);
|
|
53
|
+
return { ...next, current: next.current === name ? null : next.current };
|
|
54
|
+
}
|
|
55
|
+
/** Terminal state. Any step still `pending` becomes `skipped`, so a reader never shows a step as
|
|
56
|
+
* "waiting" for a pipeline that has stopped. */
|
|
57
|
+
export function settleRebuildProgress(progress, status, detail = null, now = () => new Date()) {
|
|
58
|
+
const ts = now().toISOString();
|
|
59
|
+
return {
|
|
60
|
+
...progress,
|
|
61
|
+
status,
|
|
62
|
+
current: null,
|
|
63
|
+
detail,
|
|
64
|
+
updatedAt: ts,
|
|
65
|
+
endedAt: ts,
|
|
66
|
+
steps: progress.steps.map((step) => (step.status === 'pending' ? { ...step, status: 'skipped' } : step)),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Shallow structural check. The file is machine-written, so this only has to reject a truncated
|
|
70
|
+
* or hand-edited record rather than validate every field. */
|
|
71
|
+
function isRebuildProgress(value) {
|
|
72
|
+
if (!value || typeof value !== 'object')
|
|
73
|
+
return false;
|
|
74
|
+
const v = value;
|
|
75
|
+
return typeof v.status === 'string'
|
|
76
|
+
&& typeof v.reason === 'string'
|
|
77
|
+
&& typeof v.startedAt === 'string'
|
|
78
|
+
&& Array.isArray(v.steps);
|
|
79
|
+
}
|
|
80
|
+
/** Read the published record, or null when there is none / it is unreadable. Never throws: a
|
|
81
|
+
* missing or corrupt progress file must not take the daemon-status query down with it. */
|
|
82
|
+
export function readRebuildProgress(file = REBUILD_PROGRESS_FILE) {
|
|
83
|
+
try {
|
|
84
|
+
if (!existsSync(file))
|
|
85
|
+
return null;
|
|
86
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
87
|
+
return isRebuildProgress(parsed) ? parsed : null;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Publish the record. Best-effort by design: losing a progress write must never abort a rebuild
|
|
94
|
+
* that is otherwise fine, so the caller gets a boolean instead of an exception. */
|
|
95
|
+
export function writeRebuildProgress(progress, file = REBUILD_PROGRESS_FILE) {
|
|
96
|
+
try {
|
|
97
|
+
atomicWriteSync(file, JSON.stringify(progress, null, 2));
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
1
|
+
import { statSync, watch } from 'node:fs';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
export const WATCH_FALLBACK_MS = 5_000;
|
|
5
4
|
function formatWatchError(error) {
|
|
@@ -78,9 +77,12 @@ export function createSnapshotWatchMonitor(options) {
|
|
|
78
77
|
reconcile();
|
|
79
78
|
return monitor;
|
|
80
79
|
}
|
|
80
|
+
/** Stat stamp, not a content hash: this runs per fs event and per 5s polling tick, and the
|
|
81
|
+
* callers only need "did this file change" — which mtime/ctime/size/inode answer directly. */
|
|
81
82
|
function fileStamp(filePath) {
|
|
82
83
|
try {
|
|
83
|
-
|
|
84
|
+
const stat = statSync(filePath);
|
|
85
|
+
return `${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}:${stat.ino}`;
|
|
84
86
|
}
|
|
85
87
|
catch {
|
|
86
88
|
return null;
|
|
@@ -33,6 +33,10 @@ export interface RunningExecution {
|
|
|
33
33
|
run?: SteerableRun;
|
|
34
34
|
/** Stable Cortex track session id used by registry/history/query surfaces. */
|
|
35
35
|
trackSessionId?: string | null;
|
|
36
|
+
/** An Agent-tool child. It registers on its parent's channel so channel-wide cancel reaches it,
|
|
37
|
+
* and it outlives the parent's turn, but it is not the conversation: "is this channel busy"
|
|
38
|
+
* checks must not count it. */
|
|
39
|
+
subagent?: boolean;
|
|
36
40
|
/** Backend resume target snapshot from spawn time. */
|
|
37
41
|
backendSessionId?: string | null;
|
|
38
42
|
/** Live agent-turn count of the in-flight run (adapter `turn_progress`/`turn_complete`), updated
|
|
@@ -89,6 +93,9 @@ export declare class RunRegistry {
|
|
|
89
93
|
getForegroundBySessionId(sessionId: string): RunningExecution | null;
|
|
90
94
|
/** Return all live executions registered on a channel (empty array if none). */
|
|
91
95
|
getByChannel(channel: string): RunningExecution[];
|
|
96
|
+
/** Live executions on a channel that are the channel's own work — everything except the subagent
|
|
97
|
+
* children riding on it. What a busy check means by "something is running here". */
|
|
98
|
+
getOwnByChannel(channel: string): RunningExecution[];
|
|
92
99
|
/**
|
|
93
100
|
* The newest live run registered on a channel that exposes `steer()`, or null. The run itself
|
|
94
101
|
* decides whether it can accept an injection; callers must not inspect the process.
|
|
@@ -50,6 +50,7 @@ export class RunRegistry {
|
|
|
50
50
|
trackSessionId: exec.trackSessionId ?? null,
|
|
51
51
|
backendSessionId: exec.backendSessionId ?? null,
|
|
52
52
|
numTurns: exec.numTurns ?? null,
|
|
53
|
+
subagent: exec.subagent ?? false,
|
|
53
54
|
};
|
|
54
55
|
this.byKey.set(key, entry);
|
|
55
56
|
if (entry.threadId)
|
|
@@ -133,6 +134,11 @@ export class RunRegistry {
|
|
|
133
134
|
const set = this.byChannel.get(channel);
|
|
134
135
|
return set ? Array.from(set) : [];
|
|
135
136
|
}
|
|
137
|
+
/** Live executions on a channel that are the channel's own work — everything except the subagent
|
|
138
|
+
* children riding on it. What a busy check means by "something is running here". */
|
|
139
|
+
getOwnByChannel(channel) {
|
|
140
|
+
return this.getByChannel(channel).filter((entry) => !entry.subagent);
|
|
141
|
+
}
|
|
136
142
|
/**
|
|
137
143
|
* The newest live run registered on a channel that exposes `steer()`, or null. The run itself
|
|
138
144
|
* decides whether it can accept an injection; callers must not inspect the process.
|
|
@@ -16,7 +16,23 @@ export interface StageDefinition {
|
|
|
16
16
|
continuesSession?: boolean;
|
|
17
17
|
description?: string;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
/** Setting files Claude Code may load beyond what Cortex passes explicitly (`--setting-sources`).
|
|
20
|
+
* Absent leaves the CLI's own default; `[]` loads none, which is how an agent keeps a user's
|
|
21
|
+
* `enabledPlugins` and ambient hooks out of its session. */
|
|
22
|
+
export type AgentSettingSource = 'user' | 'project' | 'local';
|
|
23
|
+
/** The environment fields an agent template owns. Every default equals the behaviour an agent that
|
|
24
|
+
* declares none of them already had, so adding the block to a definition changes nothing by itself.
|
|
25
|
+
* Mixed into {@link AgentDefinition}, {@link AgentSlotConfig} and the per-template override on
|
|
26
|
+
* {@link TemplateAgentRef}; `delegable` sits on the definition alone because it describes what the
|
|
27
|
+
* agent is rather than how one template runs it. */
|
|
28
|
+
export interface AgentEnvironment {
|
|
29
|
+
loadRules?: boolean;
|
|
30
|
+
disableHooks?: boolean;
|
|
31
|
+
skills?: boolean;
|
|
32
|
+
settingSources?: AgentSettingSource[];
|
|
33
|
+
projectContext?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface AgentDefinition extends AgentEnvironment {
|
|
20
36
|
name: string;
|
|
21
37
|
description?: string;
|
|
22
38
|
profile: string;
|
|
@@ -30,6 +46,9 @@ export interface AgentDefinition {
|
|
|
30
46
|
pluginDirs?: string[];
|
|
31
47
|
mcpComposition?: McpComposition;
|
|
32
48
|
mcpToolAllowlist?: string[];
|
|
49
|
+
/** Whether this template may be named as a subagent delegation target. Declared now so a
|
|
50
|
+
* definition can carry the intent; nothing reads it yet. */
|
|
51
|
+
delegable?: boolean;
|
|
33
52
|
/** Optional per-stage prompt map. When set, `promptTemplate` is ignored and the engine
|
|
34
53
|
* selects one stage per step based on the transition target (`"agent:stage"` syntax). */
|
|
35
54
|
stages?: Record<string, StageDefinition>;
|
|
@@ -39,7 +58,7 @@ export interface AgentDefinition {
|
|
|
39
58
|
entryStage?: string;
|
|
40
59
|
}
|
|
41
60
|
/** Template can reference an agent by name (string) or with per-template overrides (object) */
|
|
42
|
-
export type TemplateAgentRef = string | {
|
|
61
|
+
export type TemplateAgentRef = string | (AgentEnvironment & {
|
|
43
62
|
ref: string;
|
|
44
63
|
promptTemplate?: string;
|
|
45
64
|
directive?: string;
|
|
@@ -50,8 +69,8 @@ export type TemplateAgentRef = string | {
|
|
|
50
69
|
tools?: string;
|
|
51
70
|
pluginDirs?: string[];
|
|
52
71
|
mcpToolAllowlist?: string[];
|
|
53
|
-
};
|
|
54
|
-
export interface AgentSlotConfig {
|
|
72
|
+
});
|
|
73
|
+
export interface AgentSlotConfig extends AgentEnvironment {
|
|
55
74
|
slotId: AgentSlotId;
|
|
56
75
|
profile: string;
|
|
57
76
|
persistSession: boolean;
|
|
@@ -26,6 +26,9 @@ export interface ChannelOverride {
|
|
|
26
26
|
* thread is a tool for that thread, not a statement about what the next Web session should run. */
|
|
27
27
|
export interface SelectionDefault extends ChannelOverride {
|
|
28
28
|
profileName?: string;
|
|
29
|
+
/** The agent — the environment — the last composer pick ran in. Written by its own pick, never
|
|
30
|
+
* by a model/profile one: the two are independent axes and neither erases the other. */
|
|
31
|
+
agentName?: string;
|
|
29
32
|
}
|
|
30
33
|
export interface AgentState {
|
|
31
34
|
/** Globally selected profile name. `'__active__'` is init's placeholder for "use the default". */
|
|
@@ -34,6 +37,10 @@ export interface AgentState {
|
|
|
34
37
|
channelProfiles: Record<string, string>;
|
|
35
38
|
/** Thread agent applied to plain messages when no agent is named. */
|
|
36
39
|
defaultAgent: string | null;
|
|
40
|
+
/** Per-channel agent selection; beats `defaultAgent` for that channel. The agent is the
|
|
41
|
+
* conversation's ENVIRONMENT (prompt, tools, skills, rules), the twin of `channelProfiles`
|
|
42
|
+
* on the model axis — which is why the two maps are separate and neither writes the other. */
|
|
43
|
+
channelAgents: Record<string, string>;
|
|
37
44
|
/** Per-channel knobs layered on top of the resolved profile. */
|
|
38
45
|
channelOverrides: Record<string, ChannelOverride>;
|
|
39
46
|
/** Seed for the next conversation's composer — see {@link SelectionDefault}. */
|