@gajae-code/coding-agent 0.14.2 → 0.15.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/CHANGELOG.md +120 -1
- package/dist/types/async/job-manager.d.ts +4 -1
- package/dist/types/autoresearch/dashboard.d.ts +29 -4
- package/dist/types/autoresearch/data-context.d.ts +25 -0
- package/dist/types/autoresearch/git.d.ts +65 -7
- package/dist/types/autoresearch/harness.d.ts +58 -0
- package/dist/types/autoresearch/prompts.d.ts +51 -0
- package/dist/types/autoresearch/runs.d.ts +173 -0
- package/dist/types/autoresearch/types.d.ts +9 -139
- package/dist/types/capability/types.d.ts +20 -0
- package/dist/types/cli/accounts-cli.d.ts +1 -0
- package/dist/types/commands/{rlm.d.ts → autoresearch.d.ts} +2 -4
- package/dist/types/config/autorouting-contract.d.ts +146 -0
- package/dist/types/config/autorouting-generator.d.ts +40 -0
- package/dist/types/config/autorouting-tier-map.d.ts +16844 -0
- package/dist/types/config/autorouting.d.ts +35 -0
- package/dist/types/config/model-discovery-manager.d.ts +8 -1
- package/dist/types/config/model-registry.d.ts +30 -1
- package/dist/types/config/provider-selection-policy.d.ts +23 -0
- package/dist/types/config/settings-schema.d.ts +61 -3
- package/dist/types/config/settings.d.ts +3 -0
- package/dist/types/coordinator/contract.d.ts +1 -1
- package/dist/types/coordinator-mcp/durability.d.ts +29 -0
- package/dist/types/coordinator-mcp/event-webhook.d.ts +50 -0
- package/dist/types/coordinator-mcp/question-state.d.ts +1 -1
- package/dist/types/coordinator-mcp/server.d.ts +14 -0
- package/dist/types/crash/index-store.d.ts +3 -0
- package/dist/types/crash/record-loader.d.ts +2 -0
- package/dist/types/crash/upstream/relay.d.ts +5 -3
- package/dist/types/cursor.d.ts +12 -0
- package/dist/types/defaults/gjc-defaults.d.ts +35 -1
- package/dist/types/defaults/gjc-skills.generated.d.ts +1 -1
- package/dist/types/discovery/helpers.d.ts +1 -1
- package/dist/types/edit/index.d.ts +2 -1
- package/dist/types/eval/py/executor.d.ts +2 -0
- package/dist/types/extensibility/extensions/loader.d.ts +32 -0
- package/dist/types/extensibility/gjc-plugins/types.d.ts +1 -1
- package/dist/types/extensibility/skills.d.ts +2 -0
- package/dist/types/gjc-runtime/autoresearch-runtime.d.ts +194 -0
- package/dist/types/gjc-runtime/gc-runtime.d.ts +1 -1
- package/dist/types/gjc-runtime/psmux-detect.d.ts +1 -1
- package/dist/types/gjc-runtime/python-transcript.d.ts +19 -0
- package/dist/types/gjc-runtime/ralplan-runtime.d.ts +2 -8
- package/dist/types/gjc-runtime/session-layout.d.ts +6 -3
- package/dist/types/gjc-runtime/state-renderer.d.ts +0 -22
- package/dist/types/gjc-runtime/state-schema.d.ts +7 -7
- package/dist/types/gjc-runtime/tmux-common.d.ts +2 -2
- package/dist/types/gjc-runtime/ultragoal-change-set.d.ts +38 -1
- package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +2 -24
- package/dist/types/gjc-runtime/ultragoal-validation-policy.d.ts +73 -0
- package/dist/types/gjc-runtime/workflow-recovery-projection.d.ts +100 -0
- package/dist/types/hooks/skill-keywords.d.ts +1 -1
- package/dist/types/main.d.ts +0 -10
- package/dist/types/modes/acp/acp-agent.d.ts +13 -6
- package/dist/types/modes/components/model-selector.d.ts +14 -0
- package/dist/types/modes/components/skill-hud/render.d.ts +6 -1
- package/dist/types/modes/components/smart-routing-panel.d.ts +82 -0
- package/dist/types/modes/controllers/selector-controller.d.ts +14 -0
- package/dist/types/modes/interactive-mode.d.ts +3 -0
- package/dist/types/modes/types.d.ts +9 -0
- package/dist/types/rlm/artifacts.d.ts +4 -4
- package/dist/types/runtime/optional-runtime-services.d.ts +2 -1
- package/dist/types/runtime/workspace-tree-service.d.ts +5 -1
- package/dist/types/runtime-mcp/config.d.ts +6 -0
- package/dist/types/runtime-mcp/manager.d.ts +10 -0
- package/dist/types/sdk/acp/adapter.d.ts +0 -4
- package/dist/types/sdk/broker/broker.d.ts +1 -1
- package/dist/types/sdk/broker/lifecycle.d.ts +57 -2
- package/dist/types/sdk/broker/session-index.d.ts +15 -0
- package/dist/types/sdk/bus/chat-daemon-control.d.ts +6 -0
- package/dist/types/sdk/bus/chat-daemon-runtime.d.ts +4 -0
- package/dist/types/sdk/bus/index.d.ts +8 -0
- package/dist/types/sdk/bus/kind-aware-reconciliation.d.ts +2 -0
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +12 -2
- package/dist/types/sdk/client/client.d.ts +39 -4
- package/dist/types/sdk/host/host.d.ts +1 -0
- package/dist/types/sdk/host/internal-autorouting-state.d.ts +3 -0
- package/dist/types/sdk/host/model-pin.d.ts +29 -0
- package/dist/types/sdk/host/session-runtime.d.ts +2 -1
- package/dist/types/sdk/lifecycle-session.d.ts +13 -0
- package/dist/types/sdk/router/session-router.d.ts +27 -1
- package/dist/types/sdk/session.d.ts +11 -1
- package/dist/types/session/agent-session.d.ts +36 -6
- package/dist/types/session/artifacts.d.ts +16 -1
- package/dist/types/session/internal/managed-session-storage.d.ts +7 -0
- package/dist/types/session/session-manager.d.ts +84 -2
- package/dist/types/session/session-staging-paths.d.ts +3 -0
- package/dist/types/skill-state/canonical-skills.d.ts +1 -1
- package/dist/types/skill-state/workflow-hud.d.ts +12 -21
- package/dist/types/skill-state/workflow-mutation-guard.d.ts +1 -0
- package/dist/types/slash-commands/helpers/autorouting-status.d.ts +8 -0
- package/dist/types/system-prompt.d.ts +23 -0
- package/dist/types/task/executor.d.ts +35 -4
- package/dist/types/task/index.d.ts +17 -3
- package/dist/types/task/receipt.d.ts +3 -1
- package/dist/types/task/types.d.ts +144 -0
- package/dist/types/tools/atomic-file-write.d.ts +72 -0
- package/dist/types/tools/descriptors.d.ts +1 -0
- package/dist/types/tools/index.d.ts +36 -1
- package/dist/types/tools/move-session.d.ts +40 -0
- package/dist/types/tools/python.d.ts +12 -0
- package/dist/types/tools/resource-gc.d.ts +0 -3
- package/dist/types/tools/search.d.ts +8 -1
- package/dist/types/tools/skill.d.ts +9 -4
- package/dist/types/tools/subagent.d.ts +33 -3
- package/dist/types/utils/xml-escape.d.ts +2 -0
- package/dist/types/workflow/workflow-intent-diff.d.ts +2 -2
- package/dist/types/workflow/workflow-intent-report-consumer.d.ts +1 -1
- package/package.json +11 -12
- package/scripts/build-sdk-package-smoke.ts +7 -5
- package/scripts/check-autorouting-tier-map.ts +183 -0
- package/scripts/generate-sdk-operation-inventory.ts +12 -0
- package/scripts/generate-tool-catalog.ts +40 -5
- package/src/async/job-manager.ts +5 -2
- package/src/autoresearch/dashboard.ts +134 -314
- package/src/autoresearch/data-context.ts +35 -0
- package/src/autoresearch/git.ts +186 -26
- package/src/autoresearch/{helpers.ts → harness.ts} +65 -40
- package/src/autoresearch/{prompt-setup.md → prompts/prompt-setup.md} +7 -7
- package/src/autoresearch/prompts/prompt.md +103 -0
- package/src/autoresearch/prompts.ts +126 -0
- package/src/autoresearch/runs.ts +708 -0
- package/src/autoresearch/types.ts +9 -150
- package/src/capability/index.ts +4 -4
- package/src/capability/types.ts +20 -0
- package/src/cli/accounts-cli.ts +21 -5
- package/src/cli/config-cli.ts +25 -1
- package/src/cli/fast-help.ts +1 -2
- package/src/cli/list-models.ts +5 -8
- package/src/cli/setup-cli.ts +8 -0
- package/src/cli.ts +2 -21
- package/src/commands/autoresearch.ts +33 -0
- package/src/commands/coordinator.ts +15 -0
- package/src/commands/launch.ts +2 -4
- package/src/commands/quick-lane.ts +1 -1
- package/src/commands/sdk.ts +24 -0
- package/src/commands/state.ts +1 -1
- package/src/config/autorouting-contract.ts +474 -0
- package/src/config/autorouting-generator.ts +238 -0
- package/src/config/autorouting-tier-map.ts +6108 -0
- package/src/config/autorouting.ts +120 -0
- package/src/config/model-discovery-manager.ts +42 -11
- package/src/config/model-registry.ts +348 -68
- package/src/config/provider-selection-policy.ts +60 -9
- package/src/config/settings-schema.ts +195 -6
- package/src/config/settings.ts +62 -1
- package/src/config.ts +2 -3
- package/src/coordinator/contract.ts +0 -1
- package/src/coordinator-mcp/codex-handoff.ts +68 -42
- package/src/coordinator-mcp/durability.ts +200 -0
- package/src/coordinator-mcp/event-webhook.ts +278 -0
- package/src/coordinator-mcp/question-state.ts +109 -46
- package/src/coordinator-mcp/server.ts +932 -504
- package/src/crash/index-store.ts +126 -22
- package/src/crash/record-loader.ts +7 -0
- package/src/crash/upstream/relay.ts +82 -34
- package/src/cursor.ts +84 -1
- package/src/debug/index.ts +26 -0
- package/src/defaults/gjc/skills/autoresearch/SKILL.md +116 -0
- package/src/defaults/gjc/skills/autoresearch/auto-critic.md +46 -0
- package/src/defaults/gjc/skills/autoresearch/auto-iterate.md +42 -0
- package/src/defaults/gjc/skills/deep-interview/SKILL.md +17 -37
- package/src/defaults/gjc/skills/ralplan/SKILL.md +21 -18
- package/src/defaults/gjc/skills/ultragoal/SKILL.md +6 -17
- package/src/defaults/gjc/skills/ultragoal/ai-slop-cleaner.md +2 -2
- package/src/defaults/gjc-defaults.ts +89 -2
- package/src/defaults/gjc-skills.generated.ts +24 -17
- package/src/discovery/builtin.ts +18 -5
- package/src/discovery/helpers.ts +6 -6
- package/src/edit/index.ts +5 -2
- package/src/eval/py/executor.ts +8 -0
- package/src/extensibility/extensions/loader.ts +135 -13
- package/src/extensibility/extensions/wrapper.ts +1 -2
- package/src/extensibility/gjc-plugins/schema.ts +1 -1
- package/src/extensibility/runtime-skill-discovery.ts +2 -2
- package/src/extensibility/skill-management.ts +2 -3
- package/src/extensibility/skills.ts +16 -8
- package/src/gjc-runtime/autoresearch-runtime.ts +1509 -0
- package/src/gjc-runtime/gc-render.ts +0 -1
- package/src/gjc-runtime/gc-runtime.ts +1 -11
- package/src/gjc-runtime/launch-tmux.ts +3 -3
- package/src/gjc-runtime/psmux-detect.ts +2 -2
- package/src/gjc-runtime/python-transcript.ts +58 -0
- package/src/gjc-runtime/ralplan-runtime.ts +6 -18
- package/src/gjc-runtime/session-layout.ts +18 -7
- package/src/gjc-runtime/session-state-sidecar.ts +58 -9
- package/src/gjc-runtime/state-renderer.ts +0 -38
- package/src/gjc-runtime/state-runtime.ts +43 -22
- package/src/gjc-runtime/state-schema.ts +1 -1
- package/src/gjc-runtime/tmux-common.ts +7 -7
- package/src/gjc-runtime/ultragoal-change-set.ts +232 -11
- package/src/gjc-runtime/ultragoal-runtime.ts +309 -114
- package/src/gjc-runtime/ultragoal-validation-policy.ts +247 -0
- package/src/gjc-runtime/workflow-command-ref.ts +15 -11
- package/src/gjc-runtime/workflow-manifest.generated.json +413 -532
- package/src/gjc-runtime/workflow-manifest.ts +43 -83
- package/src/gjc-runtime/workflow-recovery-projection.ts +616 -0
- package/src/hooks/skill-keywords.ts +3 -3
- package/src/hooks/skill-state.ts +2 -2
- package/src/internal-urls/docs-index.generated.ts +26 -24
- package/src/lsp/index.ts +25 -5
- package/src/main.ts +2 -27
- package/src/modes/acp/acp-agent.ts +200 -75
- package/src/modes/components/model-selector.ts +216 -13
- package/src/modes/components/oauth-selector.ts +5 -5
- package/src/modes/components/skill-hud/render.ts +173 -35
- package/src/modes/components/smart-routing-panel.ts +531 -0
- package/src/modes/components/tool-status-header.ts +6 -3
- package/src/modes/controllers/command-controller.ts +17 -7
- package/src/modes/controllers/input-controller.ts +44 -9
- package/src/modes/controllers/runtime-mcp-command-controller.ts +4 -0
- package/src/modes/controllers/selector-controller.ts +298 -65
- package/src/modes/interactive-mode.ts +8 -1
- package/src/modes/shared/agent-wire/workflow-gate-types.ts +1 -1
- package/src/modes/types.ts +9 -1
- package/src/prompts/agents/planner.md +1 -1
- package/src/prompts/system/system-prompt.md +1 -1
- package/src/prompts/system/volatile-project-context.md +2 -1
- package/src/prompts/tools/move-session.md +15 -0
- package/src/prompts/tools/python.md +12 -0
- package/src/prompts/tools/skill-discovery.md +1 -1
- package/src/prompts/tools/skill.md +2 -2
- package/src/prompts/tools/task-summary.md +1 -0
- package/src/prompts/tools/task.md +6 -0
- package/src/rlm/artifacts.ts +12 -10
- package/src/runtime/optional-runtime-services.ts +3 -2
- package/src/runtime/workspace-tree-service.ts +11 -3
- package/src/runtime-mcp/config.ts +8 -1
- package/src/runtime-mcp/manager.ts +33 -0
- package/src/sdk/acp/adapter.ts +48 -1
- package/src/sdk/broker/broker.ts +30 -2
- package/src/sdk/broker/discovery.ts +217 -2
- package/src/sdk/broker/lifecycle.ts +385 -59
- package/src/sdk/broker/session-index.ts +243 -48
- package/src/sdk/broker/transport.ts +1 -0
- package/src/sdk/bus/chat-daemon-control.ts +8 -2
- package/src/sdk/bus/chat-daemon-runtime.ts +5 -0
- package/src/sdk/bus/index.ts +208 -11
- package/src/sdk/bus/kind-aware-reconciliation.ts +16 -0
- package/src/sdk/bus/reconciliation-store.ts +27 -5
- package/src/sdk/bus/telegram-daemon-contract.ts +12 -2
- package/src/sdk/client/client.ts +204 -22
- package/src/sdk/host/host.ts +16 -0
- package/src/sdk/host/internal-autorouting-state.ts +13 -0
- package/src/sdk/host/model-pin.ts +101 -0
- package/src/sdk/host/reverse-leases.ts +2 -1
- package/src/sdk/host/session-runtime.test.ts +224 -1
- package/src/sdk/host/session-runtime.ts +125 -37
- package/src/sdk/lifecycle/service.ts +3 -1
- package/src/sdk/lifecycle-session.ts +42 -1
- package/src/sdk/protocol/operation-inventory.generated.json +66 -0
- package/src/sdk/router/session-router.ts +375 -36
- package/src/sdk/session.ts +547 -47
- package/src/session/account-inventory.ts +1 -1
- package/src/session/agent-session.ts +765 -189
- package/src/session/artifacts.ts +234 -4
- package/src/session/internal/managed-session-storage.ts +91 -4
- package/src/session/provider-safety-stop-hint.ts +3 -2
- package/src/session/session-manager.ts +775 -16
- package/src/session/session-staging-paths.ts +8 -0
- package/src/setup/hermes/templates/operator-instructions.v1.md +0 -1
- package/src/setup/host-plugin-setup.ts +2 -2
- package/src/skill-state/active-state.ts +2 -2
- package/src/skill-state/canonical-skills.ts +1 -1
- package/src/skill-state/initial-phase.ts +1 -1
- package/src/skill-state/workflow-hud.ts +41 -41
- package/src/skill-state/workflow-mutation-guard.ts +26 -7
- package/src/slash-commands/builtin-registry.ts +77 -0
- package/src/slash-commands/helpers/autorouting-status.ts +55 -0
- package/src/system-prompt.ts +102 -5
- package/src/task/discovery.ts +2 -3
- package/src/task/executor.ts +617 -43
- package/src/task/index.ts +262 -15
- package/src/task/receipt.ts +30 -0
- package/src/task/render.ts +11 -1
- package/src/task/types.ts +316 -0
- package/src/tools/atomic-file-write.ts +594 -0
- package/src/tools/bisect.ts +3 -2
- package/src/tools/descriptors.test.ts +3 -0
- package/src/tools/descriptors.ts +24 -0
- package/src/tools/image-gen.ts +5 -1
- package/src/tools/index.ts +62 -5
- package/src/tools/move-session.ts +107 -0
- package/src/tools/python.ts +205 -0
- package/src/tools/read.ts +88 -15
- package/src/tools/renderers.ts +2 -0
- package/src/tools/resource-gc.ts +8 -177
- package/src/tools/search.ts +30 -6
- package/src/tools/skill-discovery.ts +1 -0
- package/src/tools/skill.ts +37 -7
- package/src/tools/subagent-render.ts +119 -13
- package/src/tools/subagent.ts +91 -74
- package/src/tools/tool-catalog.generated.ts +64 -2
- package/src/tools/write.ts +16 -12
- package/src/utils/xml-escape.ts +14 -0
- package/src/web/search/providers/codex.ts +2 -2
- package/src/workflow/workflow-intent-diff.ts +13 -12
- package/src/workflow/workflow-intent-report-consumer.ts +6 -6
- package/dist/types/autoresearch/helpers.d.ts +0 -24
- package/dist/types/autoresearch/index.d.ts +0 -2
- package/dist/types/autoresearch/state.d.ts +0 -17
- package/dist/types/autoresearch/storage.d.ts +0 -142
- package/dist/types/autoresearch/tools/init-experiment.d.ts +0 -31
- package/dist/types/autoresearch/tools/log-experiment.d.ts +0 -23
- package/dist/types/autoresearch/tools/run-experiment.d.ts +0 -8
- package/dist/types/autoresearch/tools/update-notes.d.ts +0 -12
- package/dist/types/commands/team.d.ts +0 -24
- package/dist/types/gjc-runtime/team-gc.d.ts +0 -7
- package/dist/types/gjc-runtime/team-launch.d.ts +0 -61
- package/dist/types/gjc-runtime/team-notify.d.ts +0 -45
- package/dist/types/gjc-runtime/team-runtime.d.ts +0 -336
- package/dist/types/gjc-runtime/team-store.d.ts +0 -168
- package/dist/types/gjc-runtime/team-worker-heartbeat.d.ts +0 -43
- package/dist/types/gjc-runtime/team-worker-memory-guard.d.ts +0 -92
- package/dist/types/gjc-runtime/team-workers.d.ts +0 -83
- package/dist/types/rlm/index.d.ts +0 -47
- package/dist/types/rlm/preset.d.ts +0 -23
- package/dist/types/rlm/python-tool.d.ts +0 -16
- package/src/autoresearch/command-resume.md +0 -14
- package/src/autoresearch/index.ts +0 -536
- package/src/autoresearch/prompt.md +0 -103
- package/src/autoresearch/resume-message.md +0 -10
- package/src/autoresearch/state.ts +0 -273
- package/src/autoresearch/storage.ts +0 -699
- package/src/autoresearch/tools/init-experiment.ts +0 -272
- package/src/autoresearch/tools/log-experiment.ts +0 -524
- package/src/autoresearch/tools/run-experiment.ts +0 -475
- package/src/autoresearch/tools/update-notes.ts +0 -109
- package/src/commands/rlm.ts +0 -19
- package/src/commands/team.ts +0 -238
- package/src/defaults/gjc/skills/deep-interview/auto-research-greenfield.md +0 -42
- package/src/defaults/gjc/skills/team/SKILL.md +0 -467
- package/src/gjc-runtime/team-gc.ts +0 -49
- package/src/gjc-runtime/team-launch.ts +0 -404
- package/src/gjc-runtime/team-notify.ts +0 -326
- package/src/gjc-runtime/team-runtime.ts +0 -5923
- package/src/gjc-runtime/team-store.ts +0 -878
- package/src/gjc-runtime/team-worker-heartbeat.ts +0 -149
- package/src/gjc-runtime/team-worker-memory-guard.ts +0 -363
- package/src/gjc-runtime/team-workers.ts +0 -1123
- package/src/prompts/system/rlm-report-command.md +0 -1
- package/src/prompts/system/rlm-research.md +0 -23
- package/src/rlm/index.ts +0 -365
- package/src/rlm/preset.ts +0 -76
- package/src/rlm/python-tool.ts +0 -68
package/src/task/types.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { ThinkingLevel } from "@gajae-code/agent-core";
|
|
2
2
|
import type { Usage } from "@gajae-code/ai/core";
|
|
3
|
+
import type { FallbackTriggerClass } from "@gajae-code/ai/utils/fallback-transport";
|
|
3
4
|
import { $env } from "@gajae-code/utils";
|
|
4
5
|
import * as z from "zod/v4";
|
|
6
|
+
import { AUTOROUTING_SELECTOR_MAX_LENGTH, type AutoroutingReasonCode } from "../config/autorouting-contract";
|
|
5
7
|
import { isValidTaskId, TASK_ID_DESCRIPTION } from "./id";
|
|
6
8
|
import type { TaskResultReceipt } from "./receipt";
|
|
7
9
|
import type { SpawnRoiReconciliation } from "./roi-reconciliation";
|
|
@@ -97,6 +99,10 @@ const createTaskItemSchema = (_contextEnabled: boolean) =>
|
|
|
97
99
|
id: z.string().max(48).refine(isValidTaskId, TASK_ID_DESCRIPTION).describe("filesystem-safe task identifier"),
|
|
98
100
|
description: z.string().describe("ui label, not seen by subagent"),
|
|
99
101
|
assignment: z.string().describe(assignmentDescription),
|
|
102
|
+
tier: z
|
|
103
|
+
.enum(["fast", "balanced", "strong"])
|
|
104
|
+
.optional()
|
|
105
|
+
.describe("Advisory unless autorouting is enabled; omitted routes as balanced."),
|
|
100
106
|
executionMode: z
|
|
101
107
|
.enum(["default", "ultragoal-red-team"])
|
|
102
108
|
.optional()
|
|
@@ -427,6 +433,154 @@ export function createSetupFailureSummary(error: unknown): SetupFailureSummary {
|
|
|
427
433
|
};
|
|
428
434
|
}
|
|
429
435
|
|
|
436
|
+
/** Bounded, redaction-safe summary of a terminal local (non-provider) subagent failure. */
|
|
437
|
+
export interface LocalErrorSummary {
|
|
438
|
+
kind: string;
|
|
439
|
+
summary: string;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Closed stage vocabulary accepted at the executor trust boundary. Mirrors the
|
|
444
|
+
* agent runtime's `MANAGED_LOCAL_FAILURE_STAGES` overflow entries; a shape
|
|
445
|
+
* naming any other stage is rejected as untrusted (#4618).
|
|
446
|
+
*/
|
|
447
|
+
const LOCAL_OVERFLOW_STAGES: ReadonlySet<string> = new Set(["overflow.preMeasure", "overflow.staged"]);
|
|
448
|
+
|
|
449
|
+
const isLocalOverflowCounter = (value: unknown): value is number =>
|
|
450
|
+
typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Runtime-validate a structured overflow diagnostic at the consuming trust
|
|
454
|
+
* boundary. Presence on an `AssistantMessage` is NOT authenticity: a foreign
|
|
455
|
+
* provider/stream payload could set the field, so every value is checked —
|
|
456
|
+
* closed `stage`/`exceeded` literals and finite non-negative integer counters.
|
|
457
|
+
* Returns `undefined` for anything that fails, and the caller then degrades to
|
|
458
|
+
* a fixed neutral sentence instead of interpolating untrusted values (#4618).
|
|
459
|
+
*/
|
|
460
|
+
export function validateLocalOverflowShape(overflow: unknown):
|
|
461
|
+
| {
|
|
462
|
+
stage: string;
|
|
463
|
+
exceeded: "events" | "bytes" | "both";
|
|
464
|
+
stagedEventCount: number;
|
|
465
|
+
stagedBytes: number;
|
|
466
|
+
incomingEventBytes: number;
|
|
467
|
+
maxStagedEvents: number;
|
|
468
|
+
maxStagedBytes: number;
|
|
469
|
+
}
|
|
470
|
+
| undefined {
|
|
471
|
+
if (!overflow || typeof overflow !== "object") return undefined;
|
|
472
|
+
const shape = overflow as Record<string, unknown>;
|
|
473
|
+
if (typeof shape.stage !== "string" || !LOCAL_OVERFLOW_STAGES.has(shape.stage)) return undefined;
|
|
474
|
+
if (shape.exceeded !== "events" && shape.exceeded !== "bytes" && shape.exceeded !== "both") return undefined;
|
|
475
|
+
const stagedEventCount = shape.stagedEventCount;
|
|
476
|
+
const stagedBytes = shape.stagedBytes;
|
|
477
|
+
const incomingEventBytes = shape.incomingEventBytes;
|
|
478
|
+
const maxStagedEvents = shape.maxStagedEvents;
|
|
479
|
+
const maxStagedBytes = shape.maxStagedBytes;
|
|
480
|
+
if (
|
|
481
|
+
!isLocalOverflowCounter(stagedEventCount) ||
|
|
482
|
+
!isLocalOverflowCounter(stagedBytes) ||
|
|
483
|
+
!isLocalOverflowCounter(incomingEventBytes) ||
|
|
484
|
+
!isLocalOverflowCounter(maxStagedEvents) ||
|
|
485
|
+
!isLocalOverflowCounter(maxStagedBytes)
|
|
486
|
+
) {
|
|
487
|
+
return undefined;
|
|
488
|
+
}
|
|
489
|
+
// The shape must be internally consistent with the cap it claims tripped,
|
|
490
|
+
// so a fabricated near-miss cannot masquerade as a real rejection.
|
|
491
|
+
const projectedEvents = stagedEventCount + 1;
|
|
492
|
+
const projectedBytes = stagedBytes + incomingEventBytes;
|
|
493
|
+
if (shape.exceeded === "events" || shape.exceeded === "both") {
|
|
494
|
+
if (projectedEvents <= maxStagedEvents) return undefined;
|
|
495
|
+
}
|
|
496
|
+
if (shape.exceeded === "bytes" || shape.exceeded === "both") {
|
|
497
|
+
if (projectedBytes <= maxStagedBytes) return undefined;
|
|
498
|
+
}
|
|
499
|
+
return {
|
|
500
|
+
stage: shape.stage,
|
|
501
|
+
exceeded: shape.exceeded,
|
|
502
|
+
stagedEventCount,
|
|
503
|
+
stagedBytes,
|
|
504
|
+
incomingEventBytes,
|
|
505
|
+
maxStagedEvents,
|
|
506
|
+
maxStagedBytes,
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Render the parent-facing summary of a validated overflow diagnostic. Built
|
|
512
|
+
* ONLY from the closed-vocabulary stage/exceeded literals and the numeric
|
|
513
|
+
* counters — no producer-controlled text participates, so a hostile or buggy
|
|
514
|
+
* child can inject nothing through this path (#4618).
|
|
515
|
+
*/
|
|
516
|
+
export function formatBufferOverflowSummary(overflow: {
|
|
517
|
+
stage: string;
|
|
518
|
+
exceeded: "events" | "bytes" | "both";
|
|
519
|
+
stagedEventCount: number;
|
|
520
|
+
stagedBytes: number;
|
|
521
|
+
incomingEventBytes: number;
|
|
522
|
+
maxStagedEvents: number;
|
|
523
|
+
maxStagedBytes: number;
|
|
524
|
+
}): string {
|
|
525
|
+
return (
|
|
526
|
+
`staging-buffer overflow at ${overflow.stage} (exceeded=${overflow.exceeded}); ` +
|
|
527
|
+
`retained ${overflow.stagedEventCount}/${overflow.maxStagedEvents} events, ` +
|
|
528
|
+
`${overflow.stagedBytes} staged bytes; rejected event ${overflow.incomingEventBytes} bytes; ` +
|
|
529
|
+
`projected ${overflow.stagedBytes + overflow.incomingEventBytes}/${overflow.maxStagedBytes} bytes. ` +
|
|
530
|
+
"Local gjc staging limit, not a provider or context-window failure; re-issuing reproduces it."
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Fixed, bounded summary for a terminal snapshot failure — never free-form child text (#4618). */
|
|
535
|
+
const LOCAL_SNAPSHOT_FAILURE_SUMMARY =
|
|
536
|
+
"Managed fallback could not produce a serializable event snapshot (local snapshot bug, not a provider failure).";
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Build the safe parent-facing summary for a terminal local failure.
|
|
540
|
+
*
|
|
541
|
+
* Trust boundary: the structured `bufferOverflow` shape is runtime-validated
|
|
542
|
+
* (`validateLocalOverflowShape`) before any value is interpolated — closed
|
|
543
|
+
* literals and checked integers only. A shape that fails validation, or an
|
|
544
|
+
* overflow kind with no shape at all, degrades to a fixed neutral sentence.
|
|
545
|
+
* `local_snapshot_failure` uses a fixed sentence too: regex redaction cannot
|
|
546
|
+
* make arbitrary child message text safe to embed in a parent receipt.
|
|
547
|
+
*/
|
|
548
|
+
export function createLocalErrorSummary(
|
|
549
|
+
kind: unknown,
|
|
550
|
+
_message: string | undefined,
|
|
551
|
+
overflow?: unknown,
|
|
552
|
+
): LocalErrorSummary {
|
|
553
|
+
const normalizedKind = kind === "local_buffer_overflow" || kind === "local_snapshot_failure" ? kind : "local";
|
|
554
|
+
if (normalizedKind === "local_buffer_overflow") {
|
|
555
|
+
const validated = validateLocalOverflowShape(overflow);
|
|
556
|
+
return {
|
|
557
|
+
kind: normalizedKind,
|
|
558
|
+
summary: validated
|
|
559
|
+
? formatBufferOverflowSummary(validated)
|
|
560
|
+
: "Local staging-buffer overflow; structured diagnostic unavailable.",
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
if (normalizedKind === "local_snapshot_failure") {
|
|
564
|
+
return {
|
|
565
|
+
kind: normalizedKind,
|
|
566
|
+
// Fixed text: a self-labeled foreign error can set the kind, and no
|
|
567
|
+
// free-form message — redacted or not — is forwarded to the parent.
|
|
568
|
+
summary: LOCAL_SNAPSHOT_FAILURE_SUMMARY,
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
return {
|
|
572
|
+
kind: normalizedKind,
|
|
573
|
+
summary: "Subagent failed with a local error.",
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const ASSISTANT_LOCAL_ERROR_KINDS: ReadonlySet<string> = new Set(["local_buffer_overflow", "local_snapshot_failure"]);
|
|
578
|
+
|
|
579
|
+
/** Whether an assistant terminal message carries a known local (non-provider) failure kind. */
|
|
580
|
+
export function isAssistantLocalErrorKind(kind: unknown): kind is "local_buffer_overflow" | "local_snapshot_failure" {
|
|
581
|
+
return typeof kind === "string" && ASSISTANT_LOCAL_ERROR_KINDS.has(kind);
|
|
582
|
+
}
|
|
583
|
+
|
|
430
584
|
export interface TaskRecoveryArtifactRef {
|
|
431
585
|
uri: string;
|
|
432
586
|
sizeBytes: number;
|
|
@@ -447,6 +601,159 @@ export interface TaskPersistenceResult {
|
|
|
447
601
|
recoveryRef?: TaskRecoveryArtifactRef;
|
|
448
602
|
}
|
|
449
603
|
|
|
604
|
+
export type RoutingSubstitution = "auth_substituted" | "assistant_model_mismatch";
|
|
605
|
+
|
|
606
|
+
/** A typed failure observed while an autorouting candidate is still before the real provider fence. */
|
|
607
|
+
export type AutoroutingPreflightFailure =
|
|
608
|
+
| {
|
|
609
|
+
kind: "local";
|
|
610
|
+
op: "auth_resolve" | "session_open" | "tool_bootstrap" | "preflight_validation";
|
|
611
|
+
transient: boolean;
|
|
612
|
+
}
|
|
613
|
+
| { kind: "transport"; class: FallbackTriggerClass };
|
|
614
|
+
|
|
615
|
+
export type AutoroutingAttemptCode =
|
|
616
|
+
| "probe_passed"
|
|
617
|
+
| "accepted"
|
|
618
|
+
| "spawn_transient_retry"
|
|
619
|
+
| "credential_unavailable"
|
|
620
|
+
| "config_invalid_terminal"
|
|
621
|
+
| "post_acceptance_failure"
|
|
622
|
+
| "unclassified_terminal";
|
|
623
|
+
|
|
624
|
+
export type AutoroutingAttempt = {
|
|
625
|
+
selector: string;
|
|
626
|
+
phase: "probe" | "durable";
|
|
627
|
+
code: AutoroutingAttemptCode;
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
export type AutoroutingSkip = {
|
|
631
|
+
selector: string;
|
|
632
|
+
code: AutoroutingReasonCode;
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
export interface TaskRoutingEvidence {
|
|
636
|
+
tier: "fast" | "balanced" | "strong";
|
|
637
|
+
requestedTier?: "fast" | "balanced" | "strong";
|
|
638
|
+
defaultTierApplied?: true;
|
|
639
|
+
requestedSelector: string;
|
|
640
|
+
authResolvedModel?: string;
|
|
641
|
+
effectiveModel?: string;
|
|
642
|
+
notExecuted?: true;
|
|
643
|
+
substitutions: RoutingSubstitution[];
|
|
644
|
+
manualFallbackReason?: "tier_unmatched" | "tier_missing_in_map";
|
|
645
|
+
freshOnResume?: true;
|
|
646
|
+
note?: string;
|
|
647
|
+
skips?: AutoroutingSkip[];
|
|
648
|
+
omittedSkipCount?: number;
|
|
649
|
+
omittedByCode?: Partial<Record<AutoroutingSkip["code"], number>>;
|
|
650
|
+
attempts?: AutoroutingAttempt[];
|
|
651
|
+
terminal?: "preflight_exhausted" | "all_candidates_skipped";
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const AUTOROUTING_ATTEMPT_CODES = new Set<AutoroutingAttemptCode>([
|
|
655
|
+
"probe_passed",
|
|
656
|
+
"accepted",
|
|
657
|
+
"spawn_transient_retry",
|
|
658
|
+
"credential_unavailable",
|
|
659
|
+
"config_invalid_terminal",
|
|
660
|
+
"post_acceptance_failure",
|
|
661
|
+
"unclassified_terminal",
|
|
662
|
+
]);
|
|
663
|
+
|
|
664
|
+
const ROUTING_UNSAFE_TEXT_RE = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u;
|
|
665
|
+
|
|
666
|
+
function validBoundedSelector(value: unknown): value is string {
|
|
667
|
+
return (
|
|
668
|
+
typeof value === "string" &&
|
|
669
|
+
value.length > 0 &&
|
|
670
|
+
value.length <= AUTOROUTING_SELECTOR_MAX_LENGTH &&
|
|
671
|
+
!ROUTING_UNSAFE_TEXT_RE.test(value)
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export function assertRoutingEvidenceInvariant(evidence: TaskRoutingEvidence): void {
|
|
676
|
+
const terminalWithoutModel = evidence.terminal !== undefined || evidence.notExecuted === true;
|
|
677
|
+
if (
|
|
678
|
+
!terminalWithoutModel &&
|
|
679
|
+
(!evidence.effectiveModel || evidence.effectiveModel.length > AUTOROUTING_SELECTOR_MAX_LENGTH)
|
|
680
|
+
)
|
|
681
|
+
throw new Error("Invalid effective routing model.");
|
|
682
|
+
if (!validBoundedSelector(evidence.requestedSelector)) throw new Error("Invalid requested routing selector.");
|
|
683
|
+
if (evidence.authResolvedModel && evidence.authResolvedModel === evidence.effectiveModel)
|
|
684
|
+
throw new Error("authResolvedModel must differ from effectiveModel when present.");
|
|
685
|
+
if (evidence.authResolvedModel !== undefined && !validBoundedSelector(evidence.authResolvedModel))
|
|
686
|
+
throw new Error("Invalid auth-resolved routing model.");
|
|
687
|
+
|
|
688
|
+
if (evidence.skips && evidence.skips.length > 16) throw new Error("Too many autorouting skips.");
|
|
689
|
+
if (evidence.attempts && evidence.attempts.length > 6) throw new Error("Too many autorouting attempts.");
|
|
690
|
+
if (
|
|
691
|
+
evidence.omittedSkipCount !== undefined &&
|
|
692
|
+
(!Number.isSafeInteger(evidence.omittedSkipCount) || evidence.omittedSkipCount < 0)
|
|
693
|
+
)
|
|
694
|
+
throw new Error("Invalid omitted autorouting skip count.");
|
|
695
|
+
for (const [code, count] of Object.entries(evidence.omittedByCode ?? {})) {
|
|
696
|
+
if (!Number.isSafeInteger(count) || count < 0) throw new Error("Invalid omitted autorouting skip aggregate.");
|
|
697
|
+
if (
|
|
698
|
+
!(
|
|
699
|
+
code in
|
|
700
|
+
{
|
|
701
|
+
tier_unmatched: true,
|
|
702
|
+
tier_missing_in_map: true,
|
|
703
|
+
config_invalid: true,
|
|
704
|
+
map_absent: true,
|
|
705
|
+
selector_not_provider_qualified: true,
|
|
706
|
+
auth_substituted: true,
|
|
707
|
+
assistant_model_mismatch: true,
|
|
708
|
+
provider_disabled: true,
|
|
709
|
+
snapshot_missing: true,
|
|
710
|
+
credential_unavailable: true,
|
|
711
|
+
preflight_spawn_failed: true,
|
|
712
|
+
preflight_exhausted: true,
|
|
713
|
+
}
|
|
714
|
+
)
|
|
715
|
+
)
|
|
716
|
+
throw new Error("Invalid omitted autorouting skip code.");
|
|
717
|
+
}
|
|
718
|
+
for (const skip of evidence.skips ?? []) {
|
|
719
|
+
if (!validBoundedSelector(skip.selector)) throw new Error("Invalid autorouting skip selector.");
|
|
720
|
+
if (
|
|
721
|
+
!(
|
|
722
|
+
skip.code in
|
|
723
|
+
{
|
|
724
|
+
tier_unmatched: true,
|
|
725
|
+
tier_missing_in_map: true,
|
|
726
|
+
config_invalid: true,
|
|
727
|
+
map_absent: true,
|
|
728
|
+
selector_not_provider_qualified: true,
|
|
729
|
+
auth_substituted: true,
|
|
730
|
+
assistant_model_mismatch: true,
|
|
731
|
+
provider_disabled: true,
|
|
732
|
+
snapshot_missing: true,
|
|
733
|
+
credential_unavailable: true,
|
|
734
|
+
preflight_spawn_failed: true,
|
|
735
|
+
preflight_exhausted: true,
|
|
736
|
+
}
|
|
737
|
+
)
|
|
738
|
+
)
|
|
739
|
+
throw new Error("Invalid autorouting skip code.");
|
|
740
|
+
}
|
|
741
|
+
for (const attempt of evidence.attempts ?? []) {
|
|
742
|
+
if (!validBoundedSelector(attempt.selector) || !AUTOROUTING_ATTEMPT_CODES.has(attempt.code))
|
|
743
|
+
throw new Error("Invalid autorouting attempt.");
|
|
744
|
+
if (attempt.code === "accepted" && attempt.phase !== "durable")
|
|
745
|
+
throw new Error("accepted requires durable phase.");
|
|
746
|
+
if (attempt.code === "probe_passed" && attempt.phase !== "probe")
|
|
747
|
+
throw new Error("probe_passed requires probe phase.");
|
|
748
|
+
if (attempt.phase === "probe" && attempt.code === "post_acceptance_failure")
|
|
749
|
+
throw new Error("post_acceptance_failure requires durable phase.");
|
|
750
|
+
if (attempt.phase === "durable" && attempt.code === "probe_passed")
|
|
751
|
+
throw new Error("probe_passed requires probe phase.");
|
|
752
|
+
}
|
|
753
|
+
if (evidence.terminal === undefined && evidence.omittedSkipCount && !evidence.skips)
|
|
754
|
+
throw new Error("Omitted skips require skip evidence.");
|
|
755
|
+
}
|
|
756
|
+
|
|
450
757
|
/** Result from a single agent execution */
|
|
451
758
|
export interface SingleResult {
|
|
452
759
|
index: number;
|
|
@@ -468,13 +775,22 @@ export interface SingleResult {
|
|
|
468
775
|
contextTokens?: number;
|
|
469
776
|
/** Model's context window in tokens, when known. */
|
|
470
777
|
contextWindow?: number;
|
|
778
|
+
routing?: TaskRoutingEvidence;
|
|
779
|
+
|
|
471
780
|
modelOverride?: string | string[];
|
|
472
781
|
modelSubstitutionWarning?: ModelSubstitutionWarning;
|
|
473
782
|
/** Whether the resolved subagent model ran under the effective fast service tier. */
|
|
474
783
|
fastMode?: boolean;
|
|
475
784
|
error?: string;
|
|
785
|
+
/** Safe summary of a terminal local (non-provider) failure kind, e.g. `local_buffer_overflow`. */
|
|
786
|
+
localErrorSummary?: LocalErrorSummary;
|
|
476
787
|
/** Safe diagnostic for a failure before the subagent sent its first LLM request. */
|
|
477
788
|
setupFailure?: SetupFailureSummary;
|
|
789
|
+
/** Internal typed autorouting preflight outcome; receipt sanitization omits this field. */
|
|
790
|
+
preflightFailure?: AutoroutingPreflightFailure;
|
|
791
|
+
preflightFenceCrossed?: boolean;
|
|
792
|
+
preflightProbeAccepted?: boolean;
|
|
793
|
+
preflightCommitFailure?: boolean;
|
|
478
794
|
aborted?: boolean;
|
|
479
795
|
abortReason?: string;
|
|
480
796
|
|