@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
package/README.md
CHANGED
|
@@ -147,16 +147,17 @@ variable reference, file layout, and precedence rules are in
|
|
|
147
147
|
| [Browser Access](./docs/browser-access.md) | Web workbench authentication and deployment |
|
|
148
148
|
| [Slack Setup](./docs/slack-setup.md) | App creation, token collection, Socket Mode, scopes |
|
|
149
149
|
| [Configuration](./docs/configuration.md) | Full `.env` and `config/settings.json` reference, `profiles.json`, file layout, hot-reload |
|
|
150
|
-
| [CLI Reference](./docs/cli-reference.md) | `cortex`, `cortex-task`, `cortex-
|
|
150
|
+
| [CLI Reference](./docs/cli-reference.md) | `cortex`, `cortex-task`, `cortex-signal` — every subcommand and flag |
|
|
151
151
|
| [Backends](./docs/backends.md) | Claude Code vs PI, feature matrix, fallback, cost reporting |
|
|
152
152
|
| [Architecture](./docs/architecture.md) | Server layers, WS protocol, event bus |
|
|
153
153
|
| [Threads](./docs/threads.md) | Multi-agent pipelines, templates, transitions, hooks |
|
|
154
|
-
| [Tasks](./docs/tasks.md) | TASKS.yaml format, lifecycle, dispatch,
|
|
154
|
+
| [Tasks](./docs/tasks.md) | TASKS.yaml format, lifecycle, dispatch, acceptance ledger |
|
|
155
155
|
| [Memory](./docs/memory.md) | EXP/K/PAT atomized knowledge, project log governance |
|
|
156
156
|
| [Skills & Plugins](./docs/skills-and-plugins.md) | Skill authoring, plugin layout, third-party plugins |
|
|
157
157
|
| [Scheduling](./docs/scheduling.md) | Interval/daily/weekly/once schedules, preCheck, fallback |
|
|
158
158
|
| [Safety & Approvals](./docs/safety-and-approvals.md) | Blast-radius classes, approval workflow, audit trail |
|
|
159
159
|
| [Hooks](./docs/hooks.md) | Hook lifecycle, hook-bridge, custom hooks in settings.json |
|
|
160
|
+
| [Waitpoints](./docs/waitpoints.md) | Waiting on external jobs without polling: arm, signal, quorum, expiry |
|
|
160
161
|
| [MCP](./docs/mcp.md) | Privilege-scoped Cortex MCP servers, third-party MCP |
|
|
161
162
|
| [Cross-machine](./docs/cross-machine.md) | cortex-client deployment, remote tools, network topology |
|
|
162
163
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "
|
|
2
|
+
"id": "agents-md-injector-session-start",
|
|
3
3
|
"event": "agent:session-start",
|
|
4
4
|
"matcher": "startup|resume|clear|compact",
|
|
5
5
|
"run": {
|
|
6
|
-
"script": "
|
|
6
|
+
"script": "agents-md-injector.mjs"
|
|
7
7
|
},
|
|
8
8
|
"enabled": true,
|
|
9
|
-
"version": "2026.
|
|
9
|
+
"version": "2026.9.15"
|
|
10
10
|
}
|
|
@@ -8,8 +8,8 @@ Managed declarative hooks shipped into the user hook registry.
|
|
|
8
8
|
| 05-memory-ref-tracker.json | tracker | Tracks memory reference reads |
|
|
9
9
|
| 06-rules-loader.json | loader | Loads matching rules after reads |
|
|
10
10
|
| 07-session-activity-tracker.json | tracker | Records session tool activity |
|
|
11
|
-
| 08-
|
|
12
|
-
| 10-
|
|
11
|
+
| 08-agents-md-injector-post-tool.json | context | Injects directory context after tools |
|
|
12
|
+
| 10-agents-md-injector-session-start.json | context | Injects context at session start |
|
|
13
13
|
| 11-task-status-check.json | thread | Checks task state when dispatch threads end |
|
|
14
14
|
| 12-session-new-hook.json | session | Flushes memory before starting a new session |
|
|
15
15
|
| 13-status-md-guard.json | guard | Enforces STATUS.md register size caps |
|
|
@@ -5,7 +5,7 @@ Managed hook scripts deployed into the runtime hook directory.
|
|
|
5
5
|
| filename | role | function |
|
|
6
6
|
|---|---|---|
|
|
7
7
|
| cortex-hook-api.mjs | library | posts non-empty question arrays for hooks |
|
|
8
|
-
|
|
|
8
|
+
| agents-md-injector.mjs | context | Injects matching directory context; also exports runHook for in-process callers |
|
|
9
9
|
| memory-ref-tracker.mjs | tracker | Records memory reference reads |
|
|
10
10
|
| new-session-hook.mjs | session | Builds the new-session flush prompt |
|
|
11
11
|
| rules-loader.mjs | loader | Loads matching rules after file reads |
|
|
@@ -1,33 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @cortex-hook-version 2026.
|
|
2
|
+
// @cortex-hook-version 2026.9.15 ← set to the current release version (agent-server/package.json) whenever you change this hook; syncManagedHooks then refreshes deployed installs
|
|
3
3
|
// input: stdin JSON — Claude Code hook event or PI hook-bridge payload; or runHook(payload, env)
|
|
4
4
|
// output: { hookSpecificOutput: { hookEventName, additionalContext, matched } }
|
|
5
5
|
// Exported `runHook` is the in-process entry point: the PI hook bridge calls it directly
|
|
6
6
|
// instead of spawning this file, so every path here takes its scope from the `env`
|
|
7
7
|
// argument rather than process.env (one daemon process serves many sessions).
|
|
8
|
-
// pos: Inject
|
|
8
|
+
// pos: Inject the AGENTS.md / AGENTS.local.md ancestor chain that THE BACKEND DOES NOT LOAD.
|
|
9
|
+
// Both backends load AGENTS.md natively now, so this hook only covers their blind spots
|
|
10
|
+
// (see backendLoadsNatively below for the measured matrix):
|
|
11
|
+
// · paths outside the session cwd tree — neither backend loads these
|
|
12
|
+
// · AGENTS.local.md, anywhere — neither backend has a `.local` name
|
|
13
|
+
// · descendants of cwd, on PI — PI walks cwd→root only, never downward
|
|
14
|
+
// Anything the backend already loaded is recorded in the dedup cache WITHOUT being
|
|
15
|
+
// injected, so the agent never receives the same rules twice.
|
|
9
16
|
// 2-event dispatch:
|
|
10
17
|
// PostToolUse (Read|Edit) — from tool_input.file_path/path
|
|
11
18
|
// SessionStart (startup|resume|clear|compact) — from payload.cwd
|
|
12
19
|
// Shared per-session cache with remote MCP injection under tmp/cortexmd-cache
|
|
13
20
|
// — stable session + physical host + path + mtime dedup across tool families
|
|
14
21
|
// — only files actually injected are marked seen; truncated files stay eligible
|
|
15
|
-
// markOnlyPaths: exact
|
|
22
|
+
// markOnlyPaths: exact AGENTS.md tool target → cache update only, no duplicate
|
|
16
23
|
// Total length guard at 9,500 chars; files that overflow the budget are turned into an
|
|
17
24
|
// explicit "Read EACH of these files now" instruction instead of a silent drop
|
|
18
|
-
// >>> If I am updated, be sure to update my header comment and the
|
|
25
|
+
// >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
|
|
19
26
|
|
|
20
27
|
import {
|
|
21
28
|
closeSync, existsSync, mkdirSync, openSync, readFileSync,
|
|
22
29
|
renameSync, rmSync, statSync, writeFileSync,
|
|
23
30
|
} from 'fs';
|
|
24
|
-
import { join, resolve, dirname, basename } from 'path';
|
|
31
|
+
import { join, resolve, dirname, basename, sep } from 'path';
|
|
25
32
|
import { homedir, hostname } from 'os';
|
|
26
33
|
import { fileURLToPath } from 'url';
|
|
27
34
|
|
|
28
35
|
const HOSTNAME = hostname();
|
|
29
36
|
const HOST_ID = HOSTNAME.toLowerCase();
|
|
30
|
-
const
|
|
37
|
+
const AGENTS_MD_NAMES = ['AGENTS.md', 'AGENTS.local.md'];
|
|
38
|
+
/** Names neither backend loads on its own — always ours to inject. */
|
|
39
|
+
const LOCAL_ONLY_NAMES = new Set(['AGENTS.local.md']);
|
|
40
|
+
/** Claude's AGENTS.md fallback is all-or-nothing: a single CLAUDE.md anywhere in the cwd
|
|
41
|
+
* ancestor chain makes it load THAT family and ignore every AGENTS.md. */
|
|
42
|
+
const CLAUDE_MD_NAMES = ['CLAUDE.md', 'CLAUDE.local.md', join('.claude', 'CLAUDE.md')];
|
|
31
43
|
const MAX_FILE_SIZE = 200 * 1024;
|
|
32
44
|
const MAX_DEPTH = 20;
|
|
33
45
|
const MAX_CONTEXT_CHARS = 9500;
|
|
@@ -40,7 +52,7 @@ const SESSION_ID_RE = /^[A-Za-z0-9._-]+$/;
|
|
|
40
52
|
function hookPaths(env) {
|
|
41
53
|
const home = env.CORTEX_HOME ? resolve(env.CORTEX_HOME) : join(homedir(), '.cortex');
|
|
42
54
|
return {
|
|
43
|
-
homeFallback: join(home, '
|
|
55
|
+
homeFallback: join(home, 'AGENTS.md'),
|
|
44
56
|
cacheDir: join(home, 'tmp', 'cortexmd-cache'),
|
|
45
57
|
};
|
|
46
58
|
}
|
|
@@ -59,32 +71,34 @@ function tryReadEntry(filePath) {
|
|
|
59
71
|
}
|
|
60
72
|
}
|
|
61
73
|
|
|
74
|
+
/** The directory an ancestor walk should start from: the path itself when it is a directory,
|
|
75
|
+
* otherwise its parent (also the right answer for a path that does not exist). */
|
|
76
|
+
function startDir(targetFilePath) {
|
|
77
|
+
const resolved = resolve(targetFilePath);
|
|
78
|
+
try {
|
|
79
|
+
const st = statSync(resolved, { throwIfNoEntry: false });
|
|
80
|
+
return (st && st.isDirectory()) ? resolved : dirname(resolved);
|
|
81
|
+
} catch {
|
|
82
|
+
return dirname(resolved);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
62
86
|
/** Walk from the directory containing `targetFilePath` up to the filesystem root,
|
|
63
|
-
* collecting
|
|
64
|
-
* home fallback at ~/.cortex/
|
|
65
|
-
* If targetFilePath is a directory, scan that directory and its ancestors.
|
|
66
|
-
* If it is a file (or does not exist), scan its parent directory and ancestors. */
|
|
87
|
+
* collecting AGENTS.md and AGENTS.local.md at each level. Also appends the
|
|
88
|
+
* home fallback at ~/.cortex/AGENTS.md if present. Returns leaf→root order. */
|
|
67
89
|
function scanChain(targetFilePath, paths) {
|
|
68
90
|
const entries = [];
|
|
69
91
|
const seen = new Set();
|
|
70
92
|
|
|
71
|
-
let resolved;
|
|
72
|
-
try {
|
|
73
|
-
resolved = resolve(targetFilePath);
|
|
74
|
-
} catch {
|
|
75
|
-
return entries;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
93
|
let dir;
|
|
79
94
|
try {
|
|
80
|
-
|
|
81
|
-
dir = (st && st.isDirectory()) ? resolved : dirname(resolved);
|
|
95
|
+
dir = startDir(targetFilePath);
|
|
82
96
|
} catch {
|
|
83
|
-
|
|
97
|
+
return entries;
|
|
84
98
|
}
|
|
85
99
|
|
|
86
100
|
for (let depth = 0; depth < MAX_DEPTH; depth++) {
|
|
87
|
-
for (const name of
|
|
101
|
+
for (const name of AGENTS_MD_NAMES) {
|
|
88
102
|
const p = join(dir, name);
|
|
89
103
|
if (seen.has(p)) continue;
|
|
90
104
|
seen.add(p);
|
|
@@ -106,6 +120,66 @@ function scanChain(targetFilePath, paths) {
|
|
|
106
120
|
return entries;
|
|
107
121
|
}
|
|
108
122
|
|
|
123
|
+
// ── backend coverage ──
|
|
124
|
+
//
|
|
125
|
+
// Measured against Claude Code 2.1.278 and pi (@earendil-works/pi-coding-agent):
|
|
126
|
+
//
|
|
127
|
+
// memory file location | Claude | PI | ours?
|
|
128
|
+
// --------------------------------+--------+-----+-------
|
|
129
|
+
// ancestor of cwd (incl. cwd) | yes | yes | no
|
|
130
|
+
// descendant of cwd, read by tool | yes | no | PI only
|
|
131
|
+
// outside the cwd tree | no | no | both
|
|
132
|
+
// *.local.md, anywhere | no | no | both
|
|
133
|
+
//
|
|
134
|
+
// Claude resolves its fallback through the `claude-md-or-agents-md` setting, whose default
|
|
135
|
+
// loads AGENTS.md ONLY when no CLAUDE.md exists in the chain — hence the guard below. PI
|
|
136
|
+
// reads ["AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"] per directory, cwd→root, and never
|
|
137
|
+
// descends, so on PI this hook is the only thing that delivers a project's own index file.
|
|
138
|
+
|
|
139
|
+
/** True when a CLAUDE.md-family file sits in the cwd ancestor chain, which switches Claude off
|
|
140
|
+
* the AGENTS.md fallback entirely. Cheap: same walk shape as scanChain, existence checks only. */
|
|
141
|
+
function claudeMdInChain(cwd) {
|
|
142
|
+
let dir;
|
|
143
|
+
try {
|
|
144
|
+
dir = startDir(cwd);
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
for (let depth = 0; depth < MAX_DEPTH; depth++) {
|
|
149
|
+
for (const name of CLAUDE_MD_NAMES) {
|
|
150
|
+
try {
|
|
151
|
+
if (existsSync(join(dir, name))) return true;
|
|
152
|
+
} catch { /* unreadable — treat as absent */ }
|
|
153
|
+
}
|
|
154
|
+
const parent = dirname(dir);
|
|
155
|
+
if (parent === dir) break;
|
|
156
|
+
dir = parent;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function isAncestorOrSelf(dir, cwd) {
|
|
162
|
+
return dir === cwd || cwd.startsWith(dir.endsWith(sep) ? dir : dir + sep);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function isUnder(dir, cwd) {
|
|
166
|
+
return dir === cwd || dir.startsWith(cwd.endsWith(sep) ? cwd : cwd + sep);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether the backend has already put this entry in the agent's context on its own.
|
|
171
|
+
* Such entries are marked in the dedup cache but never injected — that is the whole point of
|
|
172
|
+
* this hook after both backends gained native AGENTS.md support.
|
|
173
|
+
*/
|
|
174
|
+
function backendLoadsNatively(entry, cwd, backend, claudeUsesAgentsMd) {
|
|
175
|
+
if (LOCAL_ONLY_NAMES.has(basename(entry.path))) return false;
|
|
176
|
+
if (!cwd) return false;
|
|
177
|
+
const dir = dirname(entry.path);
|
|
178
|
+
if (backend === 'pi') return isAncestorOrSelf(dir, cwd);
|
|
179
|
+
if (!claudeUsesAgentsMd) return false;
|
|
180
|
+
return isAncestorOrSelf(dir, cwd) || isUnder(dir, cwd);
|
|
181
|
+
}
|
|
182
|
+
|
|
109
183
|
// ── cache helpers ──
|
|
110
184
|
|
|
111
185
|
function loadCache(sessionId, paths) {
|
|
@@ -186,7 +260,7 @@ function buildContext(entries) {
|
|
|
186
260
|
// Walk entries in original order (leaf→root), inlining each as a block until the char
|
|
187
261
|
// budget is exhausted. Once exhausted, the remaining entries are NOT inlined — instead
|
|
188
262
|
// they are turned into an explicit read-instruction below, so their rules are never
|
|
189
|
-
// silently dropped (e.g. a root-level
|
|
263
|
+
// silently dropped (e.g. a root-level AGENTS.local.md carrying dev/safety rules).
|
|
190
264
|
const includedBlocks = [];
|
|
191
265
|
const includedPaths = [];
|
|
192
266
|
const truncated = [];
|
|
@@ -194,7 +268,7 @@ function buildContext(entries) {
|
|
|
194
268
|
let budgetExhausted = false;
|
|
195
269
|
|
|
196
270
|
for (const e of entries) {
|
|
197
|
-
const block = `<system-reminder>\nAuto-loaded
|
|
271
|
+
const block = `<system-reminder>\nAuto-loaded AGENTS.md from ${HOSTNAME}:${e.path} (ancestor of accessed path, outside the session working directory). These instructions apply to files under this directory.\n\n${e.content}\n</system-reminder>`;
|
|
198
272
|
if (budgetExhausted || totalLen + block.length > MAX_CONTEXT_CHARS) {
|
|
199
273
|
budgetExhausted = true; // match prior behavior: stop inlining at the first overflow
|
|
200
274
|
truncated.push(e);
|
|
@@ -212,7 +286,7 @@ function buildContext(entries) {
|
|
|
212
286
|
if (truncated.length > 0) {
|
|
213
287
|
const list = truncated.map(e => `- ${e.path}`).join('\n');
|
|
214
288
|
parts.push(
|
|
215
|
-
`<system-reminder>\n⚠️ ${truncated.length}
|
|
289
|
+
`<system-reminder>\n⚠️ ${truncated.length} AGENTS rule file(s) were too large to inline here. ` +
|
|
216
290
|
`Read EACH of the following files now to load their rules before proceeding:\n${list}\n</system-reminder>`
|
|
217
291
|
);
|
|
218
292
|
}
|
|
@@ -227,6 +301,10 @@ function buildContext(entries) {
|
|
|
227
301
|
* Run the hook against one payload and one session environment.
|
|
228
302
|
* Returns the hook output object, or null when this event injects nothing.
|
|
229
303
|
* Pure of process state apart from the filesystem, so the PI bridge can call it in-process.
|
|
304
|
+
*
|
|
305
|
+
* SessionStart is deliberately mark-only in the common case: the backend has just loaded the
|
|
306
|
+
* cwd ancestor chain itself, so recording those paths in the shared cache is what stops the
|
|
307
|
+
* first PostToolUse from injecting them a second time.
|
|
230
308
|
*/
|
|
231
309
|
export function runHook(payload, env = process.env) {
|
|
232
310
|
const paths = hookPaths(env);
|
|
@@ -236,6 +314,10 @@ export function runHook(payload, env = process.env) {
|
|
|
236
314
|
const sessionId = stableSessionId && SESSION_ID_RE.test(stableSessionId)
|
|
237
315
|
? stableSessionId
|
|
238
316
|
: payload.session_id;
|
|
317
|
+
// Default to PI, the backend with the SMALLER native coverage. Guessing "claude" for an
|
|
318
|
+
// undeclared spawn would make us skip descendants of cwd that PI never loads — a silent loss of
|
|
319
|
+
// rules. Guessing "pi" only risks injecting something Claude already had: wasteful, never wrong.
|
|
320
|
+
const backend = env.CORTEX_BACKEND?.trim() === 'claude' ? 'claude' : 'pi';
|
|
239
321
|
|
|
240
322
|
let scanRoot = null;
|
|
241
323
|
if (hookEventName === 'PostToolUse') {
|
|
@@ -250,13 +332,22 @@ export function runHook(payload, env = process.env) {
|
|
|
250
332
|
const entries = scanChain(scanRoot, paths);
|
|
251
333
|
if (entries.length === 0) return null;
|
|
252
334
|
|
|
335
|
+
const cwd = typeof payload.cwd === 'string' && payload.cwd ? resolve(payload.cwd) : null;
|
|
336
|
+
const claudeUsesAgentsMd = backend === 'claude' && cwd ? !claudeMdInChain(cwd) : false;
|
|
337
|
+
|
|
253
338
|
const lock = acquireLock(sessionId, paths);
|
|
254
339
|
try {
|
|
255
340
|
const cache = loadCache(sessionId, paths);
|
|
341
|
+
|
|
342
|
+
// Paths whose mtime we record without injecting: the file the tool just returned in full,
|
|
343
|
+
// plus everything the backend loaded on its own.
|
|
256
344
|
const markOnlyPaths = new Set();
|
|
257
345
|
if (hookEventName === 'PostToolUse') {
|
|
258
346
|
const targetPath = resolve(payload.tool_input?.file_path || payload.tool_input?.path || '');
|
|
259
|
-
if (
|
|
347
|
+
if (AGENTS_MD_NAMES.includes(basename(targetPath))) markOnlyPaths.add(targetPath);
|
|
348
|
+
}
|
|
349
|
+
for (const entry of entries) {
|
|
350
|
+
if (backendLoadsNatively(entry, cwd, backend, claudeUsesAgentsMd)) markOnlyPaths.add(entry.path);
|
|
260
351
|
}
|
|
261
352
|
|
|
262
353
|
let changed = false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// input: node:http and Cortex hook environment
|
|
2
|
-
// output: askUser helper @cortex-hook-version 2026.
|
|
2
|
+
// output: askUser helper @cortex-hook-version 2026.9.15
|
|
3
3
|
// pos: Hook script interaction client
|
|
4
|
-
// >>> If updated, update this header and the folder
|
|
4
|
+
// >>> If updated, update this header and the folder AGENTS.md <<<
|
|
5
5
|
|
|
6
6
|
import http from 'node:http';
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @cortex-hook-version 2026.
|
|
2
|
+
// @cortex-hook-version 2026.9.15-2
|
|
3
3
|
// input: stdin { channel, sessionId, sessionName, trigger, timestampIso } + env CORTEX_HOOK_*
|
|
4
4
|
// output: stdout — prompt to inject into the closing session (empty stdout = skip)
|
|
5
5
|
// pos: !new pre-close memory flush hook — recall valuable user and project info from the session, write to corresponding context files
|
|
6
|
-
// >>> If I am updated, be sure to update my header comment and the
|
|
6
|
+
// >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
|
|
7
7
|
|
|
8
8
|
import { execSync } from 'child_process';
|
|
9
9
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @cortex-hook-version 2026.
|
|
2
|
+
// @cortex-hook-version 2026.9.15-2
|
|
3
3
|
// input: stdin JSON — Claude Code PostToolUse event or PI hook-bridge payload
|
|
4
4
|
// output: { matched: [...], hookSpecificOutput: { additionalContext: "..." } }
|
|
5
5
|
// pos: Read/Grep hook — check if file path matches scoped rules in ~/.cortex/rules/
|
|
6
6
|
// On match, return rule content for Claude (additionalContext) and PI (content mutation) injection
|
|
7
7
|
// Session-level dedup: each rule injected at most once per session (on first match)
|
|
8
|
-
// >>> If I am updated, be sure to update my header comment and the
|
|
8
|
+
// >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
|
|
9
9
|
|
|
10
10
|
import { readFileSync, readdirSync, statSync, existsSync, mkdirSync, renameSync, writeFileSync } from 'fs';
|
|
11
11
|
import { join, resolve, dirname } from 'path';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @cortex-hook-version 2026.
|
|
2
|
+
// @cortex-hook-version 2026.9.15
|
|
3
3
|
// input: stdin JSON — Claude Code PreToolUse event payload
|
|
4
4
|
// output: stdout JSON — { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision, permissionDecisionReason }, systemMessage? }
|
|
5
5
|
// pos: PreToolUse hook — intercepts Edit/Write on size-capped context files and
|
|
6
6
|
// enforces their caps (limit table below; rules/status-md.md, rules/issues-md.md,
|
|
7
|
-
// rules/
|
|
7
|
+
// rules/agents-md.md): deny writes whose result exceeds the caps, unless the
|
|
8
8
|
// write shrinks an already-over-limit file (so cleanup stays possible); warn
|
|
9
9
|
// when approaching the cap. Guarded files:
|
|
10
10
|
// context/projects/<p>/STATUS.md — 80 lines / 6KB (state register)
|
|
11
11
|
// context/projects/<p>/ISSUES.md — 80 lines / 6KB (friction log)
|
|
12
|
-
//
|
|
13
|
-
// >>> If I am updated, be sure to update my header comment and the
|
|
12
|
+
// AGENTS.md anywhere under a context/ tree — 120 lines / 8KB (injected index)
|
|
13
|
+
// >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
|
|
14
14
|
|
|
15
15
|
import { readFileSync, existsSync } from 'fs';
|
|
16
16
|
import { resolve, sep } from 'path';
|
|
@@ -61,16 +61,16 @@ const LIMIT_RULES = [
|
|
|
61
61
|
],
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
|
-
name: '
|
|
65
|
-
ruleFile: 'rules/
|
|
66
|
-
matches: (parts) => parts[parts.length - 1] === '
|
|
64
|
+
name: 'AGENTS.md',
|
|
65
|
+
ruleFile: 'rules/agents-md.md',
|
|
66
|
+
matches: (parts) => parts[parts.length - 1] === 'AGENTS.md' && parts.includes('context'),
|
|
67
67
|
maxLines: 120,
|
|
68
68
|
maxBytes: 8 * 1024,
|
|
69
69
|
warnLines: 90,
|
|
70
70
|
warnBytes: 6656,
|
|
71
71
|
capLabel: '120 lines AND 8KB',
|
|
72
72
|
trimAdvice: [
|
|
73
|
-
'
|
|
73
|
+
'AGENTS.md is a directory index loaded into every agent that works here: it answers "what is here, where to look", not the content itself. Trim before writing:',
|
|
74
74
|
'- collapse atomic directories (experiments/ knowledge/ patterns/ decisions/) to one line each pointing at their index.md,',
|
|
75
75
|
'- entry summaries already live in the atomic files and their auto-generated index.md — never duplicate them here,',
|
|
76
76
|
'- keep each index line to one sentence + pointer (<=200 chars).',
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
// input: stdin thread lifecycle payload, argv identity fallback
|
|
4
4
|
// output: HookResult for unresolved dispatch task state
|
|
5
5
|
// pos: Checks task status after a dispatched thread terminates
|
|
6
|
-
// >>> If I am updated, update my header comment and the parent folder's
|
|
6
|
+
// >>> If I am updated, update my header comment and the parent folder's AGENTS.md <<<
|
|
7
7
|
|
|
8
|
-
import { readFileSync, existsSync
|
|
8
|
+
import { readFileSync, existsSync } from 'fs';
|
|
9
9
|
import * as path from 'path';
|
|
10
10
|
import { homedir } from 'os';
|
|
11
11
|
|
|
@@ -16,8 +16,6 @@ const PROJECTS_DIR = process.env.CORTEX_PROJECTS_DIR
|
|
|
16
16
|
? path.resolve(process.env.CORTEX_PROJECTS_DIR)
|
|
17
17
|
: path.join(DATA_DIR, 'context', 'projects');
|
|
18
18
|
|
|
19
|
-
const CORTEX_RUN_DIR = path.join(DATA_DIR, 'tmp', 'cortex-run');
|
|
20
|
-
|
|
21
19
|
function noop() {
|
|
22
20
|
console.log(JSON.stringify({ insertAgent: false }));
|
|
23
21
|
}
|
|
@@ -79,35 +77,6 @@ function findTaskById(content, taskId) {
|
|
|
79
77
|
return task;
|
|
80
78
|
}
|
|
81
79
|
|
|
82
|
-
/** Find a cortex-run state file that references the given task. */
|
|
83
|
-
function findStateFileForTask(project, taskId) {
|
|
84
|
-
try {
|
|
85
|
-
if (!existsSync(CORTEX_RUN_DIR)) return null;
|
|
86
|
-
for (const entry of readdirSync(CORTEX_RUN_DIR, { withFileTypes: true })) {
|
|
87
|
-
if (!entry.isDirectory()) continue;
|
|
88
|
-
const statePath = path.join(CORTEX_RUN_DIR, entry.name, 'state.json');
|
|
89
|
-
if (!existsSync(statePath)) continue;
|
|
90
|
-
try {
|
|
91
|
-
const state = JSON.parse(readFileSync(statePath, 'utf8'));
|
|
92
|
-
if (state.task_project === project && state.task_id === taskId) {
|
|
93
|
-
return { runName: entry.name, ...state };
|
|
94
|
-
}
|
|
95
|
-
} catch {}
|
|
96
|
-
}
|
|
97
|
-
} catch {}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** Check if a PID is still alive. */
|
|
102
|
-
function pidAlive(pid) {
|
|
103
|
-
try {
|
|
104
|
-
process.kill(pid, 0);
|
|
105
|
-
return true;
|
|
106
|
-
} catch {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
80
|
async function main() {
|
|
112
81
|
let input = '';
|
|
113
82
|
for await (const chunk of process.stdin) input += chunk;
|
|
@@ -146,27 +115,20 @@ async function main() {
|
|
|
146
115
|
// Task is done — nothing to do.
|
|
147
116
|
if (task.status === 'done') { noop(); return; }
|
|
148
117
|
|
|
149
|
-
// Task is pending —
|
|
118
|
+
// Task is pending — something outside this thread owns its completion (a waitpoint signal, an
|
|
119
|
+
// operator). No recovery is automatic; just make the limbo visible to the agent that ran.
|
|
150
120
|
if (task.status === 'pending') {
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
targetAgent,
|
|
163
|
-
prompt: [
|
|
164
|
-
`FYI: task [id: ${taskId}] in project "${project}" is still [pending] but cortex-run ${note}.`,
|
|
165
|
-
'Per current policy, pending→done recovery is not automatic. Check manually if needed.',
|
|
166
|
-
].join('\n'),
|
|
167
|
-
}));
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
121
|
+
const targetAgent = ctx.previousAgent;
|
|
122
|
+
if (targetAgent) {
|
|
123
|
+
console.log(JSON.stringify({
|
|
124
|
+
insertAgent: false,
|
|
125
|
+
targetAgent,
|
|
126
|
+
prompt: [
|
|
127
|
+
`FYI: task [id: ${taskId}] in project "${project}" is still [pending] and the thread has finished.`,
|
|
128
|
+
'Per current policy, pending→done recovery is not automatic. Check manually if needed.',
|
|
129
|
+
].join('\n'),
|
|
130
|
+
}));
|
|
131
|
+
return;
|
|
170
132
|
}
|
|
171
133
|
noop();
|
|
172
134
|
return;
|
|
@@ -180,37 +142,17 @@ async function main() {
|
|
|
180
142
|
const targetAgent = ctx.previousAgent;
|
|
181
143
|
if (!targetAgent) { noop(); return; }
|
|
182
144
|
|
|
183
|
-
//
|
|
184
|
-
const stateFile = findStateFileForTask(project, taskId);
|
|
185
|
-
|
|
186
|
-
if (stateFile && stateFile.status === 'running') {
|
|
187
|
-
// cortex-run is running — this is a legitimate pending case.
|
|
188
|
-
// Engineer forgot to call cortex-task pending; auto-transition.
|
|
189
|
-
console.log(JSON.stringify({
|
|
190
|
-
insertAgent: false,
|
|
191
|
-
targetAgent,
|
|
192
|
-
prompt: [
|
|
193
|
-
`Auto-detected: task [id: ${taskId}] in project "${project}" is still claimed,`,
|
|
194
|
-
`but a cortex-run process "(${stateFile.runName})" is running for this task (PID ${stateFile.pid}).`,
|
|
195
|
-
`The engineer likely forgot to mark the task pending. Call:`,
|
|
196
|
-
` cortex-task pending --project ${project} --task-id ${taskId}`,
|
|
197
|
-
].join('\n'),
|
|
198
|
-
}));
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// No cortex-run state file — genuine orphan.
|
|
203
|
-
// Unclaim and prompt agent to resolve.
|
|
145
|
+
// The thread finished without transitioning the task — prompt the agent to resolve it.
|
|
204
146
|
console.log(JSON.stringify({
|
|
205
147
|
insertAgent: false,
|
|
206
148
|
targetAgent,
|
|
207
149
|
prompt: [
|
|
208
|
-
`Status check: task [id: ${taskId}] in project "${project}" is still marked [claimed] in TASKS.yaml, but the thread has finished
|
|
150
|
+
`Status check: task [id: ${taskId}] in project "${project}" is still marked [claimed] in TASKS.yaml, but the thread has finished.`,
|
|
209
151
|
'',
|
|
210
152
|
'Resolve the task status now — do not leave it in limbo:',
|
|
211
153
|
`- If done-when conditions are satisfied: cortex-task complete --project ${project} --task-id ${taskId} --note "<what you did>"`,
|
|
212
154
|
`- If blocked by external reasons: cortex-task block --project ${project} --task-id ${taskId} --reason "<reason>"`,
|
|
213
|
-
`- If
|
|
155
|
+
`- If something outside this thread still has to finish: cortex-task pending --project ${project} --task-id ${taskId}`,
|
|
214
156
|
`- If none of the above apply: cortex-task unclaim --project ${project} --task-id ${taskId}`,
|
|
215
157
|
'',
|
|
216
158
|
'After updating the task, commit the TASKS.yaml change.',
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// @cortex-hook-version 2026.
|
|
2
|
+
// @cortex-hook-version 2026.9.15-2
|
|
3
3
|
// input: stdin JSON — Claude Code PreToolUse event payload
|
|
4
4
|
// output: stdout JSON — { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision, permissionDecisionReason } }
|
|
5
5
|
// pos: PreToolUse hook — intercepts Edit/Write on **/TASKS.yaml, checks project lock
|
|
6
6
|
// allow when current process holds the lock; deny + helpful message otherwise
|
|
7
7
|
// Owner identity: process.env.CORTEX_EXECUTION_ID ?? manual:<user>:<pid>
|
|
8
|
-
// >>> If I am updated, be sure to update my header comment and the
|
|
8
|
+
// >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
|
|
9
9
|
|
|
10
10
|
import { readFileSync, existsSync } from 'fs';
|
|
11
11
|
import { basename, resolve } from 'path';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortex-commission",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Commission mode skill bundle — how to work inside a contract-anchored long task: ledger entries, surprise triage, checkpoint discipline. Loaded
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Commission mode skill bundle — how to work inside a contract-anchored long task: ledger entries, surprise triage, checkpoint discipline. Loaded once a contract has landed and the session is bound to the commission. Creating a commission is not covered here; that protocol lives in the cortex_commission_start tool."
|
|
5
5
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
3
|
"name": "cortex-commission",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Commission mode skill bundle — how to work inside a contract-anchored long task: ledger entries, surprise triage, checkpoint discipline. Loaded
|
|
4
|
+
"version": "0.5.0",
|
|
5
|
+
"description": "Commission mode skill bundle — how to work inside a contract-anchored long task: ledger entries, surprise triage, checkpoint discipline. Loaded once a contract has landed and the session is bound to the commission. Creating a commission is not covered here; that protocol lives in the cortex_commission_start tool."
|
|
6
6
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: commission
|
|
3
|
-
description: "How to work inside a commission — a contract-anchored long task. Loaded
|
|
3
|
+
description: "How to work inside a commission — a contract-anchored long task. Loaded once the contract lands and this session is bound to the commission; while a contract is still being drafted, the protocol lives in the cortex_commission_start tool instead. Covers maintenance: ledger entries, surprise triage, checkpoint discipline, gates."
|
|
4
4
|
allowed-tools: Read, Write, Edit, Bash, Grep, Glob, mcp__cortex-core__cortex_context, mcp__cortex-core__cortex_ask_user, mcp__cortex-core__send_decision
|
|
5
5
|
metadata:
|
|
6
6
|
author: "Cortex"
|
|
7
|
-
version: "3.
|
|
7
|
+
version: "3.2.0"
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
# Working inside a commission
|
|
@@ -26,7 +26,7 @@ commissions/<slug>/
|
|
|
26
26
|
|
|
27
27
|
The [Commission] block is only an index — it names contract.md and ledger.md, it does not carry their contents. Read both at the start of the session, and re-read contract.md (including its Revisions section) at every checkpoint; the user may have edited it.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
You are reading this because a contract already exists. A session still drafting one does not load this skill at all: creation is carried entirely by `cortex_commission_start`, and this skill arrives with the contract.
|
|
30
30
|
|
|
31
31
|
## Surprise triage
|
|
32
32
|
|
|
@@ -51,7 +51,7 @@ lark-cli auth status
|
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
Notes:
|
|
54
|
-
- Cortex runs on **
|
|
54
|
+
- Cortex runs on the **agent-server host**; install/run there. `lark-cli` stores credentials in the
|
|
55
55
|
OS keychain (falls back to a local file on headless Linux).
|
|
56
56
|
- `config init` is non-interactive via `--app-id <id> --app-secret-stdin` and refuses
|
|
57
57
|
only inside OpenClaw/Hermes agent workspaces (Cortex is neither).
|
|
@@ -120,12 +120,12 @@ cd <cortex-repo>/agent-server && node --import tsx src/domain/remote/client-boot
|
|
|
120
120
|
or place the bundle by hand:
|
|
121
121
|
|
|
122
122
|
```bash
|
|
123
|
-
# Build from source (dev) — produces dist/client.mjs +
|
|
123
|
+
# Build from source (dev) — produces dist/client.mjs (+ a cortex-run-watcher.mjs compatibility stub)
|
|
124
124
|
cd <cortex-repo>/client && npm run bundle
|
|
125
125
|
|
|
126
126
|
# Ship to the device
|
|
127
127
|
ssh user@host "mkdir -p ~/.cortex/client/current"
|
|
128
|
-
scp dist/client.mjs dist/cortex-run-watcher.mjs user@host:.cortex/client/current/
|
|
128
|
+
scp dist/client.mjs dist/cortex-run-watcher.mjs user@host:.cortex/client/current/ # both files: the update protocol checks names
|
|
129
129
|
```
|
|
130
130
|
|
|
131
131
|
### 3. Write the config
|