@cortex-agent/server 2026.9.14 → 2026.9.21
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/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-commission/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-commission/plugin.json +2 -2
- package/defaults/plugins/cortex-commission/skills/commission/SKILL.md +3 -3
- 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/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 +0 -6
- package/dist/agent-adapter/claude/adapter.js +0 -8
- package/dist/agent-adapter/claude/defaults.d.ts +10 -7
- package/dist/agent-adapter/claude/defaults.js +18 -16
- package/dist/agent-adapter/claude/hooks-builder.js +2 -2
- package/dist/agent-adapter/claude/spawn-args.d.ts +0 -3
- package/dist/agent-adapter/claude/spawn-args.js +20 -16
- 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/mcp-bridge-logic.d.ts +11 -2
- package/dist/agent-adapter/pi/mcp-bridge-logic.js +32 -1
- package/dist/agent-adapter/pi/mcp-bridge.js +16 -15
- package/dist/agent-adapter/pi/session-options.d.ts +0 -6
- package/dist/agent-adapter/pi/session-options.js +1 -8
- package/dist/agent-adapter/types.d.ts +1 -1
- package/dist/core/mcp-tool-gate.d.ts +3 -17
- package/dist/core/mcp-tool-gate.js +4 -19
- 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/settings-spec.d.ts +22 -1
- package/dist/core/settings-spec.js +33 -2
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/utils.d.ts +1 -1
- package/dist/core/utils.js +1 -1
- package/dist/domain/agents/config.d.ts +1 -1
- package/dist/domain/agents/config.js +1 -1
- package/dist/domain/agents/profile-switch.d.ts +1 -1
- package/dist/domain/agents/profile-switch.js +3 -5
- package/dist/domain/agents/subagent/runner.js +0 -1
- package/dist/domain/commissions/commission-draft.d.ts +58 -0
- package/dist/domain/commissions/commission-draft.js +87 -4
- package/dist/domain/commissions/commission-finalize.d.ts +8 -3
- package/dist/domain/commissions/commission-finalize.js +14 -0
- package/dist/domain/executions/registry.d.ts +1 -2
- package/dist/domain/executions/registry.js +0 -3
- 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/commission-tools.d.ts +12 -1
- package/dist/domain/mcp/tools/commission-tools.js +68 -14
- 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/projects/project-store.d.ts +1 -1
- package/dist/domain/projects/project-store.js +3 -3
- package/dist/domain/remote/client-hot-reload.js +3 -1
- package/dist/domain/remote/client-manager.js +105 -126
- package/dist/domain/remote/client-ssh-tunnel.d.ts +16 -5
- package/dist/domain/remote/client-ssh-tunnel.js +12 -5
- 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/builders.js +0 -1
- package/dist/domain/runs/compact.js +0 -1
- package/dist/domain/runs/engine-spec.d.ts +11 -4
- package/dist/domain/runs/engine-spec.js +7 -4
- package/dist/domain/runs/prompt.js +16 -10
- package/dist/domain/runs/request.d.ts +0 -1
- package/dist/domain/sessions/session-hooks.d.ts +5 -12
- package/dist/domain/sessions/session-hooks.js +6 -13
- package/dist/domain/sessions/session-lifecycle.d.ts +4 -4
- package/dist/domain/sessions/session-lifecycle.js +5 -6
- package/dist/domain/sessions/session-retention.d.ts +1 -3
- package/dist/domain/sessions/session-retention.js +9 -26
- package/dist/domain/sessions/session-use.d.ts +32 -0
- package/dist/domain/sessions/session-use.js +63 -0
- package/dist/domain/sessions/session.js +6 -5
- package/dist/domain/system/server-update-check.js +29 -1
- package/dist/domain/system/update-ui-state.d.ts +32 -0
- package/dist/domain/system/update-ui-state.js +63 -0
- 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 +2 -2
- package/dist/domain/tasks/system/task-cli.js +2 -2
- package/dist/domain/tasks/system/task-state.js +1 -1
- package/dist/domain/threads/runner.js +3 -2
- package/dist/domain/ui-service/app-router.d.ts +54 -3
- package/dist/domain/ui-service/app-router.js +12 -14
- package/dist/domain/ui-service/input-schemas.d.ts +49 -5
- package/dist/domain/ui-service/input-schemas.js +35 -9
- package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
- package/dist/domain/ui-service/mutate/sessions.d.ts +17 -1
- package/dist/domain/ui-service/mutate/sessions.js +83 -3
- package/dist/domain/ui-service/mutate/system.d.ts +3 -1
- package/dist/domain/ui-service/mutate/system.js +13 -0
- 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 +1 -1
- 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 +1 -1
- package/dist/domain/ui-service/query/sessions.js +7 -0
- package/dist/domain/ui-service/query/system.d.ts +2 -1
- package/dist/domain/ui-service/query/system.js +4 -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 +3 -0
- package/dist/domain/ui-service/query-input-schemas.js +3 -0
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +175 -50
- package/dist/domain/ui-service/types.js +1 -1
- package/dist/domain/ui-service/ui-service.js +13 -33
- 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 +39 -29
- package/dist/entry/auth-login-cli.js +1 -1
- package/dist/entry/auth-login-terminal.js +1 -1
- 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 +5 -3
- package/dist/events/event-types.d.ts +5 -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 +4 -3
- package/dist/orchestration/agent-runner.js +25 -23
- package/dist/orchestration/attachments-store.d.ts +31 -0
- package/dist/orchestration/attachments-store.js +184 -0
- package/dist/orchestration/conversation-request.d.ts +30 -8
- package/dist/orchestration/conversation-request.js +62 -26
- package/dist/orchestration/edit-retry.js +2 -1
- package/dist/orchestration/interactions/ask-user-resume.js +2 -1
- package/dist/orchestration/interactions/plan-approvals.js +1 -1
- package/dist/orchestration/interactions/ui-update-prompt.d.ts +8 -0
- package/dist/orchestration/interactions/ui-update-prompt.js +47 -0
- package/dist/orchestration/outputs-store.d.ts +11 -0
- package/dist/orchestration/outputs-store.js +32 -6
- package/dist/orchestration/resume-dispatcher.js +2 -2
- 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 +240 -39
- package/dist/orchestration/session-compact.d.ts +3 -0
- package/dist/orchestration/session-compact.js +3 -2
- package/dist/orchestration/session-events.d.ts +6 -0
- package/dist/orchestration/session-events.js +5 -0
- 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 +11 -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 +21 -9
- 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/app-update.d.ts +11 -0
- package/dist/platform/ui-http/app-update.js +3 -0
- 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-ledger-repo.d.ts +10 -19
- package/dist/store/conversation-ledger-repo.js +143 -152
- 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.d.ts +34 -0
- package/dist/store/session-registry-import.js +182 -0
- package/dist/store/session-registry-journal.d.ts +107 -0
- package/dist/store/session-registry-journal.js +308 -19
- package/dist/store/session-registry-repo.d.ts +113 -28
- package/dist/store/session-registry-repo.js +288 -105
- package/dist/store/version-migrations.d.ts +29 -3
- package/dist/store/version-migrations.js +288 -24
- package/dist/store/waitpoint-repo.d.ts +108 -0
- package/dist/store/waitpoint-repo.js +94 -0
- package/package.json +2 -2
- package/web/dist/assets/index-CwwQNMpP.css +1 -0
- package/web/dist/assets/index-DLSfgq3o.js +444 -0
- package/web/dist/assets/{index-aHbOZSP6.js → index-DZTuqUO4.js} +1 -1
- package/web/dist/index.html +2 -2
- 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/dist/store/session-repo.d.ts +0 -65
- package/dist/store/session-repo.js +0 -184
- package/web/dist/assets/index-BuXbCsuz.js +0 -444
- package/web/dist/assets/index-CCPxQ94C.css +0 -1
- /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
|
@@ -34,7 +34,7 @@ Inspect the project's code and resources. If multiple machines host parts of the
|
|
|
34
34
|
|
|
35
35
|
Create the project directory and files under `context/projects/<project-name>/`:
|
|
36
36
|
|
|
37
|
-
###
|
|
37
|
+
### AGENTS.md (required) — Project index
|
|
38
38
|
|
|
39
39
|
This is the entry point for future sessions. Must include:
|
|
40
40
|
- One-line project description
|
|
@@ -129,13 +129,13 @@ Skip for projects already in late-stage delivery. Create only when the project h
|
|
|
129
129
|
|
|
130
130
|
## Step 3: Update Indexes
|
|
131
131
|
|
|
132
|
-
1. Add the project to `context/projects/
|
|
132
|
+
1. Add the project to `context/projects/AGENTS.md` project list table
|
|
133
133
|
2. Add the project to `context/OVERVIEW.md`
|
|
134
134
|
|
|
135
135
|
## Step 4: Commit
|
|
136
136
|
|
|
137
137
|
```
|
|
138
|
-
git add context/projects/<project-name>/ context/projects/
|
|
138
|
+
git add context/projects/<project-name>/ context/projects/AGENTS.md context/OVERVIEW.md
|
|
139
139
|
git commit -m "project-init: add <project-name> (<brief description>)"
|
|
140
140
|
```
|
|
141
141
|
|
|
@@ -150,7 +150,7 @@ Output a structured summary:
|
|
|
150
150
|
## Principles
|
|
151
151
|
|
|
152
152
|
- **Read the README and core docs first** — understanding the project is prerequisite to useful context files
|
|
153
|
-
-
|
|
153
|
+
- AGENTS.md is the most important file — it's the entry point for all future sessions
|
|
154
154
|
- Location map must be exhaustive — every relevant path on every machine
|
|
155
155
|
- Auto-generated content is clearly marked — the user owns the final version
|
|
156
156
|
- mission.md is a draft until the user confirms
|
|
@@ -146,7 +146,7 @@ The following mutation commands **must** hold the project lock first, otherwise
|
|
|
146
146
|
- `decompose` — Decompose into subtasks
|
|
147
147
|
- `assign-ids` — Assign task IDs
|
|
148
148
|
|
|
149
|
-
Lifecycle commands (claim / complete / block / unblock / pause / resume / approval series / stop, etc.) **do not need** a lock — they are called routinely by the dispatcher
|
|
149
|
+
Lifecycle commands (claim / complete / block / unblock / pause / resume / approval series / stop, etc.) **do not need** a lock — they are called routinely by the dispatcher on automated paths.
|
|
150
150
|
|
|
151
151
|
### Lock semantics
|
|
152
152
|
|
|
@@ -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.
|
|
@@ -12,8 +12,6 @@ interface ClaudeSessionOptions {
|
|
|
12
12
|
needsResume: boolean;
|
|
13
13
|
model?: string | null;
|
|
14
14
|
isUserInitiated?: boolean;
|
|
15
|
-
/** Expose the commission-creation tools; set only while a contract is being drafted. */
|
|
16
|
-
commissionTools?: boolean;
|
|
17
15
|
callbackSource?: string | null;
|
|
18
16
|
scheduleTaskId?: string | null;
|
|
19
17
|
sessionKey?: string | null;
|
|
@@ -67,9 +65,6 @@ export interface ClaudeSpawnCompatibility {
|
|
|
67
65
|
routeIdentity: string;
|
|
68
66
|
composition: McpComposition;
|
|
69
67
|
interactionBridge: boolean;
|
|
70
|
-
/** Adding the commission tools rewrites `--tools`, which a live process cannot be re-pointed
|
|
71
|
-
* at, so a change must force a fresh spawn + `--resume`. */
|
|
72
|
-
commissionTools: boolean;
|
|
73
68
|
tools: string | null;
|
|
74
69
|
pluginCapabilityFingerprint: string | null;
|
|
75
70
|
pluginDirs: string[];
|
|
@@ -101,7 +96,6 @@ declare class ClaudeSession implements TurnHost {
|
|
|
101
96
|
/** Model name requested via --model CLI arg (used as fallback for cost_record). */
|
|
102
97
|
modelName: string | null;
|
|
103
98
|
private isUserInitiated;
|
|
104
|
-
private commissionTools;
|
|
105
99
|
private callbackSource;
|
|
106
100
|
private scheduleTaskId;
|
|
107
101
|
private claudeAgent;
|
|
@@ -72,7 +72,6 @@ export function sameClaudeSpawnCompatibility(left, right) {
|
|
|
72
72
|
&& left.routeIdentity === right.routeIdentity
|
|
73
73
|
&& left.composition === right.composition
|
|
74
74
|
&& left.interactionBridge === right.interactionBridge
|
|
75
|
-
&& left.commissionTools === right.commissionTools
|
|
76
75
|
&& left.tools === right.tools
|
|
77
76
|
&& left.pluginCapabilityFingerprint === right.pluginCapabilityFingerprint
|
|
78
77
|
&& left.supplementalMcpConfigIdentity === right.supplementalMcpConfigIdentity
|
|
@@ -88,7 +87,6 @@ function compatibilityFromOptions(options) {
|
|
|
88
87
|
routeIdentity: claudeRouteIdentity(options),
|
|
89
88
|
composition,
|
|
90
89
|
interactionBridge: composition === 'direct' && options.isUserInitiated === true,
|
|
91
|
-
commissionTools: options.commissionTools === true,
|
|
92
90
|
tools: options.tools ?? null,
|
|
93
91
|
pluginCapabilityFingerprint: options.pluginCapabilityFingerprint ?? null,
|
|
94
92
|
pluginDirs: cloneTextArray(options.pluginDirs),
|
|
@@ -112,7 +110,6 @@ export function claudeCompatibilityIdentity(compatibility) {
|
|
|
112
110
|
['routeIdentity', compatibility.routeIdentity],
|
|
113
111
|
['composition', compatibility.composition],
|
|
114
112
|
['interactionBridge', compatibility.interactionBridge],
|
|
115
|
-
['commissionTools', compatibility.commissionTools],
|
|
116
113
|
['tools', compatibility.tools],
|
|
117
114
|
['pluginCapabilityFingerprint', compatibility.pluginCapabilityFingerprint],
|
|
118
115
|
['supplementalMcpConfigIdentity', compatibility.supplementalMcpConfigIdentity],
|
|
@@ -140,7 +137,6 @@ class ClaudeSession {
|
|
|
140
137
|
/** Model name requested via --model CLI arg (used as fallback for cost_record). */
|
|
141
138
|
modelName;
|
|
142
139
|
isUserInitiated;
|
|
143
|
-
commissionTools;
|
|
144
140
|
callbackSource;
|
|
145
141
|
scheduleTaskId;
|
|
146
142
|
claudeAgent;
|
|
@@ -195,7 +191,6 @@ class ClaudeSession {
|
|
|
195
191
|
this.cwd = resolveSpawnCwd(options.cwd);
|
|
196
192
|
this.turns = new ClaudeTurnMachine(this, createContextUsageTracker(this.modelName, this.cwd, options));
|
|
197
193
|
this.isUserInitiated = options.isUserInitiated || false;
|
|
198
|
-
this.commissionTools = options.commissionTools === true;
|
|
199
194
|
this.callbackSource = options.callbackSource || null;
|
|
200
195
|
this.scheduleTaskId = options.scheduleTaskId || null;
|
|
201
196
|
this.claudeAgent = options.claudeAgent || null;
|
|
@@ -285,7 +280,6 @@ class ClaudeSession {
|
|
|
285
280
|
options.loadFeishuMcp = this.channel.startsWith('feishu:');
|
|
286
281
|
options.loadWebMcp = this.channel.startsWith('web:');
|
|
287
282
|
options.isUserInitiated = this.isUserInitiated;
|
|
288
|
-
options.commissionTools = this.commissionTools;
|
|
289
283
|
const env = buildClaudeEnv(this.channel, this.sessionId, this.callbackSource, this.scheduleTaskId, this.anthropicBaseUrl, this.extraEnv, this.context, this.pinnedEnv, this.unsetEnv);
|
|
290
284
|
env[MCP_BUNDLES_ENV] = encodeMcpBundles(resolveClaudeMcpBundles(options));
|
|
291
285
|
return { args: buildSpawnArgs(options), env };
|
|
@@ -566,7 +560,6 @@ function sessionRuntimeOptions(spec, composition) {
|
|
|
566
560
|
mcpComposition: composition,
|
|
567
561
|
mcpConfigPaths: spec.mcp.configPaths,
|
|
568
562
|
mcpToolAllowlist: spec.mcp.allowlist,
|
|
569
|
-
commissionTools: spec.mcp.commissionTools === true,
|
|
570
563
|
supplementalMcpConfigPath: supplemental?.path ?? null,
|
|
571
564
|
supplementalMcpConfigIdentity: supplemental?.identity ?? null,
|
|
572
565
|
browserMcpConfigPath: browser?.path ?? null,
|
|
@@ -620,7 +613,6 @@ function computeSpawnArgsForSpec(spec) {
|
|
|
620
613
|
streamDeltas: opts.streamDeltas,
|
|
621
614
|
});
|
|
622
615
|
spawnOptions.isUserInitiated = spec.flags.isUserInitiated;
|
|
623
|
-
spawnOptions.commissionTools = spec.mcp.commissionTools === true;
|
|
624
616
|
return buildSpawnArgs(spawnOptions);
|
|
625
617
|
}
|
|
626
618
|
/** D9: `claudeBackend: 'tui'` is accepted but deprecated; warn once per process, then run print. */
|
|
@@ -29,14 +29,17 @@ export declare const DEFAULT_PLAN_DIRS: string[];
|
|
|
29
29
|
* tool (see {@link ALWAYS_STRIP_TOOLS}), so both backends delegate through one implementation. */
|
|
30
30
|
export declare const DEFAULT_TOOLS = "AskUserQuestion,Bash,Edit,EnterPlanMode,ExitPlanMode,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write";
|
|
31
31
|
/**
|
|
32
|
-
* The cortex-interaction-bridge MCP tools that replace the native EnterPlanMode /
|
|
33
|
-
* AskUserQuestion
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
32
|
+
* The cortex-interaction-bridge MCP tools: the three that replace the native EnterPlanMode /
|
|
33
|
+
* ExitPlanMode / AskUserQuestion, plus the two commission-creation tools. Shared by user-initiated
|
|
34
|
+
* Claude print sessions and user-initiated PI sessions.
|
|
35
|
+
*
|
|
36
|
+
* The commission pair is listed unconditionally (DR-0037 v4). Listing it per session was v3's lever
|
|
37
|
+
* for hiding it, and that lever never existed: `--tools` filters Claude's BUILT-IN set only
|
|
38
|
+
* ("the list of available tools from the built-in set", `claude --help`), so an MCP tool registered
|
|
39
|
+
* by the bundled server was callable from every direct session whatever this list said. What keeps
|
|
40
|
+
* a commission from being bootstrapped out of an ordinary session is a state check in
|
|
41
|
+
* `commission-finalize`, not tool visibility — and a check that holds on both backends.
|
|
37
42
|
*/
|
|
38
|
-
export declare function interactionBridgeTools(commissionTools?: boolean): string[];
|
|
39
|
-
/** Default (non-commission) bridge surface. */
|
|
40
43
|
export declare const INTERACTION_BRIDGE_TOOLS: readonly string[];
|
|
41
44
|
/** Native interaction tools that must be stripped wherever the interaction bridge replaces them —
|
|
42
45
|
* i.e. a direct, user-initiated session, which is the only composition that loads the bridge.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as os from 'os';
|
|
3
3
|
import { DATA_DIR, CONFIG_DIR, HOOKS_DIR } from '../../core/utils.js';
|
|
4
|
-
import {
|
|
4
|
+
import { SUBAGENT_TOOLS } from '../../core/mcp-tool-gate.js';
|
|
5
5
|
export const IDLE_SESSION_TIMEOUT = 65 * 60 * 1000;
|
|
6
6
|
export const TURN_IDLE_TIMEOUT = 60 * 60 * 1000;
|
|
7
7
|
/** DR-0012: tmux session name prefix used by the startup migration sweep
|
|
@@ -38,22 +38,24 @@ export const DEFAULT_TOOLS = 'AskUserQuestion,Bash,Edit,EnterPlanMode,ExitPlanMo
|
|
|
38
38
|
* The bundled server is exposed under the `cortex-core` name regardless of which bundles it loads. */
|
|
39
39
|
const MCP_PREFIX = 'mcp__cortex-core__';
|
|
40
40
|
/**
|
|
41
|
-
* The cortex-interaction-bridge MCP tools that replace the native EnterPlanMode /
|
|
42
|
-
* AskUserQuestion
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
41
|
+
* The cortex-interaction-bridge MCP tools: the three that replace the native EnterPlanMode /
|
|
42
|
+
* ExitPlanMode / AskUserQuestion, plus the two commission-creation tools. Shared by user-initiated
|
|
43
|
+
* Claude print sessions and user-initiated PI sessions.
|
|
44
|
+
*
|
|
45
|
+
* The commission pair is listed unconditionally (DR-0037 v4). Listing it per session was v3's lever
|
|
46
|
+
* for hiding it, and that lever never existed: `--tools` filters Claude's BUILT-IN set only
|
|
47
|
+
* ("the list of available tools from the built-in set", `claude --help`), so an MCP tool registered
|
|
48
|
+
* by the bundled server was callable from every direct session whatever this list said. What keeps
|
|
49
|
+
* a commission from being bootstrapped out of an ordinary session is a state check in
|
|
50
|
+
* `commission-finalize`, not tool visibility — and a check that holds on both backends.
|
|
46
51
|
*/
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
/** Default (non-commission) bridge surface. */
|
|
56
|
-
export const INTERACTION_BRIDGE_TOOLS = interactionBridgeTools();
|
|
52
|
+
export const INTERACTION_BRIDGE_TOOLS = [
|
|
53
|
+
`${MCP_PREFIX}cortex_plan_enter`,
|
|
54
|
+
`${MCP_PREFIX}cortex_plan_exit`,
|
|
55
|
+
`${MCP_PREFIX}cortex_ask_user`,
|
|
56
|
+
`${MCP_PREFIX}cortex_commission_start`,
|
|
57
|
+
`${MCP_PREFIX}cortex_commission_submit`,
|
|
58
|
+
];
|
|
57
59
|
/** Native interaction tools that must be stripped wherever the interaction bridge replaces them —
|
|
58
60
|
* i.e. a direct, user-initiated session, which is the only composition that loads the bridge.
|
|
59
61
|
* The native tools drop the prompt into a mode Cortex cannot mediate headlessly. */
|
|
@@ -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 {
|
|
@@ -16,9 +16,6 @@ export interface ClaudeSpawnOptions {
|
|
|
16
16
|
mcpConfigPaths?: string[] | null;
|
|
17
17
|
/** Canonical per-tool MCP allowlist. */
|
|
18
18
|
mcpToolAllowlist?: string[] | null;
|
|
19
|
-
/** Add the two standalone commission-creation tools. Only meaningful when the interaction bridge
|
|
20
|
-
* is on, and set only while a NEW commission is being drafted (DR-0037 v3). */
|
|
21
|
-
commissionTools?: boolean;
|
|
22
19
|
/** Supplemental Claude MCP config written from portable runtime servers. */
|
|
23
20
|
supplementalMcpConfigPath?: string | null;
|
|
24
21
|
/** Omit all configured ambient hooks. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
|
-
import { ALWAYS_STRIP_TOOLS, DEFAULT_TOOLS, EMPTY_MCP_CONFIG, MCP_CONFIG, THREAD_MCP_CONFIG,
|
|
2
|
+
import { ALWAYS_STRIP_TOOLS, DEFAULT_TOOLS, EMPTY_MCP_CONFIG, MCP_CONFIG, THREAD_MCP_CONFIG, INTERACTION_BRIDGE_TOOLS, subagentBridgeTools, INTERACTION_STRIP_TOOLS, } from './defaults.js';
|
|
3
3
|
import { getSettings } from '../../core/settings.js';
|
|
4
4
|
import { materializeMcpToolAllowlistConfigs } from '../../core/config-generator.js';
|
|
5
5
|
import { MCP_INFRASTRUCTURE_TIMEOUT_MS } from '../../core/mcp-timeout.js';
|
|
@@ -31,9 +31,9 @@ function resolveMcpConfigs(options, composition) {
|
|
|
31
31
|
}
|
|
32
32
|
appendBrowserMcpConfig(configs, options, composition === 'direct');
|
|
33
33
|
const bundles = resolveClaudeMcpBundles(options);
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
34
|
+
// Only an explicitly declared allowlist materializes a gated config (subagents). A direct session
|
|
35
|
+
// declares none and therefore registers its bundles whole — deliberate since DR-0037 v4: no tool
|
|
36
|
+
// in the direct surface is hidden per session, so nothing here has to depend on config *content*.
|
|
37
37
|
const allowlist = options.mcpToolAllowlist ?? undefined;
|
|
38
38
|
return materializeMcpToolAllowlistConfigs(configs, allowlist, undefined, bundles);
|
|
39
39
|
}
|
|
@@ -94,20 +94,23 @@ function subagentTools(options) {
|
|
|
94
94
|
* The exact `--tools` list, after both native-for-MCP substitutions.
|
|
95
95
|
*
|
|
96
96
|
* `Agent` is dropped unconditionally and replaced by the MCP `agent` tool (see
|
|
97
|
-
* {@link ALWAYS_STRIP_TOOLS}). The three interaction tools are dropped only where Cortex
|
|
98
|
-
* approvals through the bridge
|
|
99
|
-
*
|
|
100
|
-
*
|
|
97
|
+
* {@link ALWAYS_STRIP_TOOLS}). The three native interaction tools are dropped only where Cortex
|
|
98
|
+
* mediates approvals through the bridge — `bridge` false (a non-user-initiated or non-direct
|
|
99
|
+
* session) means "keep the natives, add nothing back".
|
|
100
|
+
*
|
|
101
|
+
* Note what this list does NOT do: it cannot hide an MCP tool. `--tools` filters the built-in set
|
|
102
|
+
* only, so naming MCP tools here is a declaration of intent the CLI does not enforce. Anything that
|
|
103
|
+
* must be denied per session is denied at the MCP layer (`CORTEX_MCP_TOOL_ALLOWLIST`) or by the
|
|
104
|
+
* tool's own validation.
|
|
101
105
|
*/
|
|
102
|
-
function resolveEffectiveTools(options,
|
|
103
|
-
const stripInteraction = commissionTools !== null;
|
|
106
|
+
function resolveEffectiveTools(options, bridge) {
|
|
104
107
|
const kept = (options.tools || DEFAULT_TOOLS).split(',')
|
|
105
108
|
.map(tool => tool.trim())
|
|
106
109
|
.filter(tool => tool
|
|
107
110
|
&& !ALWAYS_STRIP_TOOLS.has(tool)
|
|
108
|
-
&& !(
|
|
111
|
+
&& !(bridge && INTERACTION_STRIP_TOOLS.has(tool)));
|
|
109
112
|
const appended = [
|
|
110
|
-
...(
|
|
113
|
+
...(bridge ? INTERACTION_BRIDGE_TOOLS : []),
|
|
111
114
|
...subagentTools(options),
|
|
112
115
|
];
|
|
113
116
|
return [...new Set([...kept, ...appended])].join(',');
|
|
@@ -160,12 +163,9 @@ export function buildSpawnArgs(options) {
|
|
|
160
163
|
const composition = options.mcpComposition ?? 'direct';
|
|
161
164
|
const isDirect = composition === 'direct';
|
|
162
165
|
const wantsInteractionBridge = isDirect && !!options.isUserInitiated;
|
|
163
|
-
const commissionTools = wantsInteractionBridge
|
|
164
|
-
? !!options.commissionTools
|
|
165
|
-
: null;
|
|
166
166
|
const configs = resolveMcpConfigs(options, composition);
|
|
167
167
|
const args = printModeArgs(options);
|
|
168
|
-
const tools = resolveEffectiveTools(options,
|
|
168
|
+
const tools = resolveEffectiveTools(options, wantsInteractionBridge);
|
|
169
169
|
appendCoreArgs(args, configs, composition, tools);
|
|
170
170
|
appendPromptOptions(args, options);
|
|
171
171
|
appendRepeatedOption(args, '--plugin-dir', options.pluginDirs);
|
|
@@ -310,6 +310,10 @@ export function buildClaudeEnv(channel, sessionId, callbackSource, scheduleTaskI
|
|
|
310
310
|
// CORTEX_SESSION_ID is the stable Cortex tracking id (session-activity log routing + MCP context),
|
|
311
311
|
// NOT the backend CLI's self-assigned session id. Falls back to the backend id when unset (threads).
|
|
312
312
|
env.CORTEX_SESSION_ID = context?.trackSessionId ?? sessionId;
|
|
313
|
+
// Declared, not inferred: hooks branch on which backend loaded the AGENTS.md chain natively
|
|
314
|
+
// (agents-md-injector.mjs), and "absent means Claude" would silently mis-handle any future
|
|
315
|
+
// spawn path that forgets to set it. PI states itself in agent-adapter/pi/session-options.ts.
|
|
316
|
+
env.CORTEX_BACKEND = 'claude';
|
|
313
317
|
setIfPresent(env, 'CORTEX_CALLBACK_SOURCE', callbackSource);
|
|
314
318
|
setIfPresent(env, 'CORTEX_SCHEDULE_TASK_ID', scheduleTaskId);
|
|
315
319
|
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
|
}
|
|
@@ -7,7 +7,16 @@ type PiTextContent = {
|
|
|
7
7
|
type: 'text';
|
|
8
8
|
text: string;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type PiImageContent = {
|
|
11
|
+
type: 'image';
|
|
12
|
+
data: string;
|
|
13
|
+
mimeType: string;
|
|
14
|
+
};
|
|
15
|
+
export type PiContent = PiTextContent | PiImageContent;
|
|
16
|
+
/** Map an MCP content item into PI content without silently dropping unsupported payloads.
|
|
17
|
+
* Images pass through as image blocks — PI tool results carry `(TextContent | ImageContent)[]`
|
|
18
|
+
* natively, so `remote_read` and any other image-returning MCP tool stay visible to a vision
|
|
19
|
+
* model. Only what PI cannot send inline degrades to a description. */
|
|
11
20
|
export declare function mapMcpContent(item: {
|
|
12
21
|
type: string;
|
|
13
22
|
text?: string;
|
|
@@ -20,5 +29,5 @@ export declare function mapMcpContent(item: {
|
|
|
20
29
|
mimeType?: string;
|
|
21
30
|
};
|
|
22
31
|
[key: string]: unknown;
|
|
23
|
-
}):
|
|
32
|
+
}): PiContent;
|
|
24
33
|
export {};
|
|
@@ -11,12 +11,40 @@ export function shouldLoadWeb(channel) {
|
|
|
11
11
|
export function shouldLoadThreadControl(threadId) {
|
|
12
12
|
return !!threadId;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
14
|
+
/** The inline image types every PI provider adapter can encode (`pi-ai` normalizes to exactly
|
|
15
|
+
* these). Anything else reaching a provider is a 400, so an unknown type stays a text note. */
|
|
16
|
+
const PI_IMAGE_MIMES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
|
|
17
|
+
/** The provider-safe form of `mimeType`, or null when PI cannot send it inline. */
|
|
18
|
+
function inlineImageMime(mimeType) {
|
|
19
|
+
if (!mimeType)
|
|
20
|
+
return null;
|
|
21
|
+
const base = mimeType.split(';')[0]?.trim().toLowerCase();
|
|
22
|
+
if (!base)
|
|
23
|
+
return null;
|
|
24
|
+
const normalized = base === 'image/jpg' ? 'image/jpeg' : base;
|
|
25
|
+
return PI_IMAGE_MIMES.has(normalized) ? normalized : null;
|
|
26
|
+
}
|
|
27
|
+
/** An image block PI will carry to the model, or null to fall back to a text description.
|
|
28
|
+
* A model without vision needs no guard here: `pi-ai` downgrades image blocks to a placeholder
|
|
29
|
+
* before the request is built (transform-messages.ts, `downgradeUnsupportedImages`). */
|
|
30
|
+
function inlineImage(data, mimeType) {
|
|
31
|
+
const mime = inlineImageMime(mimeType);
|
|
32
|
+
if (!mime || typeof data !== 'string' || data.length === 0)
|
|
33
|
+
return null;
|
|
34
|
+
return { type: 'image', data, mimeType: mime };
|
|
35
|
+
}
|
|
36
|
+
/** Map an MCP content item into PI content without silently dropping unsupported payloads.
|
|
37
|
+
* Images pass through as image blocks — PI tool results carry `(TextContent | ImageContent)[]`
|
|
38
|
+
* natively, so `remote_read` and any other image-returning MCP tool stay visible to a vision
|
|
39
|
+
* model. Only what PI cannot send inline degrades to a description. */
|
|
15
40
|
export function mapMcpContent(item) {
|
|
16
41
|
if (item.type === 'text' && typeof item.text === 'string') {
|
|
17
42
|
return { type: 'text', text: item.text };
|
|
18
43
|
}
|
|
19
44
|
if (item.type === 'image') {
|
|
45
|
+
const image = inlineImage(item.data, item.mimeType);
|
|
46
|
+
if (image)
|
|
47
|
+
return image;
|
|
20
48
|
const len = typeof item.data === 'string' ? item.data.length : 0;
|
|
21
49
|
return { type: 'text', text: `[Image: mimeType=${item.mimeType ?? 'unknown'}, base64(${len} chars)]` };
|
|
22
50
|
}
|
|
@@ -25,6 +53,9 @@ export function mapMcpContent(item) {
|
|
|
25
53
|
if (typeof resource.text === 'string')
|
|
26
54
|
return { type: 'text', text: resource.text };
|
|
27
55
|
if (typeof resource.blob === 'string') {
|
|
56
|
+
const image = inlineImage(resource.blob, resource.mimeType);
|
|
57
|
+
if (image)
|
|
58
|
+
return image;
|
|
28
59
|
return {
|
|
29
60
|
type: 'text',
|
|
30
61
|
text: `[Binary resource: uri=${resource.uri ?? 'unknown'}, mimeType=${resource.mimeType ?? 'unknown'}]`,
|