@sema-agent/core 5.20.0 → 5.21.1
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/CHANGELOG.md +19 -0
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-transcript-tool.d.ts +30 -0
- package/dist/agents/builtin-agents.d.ts +60 -0
- package/dist/agents/cascade.d.ts +107 -0
- package/dist/agents/cumulative-stats.d.ts +56 -0
- package/dist/agents/observer.d.ts +162 -0
- package/dist/agents/peer-admission.d.ts +95 -0
- package/dist/agents/repair-loop.d.ts +226 -0
- package/dist/agents/retain-ledger.d.ts +141 -0
- package/dist/agents/roster-store.d.ts +105 -0
- package/dist/agents/send-message-tool.d.ts +92 -0
- package/dist/agents/session-util.d.ts +5 -0
- package/dist/agents/subagent-steps.d.ts +66 -0
- package/dist/agents/subagent.d.ts +600 -0
- package/dist/agents/suspend-guard.d.ts +29 -0
- package/dist/agents/teacher.d.ts +75 -0
- package/dist/agents/team.d.ts +120 -1
- package/dist/agents/tool-filter.d.ts +34 -0
- package/dist/agents/verify.d.ts +198 -0
- package/dist/bench/metrics.d.ts +455 -0
- package/dist/brain/anthropic.d.ts +30 -0
- package/dist/brain/circuit-breaker.d.ts +33 -0
- package/dist/brain/context-overflow.d.ts +60 -3
- package/dist/brain/degrading.d.ts +67 -0
- package/dist/brain/errors.d.ts +42 -0
- package/dist/brain/failover.d.ts +15 -0
- package/dist/brain/media-degrade.d.ts +39 -0
- package/dist/brain/model-presets.d.ts +31 -0
- package/dist/brain/open-responses.d.ts +19 -0
- package/dist/brain/openai.d.ts +46 -0
- package/dist/brain/reasoning.d.ts +106 -1
- package/dist/brain/repetition.d.ts +83 -0
- package/dist/brain/request-params.d.ts +56 -0
- package/dist/brain/retry.d.ts +46 -0
- package/dist/brain/routing.d.ts +12 -0
- package/dist/brain/status-sink.d.ts +30 -1
- package/dist/brain/stream-engine.d.ts +147 -0
- package/dist/brain/stream-shared.d.ts +34 -0
- package/dist/brain/terminal-cause.d.ts +31 -0
- package/dist/brain/timeout.d.ts +107 -0
- package/dist/brain/tool-call-id.d.ts +20 -0
- package/dist/brain/tool-call-repair.d.ts +13 -0
- package/dist/config/catalog.d.ts +47 -0
- package/dist/config/defaults.d.ts +33 -0
- package/dist/core/a2a-task-state.d.ts +53 -0
- package/dist/core/a2a.d.ts +51 -0
- package/dist/core/arg-summary.d.ts +62 -0
- package/dist/core/ask-question.d.ts +272 -2
- package/dist/core/auto-compaction.d.ts +467 -0
- package/dist/core/auto-compaction.js +20 -6
- package/dist/core/auto-mode-prompt-assets.d.ts +8 -0
- package/dist/core/auto-mode-prompt.d.ts +27 -0
- package/dist/core/auto-mode.d.ts +54 -3
- package/dist/core/auto-promote.d.ts +100 -0
- package/dist/core/background-agent-store.d.ts +292 -0
- package/dist/core/background-shell.d.ts +110 -0
- package/dist/core/cache-break-detector.d.ts +34 -0
- package/dist/core/canonical-json.d.ts +57 -0
- package/dist/core/checkpoint-store.d.ts +1574 -16
- package/dist/core/compliance.d.ts +30 -0
- package/dist/core/consolidate-scope.d.ts +75 -0
- package/dist/core/context-edit.d.ts +99 -0
- package/dist/core/context-guard.d.ts +46 -0
- package/dist/core/exec-gate.d.ts +44 -0
- package/dist/core/exec-output-tail.d.ts +61 -0
- package/dist/core/file-snapshot-store.d.ts +104 -0
- package/dist/core/fs-write-gate-policy.d.ts +36 -0
- package/dist/core/git-worktree-env.d.ts +31 -0
- package/dist/core/governance-codes.d.ts +19 -0
- package/dist/core/hooks.d.ts +608 -1
- package/dist/core/human-input-projection.d.ts +37 -0
- package/dist/core/human-input-projection.js +13 -0
- package/dist/core/image-downsample.d.ts +74 -0
- package/dist/core/locked-config.d.ts +37 -0
- package/dist/core/lsp-diagnostics.d.ts +77 -0
- package/dist/core/lsp-protocol.d.ts +29 -0
- package/dist/core/lsp-session.d.ts +60 -1
- package/dist/core/lsp.d.ts +150 -1
- package/dist/core/mailbox-store.d.ts +57 -0
- package/dist/core/mcp.d.ts +381 -0
- package/dist/core/media-byte-cap.d.ts +21 -0
- package/dist/core/memory-admission.d.ts +71 -0
- package/dist/core/memory-engine/content-origin.d.ts +64 -0
- package/dist/core/memory-engine/data-plane.d.ts +43 -0
- package/dist/core/memory-engine/dual-root.d.ts +24 -0
- package/dist/core/memory-engine/engine.d.ts +230 -0
- package/dist/core/memory-engine/engine.js +103 -35
- package/dist/core/memory-engine/file-backend.d.ts +155 -0
- package/dist/core/memory-engine/frontmatter.d.ts +16 -0
- package/dist/core/memory-engine/layout.d.ts +217 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +12 -0
- package/dist/core/memory-engine/migrate.d.ts +9 -0
- package/dist/core/memory-engine/scan.d.ts +12 -0
- package/dist/core/memory-engine/scope-contract.d.ts +61 -1
- package/dist/core/memory-engine/sync-client.d.ts +87 -0
- package/dist/core/memory-engine/sync.d.ts +60 -0
- package/dist/core/memory-engine/tools.d.ts +41 -0
- package/dist/core/memory-engine/types.d.ts +188 -0
- package/dist/core/memory-recall.d.ts +141 -0
- package/dist/core/memory-vector.d.ts +20 -0
- package/dist/core/memory.d.ts +458 -0
- package/dist/core/message-utils.d.ts +6 -0
- package/dist/core/oracle-isolation.d.ts +69 -0
- package/dist/core/permission-rule-consent.d.ts +138 -0
- package/dist/core/permission-rule-model.d.ts +122 -0
- package/dist/core/permission-rule-store.d.ts +119 -3
- package/dist/core/permission-rules.d.ts +87 -1
- package/dist/core/present-plan-tool.d.ts +20 -0
- package/dist/core/pricing.d.ts +26 -0
- package/dist/core/property-harness.d.ts +86 -0
- package/dist/core/protocol-naming.d.ts +38 -0
- package/dist/core/protocol-table.d.ts +61 -0
- package/dist/core/push-queue.d.ts +1 -0
- package/dist/core/remote-env.d.ts +383 -1
- package/dist/core/retention-policy.d.ts +33 -0
- package/dist/core/retention.d.ts +51 -0
- package/dist/core/roles.d.ts +59 -0
- package/dist/core/runner/active-skill-scope.d.ts +34 -0
- package/dist/core/runner/assemble-result.d.ts +134 -0
- package/dist/core/runner/compaction-call-options.d.ts +97 -1
- package/dist/core/runner/grounding-signal.d.ts +10 -0
- package/dist/core/runner/image.d.ts +17 -0
- package/dist/core/runner/image.js +29 -15
- package/dist/core/runner/memory-consolidation.d.ts +60 -0
- package/dist/core/runner/prepare-memory.d.ts +59 -0
- package/dist/core/runner/prepare-task.d.ts +1011 -2
- package/dist/core/runner/prepare-task.js +12 -11
- package/dist/core/runner/prompt-suggestions.d.ts +7 -0
- package/dist/core/runner/runtask.d.ts +304 -3
- package/dist/core/runner/session-file-state-replay.d.ts +49 -0
- package/dist/core/runner/session-rule-policy.d.ts +58 -0
- package/dist/core/runner/strict-output-schema.d.ts +18 -3
- package/dist/core/runner/synthetic-tools.d.ts +113 -0
- package/dist/core/runner/teardown-bounded.d.ts +34 -0
- package/dist/core/runner/tool-disclosure.d.ts +227 -0
- package/dist/core/runner/tool-output-projection.d.ts +6 -0
- package/dist/core/runner/turn-attachments.d.ts +634 -0
- package/dist/core/runner/usage-accounting.d.ts +32 -0
- package/dist/core/runtime.d.ts +9 -0
- package/dist/core/safe-notify.d.ts +64 -0
- package/dist/core/safety-axis-vocab.d.ts +23 -0
- package/dist/core/safety-merge-corpus.d.ts +37 -0
- package/dist/core/scheduler.d.ts +121 -0
- package/dist/core/secret-env.d.ts +32 -0
- package/dist/core/select-model.d.ts +15 -0
- package/dist/core/sensitive-path-policy.d.ts +42 -0
- package/dist/core/session-policy-store.d.ts +94 -0
- package/dist/core/session-reconcile.d.ts +80 -0
- package/dist/core/session-store.d.ts +85 -0
- package/dist/core/session.d.ts +153 -0
- package/dist/core/shared-memory/contract.d.ts +22 -0
- package/dist/core/shared-memory/normalize.d.ts +123 -2
- package/dist/core/shared-memory/tools.d.ts +14 -0
- package/dist/core/shared-memory/types.d.ts +105 -0
- package/dist/core/shutdown-debug.d.ts +6 -0
- package/dist/core/side-query.d.ts +38 -0
- package/dist/core/side-query.js +6 -1
- package/dist/core/skill-tool-specifier.d.ts +72 -0
- package/dist/core/skills-directory.d.ts +100 -1
- package/dist/core/spec-contract.d.ts +89 -0
- package/dist/core/store-contracts/background-agent-store-contract.d.ts +31 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +26 -0
- package/dist/core/store-contracts/contract-harness.d.ts +20 -0
- package/dist/core/store-contracts/contract-kit-version.d.ts +27 -0
- package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +8 -0
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +42 -0
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +13 -0
- package/dist/core/strategy-store.d.ts +37 -0
- package/dist/core/stub-env.d.ts +7 -0
- package/dist/core/surrogate-safe-slice.d.ts +35 -0
- package/dist/core/task-notification.d.ts +202 -0
- package/dist/core/task-outcome.d.ts +53 -0
- package/dist/core/task-registry-agent.d.ts +337 -1
- package/dist/core/task-registry-monitor.d.ts +12 -0
- package/dist/core/task-registry-shared.d.ts +540 -0
- package/dist/core/task-registry.d.ts +343 -0
- package/dist/core/task-registry.js +13 -2
- package/dist/core/task-tool-shape.d.ts +44 -0
- package/dist/core/tighten-task-spec.d.ts +21 -0
- package/dist/core/tool-detach.d.ts +21 -0
- package/dist/core/tool-errors.d.ts +131 -0
- package/dist/core/tool-errors.js +4 -0
- package/dist/core/tool-name-aliases.d.ts +27 -0
- package/dist/core/tool-policy.d.ts +555 -0
- package/dist/core/tool-result-budget.d.ts +32 -0
- package/dist/core/tool-result-store.d.ts +174 -1
- package/dist/core/tools.d.ts +45 -0
- package/dist/core/trace.d.ts +323 -0
- package/dist/core/types.d.ts +3859 -2
- package/dist/core/untrusted-egress.d.ts +8 -0
- package/dist/core/untrusted-text.d.ts +156 -0
- package/dist/core/usage-window-store.d.ts +95 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/warm-resume.d.ts +17 -0
- package/dist/core/wiring-manifest.d.ts +169 -0
- package/dist/core/with-retry.d.ts +24 -0
- package/dist/core/workflow-journal-store.d.ts +160 -0
- package/dist/core/workflow-run-store-contract.d.ts +25 -0
- package/dist/core/workflow-run-store.d.ts +119 -0
- package/dist/engine/compaction/compaction.d.ts +256 -1
- package/dist/engine/compaction/utils.d.ts +94 -0
- package/dist/engine/execution-env/kill-tree.d.ts +29 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +94 -0
- package/dist/engine/harness/agent-harness.d.ts +116 -0
- package/dist/engine/harness/agent-harness.js +3 -14
- package/dist/engine/harness/messages.d.ts +15 -0
- package/dist/engine/harness/types.d.ts +464 -2
- package/dist/engine/llm/diagnostics.d.ts +4 -0
- package/dist/engine/llm/event-stream.d.ts +3 -0
- package/dist/engine/llm/index.d.ts +7 -0
- package/dist/engine/llm/types.d.ts +500 -3
- package/dist/engine/llm/validation.d.ts +3 -0
- package/dist/engine/loop/agent-loop.d.ts +87 -2
- package/dist/engine/loop/runtime-deps.d.ts +7 -0
- package/dist/engine/loop/types.d.ts +424 -0
- package/dist/engine/lsp/frame-decoder.d.ts +13 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +107 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +7 -0
- package/dist/engine/session/import-validate.d.ts +27 -0
- package/dist/engine/session/log-digest.d.ts +93 -0
- package/dist/engine/session/memory-repo.d.ts +6 -0
- package/dist/engine/session/memory-storage.d.ts +2 -0
- package/dist/engine/session/session.d.ts +75 -0
- package/dist/engine/session/storage-base.d.ts +8 -0
- package/dist/fixtures/index.d.ts +36 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +0 -1
- package/dist/internal/harness-types.d.ts +6 -0
- package/dist/internal/harness.d.ts +11 -0
- package/dist/internal/llm.d.ts +6 -0
- package/dist/orchestration/builtin-workflows.d.ts +53 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +19 -0
- package/dist/orchestration/goal.d.ts +57 -0
- package/dist/orchestration/goal.js +3 -0
- package/dist/orchestration/run-spec.d.ts +42 -0
- package/dist/orchestration/run-workflow-tool.d.ts +169 -0
- package/dist/orchestration/workflow-governance.d.ts +61 -0
- package/dist/orchestration/workflow-meta.d.ts +28 -0
- package/dist/orchestration/workflow-observe.d.ts +60 -0
- package/dist/orchestration/workflow-primitives.d.ts +23 -1
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +38 -0
- package/dist/orchestration/workflow-script-runner.d.ts +88 -0
- package/dist/orchestration/workflow-script-store.d.ts +98 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +67 -0
- package/dist/orchestration/workflow-types.d.ts +169 -2
- package/dist/orchestration/workflow.d.ts +358 -0
- package/dist/prompt-assembly/artifact-store.d.ts +33 -0
- package/dist/prompt-assembly/artifact.d.ts +25 -0
- package/dist/prompt-assembly/assemble.d.ts +20 -0
- package/dist/prompt-assembly/composer.d.ts +29 -0
- package/dist/prompt-assembly/epoch.d.ts +55 -1
- package/dist/prompt-assembly/event-registry.d.ts +35 -0
- package/dist/prompt-assembly/explain.d.ts +12 -0
- package/dist/prompt-assembly/tool-catalog.d.ts +38 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +40 -0
- package/dist/prompt-assembly/types.d.ts +115 -0
- package/dist/prompts/coordinator.d.ts +27 -0
- package/dist/prompts/default.d.ts +539 -0
- package/dist/prompts/simple-sections.d.ts +45 -0
- package/dist/prompts/supervisor.d.ts +66 -0
- package/dist/scenarios/env.d.ts +28 -0
- package/dist/scenarios/full-body.d.ts +50 -0
- package/dist/scenarios/scenario-registry.d.ts +60 -0
- package/dist/scenarios/teacher-quickstart.d.ts +27 -0
- package/dist/server/http.d.ts +17 -0
- package/dist/stores/cc/lockfile.d.ts +6 -0
- package/dist/stores/cc/mailbox-store.d.ts +8 -0
- package/dist/stores/cc/roster-adapter.d.ts +4 -0
- package/dist/stores/cc/sidecar-transcript.d.ts +66 -0
- package/dist/stores/file/background-agent-store.d.ts +24 -0
- package/dist/stores/file/checkpoint-store.d.ts +38 -0
- package/dist/stores/file/file-snapshot-store.d.ts +25 -0
- package/dist/stores/file/fs-atomic.d.ts +155 -0
- package/dist/stores/file/index.d.ts +89 -0
- package/dist/stores/file/mailbox-store.d.ts +36 -0
- package/dist/stores/file/memory-store.d.ts +82 -0
- package/dist/stores/file/permission-rule-store.d.ts +79 -0
- package/dist/stores/file/session-policy-store.d.ts +28 -0
- package/dist/stores/file/session-store.d.ts +40 -0
- package/dist/stores/file/shared-ledger.d.ts +83 -0
- package/dist/stores/file/tool-result-store.d.ts +11 -0
- package/dist/stores/file/usage-window-store.d.ts +18 -0
- package/dist/stores/file/workflow-journal-store.d.ts +100 -0
- package/dist/stores/file/workflow-run-store.d.ts +11 -0
- package/dist/tools/fs/bash-readonly-classifier.d.ts +282 -0
- package/dist/tools/fs/encoding.d.ts +60 -0
- package/dist/tools/fs/fs-bash.d.ts +133 -0
- package/dist/tools/fs/fs-pdf.d.ts +28 -0
- package/dist/tools/fs/fs-search-tools.d.ts +5 -0
- package/dist/tools/fs/fs-search-tools.js +0 -1
- package/dist/tools/fs/fs-shared.d.ts +360 -0
- package/dist/tools/fs/fs-write.d.ts +16 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
- package/dist/tools/fs/index.d.ts +79 -0
- package/dist/tools/fs/notebook.d.ts +56 -0
- package/dist/tools/fs/pdf.d.ts +70 -0
- package/dist/tools/fs/pdf.js +8 -2
- package/dist/tools/fs/repo-map.d.ts +10 -0
- package/dist/tools/fs/safety.d.ts +376 -0
- package/dist/tools/fs/search.d.ts +131 -0
- package/dist/tools/loop-tick.d.ts +24 -0
- package/dist/tools/monitor.d.ts +55 -0
- package/dist/tools/scheduler-tools.d.ts +51 -0
- package/dist/tools/sql-adapters.d.ts +18 -0
- package/dist/tools/sql.d.ts +25 -0
- package/dist/tools/task-list.d.ts +77 -0
- package/dist/tools/todo.d.ts +8 -0
- package/dist/tools/web.d.ts +184 -0
- package/dist/tools/worktree.d.ts +81 -0
- package/package.json +2 -2
- package/dist/tools/gitea-issue.d.ts +0 -13
- package/dist/tools/gitea-issue.js +0 -75
|
@@ -33,10 +33,24 @@ function summarizationCharsCapacity(model) {
|
|
|
33
33
|
}
|
|
34
34
|
export const STALE_ANCHOR_STRUCTURAL_MARGIN = 2;
|
|
35
35
|
export function sanitizeCompactionSettings(settings, contextWindow) {
|
|
36
|
+
const wide = settings;
|
|
37
|
+
const reserveInvalid = !Number.isFinite(wide.reserveTokens);
|
|
38
|
+
const keepRecentInvalid = !Number.isFinite(wide.keepRecentTokens);
|
|
39
|
+
const clampToleranceInvalid = wide.clampTolerance !== undefined && !Number.isFinite(wide.clampTolerance);
|
|
40
|
+
const summaryBudgetInvalid = wide.summaryOutputBudgetTokens !== undefined && !Number.isFinite(wide.summaryOutputBudgetTokens);
|
|
41
|
+
const base = reserveInvalid || keepRecentInvalid || clampToleranceInvalid || summaryBudgetInvalid
|
|
42
|
+
? {
|
|
43
|
+
...settings,
|
|
44
|
+
...(reserveInvalid ? { reserveTokens: DEFAULT_COMPACTION_SETTINGS.reserveTokens } : {}),
|
|
45
|
+
...(keepRecentInvalid ? { keepRecentTokens: DEFAULT_COMPACTION_SETTINGS.keepRecentTokens } : {}),
|
|
46
|
+
...(clampToleranceInvalid ? { clampTolerance: DEFAULT_CLAMP_TOLERANCE } : {}),
|
|
47
|
+
...(summaryBudgetInvalid ? { summaryOutputBudgetTokens: undefined } : {}),
|
|
48
|
+
}
|
|
49
|
+
: settings;
|
|
36
50
|
if (!contextWindow || !Number.isFinite(contextWindow) || contextWindow <= 0) {
|
|
37
|
-
return
|
|
51
|
+
return base;
|
|
38
52
|
}
|
|
39
|
-
let reserveTokens =
|
|
53
|
+
let reserveTokens = base.reserveTokens;
|
|
40
54
|
if (contextWindow - reserveTokens <= 0) {
|
|
41
55
|
reserveTokens = Math.ceil(contextWindow * FALLBACK_RESERVE_FRACTION);
|
|
42
56
|
}
|
|
@@ -45,14 +59,14 @@ export function sanitizeCompactionSettings(settings, contextWindow) {
|
|
|
45
59
|
reserveTokens = contextWindow - editAt;
|
|
46
60
|
}
|
|
47
61
|
const threshold = contextWindow - reserveTokens;
|
|
48
|
-
let keepRecentTokens =
|
|
62
|
+
let keepRecentTokens = base.keepRecentTokens;
|
|
49
63
|
if (keepRecentTokens >= threshold) {
|
|
50
64
|
keepRecentTokens = Math.max(1, Math.floor(threshold / 2));
|
|
51
65
|
}
|
|
52
|
-
if (reserveTokens ===
|
|
53
|
-
return
|
|
66
|
+
if (reserveTokens === base.reserveTokens && keepRecentTokens === base.keepRecentTokens) {
|
|
67
|
+
return base;
|
|
54
68
|
}
|
|
55
|
-
return { ...
|
|
69
|
+
return { ...base, reserveTokens, keepRecentTokens };
|
|
56
70
|
}
|
|
57
71
|
export async function maybeCompact(opts) {
|
|
58
72
|
const compactStartAt = Date.now();
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
+
/** The auto-mode classifier SYSTEM prompt shell (CC 2.1.207 `auto_mode_system_prompt`). Contains two
|
|
2
|
+
* assembly placeholders consumed by `buildAutoModePrompt`: `<permissions_template>` (replaced by the
|
|
3
|
+
* permissions document) and `<cross_session_messages_rule>` (replaced with "" — the 206/207 default). */
|
|
1
4
|
export declare const AUTO_MODE_BASE_PROMPT: string;
|
|
5
|
+
/** The external permissions document (CC 2.1.207 `permissions_external`). Four PAIRED placeholder
|
|
6
|
+
* tags wrap the DEFAULT rule sets (environment / hard deny / soft deny / allow) and one UNPAIRED tag
|
|
7
|
+
* (`<settings_deny_rules>`) marks the settings-plane deny injection point — all consumed by
|
|
8
|
+
* `buildAutoModePrompt` with the CC-exact merge semantics (user rules REPLACE the defaults; the
|
|
9
|
+
* `"$defaults"` sentinel splices the default set back in at its position). */
|
|
2
10
|
export declare const AUTO_MODE_PERMISSIONS_EXTERNAL: string;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { AutoModeClassifyInput } from "./auto-mode.js";
|
|
2
2
|
import type { Message } from "../internal/llm.js";
|
|
3
|
+
/** The sentinel a deployment puts INSIDE a rule list to splice the CC default rules back in at that
|
|
4
|
+
* position (CC `XYt = "$defaults"`). Without it, a non-empty user list REPLACES the default section. */
|
|
3
5
|
export declare const AUTO_MODE_DEFAULTS_SENTINEL = "$defaults";
|
|
6
|
+
/** Deployment-authored rule overrides for the four paired sections of the permissions document.
|
|
7
|
+
* Each entry is ONE rule (rendered as a `- ` bullet); omit a field (or pass an empty array) to keep
|
|
8
|
+
* the CC default rules for that section verbatim. */
|
|
4
9
|
export interface AutoModeRules {
|
|
5
10
|
allow?: readonly string[];
|
|
6
11
|
softDeny?: readonly string[];
|
|
@@ -9,13 +14,35 @@ export interface AutoModeRules {
|
|
|
9
14
|
}
|
|
10
15
|
export interface BuildAutoModePromptOptions {
|
|
11
16
|
rules?: AutoModeRules;
|
|
17
|
+
/** Settings-plane deny rules (tool[/argument-pattern] strings) — rendered into the
|
|
18
|
+
* `<settings_deny_rules>` slot as the CC circumvention-catching paragraph. */
|
|
12
19
|
settingsDenyRules?: readonly string[];
|
|
20
|
+
/** Extra session-context facts (e.g. the CC user-identity line) — appended as a
|
|
21
|
+
* `## Session Context` bullet block after the assembled document. */
|
|
13
22
|
sessionContext?: readonly string[];
|
|
14
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Assemble the classifier SYSTEM prompt (CC `KRg`, content-equivalent single string — CC splits the
|
|
26
|
+
* session-context tail into a second uncached block purely as a prompt-cache optimization).
|
|
27
|
+
* Every `.replace` uses the CALLBACK form: the assets and user rules are full of `$`-patterns
|
|
28
|
+
* (`$USER/...`) that a string replacement would corrupt via `$&`/`$'` substitution (CC does the same).
|
|
29
|
+
*/
|
|
15
30
|
export declare function buildAutoModePrompt(options?: BuildAutoModePromptOptions): string;
|
|
16
31
|
export interface AutoModeWindowOptions {
|
|
32
|
+
/** Newest transcript entries included (default 40). */
|
|
17
33
|
maxEntries?: number;
|
|
34
|
+
/** Per-entry excerpt cap in characters (default 2_000 — tool results and long turns are truncated
|
|
35
|
+
* head-first with a `[… N chars truncated]` marker; the classifier weighs shape over bulk). */
|
|
18
36
|
maxCharsPerEntry?: number;
|
|
19
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Render the transcript window half of the classifier's user prompt: the newest `maxEntries` messages,
|
|
40
|
+
* oldest→newest, each labeled by lane. Plain data — see the module header for the declared v1 gap vs
|
|
41
|
+
* CC's entry-formatter stack.
|
|
42
|
+
*/
|
|
20
43
|
export declare function renderAutoModeWindow(messages: readonly Message[], options?: AutoModeWindowOptions): string;
|
|
44
|
+
/**
|
|
45
|
+
* Render the pending action (the classify subject). The 207 process's step 1 keys on "the last tool
|
|
46
|
+
* call in the transcript" — this block IS that entry for our assembly, placed last in the user prompt.
|
|
47
|
+
*/
|
|
21
48
|
export declare function renderAutoModeAction(input: AutoModeClassifyInput): string;
|
package/dist/core/auto-mode.d.ts
CHANGED
|
@@ -1,34 +1,85 @@
|
|
|
1
1
|
import type { ToolCallRequest } from "./tool-policy.js";
|
|
2
|
+
/** The classifier's verdict over one pending `ask`. */
|
|
2
3
|
export type AutoModeVerdict = {
|
|
3
4
|
kind: "allow";
|
|
4
|
-
}
|
|
5
|
+
}
|
|
6
|
+
/** `category` is the matched BLOCK rule name (207 output contract); `reason` starts with `[Rule Name]`. */
|
|
7
|
+
| {
|
|
5
8
|
kind: "block";
|
|
6
9
|
category: string;
|
|
7
10
|
reason: string;
|
|
8
|
-
}
|
|
11
|
+
}
|
|
12
|
+
/** The classifier could not run: model error/timeout, or the session breaker is open. NOT a decision. */
|
|
13
|
+
| {
|
|
9
14
|
kind: "unavailable";
|
|
10
15
|
cause: "error" | "timeout" | "breaker_open";
|
|
11
|
-
}
|
|
16
|
+
}
|
|
17
|
+
/** The model responded but not in the `<block>…` contract shape. NOT a decision. */
|
|
18
|
+
| {
|
|
12
19
|
kind: "parse_error";
|
|
13
20
|
raw: string;
|
|
14
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Parse the 207 classifier output contract:
|
|
24
|
+
* blocked: `<block>yes</block><category>Rule Name</category><reason>[Rule Name] …</reason>`
|
|
25
|
+
* allowed: `<block>no</block>`
|
|
26
|
+
* The contract says the ENTIRE response must begin with `<block>` — we strip `<thinking>` blocks
|
|
27
|
+
* first (CC-anchored: the 206 body's `dJi` removes closed thinking blocks AND a dangling unclosed
|
|
28
|
+
* tail before its own block-scan — a reasoning model's scratch space is not part of the verdict),
|
|
29
|
+
* then tolerate leading whitespace (models routinely emit a leading newline) but nothing else: any
|
|
30
|
+
* other preamble is a `parse_error` (fail-closed; 207 vocabulary: `automode-parsing-error`).
|
|
31
|
+
*
|
|
32
|
+
* Declared STRICTER than the CC parser (`iJi`: first `<block>` ANYWHERE in the response, closing tag
|
|
33
|
+
* optional): a free-scan lets a prompt-injected preamble seed the verdict; our contract-anchored
|
|
34
|
+
* parse costs only a fallback to the original human chain on the mismatch, never a silent allow.
|
|
35
|
+
*
|
|
36
|
+
* Strictness is polarity-asymmetric (codex review, confirmed HIGH):
|
|
37
|
+
* - an ALLOW must be UNAMBIGUOUS: `<block>no</block>` followed by anything but whitespace —
|
|
38
|
+
* a second conflicting `<block>yes</block>`, trailing prose, any tail at all — violates the
|
|
39
|
+
* contract and maps to `parse_error` (the ask flows the original human chain, never a silent
|
|
40
|
+
* allow on a malformed response);
|
|
41
|
+
* - a stated BLOCK tolerates a tail (that is where `<category>`/`<reason>` live, and extra
|
|
42
|
+
* content after a block verdict can only ever be judged in the blocking direction) — a
|
|
43
|
+
* `<block>yes</block>` with MISSING/empty `<category>`/`<reason>` still maps to `block`
|
|
44
|
+
* (with "" placeholders): the block intent is unambiguous, and downgrading a stated block
|
|
45
|
+
* to parse_error (⇒ the ask may later auto-deny OR a human may approve) would weaken the
|
|
46
|
+
* classifier's explicit verdict on the exact calls it flagged.
|
|
47
|
+
*/
|
|
15
48
|
export declare function parseAutoModeResponse(text: string): AutoModeVerdict;
|
|
49
|
+
/** What the decider hands the deployment's `classify` hook (the assembled prompt is the hook's job
|
|
50
|
+
* when it owns assembly; when using {@link buildAutoModePrompt} the decider passes its output). */
|
|
16
51
|
export interface AutoModeClassifyInput {
|
|
52
|
+
/** The pending tool call — FINAL post-hook/post-rewrite args (the same args the gate adjudicated). */
|
|
17
53
|
req: ToolCallRequest;
|
|
54
|
+
/** The human-readable text of the ask being decided (policy/safety message), when present. */
|
|
18
55
|
askMessage?: string;
|
|
19
56
|
}
|
|
57
|
+
/** The pluggable model leg: given the classify input, return the model's raw text response.
|
|
58
|
+
* Deployment-injected (roster cheap tier per [672]③); MAY throw / reject — the decider fail-closes. */
|
|
20
59
|
export type AutoModeClassifyFn = (input: AutoModeClassifyInput, signal?: AbortSignal) => Promise<string>;
|
|
21
60
|
export interface AutoModeDeciderOptions {
|
|
22
61
|
classify: AutoModeClassifyFn;
|
|
62
|
+
/** Hard cap on one classification round-trip. Default 15_000 ms (sema 裁量 — CC's constant is not
|
|
63
|
+
* established; a permission gate must not stall the whole run on a slow classifier). */
|
|
23
64
|
timeoutMs?: number;
|
|
65
|
+
/** Consecutive-failure threshold that opens the session breaker (default 3, [672]② "连续 N 失败").
|
|
66
|
+
* Failures = unavailable(error|timeout) + parse_error. A successful round (allow/block) resets it. */
|
|
24
67
|
failureThreshold?: number;
|
|
68
|
+
/** Fired ONCE when the breaker opens ([672]②: "本 session 退回非 auto + 一次性告警"). */
|
|
25
69
|
onBreakerOpen?: (info: {
|
|
26
70
|
consecutiveFailures: number;
|
|
27
71
|
lastCause: string;
|
|
28
72
|
}) => void;
|
|
29
73
|
}
|
|
30
74
|
export interface AutoModeDecider {
|
|
75
|
+
/** Never rejects. Any internal failure surfaces as `unavailable`/`parse_error` (fail-closed). */
|
|
31
76
|
decide(input: AutoModeClassifyInput, signal?: AbortSignal): Promise<AutoModeVerdict>;
|
|
77
|
+
/** True once the session breaker has opened (it never half-opens: [672]② is a SESSION fallback
|
|
78
|
+
* to non-auto, not a retry window — a flapping classifier must not oscillate the permission mode). */
|
|
32
79
|
breakerOpen(): boolean;
|
|
33
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Session-scoped decider: timeout + fail-closed error mapping + a one-way circuit breaker.
|
|
83
|
+
* One instance per run/session — the breaker state is the session's "退回非 auto" latch.
|
|
84
|
+
*/
|
|
34
85
|
export declare function createAutoModeDecider(opts: AutoModeDeciderOptions): AutoModeDecider;
|
|
@@ -1,25 +1,125 @@
|
|
|
1
1
|
import type { OracleIsolationVerdict } from "./oracle-isolation.js";
|
|
2
2
|
import type { SkillManifest } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The terminal of {@link decideAutoPromote}.
|
|
5
|
+
* - `"auto_promote"` — the ONLY exit that skips human review. Reachable only when all four prior guards
|
|
6
|
+
* (tripwire / irreversible / statistics / concurrence) clear AND all four gates are present+passing.
|
|
7
|
+
* - `"candidate_only"` — surface the artifact as a candidate; the SOLE shortfall is the oracle isolation class
|
|
8
|
+
* being downgraded to `in_process_probe_only` (oracle-isolation.ts:34) with everything else passing.
|
|
9
|
+
* - `"needs_human"` — fail-closed default: escalate to a human (any guard tripped, any other gate failing).
|
|
10
|
+
*/
|
|
3
11
|
export type AutoPromoteTerminal = "auto_promote" | "candidate_only" | "needs_human";
|
|
12
|
+
/**
|
|
13
|
+
* Gate-2 + Gate-3 lineage-bound handle (裁决净增③ / P0#3 / P1 lineage-bind). `gate2Verdict` and `manifest`
|
|
14
|
+
* MUST come from the SAME atomic `appendPromotable` write (memory.ts:295) — this struct bundles them into one
|
|
15
|
+
* handle so the decision can never pair a verdict with a divergent manifest ("assume two booleans are
|
|
16
|
+
* co-sourced" is the bug this prevents). `lineageId` keys the active-skill-scope frame (active-skill-scope.ts).
|
|
17
|
+
*/
|
|
4
18
|
export interface PromotedRecord {
|
|
19
|
+
/** Stable lineage id of the promoted artifact; the Gate-3 scope key. */
|
|
5
20
|
lineageId: string;
|
|
21
|
+
/**
|
|
22
|
+
* Gate-2 chokepoint result: the promotable write landed WITH a positive utility verdict (memory.ts:240),
|
|
23
|
+
* or it was absent/ungated. Only `"present_positive"` is gate-passing; `"absent_or_ungated"` ⇒ needs_human.
|
|
24
|
+
*/
|
|
6
25
|
gate2Verdict: "present_positive" | "absent_or_ungated";
|
|
26
|
+
/** Gate-3 capability manifest — co-located with `gate2Verdict` in the same store record, never diverging. */
|
|
7
27
|
manifest: SkillManifest;
|
|
28
|
+
/**
|
|
29
|
+
* Gate-3 scope is armed AND has propagated across the subagent boundary (design/79 §4, design/77 §3/§7).
|
|
30
|
+
* `true` ONLY when either (a) the manifest lists NO subagent-spawn tool, or (b) its scope has propagated to
|
|
31
|
+
* spawned children. The skill→subagent manifest-scope propagation just landed in this branch (commit
|
|
32
|
+
* `04f5104`); for an artifact that lists a subagent-spawn tool whose scope has NOT propagated, this is
|
|
33
|
+
* `false` → the decision falls to `needs_human` (裁决净增⑤ / P1). A bare in-process `gate4Armed`-style
|
|
34
|
+
* boolean is intentionally NOT enough here: the propagation hole is encoded structurally into this flag.
|
|
35
|
+
*/
|
|
8
36
|
gate3Scoped: boolean;
|
|
9
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Inputs to {@link decideAutoPromote}. Every field is a PRESENCE/boolean/set the profile has already computed —
|
|
40
|
+
* the core fold inspects no numeric threshold, no stats shape, no taxonomy. The caller (a profile-promotion job)
|
|
41
|
+
* has already RE-asserted Gate-1 (`assertOracleIsolation`), run the exec-gate, read the appended Gate-2 verdict,
|
|
42
|
+
* and armed the Gate-4 seam BEFORE building this struct; this function only READS those outputs.
|
|
43
|
+
*/
|
|
10
44
|
export interface AutoPromoteInputs {
|
|
45
|
+
/** Gate-1 verdict (oracle-isolation.ts:37); the caller re-asserted it before calling this function. */
|
|
11
46
|
oracle: OracleIsolationVerdict;
|
|
47
|
+
/** Gate-2 + Gate-3 lineage-bound single handle (净增③). */
|
|
12
48
|
record: PromotedRecord;
|
|
49
|
+
/** Gate-4: the irreversibility tighten is in place (or the artifact touches no irreversible tool). */
|
|
13
50
|
gate4Armed: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* §6 permanent human door (净增①): the artifact touches at least one irreversible TYPED tool. When true the
|
|
53
|
+
* decision is ALWAYS `needs_human`, even if everything else would pass — because G4 is pure in-process
|
|
54
|
+
* gate-PRESENCE (2-of-3 asymmetry) and `gate4Armed` alone ("the gate is wired") is not trustworthy for an
|
|
55
|
+
* irreversible action.
|
|
56
|
+
*/
|
|
14
57
|
touchesIrreversibleTool: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The profile's statistics RAN for this run (it produced a verdict). Core requires PRESENCE only — the
|
|
60
|
+
* statistical THRESHOLDS (train/val/test split, canary, min-samples, cost-per-truly-correct) are profile.
|
|
61
|
+
*/
|
|
15
62
|
statisticsPresent: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The KIND labels of the independent mechanical signals that concur. Core enforces `size >= 2` DISTINCT
|
|
65
|
+
* kinds (净增②) — feeding the SAME kind twice still yields size 1 (it's a Set keyed by kind). WHICH kinds
|
|
66
|
+
* count, and whether they are truly de-correlated, are profile concerns (§7 honest residual).
|
|
67
|
+
*/
|
|
16
68
|
concurringSignals: ReadonlySet<string>;
|
|
69
|
+
/** Tripwire result — ESCALATE-ONLY (§5 ③); when `escalate` it always wins and is never cleared. */
|
|
17
70
|
tripwire: TripwireResult;
|
|
18
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* The fail-closed PRESENCE AND-chain (design/79 §1 §2). Any missing/failing gate ⇒ NEVER `auto_promote`; it
|
|
74
|
+
* degrades to `needs_human` (or, for the single oracle-isolation-class shortfall, `candidate_only`). This
|
|
75
|
+
* function computes NO numeric threshold — only PRESENCE/boolean/set-size checks.
|
|
76
|
+
*
|
|
77
|
+
* **Guard order (load-bearing):**
|
|
78
|
+
* 1. `tripwire.escalate` → needs_human (tripwire always wins, never clears — §5 ③)
|
|
79
|
+
* 2. `touchesIrreversibleTool` → needs_human (§6 permanent human door — 净增①; even if all else passes)
|
|
80
|
+
* 3. `!statisticsPresent` → needs_human (statistics must have RAN — core-required; thresholds are profile)
|
|
81
|
+
* 4. `concurringSignals.size < 2` → needs_human (≥2 DISTINCT KIND mechanical signals concur — 净增②)
|
|
82
|
+
* 5. the four-gate present-passing check; if not all pass, the SOLE-shortfall arm:
|
|
83
|
+
* `in_process_probe_only` oracle (and every other gate passing) → `candidate_only`; otherwise needs_human.
|
|
84
|
+
* 6. all four gates present+passing (with guards clear) → `auto_promote` (the only auto exit).
|
|
85
|
+
*/
|
|
19
86
|
export declare function decideAutoPromote(i: AutoPromoteInputs): AutoPromoteTerminal;
|
|
87
|
+
/**
|
|
88
|
+
* The result of {@link deriveTripwire}: an ESCALATE-ONLY advisory. `escalate` can only ever be set to `true`
|
|
89
|
+
* by a scan; a clean scan contributes nothing and NEVER clears another scan's escalation. `reasons` carries
|
|
90
|
+
* the matched tokens / drifted symbols for observability.
|
|
91
|
+
*/
|
|
20
92
|
export interface TripwireResult {
|
|
21
93
|
escalate: boolean;
|
|
22
94
|
reasons: string[];
|
|
23
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The CORE-FROZEN denylist floor (design/79 §3 净增④ / P0#4): a safety invariant the profile MAY NOT remove.
|
|
98
|
+
* `deriveTripwire`'s `profileTokens` may only UNION (add) to this — never subtract — resolving the tension
|
|
99
|
+
* between "the token set can rot (new exfil primitives appear)" and "constitution-minimal". These are RAW-BYTE
|
|
100
|
+
* substrings scanned against the artifact's raw bytes INCLUDING its markdown bytes (extractSymbols skips
|
|
101
|
+
* markdown, so the byte scan is what covers prose/fenced-code that names an egress/exec primitive).
|
|
102
|
+
*/
|
|
24
103
|
export declare const FROZEN_DENYLIST_FLOOR: ReadonlySet<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Build a tripwire verdict over a promoted artifact's text. **ESCALATE-ONLY** (design/79 §3,守 design/76
|
|
106
|
+
* §5.1 r3): it can ONLY ever raise `escalate:true`; a clean artifact yields `{escalate:false, reasons:[]}` and
|
|
107
|
+
* NEVER clears anything — the REAL containment is Gate-3 runtime deny-narrowing (exhaustive at call time), not
|
|
108
|
+
* this advisory. Two mechanical scans, both escalate-only:
|
|
109
|
+
*
|
|
110
|
+
* 1. **symbol-mention drift** via {@link extractSymbols} (repo-map.ts). extractSymbols is a v1 heuristic:
|
|
111
|
+
* column-0 / source-only, it skips indented lines and is structurally INCAPABLE of being a containment
|
|
112
|
+
* proof (it can't enumerate everything the artifact can call). So it is used ONLY to ESCALATE — if a
|
|
113
|
+
* surfaced top-level symbol names a tool/capability that is NOT in `declared.allowTools`, escalate.
|
|
114
|
+
* 2. **raw-byte denylist** over the artifact's RAW bytes INCLUDING markdown bytes — {@link FROZEN_DENYLIST_FLOOR}
|
|
115
|
+
* UNIONed with `profileTokens` (add-only). A substring hit → escalate, with the matched token in `reasons`.
|
|
116
|
+
*
|
|
117
|
+
* **Fail-closed:** if EITHER scan THROWS on real content, return `{escalate:true, ...}` — a scan failure must
|
|
118
|
+
* NOT silently become "no escalation". (This is disjoint from the composition-layer "tripwire DOWN ⇒ zero
|
|
119
|
+
* contribution, never block" case, which is the caller's concern, not a throw inside the scan.)
|
|
120
|
+
*
|
|
121
|
+
* @param artifactText the artifact's raw text (markdown body included).
|
|
122
|
+
* @param declared the artifact's declared manifest — its `allowTools` is the symbol-drift baseline.
|
|
123
|
+
* @param profileTokens optional ADD-ONLY extra denylist tokens (UNIONed onto the frozen floor; cannot remove).
|
|
124
|
+
*/
|
|
25
125
|
export declare function deriveTripwire(artifactText: string, declared: SkillManifest, profileTokens?: ReadonlySet<string>): TripwireResult;
|