@sema-agent/server 7.43.0 → 7.44.0
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/USAGE.md +18 -0
- package/dist/adoption/plan.js +31 -192
- package/dist/adoption/quiesce.js +3 -86
- package/dist/adoption/runner.js +3 -140
- package/dist/adoption/sql.js +0 -74
- package/dist/adoption/wire.js +0 -80
- package/dist/approval-ask-machine.js +0 -75
- package/dist/approval-card.js +0 -323
- package/dist/approval-deny-reasons.js +0 -42
- package/dist/approval-hmac.js +0 -35
- package/dist/approval-reconciler.js +8 -166
- package/dist/approval.js +4 -67
- package/dist/audit.js +1 -44
- package/dist/auth-bridge.js +4 -47
- package/dist/auth-keys.js +0 -23
- package/dist/bake-runner/main.js +4 -65
- package/dist/bake-runner/protocol.js +3 -58
- package/dist/bake-runner/runner.js +5 -91
- package/dist/bench/l8/artifact.js +2 -61
- package/dist/bench/l8/escape.js +0 -25
- package/dist/bench/l8/index.js +0 -14
- package/dist/bench/l8/probes.js +0 -60
- package/dist/bench/l8/run-probes.js +2 -45
- package/dist/bench/s1/arms.js +14 -189
- package/dist/bench/s1/live-deps.js +11 -253
- package/dist/bench/s1/oracle.js +1 -36
- package/dist/bench/s1/repair-oracle-adapter.js +0 -30
- package/dist/bench/s1/reviewer.js +0 -34
- package/dist/bench/s1/row.js +0 -62
- package/dist/bench/s1/run-firm.js +4 -70
- package/dist/bench/s1/runner-ctx.js +0 -40
- package/dist/bench/s1/tasks.js +0 -115
- package/dist/boot/adoption.js +0 -20
- package/dist/boot/budget-tracing.js +3 -55
- package/dist/boot/config-center.js +43 -551
- package/dist/boot/coordinators.js +1 -69
- package/dist/boot/crash-last.js +0 -18
- package/dist/boot/deferred-sandbox-path-env.js +3 -119
- package/dist/boot/execution-env.js +5 -171
- package/dist/boot/governance-seams.js +0 -92
- package/dist/boot/leader.js +0 -69
- package/dist/boot/limit-sync.js +0 -2
- package/dist/boot/memory-boundary.js +3 -91
- package/dist/boot/org-memory.js +1 -25
- package/dist/boot/parked-revive-gate.js +0 -150
- package/dist/boot/permission-rules-audit.js +1 -56
- package/dist/boot/reapers.js +15 -273
- package/dist/boot/resolve-spec.js +9 -768
- package/dist/boot/retention-lane.js +4 -87
- package/dist/boot/runner-deps.js +3 -297
- package/dist/boot/runtime-caps.js +0 -40
- package/dist/boot/session-faces.js +2 -133
- package/dist/boot/shutdown.js +9 -83
- package/dist/boot/side-query-lane.js +2 -137
- package/dist/boot/stores.js +15 -215
- package/dist/boot/task-list-lane.js +0 -18
- package/dist/boot/webfetch-summarize-lane.js +0 -47
- package/dist/boot/workflow-orchestration.js +3 -99
- package/dist/boot-reclaim.js +0 -20
- package/dist/bounded-session-map.js +0 -19
- package/dist/brain.js +2 -139
- package/dist/budget.js +9 -244
- package/dist/capabilities/builtin-tools.js +0 -3
- package/dist/capabilities/center-plugins.js +6 -51
- package/dist/capabilities/center-prompts.js +6 -71
- package/dist/capabilities/code-review-council.js +7 -40
- package/dist/capabilities/collab-workflows.js +1 -44
- package/dist/capabilities/hands-lane.js +0 -65
- package/dist/capabilities/memory-notice.js +0 -70
- package/dist/capabilities/prompt.js +0 -14
- package/dist/capabilities/prompts/code-review.js +0 -14
- package/dist/capabilities/prompts/identity.js +0 -6
- package/dist/capabilities/prompts/team.js +0 -4
- package/dist/capabilities/repo-tools.js +0 -34
- package/dist/capabilities/sandbox-file-send.js +3 -92
- package/dist/capabilities/scenarios.d.ts +0 -1
- package/dist/capabilities/scenarios.js +18 -279
- package/dist/capabilities/select-environment-tool.js +0 -32
- package/dist/capabilities/send-user-file-tool.js +2 -66
- package/dist/capabilities/skills.d.ts +1 -2
- package/dist/capabilities/skills.js +3 -21
- package/dist/capabilities/team.d.ts +3 -11
- package/dist/capabilities/team.js +3 -51
- package/dist/capabilities/tool-defer.js +0 -3
- package/dist/config-center/apply-effective.js +15 -330
- package/dist/config-center/apply-ledger.js +5 -38
- package/dist/config-center/facade.js +0 -41
- package/dist/config-center/hot-keys-registry.js +0 -20
- package/dist/config-center/http-client.js +2 -125
- package/dist/config-center/mcp-revocation.js +2 -34
- package/dist/config-center/read-face.js +0 -59
- package/dist/config-center/restart-signal.js +1 -85
- package/dist/config-center/skills-mcp.d.ts +1 -1
- package/dist/config-center/skills-mcp.js +9 -76
- package/dist/config-center/stage-limits.js +8 -35
- package/dist/config-invariants.js +0 -16
- package/dist/config-lkg.js +0 -42
- package/dist/config-provider.js +3 -186
- package/dist/config-types.js +0 -5
- package/dist/config.js +107 -1145
- package/dist/degenerate-instrument.js +3 -67
- package/dist/deployment-governance.js +0 -124
- package/dist/digest-form.js +0 -12
- package/dist/elicitation.js +3 -86
- package/dist/env-facts.js +7 -75
- package/dist/fleet/fleet-bus.js +34 -507
- package/dist/fleet/fleet-reconciler.js +9 -149
- package/dist/fleet/fleet-terminal-window.js +10 -178
- package/dist/fleet/subagent-tail-bus.js +3 -72
- package/dist/fleet-client.js +10 -70
- package/dist/fleet-lease.js +5 -79
- package/dist/git-api-kind.js +0 -3
- package/dist/governance-ask-marks.js +2 -78
- package/dist/hooks/branch-transcript.js +0 -74
- package/dist/hooks/cc-agent-hook-prompt.js +0 -29
- package/dist/hooks/cc-stop-prompt.js +1 -46
- package/dist/hooks/hook-llm.js +1 -53
- package/dist/hooks/hook-runner.js +20 -414
- package/dist/http/active-run-conflict.js +4 -129
- package/dist/http/cursor-fingerprint.d.ts +5 -0
- package/dist/http/cursor-fingerprint.js +5 -0
- package/dist/http/idempotency.js +0 -37
- package/dist/http/principal-gate.js +3 -40
- package/dist/http/route-ctx.js +0 -9
- package/dist/http/routes/a2a-serve.js +7 -319
- package/dist/http/routes/admin-config-refresh.js +0 -4
- package/dist/http/routes/admin-drain.js +0 -10
- package/dist/http/routes/adoption.js +1 -29
- package/dist/http/routes/agents-roster.js +1 -47
- package/dist/http/routes/approvals-assistant.js +32 -395
- package/dist/http/routes/attachments.js +4 -22
- package/dist/http/routes/capabilities.js +3 -420
- package/dist/http/routes/diagnostics.js +1 -81
- package/dist/http/routes/fleet.js +9 -185
- package/dist/http/routes/images.js +14 -239
- package/dist/http/routes/leader.js +0 -13
- package/dist/http/routes/memory-bundle.js +1 -61
- package/dist/http/routes/memory-policy.js +9 -99
- package/dist/http/routes/notify-wake.js +3 -37
- package/dist/http/routes/observability.js +2 -19
- package/dist/http/routes/retention-ops.js +2 -34
- package/dist/http/routes/rules.js +1 -93
- package/dist/http/routes/runs.js +64 -873
- package/dist/http/routes/session-sync.js +19 -258
- package/dist/http/routes/sessions-list.js +17 -43
- package/dist/http/routes/sessions.js +34 -226
- package/dist/http/routes/shared-memory.js +5 -36
- package/dist/http/routes/side-query.js +1 -87
- package/dist/http/routes/tasks.js +52 -722
- package/dist/http/routes/trace-usage.js +32 -195
- package/dist/http/routes/workflows.js +19 -195
- package/dist/http/run-meta.js +0 -6
- package/dist/http/send.js +0 -32
- package/dist/http/server.js +92 -1597
- package/dist/http/sse-lifecycle.js +2 -13
- package/dist/http/sse-log.js +3 -48
- package/dist/http/tar.js +5 -21
- package/dist/http/verify-rounds.js +0 -5
- package/dist/http/wire-gate.js +0 -9
- package/dist/http/workspace-content.js +0 -10
- package/dist/images/bake-validate.js +1 -70
- package/dist/images/manifest.js +1 -6
- package/dist/index.js +0 -21
- package/dist/key-resolver.js +2 -17
- package/dist/leader/diffout.js +1 -20
- package/dist/leader/diffup.js +0 -47
- package/dist/leader/endpoint.js +2 -57
- package/dist/leader/fanout.js +3 -45
- package/dist/leader/grader-env-factory.js +3 -72
- package/dist/leader/leader.js +5 -156
- package/dist/leader/merge.js +8 -115
- package/dist/leader/planner.js +3 -54
- package/dist/leader/repair-oracle.js +1 -60
- package/dist/leader/repair-wire.js +2 -79
- package/dist/leader/wire.js +8 -307
- package/dist/lsp/e2b-bridge.js +4 -64
- package/dist/lsp/e2b-manager.js +6 -94
- package/dist/lsp/lsp-frames.js +0 -12
- package/dist/lsp/manager.js +4 -96
- package/dist/lsp/ws-transport.js +5 -55
- package/dist/lsp-evict.js +1 -15
- package/dist/main.js +57 -765
- package/dist/memory-bundle-engine.js +0 -55
- package/dist/memory-export.js +0 -4
- package/dist/memory-posture.js +1 -15
- package/dist/memory-scope.js +11 -148
- package/dist/memory-sync-client.js +2 -44
- package/dist/memory-sync.js +1 -80
- package/dist/model-select.js +3 -80
- package/dist/observability/cost-quota.js +1 -17
- package/dist/observability/cost-taxonomy.js +0 -34
- package/dist/observability/fail-open.js +7 -86
- package/dist/observability/logger.js +0 -6
- package/dist/observability/metrics.js +0 -94
- package/dist/observability/otel-exporter.js +3 -13
- package/dist/observability/principal-context.js +0 -9
- package/dist/observability/prompt-manifest.js +1 -37
- package/dist/observability/rate-limit.js +0 -4
- package/dist/observability/secret-env-scrub.js +2 -56
- package/dist/observability/tool-trace.js +1 -70
- package/dist/orchestration/hardened-vm-runner.js +4 -118
- package/dist/orchestration/hardened-vm-worker-runner.js +1 -26
- package/dist/orchestration/hardened-vm-worker.js +0 -27
- package/dist/orchestration/subagent-steer.js +1 -45
- package/dist/orchestration/workflow-agent-steer.js +1 -80
- package/dist/orchestration/workflow-completion-inbox.js +32 -285
- package/dist/orchestration/workflow-notify-journal.js +16 -259
- package/dist/org-memory-admission.js +3 -47
- package/dist/parent-watch.js +2 -48
- package/dist/parked-decide.js +1 -109
- package/dist/per-task-image.js +0 -57
- package/dist/plan-cache-probe.js +3 -27
- package/dist/plugins/adoption-log-sql.js +2 -119
- package/dist/plugins/approval-ask-store-memory.js +3 -38
- package/dist/plugins/approval-ask-store-sql.js +6 -188
- package/dist/plugins/approval-exemption-store.js +2 -28
- package/dist/plugins/background-agent-store-sql.js +4 -105
- package/dist/plugins/background-shell-support.js +14 -122
- package/dist/plugins/blob-backend.js +6 -169
- package/dist/plugins/breaker-state-sql.js +8 -46
- package/dist/plugins/caching-session-store.js +4 -106
- package/dist/plugins/checkpoint-store-sql.js +18 -505
- package/dist/plugins/e2b-orphan-reclaim.js +0 -45
- package/dist/plugins/file-outcome-sink.js +0 -9
- package/dist/plugins/file-resume-anchor-store.js +4 -43
- package/dist/plugins/file-run-store.js +26 -364
- package/dist/plugins/file-snapshot-store-sql.js +10 -181
- package/dist/plugins/fork-routing-session-store.js +8 -111
- package/dist/plugins/host-platform.js +2 -91
- package/dist/plugins/image-bake-store-sql.js +7 -250
- package/dist/plugins/image-index-sql.js +4 -123
- package/dist/plugins/k8s-bg-scripts.js +4 -88
- package/dist/plugins/k8s-exec-protocol.js +0 -41
- package/dist/plugins/leader-run-store-sql.js +0 -101
- package/dist/plugins/local-checkpoint-store.js +8 -128
- package/dist/plugins/local-session-store.js +34 -296
- package/dist/plugins/local-task-attachment-store.js +2 -16
- package/dist/plugins/mailbox-store-sql.js +8 -65
- package/dist/plugins/memory-embedder-fingerprint.js +5 -166
- package/dist/plugins/memory-embedder.js +4 -70
- package/dist/plugins/memory-engine-pg.js +6 -170
- package/dist/plugins/memory-engine-tidb.js +7 -155
- package/dist/plugins/memory-engine-vector-util.js +0 -10
- package/dist/plugins/memory-key-guards.js +0 -34
- package/dist/plugins/memory-origin-law.js +0 -187
- package/dist/plugins/memory-resume-anchor-store.js +0 -17
- package/dist/plugins/memory-run-store.js +12 -89
- package/dist/plugins/memory-session-policy-store.js +0 -17
- package/dist/plugins/memory-sync-store-pg.js +4 -49
- package/dist/plugins/memory-sync-store-tidb.js +3 -35
- package/dist/plugins/outcome-ledger-sql.js +3 -97
- package/dist/plugins/permission-rule-store-file.js +5 -133
- package/dist/plugins/permission-rule-store-sql.d.ts +3 -0
- package/dist/plugins/permission-rule-store-sql.js +50 -307
- package/dist/plugins/pg-cost-quota.js +0 -7
- package/dist/plugins/pg-pool.js +0 -92
- package/dist/plugins/pg-rate-limiter.js +2 -13
- package/dist/plugins/pg-safe-json.js +4 -40
- package/dist/plugins/pg-session-storage.js +25 -189
- package/dist/plugins/posix-shell-fs.js +1 -31
- package/dist/plugins/remote-env-adb.js +12 -101
- package/dist/plugins/remote-env-e2b.js +40 -371
- package/dist/plugins/remote-env-file-error.js +0 -37
- package/dist/plugins/remote-env-host.js +63 -483
- package/dist/plugins/remote-env-k8s.js +32 -326
- package/dist/plugins/remote-env-local-docker.js +24 -157
- package/dist/plugins/remote-env-ssh.js +20 -128
- package/dist/plugins/remote-scratchpad.js +2 -32
- package/dist/plugins/remote-shell.js +1 -32
- package/dist/plugins/resume-anchor-store-sql.js +0 -11
- package/dist/plugins/retention-lane-store-sql.js +0 -108
- package/dist/plugins/retention-store-sql.js +4 -383
- package/dist/plugins/roster-store-sql.js +0 -55
- package/dist/plugins/run-store-sql.js +14 -251
- package/dist/plugins/s3-presign.js +2 -49
- package/dist/plugins/scheduler-support.js +3 -80
- package/dist/plugins/send-file-ledger.js +4 -53
- package/dist/plugins/send-user-file.js +4 -94
- package/dist/plugins/session-placement.js +1 -89
- package/dist/plugins/session-policy-store-sql.js +3 -81
- package/dist/plugins/session-store.js +0 -57
- package/dist/plugins/shared-memory-store-sql.js +4 -167
- package/dist/plugins/sql-driver.js +0 -17
- package/dist/plugins/sql-errors.js +0 -7
- package/dist/plugins/sql-escape.js +0 -8
- package/dist/plugins/sql-row-helpers.js +0 -25
- package/dist/plugins/store-backend.js +42 -222
- package/dist/plugins/store-contracts.js +2 -46
- package/dist/plugins/task-attachment-store.js +3 -49
- package/dist/plugins/task-list-store-sql.js +0 -79
- package/dist/plugins/tidb-cost-quota.js +1 -4
- package/dist/plugins/tidb-pool.js +1 -207
- package/dist/plugins/tidb-rate-limiter.js +3 -9
- package/dist/plugins/tidb-session-storage.js +4 -70
- package/dist/plugins/tidb-session-store.js +19 -341
- package/dist/plugins/tool-result-store-sql.js +4 -179
- package/dist/plugins/usage-window-store-sql.js +0 -8
- package/dist/plugins/web-search.js +10 -132
- package/dist/plugins/workflow-journal-store-sql.js +2 -58
- package/dist/plugins/workflow-run-store-sql.js +6 -91
- package/dist/plugins/worktree-isolation.js +6 -126
- package/dist/plugins/write-behind-counter.js +16 -75
- package/dist/principal-jwt.js +5 -60
- package/dist/project-memory.js +15 -146
- package/dist/prompts-domain-validate.js +1 -51
- package/dist/question.js +2 -111
- package/dist/resource-suspend.js +0 -18
- package/dist/router/route-orchestration.js +0 -77
- package/dist/rules-consent.d.ts +44 -5
- package/dist/rules-consent.js +75 -215
- package/dist/run-local.js +14 -381
- package/dist/runs.js +29 -617
- package/dist/runtime-caps-resolver.js +6 -132
- package/dist/runtime-governance.js +1 -232
- package/dist/sandbox-pkg-source.js +0 -37
- package/dist/sealed-key.js +3 -68
- package/dist/security.js +6 -291
- package/dist/session-leaf-bus.js +0 -32
- package/dist/session-sync-content.js +1 -69
- package/dist/session-sync-kernel.js +3 -60
- package/dist/session-sync.js +3 -66
- package/dist/session-titler.js +7 -41
- package/dist/session-watch.js +9 -73
- package/dist/shared-memory-scope-authorizer.js +0 -18
- package/dist/sighup-idle.js +1 -12
- package/dist/spec-fields.js +4 -143
- package/dist/store-live-probe.js +3 -49
- package/dist/task-a2a.js +1 -126
- package/dist/task-cwd.js +1 -103
- package/dist/task-mcp.js +1 -89
- package/dist/task-settings.js +10 -300
- package/dist/task-workflow.js +8 -75
- package/dist/tool-approval.d.ts +28 -1
- package/dist/tool-approval.js +70 -1430
- package/dist/trace/artifacts.js +5 -20
- package/dist/trace/engine-notice-wire.js +6 -138
- package/dist/trace/ledger-sink.js +7 -96
- package/dist/trace/project.js +4 -448
- package/dist/trace/redact.js +9 -77
- package/dist/turn-activity.js +1 -27
- package/dist/usage-analytics.js +4 -34
- package/dist/wall-clock-jump-guard.js +1 -68
- package/package.json +3 -3
- package/dist/capabilities/scenario-alias.d.ts +0 -27
- package/dist/capabilities/scenario-alias.js +0 -61
|
@@ -1,37 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CC `hook_agent` 臂(`type:"agent"` 钩子条目)的评估者系统提示 —— **CC 逐字移植**(A-065 P2-5 修:
|
|
3
|
-
* 此前 agent 臂一个字的系统提示都不发,评估者拿不到「你在判什么/可以用工具去查/少走几步」任何一条,
|
|
4
|
-
* 判词质量静默劣化且黑盒极难察觉;`cc-stop-prompt.ts` 把孪生的 prompt 臂做到字节级 ALIGNED,本臂却整块
|
|
5
|
-
* 漏在考据之外=UNANCHORED)。
|
|
6
|
-
*
|
|
7
|
-
* ── 出处(第一手核过)────────────────────────────────────────────────────────────────────────
|
|
8
|
-
* `sema-agent/cc-decoded` 的 `pretty223.js:645295-645313`(`querySource:"hook_agent"` 在 `:645360`)。
|
|
9
|
-
* CC 该臂与 prompt 臂(`cc-stop-prompt.ts`)**不是同一批文本**:两档头句按事件名选
|
|
10
|
-
* (`r === "Stop" || r === "SubagentStop"` ⇒ verify 档,其余 ⇒ evaluate 档),尾段共用。
|
|
11
|
-
*
|
|
12
|
-
* ── 登记偏离(载体差异,[1134] 锚定纪律:能逐字的逐字,搬不动的显式登记而非静默改写)──────────
|
|
13
|
-
* CC 的完整模板还有两段本仓**刻意不搬**:
|
|
14
|
-
* 1. transcript 文件句("The conversation transcript is available at: ${路径}\nYou can read this
|
|
15
|
-
* file to analyze the conversation history if needed.")——CC 给评估者落一个转录**文件**并往
|
|
16
|
-
* session allow 规则里加 `Read(/<path>)`;本仓 agent 载体(main.ts hookAgent = runTask 读-only
|
|
17
|
-
* 子代理)没有转录文件设施,照搬=指向不存在文件的幻觉指令,比不发更糟。
|
|
18
|
-
* 2. 判词形句("When done, return your result using the ${结构化工具} tool with:\n- ok: true …\n
|
|
19
|
-
* - ok: false with reason …")——CC 给评估者挂了一只专用结构化输出工具并按 {ok, reason} 转译;
|
|
20
|
-
* 本仓决策面=子代理 final 文本折伪 stdout 走 `parseHookStdout`(JSON=SyncHookOutput 决策,
|
|
21
|
-
* 非 JSON=该事件对 plain text 的既有语义),判词形由 hook 作者自己的 prompt 承担——系统提示再
|
|
22
|
-
* 指定一个 {ok, reason} 形会与作者 prompt 的输出指令**打架**,且本仓没有那只工具。
|
|
23
|
-
* 另两处已有登记的正当偏离(不在本文件):步数上限 CC `M = 50` vs 本仓 `maxTurns: 10`(成本收窄,
|
|
24
|
-
* main.ts 成文);`thinkingConfig`/`mode:"dontAsk"` 等 CC 载体旋钮不适用本仓 runTask 形。
|
|
25
|
-
*/
|
|
26
|
-
/** Stop / SubagentStop 档头句(CC 逐字)。 */
|
|
27
1
|
export const CC_AGENT_HOOK_HEAD_STOP = "You are verifying a stop condition in Claude Code. Your task is to verify that the agent completed the given plan.";
|
|
28
|
-
/** 其余事件档头句(CC 逐字,`${event}` 为事件名插值——CC 原文即模板插值形)。 */
|
|
29
2
|
export function ccAgentHookHeadFor(event) {
|
|
30
3
|
return event === "Stop" || event === "SubagentStop" ? CC_AGENT_HOOK_HEAD_STOP : `You are evaluating a ${event} hook in Claude Code. Your task is to evaluate the condition described in the user message.`;
|
|
31
4
|
}
|
|
32
|
-
/** 工具指令段(CC 逐字;两档共用尾段中可搬的部分——transcript 句与判词形句见头注登记偏离)。 */
|
|
33
5
|
export const CC_AGENT_HOOK_TOOLS_SEGMENT = "Use the available tools to inspect the codebase and verify the condition.\nUse as few steps as possible - be efficient and direct.";
|
|
34
|
-
/** agent 臂评估者的完整系统提示:两档头句 + 工具指令段。 */
|
|
35
6
|
export function ccAgentHookSystemFor(event) {
|
|
36
7
|
return `${ccAgentHookHeadFor(event)}\n\n${CC_AGENT_HOOK_TOOLS_SEGMENT}`;
|
|
37
8
|
}
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CC `execPromptHook` 的**逐字**移植面:两档系统提示 + `{ok, reason, impossible?}` 判词的解析与映射。
|
|
3
|
-
*
|
|
4
|
-
* ── 为什么单独一个文件 ──────────────────────────────────────────────────────────────────────────
|
|
5
|
-
* 本仓有 clay 的**提示词面锚定 CC 逐字**令(偏离仅限超集/品牌二类且需登记)。把这两段正文与它们的
|
|
6
|
-
* 判词形收在一处,才谈得上机器看守(见 `test/cc-stop-prompt.test.ts` 的字节钉)。
|
|
7
|
-
*
|
|
8
|
-
* ── 出处(我**第一手**核过,不是照抄转述)────────────────────────────────────────────────────────
|
|
9
|
-
* `sema-agent/cc-decoded` 的 `pretty220.js:609309` 起(219/218 同构)。逐字核实的四件:
|
|
10
|
-
* · 两档判据是 **hook 事件名**:`c = r === "Stop" || r === "SubagentStop"` ⇒ 这两个事件用**完整版**,其余用简版;
|
|
11
|
-
* · user 消息也被包装(见 {@link wrapCondition}),原文预设**会话就在上文**("transcript **above**");
|
|
12
|
-
* · 评估者 `thinkingConfig: { type: "disabled", mechanical: !0 }`(A-065 P4-2:引文补 `mechanical` 键)+
|
|
13
|
-
* **`tools: []`** —— 它是**纯判官**,不能自己去查;
|
|
14
|
-
* · 会话消息**整段前置**(`s && s.length > 0 ? [...prepend(s), p] : [p]`),不是摘要。
|
|
15
|
-
* ⚠️ 语料把**正文/标点**非 ASCII 存成 `\uXXXX` 六字符字面量(正文里那两个破折号是 `\u2014`)——**grep 真字符会全假阴**。
|
|
16
|
-
* 所以下面也用 `\u2014` 转义:源码保持 ASCII,运行时是同一个字符。
|
|
17
|
-
* (A-065 P4-5 量词修:locale/语言名表是例外——`日本語`/`русский` 等 127 个字面非 ASCII 字节在语料里
|
|
18
|
-
* 存活;另注 `grep -c` 数行不数次,计数用它会低估。)
|
|
19
|
-
* ⚠️ **为什么必须自己核**:cli 报过他们移植的那段是**第三种措辞**(与 CC 220 的两个分支都不逐字相同,
|
|
20
|
-
* 应是从更早版本移植后 CC 改过而没跟)。转述会漂,语料不会。
|
|
21
|
-
*/
|
|
22
|
-
/** 完整版(**Stop / SubagentStop** 用)。CC `pretty220.js` 逐字。 */
|
|
23
1
|
export const CC_STOP_PROMPT_SYSTEM_FULL = `You are evaluating a stop-condition hook in Claude Code. Read the conversation transcript carefully, then judge whether the user-provided condition is satisfied.
|
|
24
2
|
|
|
25
3
|
Your response must be a JSON object with one of these shapes:
|
|
@@ -30,7 +8,6 @@ Your response must be a JSON object with one of these shapes:
|
|
|
30
8
|
Always include a "reason" field, quoting specific text from the transcript whenever possible. If the transcript does not contain clear evidence that the condition is satisfied, return {"ok": false, "reason": "insufficient evidence in transcript"}.
|
|
31
9
|
|
|
32
10
|
Only use {"ok": false, "impossible": true} when the condition is genuinely unachievable in this session \u2014 for example: the condition is self-contradictory, it depends on a resource or capability that is unavailable, or the assistant has explicitly tried, exhausted reasonable approaches, and stated it cannot be done. Apply your own judgment when deciding this \u2014 the assistant claiming the goal is impossible is evidence, not proof; independently confirm the condition is genuinely unachievable rather than deferring to the assistant's self-assessment. Do not use it just because the goal has not been reached yet or because progress is slow. When in doubt, return {"ok": false} without "impossible".`;
|
|
33
|
-
/** 简版(其余事件用)。CC `pretty220.js` 逐字。 */
|
|
34
11
|
export const CC_STOP_PROMPT_SYSTEM_SIMPLE = `You are evaluating a hook condition in Claude Code. Judge whether the user-provided condition is met.
|
|
35
12
|
|
|
36
13
|
Your response must be a JSON object with one of these shapes:
|
|
@@ -38,26 +15,16 @@ Your response must be a JSON object with one of these shapes:
|
|
|
38
15
|
- {"ok": false, "reason": "<reason the condition is not met>"}
|
|
39
16
|
|
|
40
17
|
Always include a "reason" field.`;
|
|
41
|
-
/** 事件名 → 用哪一档。CC 判据逐字:`r === "Stop" || r === "SubagentStop"`。 */
|
|
42
18
|
export function ccPromptSystemFor(event) {
|
|
43
19
|
return event === "Stop" || event === "SubagentStop" ? CC_STOP_PROMPT_SYSTEM_FULL : CC_STOP_PROMPT_SYSTEM_SIMPLE;
|
|
44
20
|
}
|
|
45
|
-
/**
|
|
46
|
-
* CC 对 user 消息的包装(**仅**完整版档位)。原文逐字,注意 "transcript **above**" ——
|
|
47
|
-
* 它预设会话已经在上文,所以调用方必须真的把会话放在前面,否则这句话本身就是在骗模型。
|
|
48
|
-
*/
|
|
49
21
|
export function wrapCondition(event, condition) {
|
|
50
22
|
if (event !== "Stop" && event !== "SubagentStop")
|
|
51
23
|
return condition;
|
|
52
24
|
return `Based on the conversation transcript above, has the following stopping condition been satisfied? Answer based on transcript evidence only.\n\nCondition: ${condition}`;
|
|
53
25
|
}
|
|
54
|
-
/**
|
|
55
|
-
* 解析模型判词。**解析不出来 ⇒ `undefined`**(= 无判决),绝不臆测成 `ok:false` ——
|
|
56
|
-
* 🔴 Stop 钩子的 `ok:false` **等于拦住停止**,把"读不懂"当成"没满足"会让一次解析失败变成一次拦停。
|
|
57
|
-
*/
|
|
58
26
|
export function parseCcVerdict(text) {
|
|
59
27
|
const raw = text.trim();
|
|
60
|
-
// 模型常把 JSON 包在 ```json 围栏或散文里 —— 取第一个平衡的 {...} 块。
|
|
61
28
|
const start = raw.indexOf("{");
|
|
62
29
|
if (start < 0)
|
|
63
30
|
return undefined;
|
|
@@ -71,7 +38,7 @@ export function parseCcVerdict(text) {
|
|
|
71
38
|
try {
|
|
72
39
|
const o = JSON.parse(raw.slice(start, i + 1));
|
|
73
40
|
if (typeof o.ok !== "boolean")
|
|
74
|
-
return undefined;
|
|
41
|
+
return undefined;
|
|
75
42
|
return {
|
|
76
43
|
ok: o.ok,
|
|
77
44
|
...(typeof o.reason === "string" ? { reason: o.reason } : {}),
|
|
@@ -86,17 +53,5 @@ export function parseCcVerdict(text) {
|
|
|
86
53
|
}
|
|
87
54
|
return undefined;
|
|
88
55
|
}
|
|
89
|
-
/**
|
|
90
|
-
* CC 条件评估者的**输出额度**。
|
|
91
|
-
*
|
|
92
|
-
* 🔴 为什么不能用载体缺省(1024):CC 的系统提示**明确要求**评估者
|
|
93
|
-
* 「quote evidence from the transcript」——判词天然带引文;而**推理档模型的 thinking 与输出共用**这份额度。
|
|
94
|
-
* cli 的 live 围栏实测两种失败形,**同一根因**:①判词 JSON 被截断(`{"ok": true, "reason": "The first user…` 然后没了)
|
|
95
|
-
* ②一个字都没吐出来(thinking 吃光)。**两种都导致判词整条被丢弃 ⇒ fail-open(该拦没拦)** ——
|
|
96
|
-
* 而用户设 `enforced` 的全部意义就是「没达成别停」,这正是守卫在最需要它的时候静默失效。
|
|
97
|
-
*
|
|
98
|
-
* 4096 的取法:判词本身是个小 JSON + 一段引文(几百 token 足够),其余留给 thinking;
|
|
99
|
-
* 同时它安全地低于所有在用模型的输出硬顶(超硬顶会让整请求 400)。
|
|
100
|
-
*/
|
|
101
56
|
export const CC_EVALUATOR_MAX_OUTPUT_TOKENS = 4096;
|
|
102
57
|
//# sourceMappingURL=cc-stop-prompt.js.map
|
package/dist/hooks/hook-llm.js
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { matchCatalogModel } from "../model-select.js";
|
|
2
2
|
export function createHookLlm(deps) {
|
|
3
3
|
const { config, metrics } = deps;
|
|
4
|
-
// anthropic 路由自己的 baseUrl(与 core createAnthropicBrain 同一解析链:model.baseUrl || config.baseUrl
|
|
5
|
-
// || 官方缺省)。路由未装(无 ANTHROPIC 凭据 ⇒ config.anthropic 缺席)⇒ undefined,分派据此判
|
|
6
|
-
// 「这个部署有没有 anthropic 腿」。
|
|
7
4
|
const anthropicRouteBaseUrl = () => config.anthropic ? config.anthropic.baseUrl || "https://api.anthropic.com" : undefined;
|
|
8
|
-
// catalog KEY(name)≠ provider model id——registry 热应用后两者可分叉。分别返回:
|
|
9
|
-
// `catalogRef`(hookAgent 用,core resolveModel 按 deps.models 键解析;也是 keyResolver 的查键)与
|
|
10
|
-
// `providerModelId`+`baseUrl`+`api`(hookLlm 直连用)。baseUrl 缺省按 api 分家:openai 形落主网关
|
|
11
|
-
// (现状);anthropic 形落 anthropic 路由自己的 baseUrl——provider=anthropic 的模型在 brain 路由里
|
|
12
|
-
// 从不走 openai 网关,titler 兜到 gatewayBaseUrl 缺省值即上述每会话必现 fetch failed 的根因。
|
|
13
|
-
// anthropic 形两头都缺(模型无 per-model baseUrl 且路由未装)= 一句话诚实 fail,说清缺什么配置。
|
|
14
5
|
const shapeFrom = (catalogRef, m, providerModelId) => {
|
|
15
6
|
const api = m?.api === "anthropic-messages" || m?.provider === "anthropic" ? "anthropic-messages" : "openai-completions";
|
|
16
7
|
if (api === "anthropic-messages") {
|
|
@@ -25,27 +16,17 @@ export function createHookLlm(deps) {
|
|
|
25
16
|
}
|
|
26
17
|
return { ok: true, catalogRef, providerModelId, baseUrl: m?.baseUrl || config.gatewayBaseUrl, api };
|
|
27
18
|
};
|
|
28
|
-
// 默认=summarize 角色(cheap tier,council/压缩同款;缺角色→主模型);entry.model 覆盖须命中部署
|
|
29
|
-
// catalog(单用户=自家目录全开,与 workflow 模型 allowlist 同纪律),未命中=该条目 fail(非阻断记账)。
|
|
30
|
-
// ({select} 形态诚实落主模型——hook 是廉价判定调用,不值得拉 select 机制。)
|
|
31
19
|
const hookModelFor = (requested) => {
|
|
32
20
|
const shape = (ref) => shapeFrom(ref, config.models[ref], config.models[ref]?.id ?? ref);
|
|
33
21
|
if (requested === undefined) {
|
|
34
22
|
const sum = config.roles.summarize;
|
|
35
23
|
const roleModel = typeof sum === "string" ? sum : sum && typeof sum === "object" && "model" in sum && typeof sum.model === "string" ? sum.model : undefined;
|
|
36
|
-
// 角色名不在目录 ⇒ 当作主模型路由上的 raw provider id(主 brain 家族就是它的真实服务面),
|
|
37
|
-
// 形状/缺省 baseUrl 跟主模型走,不再无条件钉死 openai 网关。
|
|
38
24
|
if (roleModel !== undefined)
|
|
39
25
|
return config.models[roleModel] ? shape(roleModel) : shapeFrom(config.model.id, config.model, roleModel);
|
|
40
26
|
return shapeFrom(config.model.id, config.model, config.model.id);
|
|
41
27
|
}
|
|
42
28
|
if (config.models[requested])
|
|
43
29
|
return shape(requested);
|
|
44
|
-
// 复审 2026-07-29 D1:目录键是 **name** 形,而调用点会传 **provider id** 形——`http/routes/tasks.ts`
|
|
45
|
-
// 的 titler 腿([1992]②「标题跟 turn」)对对象形 spec 传的就是 `spec.model.id`。registry 热应用后
|
|
46
|
-
// name 与 id 常态分叉(目录键是运维起的短名,`Model.id` 是 provider 侧的真名),单键索引下这类请求全落到下面那条
|
|
47
|
-
// 「不在目录里」⇒ 用户每选一次非主模型,标题就 llm_failed(对话本身正常),与 [1992] 同族的病形。
|
|
48
|
-
// 双键索引沿用同仓先例 [865]② `matchCatalogModel`:name 优先、id 扫目录值、跳过 `default` 别名键。
|
|
49
30
|
const byId = matchCatalogModel(requested, config.models);
|
|
50
31
|
if (byId !== undefined)
|
|
51
32
|
return shape(byId);
|
|
@@ -61,28 +42,16 @@ export function createHookLlm(deps) {
|
|
|
61
42
|
const ac = new AbortController();
|
|
62
43
|
const t = setTimeout(() => ac.abort(), timeoutMs);
|
|
63
44
|
try {
|
|
64
|
-
// 🔴 key resolution (2026-07-13 — the session titler widened this face from
|
|
65
|
-
// "deployments that configured hooks" to EVERY default deployment): per-model key (sealed-box custody /
|
|
66
|
-
// apiKeyEnv, via the SAME hot-refreshed keyResolver the brain uses) WINS; the MAIN gateway key rides ONLY
|
|
67
|
-
// to the main gateway's own baseUrl — a roster model pointing at a FOREIGN provider must NEVER receive
|
|
68
|
-
// the main key (credential exfiltration to whoever operates that URL). Foreign + no per-model key ⇒ the
|
|
69
|
-
// request goes out UNAUTHENTICATED (the provider 401s = honest failure, nothing leaked).
|
|
70
45
|
const keyResolver = deps.getKeyResolver();
|
|
71
|
-
// 🔴 custody fail-closed(交叉评审 F1):resolver 抛错(sealed key 中毒/解密失败)≠「没配 per-model
|
|
72
|
-
// key」——吞成 undefined 会让 same-route 模型静默回落共享路由凭据照发。抛错=本次调用整体 fail,
|
|
73
|
-
// 不发任何请求(抽取前的内联版就有这个吞错,借抽取一并修死)。
|
|
74
46
|
let perModelKey;
|
|
75
47
|
if (keyResolver) {
|
|
76
48
|
try {
|
|
77
|
-
perModelKey = (await keyResolver({ name: pick.catalogRef }))?.apiKey;
|
|
49
|
+
perModelKey = (await keyResolver({ name: pick.catalogRef }))?.apiKey;
|
|
78
50
|
}
|
|
79
51
|
catch (e) {
|
|
80
52
|
return { ok: false, error: `per-model key resolution for "${pick.catalogRef}" failed — refusing to fall back to the shared route credential (${String(e)})` };
|
|
81
53
|
}
|
|
82
54
|
}
|
|
83
|
-
// URL-normalized comparison (lens-A re-review: raw string compare false-negatives on host case /
|
|
84
|
-
// default-port forms and would strand the MAIN gateway without its own key — an availability bug in
|
|
85
|
-
// the safe direction, still a bug). new URL lowercases the host and drops a default port.
|
|
86
55
|
const normUrl = (u) => {
|
|
87
56
|
try {
|
|
88
57
|
const x = new URL(u);
|
|
@@ -96,10 +65,6 @@ export function createHookLlm(deps) {
|
|
|
96
65
|
let headers;
|
|
97
66
|
let body;
|
|
98
67
|
if (pick.api === "anthropic-messages") {
|
|
99
|
-
// anthropic 腿的同路纪律 = openai 腿 sameGateway 的镜像:anthropic 路由自己的凭据(authToken 压过
|
|
100
|
-
// apiKey,brain.ts 同序)只随路由自己的 baseUrl 走;per-model key 恒胜(x-api-key,core brain 的
|
|
101
|
-
// 同一注入位)。🔴 TRUE fail-closed 同款:foreign anthropic 端点无 per-model key ⇒ 连 prompt 都
|
|
102
|
-
// 不发(prompt 内嵌用户内容,未认证发射同样把数据外泄给该 URL 的运营方)。
|
|
103
68
|
const routeBase = anthropicRouteBaseUrl();
|
|
104
69
|
const sameRoute = routeBase !== undefined && normUrl(pick.baseUrl) === normUrl(routeBase);
|
|
105
70
|
if (!perModelKey && !sameRoute) {
|
|
@@ -108,8 +73,6 @@ export function createHookLlm(deps) {
|
|
|
108
73
|
url = `${pick.baseUrl.replace(/\/+$/, "")}/v1/messages`;
|
|
109
74
|
headers = {
|
|
110
75
|
"content-type": "application/json",
|
|
111
|
-
// anthropic-version 缺省与 core brain 一致;纯 per-model 端点(路由未装但 per-model key 在)
|
|
112
|
-
// 也带版本头,取同一缺省。
|
|
113
76
|
"anthropic-version": config.anthropic?.version ?? "2023-06-01",
|
|
114
77
|
...(perModelKey
|
|
115
78
|
? { "x-api-key": perModelKey }
|
|
@@ -119,31 +82,18 @@ export function createHookLlm(deps) {
|
|
|
119
82
|
? { "x-api-key": config.anthropic.apiKey }
|
|
120
83
|
: {}),
|
|
121
84
|
};
|
|
122
|
-
// Messages API 必带 max_tokens:钳 1024 上限(交叉评审 F2)——hook 是廉价判定调用(titler 产出
|
|
123
|
-
// 一行标题),永远用不到更多;且 [854]③a 后 model.maxTokens 缺省抬到 32000,原样发给小输出上限的
|
|
124
|
-
// anthropic 形模型会整请求被拒(max_tokens 超模型硬顶=400),标题腿没必要陪这个险。
|
|
125
|
-
// 缺省 1024 是为 titler 那类"一行标题"调的;调用方可用 `maxOutputTokens` 声明自己需要更多
|
|
126
|
-
// (见该字段旁注:CC 评估者被要求引用转录,推理档的 thinking 还与输出共用额度)。
|
|
127
|
-
// 上限仍钳在模型自己的 maxTokens 以内 —— 超模型硬顶会整请求 400,这条原因没变。
|
|
128
85
|
const want = maxOutputTokens ?? 1024;
|
|
129
86
|
const maxTokens = Math.min(config.models[pick.catalogRef]?.maxTokens ?? want, want);
|
|
130
|
-
// `system` 走 Messages API 的**顶层字段**(不是一条 role:"system" 消息 —— anthropic 形不接受那个角色)。
|
|
131
87
|
body = JSON.stringify({ model: pick.providerModelId, max_tokens: maxTokens, ...(system ? { system } : {}), messages: [{ role: "user", content: prompt }] });
|
|
132
88
|
}
|
|
133
89
|
else {
|
|
134
90
|
const sameGateway = normUrl(pick.baseUrl) === normUrl(config.gatewayBaseUrl);
|
|
135
91
|
const hookKey = perModelKey ?? (sameGateway ? config.gatewayApiKey : undefined);
|
|
136
|
-
// 🔴 TRUE fail-closed (lens-A HIGH): a FOREIGN endpoint with no per-model key must not receive the
|
|
137
|
-
// REQUEST BODY either — the hook prompt embeds user content (session-titler: the objective), so an
|
|
138
|
-
// unauthenticated fire still exfiltrates data to whoever operates that URL. Refuse before fetch.
|
|
139
92
|
if (!sameGateway && !hookKey) {
|
|
140
93
|
return { ok: false, error: `hook model "${pick.catalogRef}" points at a foreign baseUrl with no per-model key — refusing to send the prompt off-gateway` };
|
|
141
94
|
}
|
|
142
95
|
url = `${pick.baseUrl.replace(/\/+$/, "")}/chat/completions`;
|
|
143
96
|
headers = { "content-type": "application/json", ...(hookKey ? { authorization: `Bearer ${hookKey}` } : {}) };
|
|
144
|
-
// `system` 在 openai 形是**前置的一条 system 消息**(与 anthropic 的顶层字段等价,两边同一语义)。
|
|
145
|
-
// openai 形此前**不发** max_tokens(用 provider 缺省)。只有调用方显式声明时才发 ——
|
|
146
|
-
// 不改 titler 那条腿的既有行为,同时让评估者能要到它需要的额度。
|
|
147
97
|
body = JSON.stringify({ model: pick.providerModelId, ...(maxOutputTokens !== undefined ? { max_tokens: maxOutputTokens } : {}), messages: [...(system ? [{ role: "system", content: system }] : []), { role: "user", content: prompt }], stream: false });
|
|
148
98
|
}
|
|
149
99
|
const r = await fetchImpl(url, { method: "POST", headers, body, signal: ac.signal });
|
|
@@ -163,8 +113,6 @@ export function createHookLlm(deps) {
|
|
|
163
113
|
return typeof text === "string" ? { ok: true, text } : { ok: false, error: "hook llm returned no content", code: "no_content" };
|
|
164
114
|
}
|
|
165
115
|
catch (e) {
|
|
166
|
-
// 网络层失败原样只有 "TypeError: fetch failed"(不是人话):带上端点与 cause(ECONNREFUSED 等),
|
|
167
|
-
// 一句话说清打的是哪个 URL、为什么挂——titler 的 llm_failed 记账/warn 原样透出这条。
|
|
168
116
|
const cause = e?.cause;
|
|
169
117
|
return {
|
|
170
118
|
ok: false,
|