@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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
You write. Every request is a piece of work in some form — a scene, a poem, lyrics, an image prompt, a name, a tagline, a character sketch — and the job is to make that piece well, in that form.
|
|
2
|
+
|
|
3
|
+
Start from the form. Each one carries its own rules: line breaks and sound in a poem, a turn in a short story, dense visual nouns in an image prompt, stress and rhythm in a lyric, the single reading a tagline has to survive. Know the genre the request is working in, then honour its conventions or break them on purpose. When the user names reference material — a file, a path, an earlier draft — read it with Read before writing.
|
|
4
|
+
|
|
5
|
+
Deliver the work and nothing else. No preamble, no "Here's a…", no note on what you were going for, no summary of what you just wrote, no closing line about how the reader might feel or what they could do next. If the piece wants a title it gets a title; otherwise it starts at its first word.
|
|
6
|
+
|
|
7
|
+
Write against the machine house style. Drop hedging openers — "I'd say", "it's worth noting", "certainly". No bullet lists unless the form itself is a list. Vary sentence length; three medium sentences in a row is a drone. Reach for the concrete noun over the abstraction: the chipped enamel mug, not a sense of domesticity. Cut stock transitions, symmetrical clause pairs, and the sentence at the end that tells the reader what to feel. Specific beats impressive.
|
|
8
|
+
|
|
9
|
+
Ask a question only when you genuinely cannot start — a missing fact that would change the whole piece. Otherwise make the call, write it, and let the draft carry the question.
|
|
10
|
+
|
|
11
|
+
Take feedback literally. "Shorter" means shorter, not restructured. "Colder" means colder, not more restrained and professional. Change what was named and leave the rest alone unless a rewrite is what was asked for.
|
|
12
|
+
|
|
13
|
+
Write in the language the user writes in, unless the request or the form calls for another. Write in the conversation. Save to a file only when the user asks for a file.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
You are Cortex, an AI assistant that helps users with research, software engineering, and project work. Understand the request, then act.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
For engineering and Q&A answers, be concise and direct; for creative deliverables, follow the requested form. Use formatting that makes the answer easy to read, and show file paths clearly.
|
|
4
4
|
|
|
5
5
|
Read relevant files before changing them. Keep changes focused on the request, verify the result, and report what was and was not checked. Be explicit about uncertainty; do not invent facts, sources, or results.
|
|
6
6
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
paths:
|
|
3
|
-
- "context/**/
|
|
3
|
+
- "context/**/AGENTS.md"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# AGENTS.md Index Convention
|
|
7
7
|
|
|
8
|
-
Directory index + entry map.
|
|
8
|
+
Directory index + entry map. Loaded into the context of every agent that works in this directory — by the backend itself (Claude Code and PI both read `AGENTS.md` natively) and, for paths outside the session working directory, by the `agents-md-injector` hook. The byte count IS the context cost, paid on every session that touches the directory. It answers "what is here, where to look", not "what the content is": each line exists so an agent knows where to read, not as a substitute for reading.
|
|
9
9
|
|
|
10
10
|
## Hard Constraints
|
|
11
11
|
|
|
12
|
-
- **Hard cap: 120 lines AND 8KB** (enforced by guard hook
|
|
12
|
+
- **Hard cap: 120 lines AND 8KB** (enforced by guard hook). The hook path truncates at 9,500 characters, so content past that line is never injected at all — pure waste.
|
|
13
13
|
- **Each index line <=200 characters**: one sentence of purpose + pointer.
|
|
14
14
|
- **One line per atomic directory**: experiments/, knowledge/, patterns/, decisions/ each take a single line in the index, pointing at their auto-generated index.md (or the directory itself). **Never enumerate per-entry summaries** — summaries already live in the atomic files' frontmatter and index.md; copies in the index are pure redundancy.
|
|
15
15
|
|
|
@@ -38,7 +38,7 @@ Evidence: EXP-NNN, EXP-NNN
|
|
|
38
38
|
|
|
39
39
|
**Reference format**: `DR-NNNN` (analogous to `EXP-NNN` and `K-NNN`). Numbering is independent within each level (system-level and each project starts from 0001).
|
|
40
40
|
|
|
41
|
-
**Indexing rule**: After adding a new DR, you must add an inline reference link in the corresponding level's
|
|
41
|
+
**Indexing rule**: After adding a new DR, you must add an inline reference link in the corresponding level's AGENTS.md.
|
|
42
42
|
|
|
43
43
|
## Boundaries with Other Knowledge Types
|
|
44
44
|
|
|
@@ -5,14 +5,14 @@ paths:
|
|
|
5
5
|
|
|
6
6
|
# Context Meta-Rules
|
|
7
7
|
|
|
8
|
-
Cross-file conventions. See the dedicated rule for each file type in the same directory (status-md.md / issues-md.md / mission-md.md / roadmap-md.md / overview-md.md /
|
|
8
|
+
Cross-file conventions. See the dedicated rule for each file type in the same directory (status-md.md / issues-md.md / mission-md.md / roadmap-md.md / overview-md.md / agents-md.md / task-system.md / experiment-format.md / decision-records.md).
|
|
9
9
|
|
|
10
10
|
## General Rules
|
|
11
11
|
|
|
12
12
|
- **All context updates are auto-committed via git**: Incremental commits, each logical unit (experiment configuration, analysis report, status update) is committed upon completion, do not accumulate until the end of the session.
|
|
13
13
|
- **Value traceability**: Every value appearing in STATUS / EXP / K / reports must be traceable — specify the script + data file that produced it, or write inline arithmetic citing the data. Numbers without sources are invalid.
|
|
14
|
-
- **Update index after creating new files**: After creating a new file in any directory, update that directory's
|
|
15
|
-
- **Decision traceability**: Each DR-NNNN within a project adds an inline reference in the project's
|
|
14
|
+
- **Update index after creating new files**: After creating a new file in any directory, update that directory's AGENTS.md index (see agents-md.md).
|
|
15
|
+
- **Decision traceability**: Each DR-NNNN within a project adds an inline reference in the project's AGENTS.md; system-level DRs are referenced in `context/AGENTS.md`.
|
|
16
16
|
|
|
17
17
|
## Index Files
|
|
18
18
|
|
|
@@ -33,7 +33,7 @@ PostToolUse hook automatically records Read/Grep access to atomic files (EXP/K/P
|
|
|
33
33
|
|------|----------------|-------------|
|
|
34
34
|
| `STATUS.md` | status-md.md | Overwrite snapshot (state register), hard limit 80 lines AND 6KB, each bullet <=2 lines |
|
|
35
35
|
| `ISSUES.md` | issues-md.md | Append, resolved entries deleted directly, hard limit 80 lines AND 6KB, each entry <=4 lines |
|
|
36
|
-
| `
|
|
36
|
+
| `AGENTS.md` (directory index) | agents-md.md | Pointer-style index, hard limit 120 lines AND 8KB, one line per atomic directory |
|
|
37
37
|
| `mission.md` | mission-md.md | Modify after user confirmation |
|
|
38
38
|
| `roadmap.md` | roadmap-md.md | Stable, milestones must contain testable checklist |
|
|
39
39
|
| `OVERVIEW.md` | overview-md.md | Synchronous update, hard limit 60 lines |
|
|
@@ -45,4 +45,4 @@ The project's "constitution": defines goals and success conditions. It is the ba
|
|
|
45
45
|
|
|
46
46
|
## Modification Process
|
|
47
47
|
|
|
48
|
-
For major re-orientations: update STATUS / roadmap / project
|
|
48
|
+
For major re-orientations: update STATUS / roadmap / project AGENTS.md in the same pass to avoid context inconsistency.
|
|
@@ -37,6 +37,10 @@ interface ClaudeSessionOptions {
|
|
|
37
37
|
browserMcpConfigIdentity?: string | null;
|
|
38
38
|
pluginCapabilityFingerprint?: string | null;
|
|
39
39
|
disableHooks?: boolean;
|
|
40
|
+
/** Drop the CLI's whole skill layer; see {@link ClaudeSpawnOptions.disableSkills}. */
|
|
41
|
+
disableSkills?: boolean;
|
|
42
|
+
/** Setting files the CLI may load; see {@link ClaudeSpawnOptions.settingSources}. */
|
|
43
|
+
settingSources?: string[];
|
|
40
44
|
streamDeltas?: boolean;
|
|
41
45
|
captureTranscriptLogs?: boolean;
|
|
42
46
|
preserveUnreportedAccounting?: boolean;
|
|
@@ -74,6 +78,12 @@ export interface ClaudeSpawnCompatibility {
|
|
|
74
78
|
/** Turning the browser on or off must force a FRESH process: a pooled Claude keeps whatever MCP
|
|
75
79
|
* set it was spawned with, so without this the toggle would silently no-op until the process died. */
|
|
76
80
|
browserMcpConfigIdentity: string | null;
|
|
81
|
+
/** `--disable-slash-commands`. Part of the identity for the same reason as the browser: the skill
|
|
82
|
+
* surface is fixed at spawn, so two agents that differ only here must not share a process. */
|
|
83
|
+
disableSkills: boolean;
|
|
84
|
+
/** `--setting-sources`. Null = the CLI's own default set; `[]` = load none. Both are decided at
|
|
85
|
+
* spawn and cannot be re-pointed afterwards. */
|
|
86
|
+
settingSources: string[] | null;
|
|
77
87
|
}
|
|
78
88
|
export declare function sameClaudeSpawnCompatibility(left: ClaudeSpawnCompatibility, right: ClaudeSpawnCompatibility): boolean;
|
|
79
89
|
/**
|
|
@@ -115,6 +125,8 @@ declare class ClaudeSession implements TurnHost {
|
|
|
115
125
|
private browserMcpConfigPath;
|
|
116
126
|
private compatibility;
|
|
117
127
|
private disableHooks;
|
|
128
|
+
private disableSkills;
|
|
129
|
+
private settingSources;
|
|
118
130
|
private streamDeltas;
|
|
119
131
|
captureTranscriptLogs: boolean;
|
|
120
132
|
preserveUnreportedAccounting: boolean;
|
|
@@ -50,6 +50,8 @@ function deriveClaudeSpawnOptions(fields) {
|
|
|
50
50
|
supplementalMcpConfigPath: fields.supplementalMcpConfigPath,
|
|
51
51
|
browserMcpConfigPath: fields.browserMcpConfigPath,
|
|
52
52
|
disableHooks: fields.disableHooks,
|
|
53
|
+
disableSkills: fields.disableSkills,
|
|
54
|
+
settingSources: fields.settingSources,
|
|
53
55
|
streamDeltas: fields.streamDeltas,
|
|
54
56
|
};
|
|
55
57
|
}
|
|
@@ -76,9 +78,11 @@ export function sameClaudeSpawnCompatibility(left, right) {
|
|
|
76
78
|
&& left.pluginCapabilityFingerprint === right.pluginCapabilityFingerprint
|
|
77
79
|
&& left.supplementalMcpConfigIdentity === right.supplementalMcpConfigIdentity
|
|
78
80
|
&& left.browserMcpConfigIdentity === right.browserMcpConfigIdentity
|
|
81
|
+
&& left.disableSkills === right.disableSkills
|
|
79
82
|
&& sameTextArray(left.pluginDirs, right.pluginDirs)
|
|
80
83
|
&& sameTextArray(left.mcpConfigPaths, right.mcpConfigPaths)
|
|
81
|
-
&& sameOptionalTextArray(left.mcpToolAllowlist, right.mcpToolAllowlist)
|
|
84
|
+
&& sameOptionalTextArray(left.mcpToolAllowlist, right.mcpToolAllowlist)
|
|
85
|
+
&& sameOptionalTextArray(left.settingSources, right.settingSources);
|
|
82
86
|
}
|
|
83
87
|
function compatibilityFromOptions(options) {
|
|
84
88
|
const composition = resolveMcpComposition(options.mcpComposition, options.context?.useCoreMcp);
|
|
@@ -94,6 +98,8 @@ function compatibilityFromOptions(options) {
|
|
|
94
98
|
mcpToolAllowlist: optionalTextArray(options.mcpToolAllowlist),
|
|
95
99
|
supplementalMcpConfigIdentity: options.supplementalMcpConfigIdentity ?? null,
|
|
96
100
|
browserMcpConfigIdentity: options.browserMcpConfigIdentity ?? null,
|
|
101
|
+
disableSkills: options.disableSkills === true,
|
|
102
|
+
settingSources: optionalTextArray(options.settingSources),
|
|
97
103
|
};
|
|
98
104
|
}
|
|
99
105
|
/**
|
|
@@ -114,9 +120,11 @@ export function claudeCompatibilityIdentity(compatibility) {
|
|
|
114
120
|
['pluginCapabilityFingerprint', compatibility.pluginCapabilityFingerprint],
|
|
115
121
|
['supplementalMcpConfigIdentity', compatibility.supplementalMcpConfigIdentity],
|
|
116
122
|
['browserMcpConfigIdentity', compatibility.browserMcpConfigIdentity],
|
|
123
|
+
['disableSkills', compatibility.disableSkills],
|
|
117
124
|
['pluginDirs', compatibility.pluginDirs],
|
|
118
125
|
['mcpConfigPaths', compatibility.mcpConfigPaths],
|
|
119
126
|
['mcpToolAllowlist', compatibility.mcpToolAllowlist],
|
|
127
|
+
['settingSources', compatibility.settingSources],
|
|
120
128
|
];
|
|
121
129
|
return JSON.stringify(fields);
|
|
122
130
|
}
|
|
@@ -156,6 +164,8 @@ class ClaudeSession {
|
|
|
156
164
|
browserMcpConfigPath;
|
|
157
165
|
compatibility;
|
|
158
166
|
disableHooks;
|
|
167
|
+
disableSkills;
|
|
168
|
+
settingSources;
|
|
159
169
|
streamDeltas;
|
|
160
170
|
captureTranscriptLogs;
|
|
161
171
|
preserveUnreportedAccounting;
|
|
@@ -209,6 +219,8 @@ class ClaudeSession {
|
|
|
209
219
|
this.browserMcpConfigPath = options.browserMcpConfigPath ?? null;
|
|
210
220
|
this.compatibility = compatibilityFromOptions(options);
|
|
211
221
|
this.disableHooks = options.disableHooks === true;
|
|
222
|
+
this.disableSkills = options.disableSkills === true;
|
|
223
|
+
this.settingSources = options.settingSources;
|
|
212
224
|
this.streamDeltas = options.streamDeltas;
|
|
213
225
|
this.onSelfClose = options.onSelfClose;
|
|
214
226
|
this.onEvict = options.onEvict;
|
|
@@ -244,6 +256,8 @@ class ClaudeSession {
|
|
|
244
256
|
supplementalMcpConfigPath: this.supplementalMcpConfigPath,
|
|
245
257
|
browserMcpConfigPath: this.browserMcpConfigPath,
|
|
246
258
|
disableHooks: this.disableHooks,
|
|
259
|
+
disableSkills: this.disableSkills,
|
|
260
|
+
settingSources: this.settingSources,
|
|
247
261
|
streamDeltas: this.streamDeltas,
|
|
248
262
|
});
|
|
249
263
|
}
|
|
@@ -566,6 +580,8 @@ function sessionRuntimeOptions(spec, composition) {
|
|
|
566
580
|
browserMcpConfigIdentity: browser?.identity ?? null,
|
|
567
581
|
pluginCapabilityFingerprint: spec.plugins.fingerprint ?? null,
|
|
568
582
|
disableHooks: spec.flags.disableHooks,
|
|
583
|
+
disableSkills: spec.flags.disableSkills,
|
|
584
|
+
settingSources: spec.flags.settingSources,
|
|
569
585
|
streamDeltas: spec.flags.streamDeltas,
|
|
570
586
|
captureTranscriptLogs: spec.flags.captureTranscripts,
|
|
571
587
|
preserveUnreportedAccounting: spec.flags.preserveUnreportedAccounting,
|
|
@@ -610,6 +626,8 @@ function computeSpawnArgsForSpec(spec) {
|
|
|
610
626
|
supplementalMcpConfigPath: opts.supplementalMcpConfigPath,
|
|
611
627
|
browserMcpConfigPath: opts.browserMcpConfigPath,
|
|
612
628
|
disableHooks: opts.disableHooks,
|
|
629
|
+
disableSkills: opts.disableSkills,
|
|
630
|
+
settingSources: opts.settingSources,
|
|
613
631
|
streamDeltas: opts.streamDeltas,
|
|
614
632
|
});
|
|
615
633
|
spawnOptions.isUserInitiated = spec.flags.isUserInitiated;
|
|
@@ -31,10 +31,10 @@ export const POST_TOOL_USE_HOOKS = [
|
|
|
31
31
|
nodeHook('rules-loader.mjs'),
|
|
32
32
|
] },
|
|
33
33
|
{ matcher: 'Read|Edit|Write|Skill', hooks: [nodeHook('session-activity-tracker.mjs')] },
|
|
34
|
-
{ matcher: 'Read|Edit', hooks: [nodeHook('
|
|
34
|
+
{ matcher: 'Read|Edit', hooks: [nodeHook('agents-md-injector.mjs')] },
|
|
35
35
|
];
|
|
36
36
|
export const SESSION_START_HOOKS = [
|
|
37
|
-
{ matcher: 'startup|resume|clear|compact', hooks: [nodeHook('
|
|
37
|
+
{ matcher: 'startup|resume|clear|compact', hooks: [nodeHook('agents-md-injector.mjs')] },
|
|
38
38
|
];
|
|
39
39
|
function buildLegacyHooksSettings() {
|
|
40
40
|
return {
|
|
@@ -20,6 +20,13 @@ export interface ClaudeSpawnOptions {
|
|
|
20
20
|
supplementalMcpConfigPath?: string | null;
|
|
21
21
|
/** Omit all configured ambient hooks. */
|
|
22
22
|
disableHooks?: boolean;
|
|
23
|
+
/** Drop the CLI's whole skill layer (`--disable-slash-commands`). This is the only lever that
|
|
24
|
+
* reaches the skills Cortex never supplied — user-level plugins, `~/.claude/skills/` and the
|
|
25
|
+
* CLI's built-ins — since `--plugin-dir` only ever adds Cortex's own. */
|
|
26
|
+
disableSkills?: boolean;
|
|
27
|
+
/** Setting files the CLI may load (`--setting-sources`). Absent keeps its default set; an empty
|
|
28
|
+
* array is passed as an empty value, which the CLI accepts as "load none". */
|
|
29
|
+
settingSources?: string[];
|
|
23
30
|
/** Explicit partial-message policy; absent reads the daemon setting. */
|
|
24
31
|
streamDeltas?: boolean;
|
|
25
32
|
/** Select Slack tools in the bundled server for Slack-originated direct sessions. */
|
|
@@ -141,6 +141,15 @@ function appendRepeatedOption(args, flag, values) {
|
|
|
141
141
|
for (const value of values ?? [])
|
|
142
142
|
args.push(flag, value);
|
|
143
143
|
}
|
|
144
|
+
/** The two levers that narrow what the CLI loads on its own behalf. `--setting-sources` takes the
|
|
145
|
+
* list verbatim, so an empty array spells the empty value the CLI reads as "load none" — that is
|
|
146
|
+
* what keeps a user's `enabledPlugins` and ambient hooks out of a minimal-surface session. */
|
|
147
|
+
function appendEnvironmentOptions(args, options) {
|
|
148
|
+
if (options.disableSkills)
|
|
149
|
+
args.push('--disable-slash-commands');
|
|
150
|
+
if (options.settingSources)
|
|
151
|
+
args.push('--setting-sources', options.settingSources.join(','));
|
|
152
|
+
}
|
|
144
153
|
function appendExtraOptions(args, options) {
|
|
145
154
|
for (const [flag, value] of Object.entries(options ?? {}))
|
|
146
155
|
args.push(flag, value);
|
|
@@ -169,6 +178,7 @@ export function buildSpawnArgs(options) {
|
|
|
169
178
|
appendCoreArgs(args, configs, composition, tools);
|
|
170
179
|
appendPromptOptions(args, options);
|
|
171
180
|
appendRepeatedOption(args, '--plugin-dir', options.pluginDirs);
|
|
181
|
+
appendEnvironmentOptions(args, options);
|
|
172
182
|
appendExtraOptions(args, options.extraOption);
|
|
173
183
|
args.push('--settings', JSON.stringify(buildClaudeSettings(options, tools)));
|
|
174
184
|
appendSessionIdentity(args, options);
|
|
@@ -310,6 +320,10 @@ export function buildClaudeEnv(channel, sessionId, callbackSource, scheduleTaskI
|
|
|
310
320
|
// CORTEX_SESSION_ID is the stable Cortex tracking id (session-activity log routing + MCP context),
|
|
311
321
|
// NOT the backend CLI's self-assigned session id. Falls back to the backend id when unset (threads).
|
|
312
322
|
env.CORTEX_SESSION_ID = context?.trackSessionId ?? sessionId;
|
|
323
|
+
// Declared, not inferred: hooks branch on which backend loaded the AGENTS.md chain natively
|
|
324
|
+
// (agents-md-injector.mjs), and "absent means Claude" would silently mis-handle any future
|
|
325
|
+
// spawn path that forgets to set it. PI states itself in agent-adapter/pi/session-options.ts.
|
|
326
|
+
env.CORTEX_BACKEND = 'claude';
|
|
313
327
|
setIfPresent(env, 'CORTEX_CALLBACK_SOURCE', callbackSource);
|
|
314
328
|
setIfPresent(env, 'CORTEX_SCHEDULE_TASK_ID', scheduleTaskId);
|
|
315
329
|
setIfPresent(env, 'ANTHROPIC_BASE_URL', anthropicBaseUrl);
|
|
@@ -54,6 +54,17 @@ export interface PendingTurn {
|
|
|
54
54
|
* (the spontaneous turn the CLI emits after a run_in_background task finishes). */
|
|
55
55
|
spontaneous?: boolean;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* One `tool_result` content block as a line of transcript text.
|
|
59
|
+
*
|
|
60
|
+
* Text passes through; everything else is DESCRIBED, never serialized. `Read` on an image answers
|
|
61
|
+
* with `[{type:'image', source:{type:'base64', data:<~500 KB>}}]`, and stringifying that put the
|
|
62
|
+
* entire payload into the tool_result event — which becomes a debug transcript row, a subagent
|
|
63
|
+
* notice pushed into the PARENT session's stream (`domain/agents/subagent/runner.ts`, not gated on
|
|
64
|
+
* debug) and a capture-log line. One image read cost ~0.5 MB on each of those paths; the model's
|
|
65
|
+
* own context never carried it, only Cortex's transcript did.
|
|
66
|
+
*/
|
|
67
|
+
export declare function describeResultBlock(item: any): string;
|
|
57
68
|
/**
|
|
58
69
|
* Extract the prompt text from a `--replay-user-messages` echo. `message.content` arrives either
|
|
59
70
|
* as a bare string or as text blocks. Returns null for anything else — notably the tool_result
|
|
@@ -25,16 +25,57 @@ function subagentAttribution(data) {
|
|
|
25
25
|
model: typeof data?.message?.model === 'string' ? data.message.model : null,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
/** Longest serialization one unrecognised result block may contribute. */
|
|
29
|
+
const RESULT_BLOCK_JSON_LIMIT = 1000;
|
|
30
|
+
function formatByteSize(bytes) {
|
|
31
|
+
if (bytes >= 1024 * 1024)
|
|
32
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
33
|
+
if (bytes >= 1024)
|
|
34
|
+
return `${Math.round(bytes / 1024)} KB`;
|
|
35
|
+
return `${bytes} B`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* One `tool_result` content block as a line of transcript text.
|
|
39
|
+
*
|
|
40
|
+
* Text passes through; everything else is DESCRIBED, never serialized. `Read` on an image answers
|
|
41
|
+
* with `[{type:'image', source:{type:'base64', data:<~500 KB>}}]`, and stringifying that put the
|
|
42
|
+
* entire payload into the tool_result event — which becomes a debug transcript row, a subagent
|
|
43
|
+
* notice pushed into the PARENT session's stream (`domain/agents/subagent/runner.ts`, not gated on
|
|
44
|
+
* debug) and a capture-log line. One image read cost ~0.5 MB on each of those paths; the model's
|
|
45
|
+
* own context never carried it, only Cortex's transcript did.
|
|
46
|
+
*/
|
|
47
|
+
export function describeResultBlock(item) {
|
|
48
|
+
if (typeof item === 'string')
|
|
49
|
+
return item;
|
|
50
|
+
if (!item || typeof item !== 'object')
|
|
51
|
+
return '';
|
|
52
|
+
if (item.type === 'text' && typeof item.text === 'string')
|
|
53
|
+
return item.text;
|
|
54
|
+
if (item.type === 'image' || item.type === 'document') {
|
|
55
|
+
const source = (item.source ?? {});
|
|
56
|
+
const mime = typeof source.media_type === 'string' ? source.media_type : item.type;
|
|
57
|
+
// base64 → bytes: the magnitude is the point, so no decode is worth its cost here.
|
|
58
|
+
if (typeof source.data === 'string')
|
|
59
|
+
return `[${mime}, ${formatByteSize(Math.floor((source.data.length * 3) / 4))}]`;
|
|
60
|
+
if (typeof source.url === 'string')
|
|
61
|
+
return `[${mime}, ${source.url}]`;
|
|
62
|
+
return `[${mime}]`;
|
|
63
|
+
}
|
|
64
|
+
const json = JSON.stringify(item) ?? '';
|
|
65
|
+
return json.length > RESULT_BLOCK_JSON_LIMIT
|
|
66
|
+
? `${json.slice(0, RESULT_BLOCK_JSON_LIMIT)}… [${json.length - RESULT_BLOCK_JSON_LIMIT} more chars]`
|
|
67
|
+
: json;
|
|
68
|
+
}
|
|
28
69
|
/** Flatten a `tool_result` block's content to the string shape every sink expects. Shared by the
|
|
29
70
|
* in-turn path and the orphan-subagent path so the two cannot drift. */
|
|
30
71
|
function toolResultText(block) {
|
|
31
72
|
if (typeof block.content === 'string')
|
|
32
73
|
return block.content;
|
|
33
|
-
if (Array.isArray(block.content))
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
74
|
+
if (Array.isArray(block.content))
|
|
75
|
+
return block.content.map(describeResultBlock).join('\n');
|
|
76
|
+
if (block.content == null)
|
|
77
|
+
return '';
|
|
78
|
+
return describeResultBlock(block.content);
|
|
38
79
|
}
|
|
39
80
|
function subagentActivityKind(data) {
|
|
40
81
|
if (data.type === 'assistant')
|
|
@@ -3,5 +3,20 @@
|
|
|
3
3
|
export interface FileAttachment {
|
|
4
4
|
mimeType: string;
|
|
5
5
|
path: string;
|
|
6
|
+
/** What the user called the file. Optional: an attachment that never had a name (a pasted
|
|
7
|
+
* image) is described by its path alone. Carried separately from `path` because the stored
|
|
8
|
+
* name is ASCII-folded and de-duplicated, so the path is not the name. */
|
|
9
|
+
name?: string;
|
|
6
10
|
}
|
|
7
|
-
|
|
11
|
+
/** An attachment the platform would not hand over, named so the model does not answer as if the
|
|
12
|
+
* user had sent nothing. */
|
|
13
|
+
export interface FailedAttachment {
|
|
14
|
+
name: string;
|
|
15
|
+
reason: string;
|
|
16
|
+
}
|
|
17
|
+
/** The block that names attachments the platform would not hand over, or '' when none did.
|
|
18
|
+
* Exported because the conversation path composes its prompt text itself and must be able to
|
|
19
|
+
* fold the same notice in — an attachment that failed to download used to be logged and then
|
|
20
|
+
* silently forgotten, leaving the agent to answer as if the user had sent nothing. */
|
|
21
|
+
export declare function formatAttachmentFailures(failures: FailedAttachment[]): string;
|
|
22
|
+
export declare function buildPrompt(userMessage: string, files: FileAttachment[], failures?: FailedAttachment[]): string;
|
|
@@ -1,23 +1,41 @@
|
|
|
1
1
|
import { IMAGE_MIMES, VIDEO_MIMES } from '../../core/media-types.js';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/** The block that names attachments the platform would not hand over, or '' when none did.
|
|
4
|
+
* Exported because the conversation path composes its prompt text itself and must be able to
|
|
5
|
+
* fold the same notice in — an attachment that failed to download used to be logged and then
|
|
6
|
+
* silently forgotten, leaving the agent to answer as if the user had sent nothing. */
|
|
7
|
+
export function formatAttachmentFailures(failures) {
|
|
8
|
+
if (failures.length === 0)
|
|
9
|
+
return '';
|
|
10
|
+
const list = failures.map(f => `${f.name} (${f.reason})`).join('\n');
|
|
11
|
+
return `[${failures.length} attachment(s) the user sent could NOT be downloaded and are `
|
|
12
|
+
+ `unavailable to you. Say so rather than answering as if they had not been sent:\n${list}\n]\n\n`;
|
|
13
|
+
}
|
|
14
|
+
/** `path` for a file stored under its own name; `path (name)` when the two differ. */
|
|
15
|
+
function describe(file) {
|
|
16
|
+
const p = file.path.replace(/\\/g, '/');
|
|
17
|
+
const name = file.name?.trim();
|
|
18
|
+
return name && name !== path.basename(p) ? `${p} (${name})` : p;
|
|
19
|
+
}
|
|
20
|
+
export function buildPrompt(userMessage, files, failures = []) {
|
|
21
|
+
if (files.length === 0 && failures.length === 0)
|
|
5
22
|
return userMessage;
|
|
6
23
|
const imageFiles = files.filter(f => IMAGE_MIMES.has(f.mimeType));
|
|
7
24
|
const videoFiles = files.filter(f => VIDEO_MIMES.has(f.mimeType));
|
|
8
25
|
const otherFiles = files.filter(f => !IMAGE_MIMES.has(f.mimeType) && !VIDEO_MIMES.has(f.mimeType));
|
|
9
26
|
let prefix = '';
|
|
10
27
|
if (imageFiles.length > 0) {
|
|
11
|
-
const paths = imageFiles.map(
|
|
28
|
+
const paths = imageFiles.map(describe).join('\n');
|
|
12
29
|
prefix += `[User sent ${imageFiles.length} image(s). Read these files to view them:\n${paths}\n]\n\n`;
|
|
13
30
|
}
|
|
14
31
|
if (videoFiles.length > 0) {
|
|
15
|
-
const paths = videoFiles.map(
|
|
32
|
+
const paths = videoFiles.map(describe).join('\n');
|
|
16
33
|
prefix += `[User sent ${videoFiles.length} video(s). Read these files to view them:\n${paths}\n]\n\n`;
|
|
17
34
|
}
|
|
18
35
|
if (otherFiles.length > 0) {
|
|
19
|
-
const fileList = otherFiles.map(
|
|
36
|
+
const fileList = otherFiles.map(describe).join('\n');
|
|
20
37
|
prefix += `[User sent ${otherFiles.length} file(s). Read these files:\n${fileList}\n]\n\n`;
|
|
21
38
|
}
|
|
22
|
-
|
|
39
|
+
prefix += formatAttachmentFailures(failures);
|
|
40
|
+
return prefix + (userMessage || (files.length > 0 ? 'Please analyze the attached file(s).' : ''));
|
|
23
41
|
}
|
|
@@ -18,8 +18,10 @@ export interface PiChildRequest {
|
|
|
18
18
|
fallbackModel?: PiModelFallback | null;
|
|
19
19
|
/** Nested session factory; tests substitute a fake. */
|
|
20
20
|
createSession?: ChildSessionFactory;
|
|
21
|
-
/** The Cortex extensions the child loads, closed over the child's own env
|
|
22
|
-
|
|
21
|
+
/** The Cortex extensions the child loads, closed over the child's own env and the provider the
|
|
22
|
+
* child declared — null whenever the selection names a model without one, which is the only
|
|
23
|
+
* honest answer before PI's resolver has run. */
|
|
24
|
+
childExtensions: (env: NodeJS.ProcessEnv, childProvider: string | null) => InlineExtension[];
|
|
23
25
|
signal?: AbortSignal;
|
|
24
26
|
forward?: ChildEventForwarder;
|
|
25
27
|
}
|
|
@@ -37,7 +37,7 @@ export async function runPiChild(request) {
|
|
|
37
37
|
model: selection.model ?? null,
|
|
38
38
|
tools: roleToolsForBackend(role, 'pi'),
|
|
39
39
|
appendSystemPrompt: role.systemPrompt ? [role.systemPrompt] : [],
|
|
40
|
-
extensions: request.childExtensions(buildChildEnv(request.parentEnv, request.agentDir)),
|
|
40
|
+
extensions: request.childExtensions(buildChildEnv(request.parentEnv, request.agentDir), selection.provider ?? null),
|
|
41
41
|
});
|
|
42
42
|
try {
|
|
43
43
|
const result = await collectChild(handle, task, request.signal, request.forward);
|
|
@@ -82,6 +82,7 @@ export function childResult(task, accumulator) {
|
|
|
82
82
|
output: accumulator.output,
|
|
83
83
|
usage: accumulator.usage,
|
|
84
84
|
model: accumulator.model,
|
|
85
|
+
provider: accumulator.provider,
|
|
85
86
|
backend: 'pi',
|
|
86
87
|
stopReason: accumulator.stopReason,
|
|
87
88
|
errorMessage: accumulator.errorMessage,
|
|
@@ -135,5 +136,8 @@ function recordAssistantMessage(accumulator, message) {
|
|
|
135
136
|
return;
|
|
136
137
|
accumulator.output = textFromMessage(message) || accumulator.output;
|
|
137
138
|
accumulator.model = stringOrPrevious(message.model, accumulator.model);
|
|
139
|
+
// Read off the child's own messages, never inherited from the parent: a child may run on another
|
|
140
|
+
// provider entirely, and a guessed name would file its spend under a provider it never used.
|
|
141
|
+
accumulator.provider = stringOrPrevious(message.provider, accumulator.provider);
|
|
138
142
|
recordTerminalState(accumulator, message);
|
|
139
143
|
}
|
|
@@ -47,8 +47,9 @@ export interface PIEventParserState {
|
|
|
47
47
|
export declare function createPIEventParserState(): PIEventParserState;
|
|
48
48
|
/**
|
|
49
49
|
* Translate one PI session event (as delivered by `AgentSession.subscribe`, an
|
|
50
|
-
* `extension_ui_request` the host raised for an extension, or a `cortex_subagent_event`
|
|
51
|
-
* tool
|
|
50
|
+
* `extension_ui_request` the host raised for an extension, or a `cortex_subagent_event` /
|
|
51
|
+
* `cortex_subagent_usage` record the Agent tool raised for a nested session) to zero or more
|
|
52
|
+
* NormalizedEvents.
|
|
52
53
|
*
|
|
53
54
|
* Dropped events (return []): turn_start, turn_end, message_start, agent_start,
|
|
54
55
|
* queue_update, compaction_end, auto_retry_start/end, message_update without text_delta,
|
|
@@ -9,8 +9,9 @@ export function createPIEventParserState() {
|
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Translate one PI session event (as delivered by `AgentSession.subscribe`, an
|
|
12
|
-
* `extension_ui_request` the host raised for an extension, or a `cortex_subagent_event`
|
|
13
|
-
* tool
|
|
12
|
+
* `extension_ui_request` the host raised for an extension, or a `cortex_subagent_event` /
|
|
13
|
+
* `cortex_subagent_usage` record the Agent tool raised for a nested session) to zero or more
|
|
14
|
+
* NormalizedEvents.
|
|
14
15
|
*
|
|
15
16
|
* Dropped events (return []): turn_start, turn_end, message_start, agent_start,
|
|
16
17
|
* queue_update, compaction_end, auto_retry_start/end, message_update without text_delta,
|
|
@@ -84,6 +85,10 @@ export function piEventToNormalized(event, state) {
|
|
|
84
85
|
const notice = subagentNoticeFrom(ev['notice']);
|
|
85
86
|
return notice ? subagentNoticeEvents(notice) : [];
|
|
86
87
|
}
|
|
88
|
+
// --- cortex_subagent_usage → one cost_record for the nested child that just ended ---
|
|
89
|
+
if (type === 'cortex_subagent_usage') {
|
|
90
|
+
return subagentUsageEvents(ev['report'], state);
|
|
91
|
+
}
|
|
87
92
|
// --- extension_error → error (non-fatal) ---
|
|
88
93
|
if (type === 'extension_error') {
|
|
89
94
|
const errVal = ev['error'];
|
|
@@ -249,6 +254,41 @@ function sumNullableCosts(left, right) {
|
|
|
249
254
|
return null;
|
|
250
255
|
return (left ?? 0) + (right ?? 0);
|
|
251
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* One finished child's spend → the `cost_record` that files it, plus its cost added to the turn
|
|
259
|
+
* the child ran inside. The turn's own `numTurns` is left alone: a subagent is work the parent
|
|
260
|
+
* delegated, not another turn the parent took.
|
|
261
|
+
*
|
|
262
|
+
* Unlike the parent's `agent_end`, a child's accumulator has already collapsed "the provider did
|
|
263
|
+
* not report this category" into 0, so these counts are what was observed rather than a proven
|
|
264
|
+
* exact total. Filed anyway: the alternative on record is nothing at all.
|
|
265
|
+
*/
|
|
266
|
+
function subagentUsageEvents(value, state) {
|
|
267
|
+
const report = asRecord(value);
|
|
268
|
+
const provider = report['provider'];
|
|
269
|
+
if (typeof provider !== 'string' || provider === '')
|
|
270
|
+
return [];
|
|
271
|
+
const usage = asRecord(report['usage']);
|
|
272
|
+
const input = nonNegativeCount(usage['input']);
|
|
273
|
+
const output = nonNegativeCount(usage['output']);
|
|
274
|
+
const cacheRead = nonNegativeCount(usage['cacheRead']);
|
|
275
|
+
const cacheCreation = nonNegativeCount(usage['cacheWrite']);
|
|
276
|
+
const turns = nonNegativeCount(usage['turns']);
|
|
277
|
+
const cost = nullableNonNegativeNumber(usage['cost']);
|
|
278
|
+
state.pendingCompletion.totalCostUsd = sumNullableCosts(state.pendingCompletion.totalCostUsd, cost);
|
|
279
|
+
const model = report['model'];
|
|
280
|
+
return [{
|
|
281
|
+
type: 'cost_record',
|
|
282
|
+
provider,
|
|
283
|
+
model: typeof model === 'string' ? model : '',
|
|
284
|
+
tokens_in: input, tokens_out: output,
|
|
285
|
+
prompt_tokens: input + cacheRead + cacheCreation, cached_tokens: cacheRead,
|
|
286
|
+
input_tokens: input, output_tokens: output,
|
|
287
|
+
cache_read_tokens: cacheRead, cache_creation_tokens: cacheCreation,
|
|
288
|
+
provider_requests: turns > 0 ? turns : null,
|
|
289
|
+
cost_usd: cost,
|
|
290
|
+
}];
|
|
291
|
+
}
|
|
252
292
|
function isSubagentEndStatus(value) {
|
|
253
293
|
return value === 'completed' || value === 'failed' || value === 'killed';
|
|
254
294
|
}
|
|
@@ -347,6 +387,10 @@ export function piContextUsageFromStats(data) {
|
|
|
347
387
|
accuracy: 'estimate',
|
|
348
388
|
};
|
|
349
389
|
}
|
|
390
|
+
/** A count the child reported, floored at 0: the accumulator only ever holds finite numbers. */
|
|
391
|
+
function nonNegativeCount(value) {
|
|
392
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
|
|
393
|
+
}
|
|
350
394
|
function nullableNonNegativeNumber(value) {
|
|
351
395
|
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;
|
|
352
396
|
}
|
|
@@ -2,12 +2,16 @@ import type { InlineExtension } from '@earendil-works/pi-coding-agent';
|
|
|
2
2
|
import type { CodexQuotaReading } from '../../core/codex-quota.js';
|
|
3
3
|
import type { PiSessionRequest } from './session-options.js';
|
|
4
4
|
import type { SubagentNotice } from './event-parser.js';
|
|
5
|
+
import type { SubagentUsageReport } from './subagent.js';
|
|
5
6
|
import type { PiSubagentBridge } from './subagent-bridge.js';
|
|
6
7
|
import { type OpenBundledMcpServer } from './mcp-bridge.js';
|
|
7
8
|
export interface CortexExtensionHooks {
|
|
9
|
+
/** Receives every provider quota reading, from this session and from its nested children alike. */
|
|
8
10
|
onProviderQuota?: (reading: CodexQuotaReading) => void;
|
|
9
11
|
/** Receives each event a subagent forwards for the parent's transcript. */
|
|
10
12
|
onSubagentEvent?: (notice: SubagentNotice) => void;
|
|
13
|
+
/** Receives each finished nested PI child's spend, so a child's tokens reach the cost ledger. */
|
|
14
|
+
onSubagentUsage?: (report: SubagentUsageReport) => void;
|
|
11
15
|
/** The daemon's subagent machinery — cross-backend children and background runs. Injected
|
|
12
16
|
* because it reaches the run registry and the delivery route (D10); left unset, the `agent`
|
|
13
17
|
* tool still delegates to nested PI children and refuses everything else. */
|
|
@@ -20,6 +24,8 @@ export interface CortexExtensionHooks {
|
|
|
20
24
|
* The four Cortex extensions a session runs with, each closed over the session's request rather
|
|
21
25
|
* than `process.env`: the MCP bridge (Cortex bundles in-process, plugin servers as independent
|
|
22
26
|
* connections), the tool shims, the hook bridge unless the role disabled hooks, and the quota
|
|
23
|
-
* probe for gateway-routed runs that have somewhere to report to.
|
|
27
|
+
* probe for gateway-routed runs that have somewhere to report to. The same quota reporter reaches
|
|
28
|
+
* nested child sessions through the shims: a child's provider calls are the parent's spend, and
|
|
29
|
+
* codex publishes quota only on real responses, so dropping the child's would starve the reading.
|
|
24
30
|
*/
|
|
25
31
|
export declare function createCortexExtensions(request: PiSessionRequest, hooks?: CortexExtensionHooks): InlineExtension[];
|
|
@@ -6,9 +6,14 @@ import { createQuotaProbe } from './quota-probe.js';
|
|
|
6
6
|
* The four Cortex extensions a session runs with, each closed over the session's request rather
|
|
7
7
|
* than `process.env`: the MCP bridge (Cortex bundles in-process, plugin servers as independent
|
|
8
8
|
* connections), the tool shims, the hook bridge unless the role disabled hooks, and the quota
|
|
9
|
-
* probe for gateway-routed runs that have somewhere to report to.
|
|
9
|
+
* probe for gateway-routed runs that have somewhere to report to. The same quota reporter reaches
|
|
10
|
+
* nested child sessions through the shims: a child's provider calls are the parent's spend, and
|
|
11
|
+
* codex publishes quota only on real responses, so dropping the child's would starve the reading.
|
|
10
12
|
*/
|
|
11
13
|
export function createCortexExtensions(request, hooks = {}) {
|
|
14
|
+
// Resolved once and handed to both probes — the session's own and the one the shims install on
|
|
15
|
+
// inheriting children — so "does this run report quota" is decided in exactly one place.
|
|
16
|
+
const reportQuota = request.reportsProviderQuota ? hooks.onProviderQuota : undefined;
|
|
12
17
|
const extensions = [
|
|
13
18
|
{
|
|
14
19
|
name: 'cortex-mcp-bridge',
|
|
@@ -18,6 +23,8 @@ export function createCortexExtensions(request, hooks = {}) {
|
|
|
18
23
|
name: 'cortex-tool-shims',
|
|
19
24
|
factory: (pi) => installToolShims(pi, request.env, {
|
|
20
25
|
onSubagentEvent: hooks.onSubagentEvent,
|
|
26
|
+
onSubagentUsage: hooks.onSubagentUsage,
|
|
27
|
+
onProviderQuota: reportQuota,
|
|
21
28
|
runForeignSubagent: hooks.subagent?.runForeignSubagent,
|
|
22
29
|
startBackgroundSubagent: hooks.subagent?.startBackgroundSubagent,
|
|
23
30
|
stopBackgroundSubagent: hooks.subagent?.stopBackgroundSubagent,
|
|
@@ -28,8 +35,8 @@ export function createCortexExtensions(request, hooks = {}) {
|
|
|
28
35
|
if (!request.disableHooks) {
|
|
29
36
|
extensions.push({ name: 'cortex-hook-bridge', factory: (pi) => installHookBridge(pi, request.env) });
|
|
30
37
|
}
|
|
31
|
-
if (
|
|
32
|
-
extensions.push({ name: 'cortex-quota-probe', factory: createQuotaProbe(
|
|
38
|
+
if (reportQuota) {
|
|
39
|
+
extensions.push({ name: 'cortex-quota-probe', factory: createQuotaProbe(reportQuota) });
|
|
33
40
|
}
|
|
34
41
|
return extensions;
|
|
35
42
|
}
|