@cortex-agent/server 2026.9.15 → 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/README.md +3 -2
- package/defaults/config/hooks/08-agents-md-injector-post-tool.json +10 -0
- package/defaults/config/hooks/{10-cortex-md-injector-session-start.json → 10-agents-md-injector-session-start.json} +3 -3
- package/defaults/config/hooks/{CORTEX.md → AGENTS.md} +2 -2
- package/defaults/config/thread-templates/agents/creative.json +17 -0
- package/defaults/hooks/{CORTEX.md → AGENTS.md} +1 -1
- package/defaults/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
- package/defaults/hooks/cortex-hook-api.mjs +2 -2
- package/defaults/hooks/new-session-hook.mjs +2 -2
- package/defaults/hooks/rules-loader.mjs +2 -2
- package/defaults/hooks/status-md-guard.mjs +8 -8
- package/defaults/hooks/task-status-check.mjs +18 -76
- package/defaults/hooks/tasks-yaml-guard.mjs +2 -2
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +2 -2
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
- package/defaults/plugins/cortex-system/skills/task/SKILL.md +1 -1
- package/defaults/prompts/systemPrompts/creative.md +13 -0
- package/defaults/prompts/systemPrompts/direct.md +1 -1
- package/defaults/rules/{cortex-md.md → agents-md.md} +4 -4
- package/defaults/rules/decision-records.md +1 -1
- package/defaults/rules/meta-conventions.md +4 -4
- package/defaults/rules/mission-md.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/hooks-builder.js +2 -2
- package/dist/agent-adapter/claude/spawn-args.d.ts +7 -0
- package/dist/agent-adapter/claude/spawn-args.js +14 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +11 -0
- package/dist/agent-adapter/claude/turn-machine.js +46 -5
- package/dist/agent-adapter/normalize/prompt-builder.d.ts +16 -1
- package/dist/agent-adapter/normalize/prompt-builder.js +24 -6
- 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 +6 -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/mcp-tool-gate.js +1 -0
- package/dist/core/media-types.d.ts +10 -0
- package/dist/core/media-types.js +34 -0
- package/dist/core/platform-settings-spec.js +1 -1
- 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/settings-spec.d.ts +21 -0
- package/dist/core/settings-spec.js +28 -1
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/types/thread-types.d.ts +23 -4
- package/dist/core/utils.d.ts +1 -1
- package/dist/core/utils.js +1 -1
- 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 +3 -2
- package/dist/domain/executions/registry.js +84 -10
- package/dist/domain/mcp/bundled-server.js +4 -3
- package/dist/domain/mcp/feishu/file.js +37 -18
- package/dist/domain/mcp/feishu/types.d.ts +3 -0
- package/dist/domain/mcp/feishu-server.js +1 -1
- package/dist/domain/mcp/tools/{cortex-md.d.ts → agents-md.d.ts} +6 -6
- package/dist/domain/mcp/tools/{cortex-md.js → agents-md.js} +6 -6
- package/dist/domain/mcp/tools/remote-file.d.ts +20 -0
- package/dist/domain/mcp/tools/remote-file.js +44 -0
- package/dist/domain/mcp/tools/slack.d.ts +2 -0
- package/dist/domain/mcp/tools/slack.js +22 -7
- package/dist/domain/mcp/tools/task-ops.js +5 -13
- package/dist/domain/mcp/tools/ui-file.js +23 -10
- package/dist/domain/mcp/tools/waitpoint.d.ts +3 -0
- package/dist/domain/mcp/tools/waitpoint.js +122 -0
- package/dist/domain/memory/agents-md-injector.d.ts +24 -0
- package/dist/domain/memory/{cortex-md-injector.js → agents-md-injector.js} +10 -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/projects/project-store.d.ts +1 -1
- package/dist/domain/projects/project-store.js +3 -3
- 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 +30 -24
- package/dist/domain/remote/client-manager.js +39 -119
- package/dist/domain/remote/cortex-client-config.d.ts +1 -1
- package/dist/domain/remote/cortex-client-config.js +1 -1
- package/dist/domain/remote/device-file.d.ts +51 -0
- package/dist/domain/remote/device-file.js +193 -0
- package/dist/domain/remote/device-port.js +3 -0
- package/dist/domain/remote/reverse-stream.d.ts +18 -7
- package/dist/domain/remote/reverse-stream.js +19 -6
- 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/claim-recovery.js +2 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +10 -1
- package/dist/domain/tasks/dispatch-utils.js +46 -1
- package/dist/domain/tasks/dispatcher.js +4 -5
- package/dist/domain/tasks/mutator.d.ts +2 -2
- package/dist/domain/tasks/mutator.js +62 -61
- package/dist/domain/tasks/system/task-cli.js +2 -2
- 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 +20 -3
- 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 +10 -4
- 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 +34 -3
- package/dist/domain/ui-service/app-router.js +9 -14
- package/dist/domain/ui-service/input-schemas.d.ts +28 -5
- package/dist/domain/ui-service/input-schemas.js +24 -9
- package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
- package/dist/domain/ui-service/mutate/sessions.d.ts +6 -1
- package/dist/domain/ui-service/mutate/sessions.js +54 -0
- package/dist/domain/ui-service/mutate/tasks.js +4 -3
- package/dist/domain/ui-service/mutate/waitpoints.d.ts +2 -0
- package/dist/domain/ui-service/mutate/waitpoints.js +20 -0
- package/dist/domain/ui-service/platform-settings.js +1 -1
- package/dist/domain/ui-service/plugins-shared.js +1 -1
- package/dist/domain/ui-service/query/config.js +20 -2
- package/dist/domain/ui-service/query/executions.js +0 -2
- package/dist/domain/ui-service/query/machine-detail.js +3 -8
- package/dist/domain/ui-service/query/memory.js +29 -35
- package/dist/domain/ui-service/query/sessions.js +96 -12
- package/dist/domain/ui-service/query/system.js +19 -0
- package/dist/domain/ui-service/query/threads.js +1 -54
- package/dist/domain/ui-service/query/waitpoints.d.ts +30 -0
- package/dist/domain/ui-service/query/waitpoints.js +117 -0
- package/dist/domain/ui-service/query-input-schemas.d.ts +4 -0
- package/dist/domain/ui-service/query-input-schemas.js +5 -0
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +229 -51
- package/dist/domain/ui-service/types.js +1 -1
- package/dist/domain/ui-service/ui-service.js +8 -31
- package/dist/domain/waitpoints/notices.d.ts +21 -0
- package/dist/domain/waitpoints/notices.js +115 -0
- package/dist/domain/waitpoints/service.d.ts +91 -0
- package/dist/domain/waitpoints/service.js +243 -0
- package/dist/entry/app.js +52 -11
- package/dist/entry/auth-login-cli.js +1 -1
- package/dist/entry/auth-login-terminal.js +1 -1
- 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/entry/init-auth.js +1 -1
- package/dist/entry/init.js +6 -6
- package/dist/entry/signal-cli.d.ts +30 -0
- package/dist/entry/signal-cli.js +207 -0
- package/dist/entry/start-ui-http.d.ts +1 -1
- package/dist/entry/start-ui-http.js +2 -2
- package/dist/events/event-types.d.ts +0 -7
- package/dist/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
- package/dist/hooks/cortex-hook-api.mjs +2 -2
- package/dist/hooks/new-session-hook.mjs +2 -2
- package/dist/hooks/rules-loader.mjs +2 -2
- package/dist/hooks/status-md-guard.mjs +8 -8
- package/dist/hooks/task-status-check.mjs +18 -76
- package/dist/hooks/tasks-yaml-guard.mjs +2 -2
- package/dist/orchestration/agent-file-send.d.ts +9 -0
- package/dist/orchestration/agent-file-send.js +21 -2
- package/dist/orchestration/agent-runner.d.ts +3 -2
- package/dist/orchestration/agent-runner.js +33 -12
- package/dist/orchestration/attachments-store.d.ts +31 -0
- package/dist/orchestration/attachments-store.js +184 -0
- package/dist/orchestration/conversation-request.d.ts +37 -0
- package/dist/orchestration/conversation-request.js +91 -22
- package/dist/orchestration/interactions/plan-approvals.js +1 -1
- package/dist/orchestration/mid-turn-inject.d.ts +3 -0
- package/dist/orchestration/mid-turn-inject.js +9 -4
- package/dist/orchestration/outputs-store.d.ts +11 -0
- package/dist/orchestration/outputs-store.js +32 -6
- package/dist/orchestration/resume-dispatcher.js +4 -2
- package/dist/orchestration/routing/commands/mode.js +114 -63
- package/dist/orchestration/routing/file-handler.d.ts +23 -2
- package/dist/orchestration/routing/file-handler.js +22 -5
- package/dist/orchestration/routing/webhook.js +193 -39
- package/dist/orchestration/session-gateway.d.ts +1 -1
- package/dist/orchestration/session-gateway.js +1 -0
- package/dist/orchestration/thread-executor.d.ts +2 -0
- package/dist/orchestration/thread-executor.js +24 -1
- package/dist/orchestration/thread-input.d.ts +3 -2
- package/dist/orchestration/thread-input.js +8 -9
- package/dist/orchestration/turn/turn-prep.d.ts +15 -1
- package/dist/orchestration/turn/turn-prep.js +19 -8
- package/dist/orchestration/turn/turn.js +1 -0
- package/dist/orchestration/waitpoint-ingress.d.ts +41 -0
- package/dist/orchestration/waitpoint-ingress.js +172 -0
- package/dist/orchestration/waitpoint-notifier.d.ts +21 -0
- package/dist/orchestration/waitpoint-notifier.js +119 -0
- package/dist/orchestration/waitpoint-remote-drain.d.ts +20 -0
- package/dist/orchestration/waitpoint-remote-drain.js +147 -0
- package/dist/orchestration/waitpoint-sweep.d.ts +42 -0
- package/dist/orchestration/waitpoint-sweep.js +87 -0
- package/dist/platform/adapters/feishu-image.d.ts +19 -0
- package/dist/platform/adapters/feishu-image.js +71 -0
- package/dist/platform/adapters/feishu.d.ts +2 -0
- package/dist/platform/adapters/feishu.js +26 -16
- package/dist/platform/ui-http/listening-ports.d.ts +1 -1
- package/dist/platform/ui-http/listening-ports.js +1 -1
- package/dist/platform/ui-http/ui-session.js +1 -1
- 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/conversation-ledger-repo.js +1 -1
- package/dist/store/execution-repo.d.ts +1 -19
- package/dist/store/execution-repo.js +1 -18
- package/dist/store/project-notes-repo.js +11 -2
- package/dist/store/prompt-migration-replacements.js +1 -1
- package/dist/store/session-registry-import.js +1 -1
- package/dist/store/session-registry-journal.d.ts +4 -0
- package/dist/store/session-registry-journal.js +5 -1
- package/dist/store/session-registry-repo.d.ts +2 -1
- package/dist/store/session-registry-repo.js +3 -1
- package/dist/store/task-repo.d.ts +6 -3
- package/dist/store/task-repo.js +26 -10
- package/dist/store/version-migrations.d.ts +13 -3
- package/dist/store/version-migrations.js +254 -24
- package/dist/store/waitpoint-repo.d.ts +108 -0
- package/dist/store/waitpoint-repo.js +94 -0
- package/package.json +3 -2
- package/web/dist/AGENTS.md +10 -0
- package/web/dist/assets/index-B1dBi8Za.css +1 -0
- package/web/dist/assets/{index-CEZ0DSei.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/defaults/config/hooks/08-cortex-md-injector-post-tool.json +0 -10
- package/dist/domain/executions/log-tailer.d.ts +0 -71
- package/dist/domain/executions/log-tailer.js +0 -194
- package/dist/domain/memory/cortex-md-injector.d.ts +0 -24
- package/dist/domain/memory/cortex-md-scanner.d.ts +0 -10
- package/dist/domain/memory/cortex-md-scanner.js +0 -66
- package/dist/domain/remote/cortex-client.d.ts +0 -1
- package/dist/domain/remote/cortex-client.js +0 -662
- package/dist/domain/tasks/system/cortex-run.d.ts +0 -25
- package/dist/domain/tasks/system/cortex-run.js +0 -360
- package/web/dist/assets/index-CRDJo39X.css +0 -1
- package/web/dist/assets/index-DjuPJVZE.js +0 -444
- /package/defaults/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/config/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/ideas/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/projects/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/scans/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/user/{CORTEX.md → AGENTS.md} +0 -0
|
@@ -6,7 +6,7 @@ import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
|
6
6
|
import { Type } from '@sinclair/typebox';
|
|
7
7
|
import { createLogger } from '../../core/log.js';
|
|
8
8
|
import { MCP_INFRASTRUCTURE_TIMEOUT_MS } from '../../core/mcp-timeout.js';
|
|
9
|
-
import { MCP_TOOL_ALLOWLIST_ENV,
|
|
9
|
+
import { MCP_TOOL_ALLOWLIST_ENV, parseMcpToolAllowlist, withoutSubagentTools, } from '../../core/mcp-tool-gate.js';
|
|
10
10
|
import { createRedirectRejectingFetch } from '../mcp-remote-fetch.js';
|
|
11
11
|
import { mapMcpContent, shouldLoadFeishu, shouldLoadSlack, shouldLoadThreadControl, shouldLoadWeb, } from './mcp-bridge-logic.js';
|
|
12
12
|
import { PI_INTERACTION_BRIDGE_ENV, PI_MCP_COMPOSITION_ENV, } from './session-options.js';
|
|
@@ -68,13 +68,13 @@ function assertUniqueServerStateNames(states) {
|
|
|
68
68
|
return states;
|
|
69
69
|
}
|
|
70
70
|
function validateToolGatedStates(env, states) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
// `parseMcpToolAllowlist` already rejects a name that exists in no bundle at all — that is the
|
|
72
|
+
// typo check, and it is the only one worth making. A name that exists but belongs to a bundle
|
|
73
|
+
// this session does not compose (`send_file` outside a web session) is simply absent here: an
|
|
74
|
+
// allowlist is an upper bound on the surface, not a demand for it, and the gate drops what it
|
|
75
|
+
// cannot register. Validating against the COMPOSED bundles used to turn "this agent also
|
|
76
|
+
// delivers files on the web" into "this agent may not run on Slack".
|
|
77
|
+
parseMcpToolAllowlist(env[MCP_TOOL_ALLOWLIST_ENV]);
|
|
78
78
|
return states;
|
|
79
79
|
}
|
|
80
80
|
function optionalBundles(env) {
|
|
@@ -291,6 +291,11 @@ export class PISession {
|
|
|
291
291
|
handleRawEvent(event) {
|
|
292
292
|
if (!this.alive)
|
|
293
293
|
return;
|
|
294
|
+
// A backgrounded child can settle after the turn that spawned it. With no turn open there is
|
|
295
|
+
// no run to file its spend under, and folding it into the parser's pending total would bill it
|
|
296
|
+
// to whichever turn comes next — so it is left unaccounted, as it was before children reported.
|
|
297
|
+
if (event.type === 'cortex_subagent_usage' && this.turnStream === null)
|
|
298
|
+
return;
|
|
294
299
|
this.resetIdleTimer();
|
|
295
300
|
this.bumpTurnIdleTimer();
|
|
296
301
|
this.observeLoop(event);
|
|
@@ -113,6 +113,9 @@ export async function createPiRuntime(request, callbacks, collaborators = {}) {
|
|
|
113
113
|
onProviderQuota: callbacks.onProviderQuota,
|
|
114
114
|
// A subagent's events reach the parent's stream as one raw record per event, no codec in between.
|
|
115
115
|
onSubagentEvent: (notice) => callbacks.onEvent({ type: 'cortex_subagent_event', notice }),
|
|
116
|
+
// Spend travels its own record rather than riding the transcript channel: the parser turns it
|
|
117
|
+
// into a cost_record, and the transcript never renders it.
|
|
118
|
+
onSubagentUsage: (report) => callbacks.onEvent({ type: 'cortex_subagent_usage', report }),
|
|
116
119
|
});
|
|
117
120
|
const sessionManager = openSessionManager(sdk, request);
|
|
118
121
|
const runtime = await sdk.createAgentSessionRuntime(runtimeFactory(sdk, request, extensions), {
|
|
@@ -146,7 +146,11 @@ export function buildSessionRequest(spec, inputs) {
|
|
|
146
146
|
thinking: thinkingLevel(spec),
|
|
147
147
|
systemPrompt: spec.prompt.system || null,
|
|
148
148
|
appendSystemPrompt: promptValues(spec.prompt.append),
|
|
149
|
-
|
|
149
|
+
// PI has no skill layer of its own to switch off: its skills are exactly the roots handed to
|
|
150
|
+
// it here, so an agent that wants none gets none by handing it nothing.
|
|
151
|
+
skillPaths: spec.flags.disableSkills
|
|
152
|
+
? []
|
|
153
|
+
: [...(spec.plugins.skillDirs ?? []), ...(spec.plugins.dirs ?? [])],
|
|
150
154
|
disableHooks: spec.flags.disableHooks === true,
|
|
151
155
|
reportsProviderQuota: !!spec.route.gatewayBaseUrl,
|
|
152
156
|
pluginMcpServers: pluginMcpServers(spec, composition, marker),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { InlineExtension, ToolDefinition } from '@earendil-works/pi-coding-agent';
|
|
2
2
|
import { type AgentRole } from '../../core/agents/roles.js';
|
|
3
3
|
import { type SubagentCatalog, type SubagentFieldDescriptions } from '../../core/agents/subagent/catalog.js';
|
|
4
|
-
import type { SubagentDetails, SubagentResult, SubagentTask } from '../../core/agents/subagent/types.js';
|
|
4
|
+
import type { SubagentDetails, SubagentResult, SubagentTask, SubagentUsage } from '../../core/agents/subagent/types.js';
|
|
5
5
|
import type { Backend } from '../types.js';
|
|
6
6
|
import type { ChildSessionFactory } from './child-session.js';
|
|
7
7
|
import type { StartBackgroundSubagent, StopBackgroundSubagent } from './background-subagent.js';
|
|
@@ -60,6 +60,13 @@ export interface ForeignSubagentRequest {
|
|
|
60
60
|
onNotice?: (notice: SubagentNotice) => void;
|
|
61
61
|
}
|
|
62
62
|
export type RunForeignSubagent = (request: ForeignSubagentRequest) => Promise<SubagentResult>;
|
|
63
|
+
/** One nested PI child's spend, handed to the host when that child ends. The ledger's unit is the
|
|
64
|
+
* child, not the message: a run of eight children files eight records, each naming who answered. */
|
|
65
|
+
export interface SubagentUsageReport {
|
|
66
|
+
provider: string;
|
|
67
|
+
model: string;
|
|
68
|
+
usage: SubagentUsage;
|
|
69
|
+
}
|
|
63
70
|
export interface SubagentToolDeps {
|
|
64
71
|
/** PI agent dir whose auth/models the `pi` children use. */
|
|
65
72
|
agentDir: string;
|
|
@@ -68,12 +75,17 @@ export interface SubagentToolDeps {
|
|
|
68
75
|
ensureRoles(): void;
|
|
69
76
|
/** Creates one nested in-process PI session per `pi` child. */
|
|
70
77
|
createSession: ChildSessionFactory;
|
|
71
|
-
/** The Cortex extensions a child session runs with, closed over the child's env
|
|
72
|
-
|
|
78
|
+
/** The Cortex extensions a child session runs with, closed over the child's env and the provider
|
|
79
|
+
* the child declared (null when only PI's resolver will know it). */
|
|
80
|
+
childExtensions: (env: NodeJS.ProcessEnv, childProvider: string | null) => InlineExtension[];
|
|
73
81
|
/** The parent session's env; each child's env is derived from it. */
|
|
74
82
|
parentEnv: NodeJS.ProcessEnv;
|
|
75
83
|
/** Receives every forwarded child event for the parent's transcript. Absent: no attribution. */
|
|
76
84
|
onEvent?: (notice: SubagentNotice) => void;
|
|
85
|
+
/** Receives each finished nested PI child's spend so it reaches the cost ledger. Absent: the
|
|
86
|
+
* child's tokens stay in the tool result and are never accounted. Children on another backend
|
|
87
|
+
* are not reported here: the daemon runner records those as runs of their own. */
|
|
88
|
+
onUsage?: (report: SubagentUsageReport) => void;
|
|
77
89
|
/** Runs children whose backend is not `pi`. Absent: such a task is an error, not a silent
|
|
78
90
|
* downgrade — a role asking for `claude` must not quietly answer from a PI model. */
|
|
79
91
|
runForeignSubagent?: RunForeignSubagent;
|
|
@@ -45,6 +45,22 @@ function buildSubagentParameters(described) {
|
|
|
45
45
|
const StopParameters = Type.Object({
|
|
46
46
|
agent_id: Type.String({ description: 'The agent_id returned when the subagent was started.' }),
|
|
47
47
|
});
|
|
48
|
+
/**
|
|
49
|
+
* Hand a nested PI child's spend to the host, once, as the child ends.
|
|
50
|
+
*
|
|
51
|
+
* Reported only when the child's own messages named the provider that answered: without one the
|
|
52
|
+
* ledger has nowhere honest to file the record, and a child that never reached a provider spent
|
|
53
|
+
* nothing to file. An aborted child files nothing — its accumulator dies with the cancelled run.
|
|
54
|
+
* Best-effort by contract: accounting must never fail a subagent that already did its work.
|
|
55
|
+
*/
|
|
56
|
+
function reportChildUsage(deps, result) {
|
|
57
|
+
if (!deps.onUsage || !result.provider || result.usage.turns === 0)
|
|
58
|
+
return;
|
|
59
|
+
try {
|
|
60
|
+
deps.onUsage({ provider: result.provider, model: result.model ?? '', usage: result.usage });
|
|
61
|
+
}
|
|
62
|
+
catch { /* best-effort */ }
|
|
63
|
+
}
|
|
48
64
|
function fallbackModel(ctx) {
|
|
49
65
|
return ctx.model ? { id: ctx.model.id, provider: ctx.model.provider } : null;
|
|
50
66
|
}
|
|
@@ -74,6 +90,8 @@ function buildRunChild(ctx, deps, roles, parentToolCallId) {
|
|
|
74
90
|
childExtensions: deps.childExtensions, signal, forward,
|
|
75
91
|
})
|
|
76
92
|
: await runForeignChild(ctx, deps, task, role, backend, ref, signal);
|
|
93
|
+
if (backend === 'pi')
|
|
94
|
+
reportChildUsage(deps, result);
|
|
77
95
|
seal(endStatusOf(result));
|
|
78
96
|
return result;
|
|
79
97
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import type { ExtensionAPI, InlineExtension } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { CodexQuotaReading } from '../../core/codex-quota.js';
|
|
2
3
|
import { type ChildSessionFactory } from './child-session.js';
|
|
3
4
|
import type { SubagentNotice } from './event-parser.js';
|
|
4
5
|
import { type OpenBundledMcpServer } from './mcp-bridge.js';
|
|
5
6
|
import type { StartBackgroundSubagent, StopBackgroundSubagent } from './background-subagent.js';
|
|
6
|
-
import { type RunForeignSubagent } from './subagent.js';
|
|
7
|
+
import { type RunForeignSubagent, type SubagentUsageReport } from './subagent.js';
|
|
7
8
|
export interface ToolShimHooks {
|
|
8
9
|
/** Receives each event a subagent forwards for the parent's transcript. */
|
|
9
10
|
onSubagentEvent?: (notice: SubagentNotice) => void;
|
|
11
|
+
/** Reports provider quota read off a nested child's responses; set only for runs that report it. */
|
|
12
|
+
onProviderQuota?: (reading: CodexQuotaReading) => void;
|
|
13
|
+
/** Receives each finished nested PI child's spend, for the cost ledger. */
|
|
14
|
+
onSubagentUsage?: (report: SubagentUsageReport) => void;
|
|
10
15
|
/** Nested session factory for subagents; tests substitute a fake. */
|
|
11
16
|
createChildSession?: ChildSessionFactory;
|
|
12
17
|
/** Runs children whose backend is not `pi`. Supplied by the host (D10); absent ⇒ the `agent`
|
|
@@ -5,6 +5,7 @@ import { loadRoles } from '../../core/agents/roles.js';
|
|
|
5
5
|
import { claudeModelOptions, decodeSubagentModels, piModelOptions, roleOptionsFrom, } from '../../core/agents/subagent/catalog.js';
|
|
6
6
|
import { createChildSession } from './child-session.js';
|
|
7
7
|
import { createMcpBridgeDeps, installMcpBridge, } from './mcp-bridge.js';
|
|
8
|
+
import { createQuotaProbe } from './quota-probe.js';
|
|
8
9
|
import { createSubagentStopTool, createSubagentTool, } from './subagent.js';
|
|
9
10
|
import { webFetchTool } from './web-fetch.js';
|
|
10
11
|
import { webSearchTool } from './web-search.js';
|
|
@@ -79,21 +80,53 @@ export function childExtensions(env, openBundledMcpServer) {
|
|
|
79
80
|
},
|
|
80
81
|
];
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The quota probe a nested child session runs with, or null when the child must not report.
|
|
85
|
+
*
|
|
86
|
+
* The host labels every reading with the provider *this run* was routed as (the adapter's
|
|
87
|
+
* `quotaReporter`), so a child that reached a different provider would have its quota filed under
|
|
88
|
+
* the parent's — throttling a provider that never produced the reading. A child's provider is only
|
|
89
|
+
* known here when it inherited the session's model outright; the moment a role or task names a
|
|
90
|
+
* model, PI's resolver picks the provider later and this side cannot prove they match. So the
|
|
91
|
+
* probe goes on inheriting children only, and an overridden child simply reports nothing.
|
|
92
|
+
*
|
|
93
|
+
* One extension serves every child: PI hands each bound session its own `pi`, so a single factory
|
|
94
|
+
* registers one listener per child rather than sharing state between them.
|
|
95
|
+
*/
|
|
96
|
+
function childQuotaProbe(hooks) {
|
|
97
|
+
if (!hooks.onProviderQuota)
|
|
98
|
+
return () => null;
|
|
99
|
+
const extension = {
|
|
100
|
+
name: 'cortex-quota-probe',
|
|
101
|
+
factory: createQuotaProbe(hooks.onProviderQuota),
|
|
102
|
+
};
|
|
103
|
+
return (sessionProvider, childProvider) => (sessionProvider && childProvider === sessionProvider ? extension : null);
|
|
104
|
+
}
|
|
82
105
|
function registerRuntimeAgent(pi, env, hooks) {
|
|
83
106
|
const agentDir = env.PI_CODING_AGENT_DIR ?? PI_AGENT_DIR;
|
|
107
|
+
// The provider this session's own model is on, known once the session starts. A child that
|
|
108
|
+
// inherited it is the only one whose quota readings can be filed under this run's provider.
|
|
109
|
+
let sessionProvider = null;
|
|
110
|
+
const quotaProbe = childQuotaProbe(hooks);
|
|
84
111
|
const deps = {
|
|
85
112
|
agentDir,
|
|
86
113
|
ensureRoles: () => ensurePIAgentRoles({ legacyDir: path.join(agentDir, 'agents') }),
|
|
87
114
|
createSession: hooks.createChildSession ?? createChildSession,
|
|
88
115
|
// The child inherits this session's opener: it is the same daemon, hosting the same bundles.
|
|
89
|
-
childExtensions: (childEnv) =>
|
|
116
|
+
childExtensions: (childEnv, childProvider) => {
|
|
117
|
+
const extensions = childExtensions(childEnv, hooks.openBundledMcpServer);
|
|
118
|
+
const probe = quotaProbe(sessionProvider, childProvider);
|
|
119
|
+
return probe ? [...extensions, probe] : extensions;
|
|
120
|
+
},
|
|
90
121
|
parentEnv: env,
|
|
91
122
|
onEvent: hooks.onSubagentEvent,
|
|
123
|
+
onUsage: hooks.onSubagentUsage,
|
|
92
124
|
runForeignSubagent: hooks.runForeignSubagent,
|
|
93
125
|
startBackgroundSubagent: hooks.startBackgroundSubagent,
|
|
94
126
|
stopBackgroundSubagent: hooks.stopBackgroundSubagent,
|
|
95
127
|
};
|
|
96
128
|
pi.on('session_start', (_event, ctx) => {
|
|
129
|
+
sessionProvider = ctx.model?.provider ?? null;
|
|
97
130
|
pi.registerTool(createSubagentTool(deps, runtimeCatalog(ctx, env, deps)));
|
|
98
131
|
const stopTool = createSubagentStopTool(deps);
|
|
99
132
|
if (stopTool)
|
|
@@ -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;
|
|
@@ -135,6 +140,7 @@ export interface UserMessage {
|
|
|
135
140
|
attachments?: {
|
|
136
141
|
mimeType: string;
|
|
137
142
|
path: string;
|
|
143
|
+
name?: string;
|
|
138
144
|
}[];
|
|
139
145
|
}
|
|
140
146
|
export interface McpStdioServerConfig {
|
|
@@ -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
|
};
|
|
@@ -12,6 +12,7 @@ export const MCP_TOOLS_BY_SERVER = {
|
|
|
12
12
|
'cost_query', 'query_executions', 'cortex_context', 'cortex_schedule_add',
|
|
13
13
|
'cortex_schedule_list', 'cortex_schedule_get', 'cortex_schedule_remove',
|
|
14
14
|
'cortex_schedule_pause', 'cortex_schedule_resume',
|
|
15
|
+
'wait_create', 'wait_check', 'wait_cancel',
|
|
15
16
|
],
|
|
16
17
|
'cortex-interaction-bridge': [
|
|
17
18
|
'cortex_plan_enter', 'cortex_plan_exit',
|
|
@@ -3,3 +3,13 @@
|
|
|
3
3
|
* two sets, so they live below both rather than in either one. */
|
|
4
4
|
export declare const IMAGE_MIMES: Set<string>;
|
|
5
5
|
export declare const VIDEO_MIMES: Set<string>;
|
|
6
|
+
/** The mime a file's first bytes actually declare, or null when they are not a known image.
|
|
7
|
+
*
|
|
8
|
+
* A platform's metadata is a claim, not a fact: Feishu hands every inbound image out as
|
|
9
|
+
* `image_key` with no type at all (Cortex called them all PNG), Slack can mislabel, and a user
|
|
10
|
+
* can rename anything. Backends sniff the bytes themselves, so a wrong mime never broke reading —
|
|
11
|
+
* it broke everything that classifies on the declared value (prompt bucket, UI attachment kind,
|
|
12
|
+
* the extension the file is stored under). */
|
|
13
|
+
export declare function sniffImageMime(head: Buffer): string | null;
|
|
14
|
+
/** The extension an image mime should be stored under, or null for a mime with no fixed one. */
|
|
15
|
+
export declare function imageMimeExtension(mimeType: string): string | null;
|