@fitlab-ai/agent-infra 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/README.zh-CN.md +0 -2
- package/dist/bin/internal-cli.js +2 -17
- package/dist/lib/agent-clients/adapter.js +0 -13
- package/dist/lib/agent-clients/adapters/antigravity-cli.js +0 -5
- package/dist/lib/agent-clients/adapters/claude-code-credentials.js +0 -17
- package/dist/lib/agent-clients/adapters/claude-code.js +0 -9
- package/dist/lib/agent-clients/adapters/codex.js +0 -52
- package/dist/lib/agent-clients/adapters/opencode.js +0 -5
- package/dist/lib/agent-clients/adapters/traecli.js +0 -5
- package/dist/lib/agent-clients/config.js +19 -54
- package/dist/lib/agent-clients/registry.js +1 -12
- package/dist/lib/agent-clients/schema.js +0 -18
- package/dist/lib/agent-clients/tokens.js +1 -2
- package/dist/lib/agent-clients/types.js +0 -1
- package/dist/lib/decide.js +2 -0
- package/dist/lib/git/worktree-identity.js +1 -9
- package/dist/lib/internal/agent-client.js +2 -62
- package/dist/lib/internal/cli-route-inventory.js +1 -5
- package/dist/lib/internal/manual-validation.js +18 -10
- package/dist/lib/internal/task-create.js +1 -1
- package/dist/lib/internal/task-event.js +1 -8
- package/dist/lib/internal/task-finalization.js +0 -1
- package/dist/lib/internal/task-lifecycle.js +2 -2
- package/dist/lib/internal/task-operation-registry.js +4 -20
- package/dist/lib/internal/task-review.js +4 -4
- package/dist/lib/platform/comment-safety.js +1 -7
- package/dist/lib/platform/in-label-sync.js +1 -14
- package/dist/lib/platform/issue-comments.js +1 -16
- package/dist/lib/platform/issues.js +1 -1
- package/dist/lib/platform/operation-coordinator.js +4 -2
- package/dist/lib/platform/pr-change-report.js +1 -4
- package/dist/lib/platform/pr-checks.js +2 -8
- package/dist/lib/platform/provider-validation.js +0 -20
- package/dist/lib/platform/pull-requests.js +73 -84
- package/dist/lib/platform/releases.js +1 -43
- package/dist/lib/platform/verification-required.js +0 -2
- package/dist/lib/platform/verification-sync.js +1 -79
- package/dist/lib/process-data/normalize.js +1 -185
- package/dist/lib/process-data/privacy.js +1 -16
- package/dist/lib/process-data/sources.js +2 -279
- package/dist/lib/render.js +0 -12
- package/dist/lib/run/index.js +15 -10
- package/dist/lib/run/skills.js +0 -3
- package/dist/lib/sandbox/commands/create.js +40 -53
- package/dist/lib/sandbox/commands/list-running.js +0 -18
- package/dist/lib/sandbox/commands/start.js +7 -8
- package/dist/lib/sandbox/constants.js +0 -6
- package/dist/lib/sandbox/control/client.js +0 -1
- package/dist/lib/sandbox/control/container-identity.js +1 -16
- package/dist/lib/sandbox/control/executor.js +0 -4
- package/dist/lib/sandbox/control/identity-sentinel.js +0 -7
- package/dist/lib/sandbox/control/lifecycle.js +21 -37
- package/dist/lib/sandbox/control/native-file-lock.js +0 -3
- package/dist/lib/sandbox/control/server.js +18 -38
- package/dist/lib/sandbox/control/state.js +1 -9
- package/dist/lib/sandbox/dockerfile.js +0 -6
- package/dist/lib/sandbox/engine.js +0 -14
- package/dist/lib/sandbox/engines/docker-exact-discovery.js +1 -4
- package/dist/lib/sandbox/engines/wsl2-paths.js +0 -3
- package/dist/lib/sandbox/recovery.js +24 -26
- package/dist/lib/sandbox/removal.js +11 -519
- package/dist/lib/sandbox/task-resolver.js +0 -41
- package/dist/lib/sandbox/tools.js +1 -4
- package/dist/lib/sandbox/workspace-view.js +1 -2
- package/dist/lib/server/display.js +0 -6
- package/dist/lib/task/activity-intent.js +45 -40
- package/dist/lib/task/activity-log.js +9 -16
- package/dist/lib/task/artifact-command.js +1 -1
- package/dist/lib/task/artifact-lifecycle.js +61 -63
- package/dist/lib/task/artifact-name.js +0 -6
- package/dist/lib/task/artifact-operations.js +3 -3
- package/dist/lib/task/capabilities.js +4 -5
- package/dist/lib/task/commands/log.js +0 -6
- package/dist/lib/task/commands/status.js +17 -60
- package/dist/lib/task/commit-operation.js +28 -39
- package/dist/lib/task/completion-facts.js +56 -43
- package/dist/lib/task/control-authority.js +23 -256
- package/dist/lib/task/control-recovery.js +3 -5
- package/dist/lib/task/create.js +2 -4
- package/dist/lib/task/decision-intents.js +8 -9
- package/dist/lib/task/delivery-target.js +1 -40
- package/dist/lib/task/events.js +84 -107
- package/dist/lib/task/finalization.js +44 -8
- package/dist/lib/task/ledger-intents.js +1 -1
- package/dist/lib/task/lifecycle-execution.js +38 -33
- package/dist/lib/task/lifecycle.js +49 -41
- package/dist/lib/task/local-artifact-finalization.js +1 -4
- package/dist/lib/task/manual-validation-evidence.js +1 -37
- package/dist/lib/task/platform-operation-recovery.js +67 -24
- package/dist/lib/task/pr-delivery-fact.js +2 -5
- package/dist/lib/task/qualification-confirmation.js +5 -7
- package/dist/lib/task/resolve-ref.js +1 -25
- package/dist/lib/task/review-command.js +2 -2
- package/dist/lib/task/review-finalization.js +1 -21
- package/dist/lib/task/review-fingerprint.js +0 -4
- package/dist/lib/task/secure-fs.js +0 -56
- package/dist/lib/task/short-id.js +1 -39
- package/dist/lib/task/skill-scope.js +0 -1
- package/dist/lib/task/verification-engine.js +58 -282
- package/dist/lib/task/verification.js +6 -3
- package/dist/lib/task/write.js +11 -1
- package/lib/agent-clients/adapter.ts +0 -76
- package/lib/agent-clients/adapters/antigravity-cli.ts +0 -5
- package/lib/agent-clients/adapters/claude-code-credentials.ts +0 -19
- package/lib/agent-clients/adapters/claude-code.ts +0 -9
- package/lib/agent-clients/adapters/codex.ts +0 -56
- package/lib/agent-clients/adapters/opencode.ts +0 -5
- package/lib/agent-clients/adapters/traecli.ts +0 -5
- package/lib/agent-clients/config.ts +20 -61
- package/lib/agent-clients/registry.ts +1 -34
- package/lib/agent-clients/schema.ts +0 -18
- package/lib/agent-clients/tokens.ts +1 -2
- package/lib/agent-clients/types.ts +0 -15
- package/lib/decide.ts +1 -0
- package/lib/git/worktree-identity.ts +0 -10
- package/lib/internal/agent-client.ts +2 -70
- package/lib/internal/cli-route-inventory.ts +1 -4
- package/lib/internal/manual-validation.ts +16 -9
- package/lib/internal/task-create.ts +0 -1
- package/lib/internal/task-event.ts +1 -5
- package/lib/internal/task-finalization.ts +0 -1
- package/lib/internal/task-lifecycle.ts +3 -5
- package/lib/internal/task-operation-registry.ts +3 -19
- package/lib/internal/task-review.ts +4 -4
- package/lib/platform/comment-safety.ts +0 -10
- package/lib/platform/github-provider.ts +0 -2
- package/lib/platform/in-label-sync.ts +0 -16
- package/lib/platform/issue-comments.ts +0 -21
- package/lib/platform/issues.ts +0 -2
- package/lib/platform/operation-coordinator.ts +4 -2
- package/lib/platform/pr-change-report.ts +0 -5
- package/lib/platform/pr-checks.ts +1 -10
- package/lib/platform/pr-review.ts +1 -1
- package/lib/platform/provider-bridge.ts +0 -1
- package/lib/platform/provider-loader.ts +1 -5
- package/lib/platform/provider-validation.ts +1 -49
- package/lib/platform/pull-requests.ts +64 -99
- package/lib/platform/releases.ts +1 -40
- package/lib/platform/verification-required.ts +0 -2
- package/lib/platform/verification-sync.ts +0 -94
- package/lib/process-data/normalize.ts +1 -186
- package/lib/process-data/privacy.ts +2 -19
- package/lib/process-data/sources.ts +3 -283
- package/lib/render.ts +0 -15
- package/lib/run/index.ts +13 -7
- package/lib/run/skills.ts +0 -4
- package/lib/sandbox/commands/create.ts +37 -74
- package/lib/sandbox/commands/list-running.ts +0 -19
- package/lib/sandbox/commands/start.ts +7 -10
- package/lib/sandbox/constants.ts +0 -8
- package/lib/sandbox/control/client.ts +0 -1
- package/lib/sandbox/control/container-identity.ts +1 -16
- package/lib/sandbox/control/executor.ts +1 -5
- package/lib/sandbox/control/identity-sentinel.ts +0 -8
- package/lib/sandbox/control/lifecycle.ts +18 -51
- package/lib/sandbox/control/native-file-lock.ts +0 -8
- package/lib/sandbox/control/protocol.ts +0 -2
- package/lib/sandbox/control/server.ts +13 -39
- package/lib/sandbox/control/state.ts +1 -10
- package/lib/sandbox/dockerfile.ts +0 -11
- package/lib/sandbox/engine.ts +0 -17
- package/lib/sandbox/engines/docker-exact-discovery.ts +1 -5
- package/lib/sandbox/engines/wsl2-paths.ts +0 -4
- package/lib/sandbox/recovery.ts +24 -26
- package/lib/sandbox/removal.ts +11 -696
- package/lib/sandbox/shell.ts +1 -1
- package/lib/sandbox/task-resolver.ts +0 -48
- package/lib/sandbox/tools.ts +1 -5
- package/lib/sandbox/workspace-view.ts +2 -4
- package/lib/server/display.ts +0 -14
- package/lib/server/process-control.ts +1 -1
- package/lib/task/activity-intent.ts +36 -44
- package/lib/task/activity-log.ts +9 -22
- package/lib/task/artifact-command.ts +1 -1
- package/lib/task/artifact-lifecycle.ts +58 -67
- package/lib/task/artifact-name.ts +0 -7
- package/lib/task/artifact-operations.ts +3 -3
- package/lib/task/capabilities.ts +5 -6
- package/lib/task/commands/log.ts +0 -7
- package/lib/task/commands/status.ts +14 -79
- package/lib/task/commit-operation.ts +29 -51
- package/lib/task/completion-facts.ts +45 -42
- package/lib/task/control-authority.ts +27 -317
- package/lib/task/control-recovery.ts +2 -5
- package/lib/task/create.ts +2 -5
- package/lib/task/decision-intents.ts +5 -5
- package/lib/task/delivery-target.ts +0 -40
- package/lib/task/events.ts +89 -123
- package/lib/task/finalization.ts +41 -9
- package/lib/task/ledger-intents.ts +1 -1
- package/lib/task/lifecycle-execution.ts +37 -89
- package/lib/task/lifecycle.ts +48 -44
- package/lib/task/local-artifact-finalization.ts +0 -7
- package/lib/task/manual-validation-evidence.ts +1 -47
- package/lib/task/platform-operation-recovery.ts +50 -26
- package/lib/task/pr-delivery-fact.ts +2 -11
- package/lib/task/qualification-confirmation.ts +6 -6
- package/lib/task/resolve-ref.ts +0 -23
- package/lib/task/review-command.ts +2 -2
- package/lib/task/review-finalization.ts +1 -27
- package/lib/task/review-fingerprint.ts +0 -8
- package/lib/task/secure-fs.ts +0 -42
- package/lib/task/short-id.ts +0 -43
- package/lib/task/skill-scope.ts +0 -1
- package/lib/task/verification-engine.ts +56 -287
- package/lib/task/verification.ts +5 -5
- package/lib/task/write.ts +12 -1
- package/package.json +2 -2
- package/templates/.agents/README.en.md +1 -3
- package/templates/.agents/README.zh-CN.md +0 -2
- package/templates/.agents/rules/README.en.md +0 -1
- package/templates/.agents/rules/README.zh-CN.md +0 -1
- package/templates/.agents/rules/commit-and-pr.en.md +1 -1
- package/templates/.agents/rules/commit-and-pr.zh-CN.md +1 -1
- package/templates/.agents/rules/no-mid-flow-questions.en.md +0 -10
- package/templates/.agents/rules/no-mid-flow-questions.zh-CN.md +0 -10
- package/templates/.agents/rules/pr-sync.en.md +1 -1
- package/templates/.agents/rules/pr-sync.zh-CN.md +1 -1
- package/templates/.agents/rules/task-management.en.md +3 -3
- package/templates/.agents/rules/task-management.zh-CN.md +3 -3
- package/templates/.agents/skills/analyze-task/SKILL.en.md +3 -3
- package/templates/.agents/skills/analyze-task/SKILL.zh-CN.md +3 -3
- package/templates/.agents/skills/cancel-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/cancel-task/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/code-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/code-task/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/commit/SKILL.en.md +2 -2
- package/templates/.agents/skills/commit/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/commit/reference/commit-orchestration.en.md +6 -6
- package/templates/.agents/skills/commit/reference/commit-orchestration.zh-CN.md +6 -6
- package/templates/.agents/skills/plan-task/SKILL.en.md +2 -2
- package/templates/.agents/skills/plan-task/SKILL.zh-CN.md +2 -2
- package/templates/.agents/skills/review-analysis/SKILL.en.md +3 -3
- package/templates/.agents/skills/review-analysis/SKILL.zh-CN.md +3 -3
- package/templates/.agents/skills/review-code/SKILL.en.md +5 -5
- package/templates/.agents/skills/review-code/SKILL.zh-CN.md +5 -5
- package/templates/.agents/skills/review-plan/SKILL.en.md +3 -3
- package/templates/.agents/skills/review-plan/SKILL.zh-CN.md +3 -3
- package/templates/.agents/skills/review-pr/SKILL.en.md +4 -4
- package/templates/.agents/skills/review-pr/SKILL.zh-CN.md +4 -4
- package/templates/.agents/skills/run-manual-validation/SKILL.en.md +1 -1
- package/templates/.agents/skills/run-manual-validation/SKILL.zh-CN.md +1 -1
- package/templates/.agents/skills/update-agent-infra/scripts/sync-templates.js +3 -75
- package/templates/.agents/templates/task.en.md +1 -0
- package/templates/.agents/templates/task.zh-CN.md +1 -0
- package/templates/.claude/settings.json +0 -24
- package/templates/.codex/hooks.json +0 -50
- package/dist/lib/agent-clients/adapters/codex-lifecycle/app-server.js +0 -582
- package/dist/lib/agent-clients/adapters/codex-lifecycle/binding.js +0 -114
- package/dist/lib/agent-clients/adapters/codex-lifecycle/build-identity.js +0 -237
- package/dist/lib/agent-clients/adapters/codex-lifecycle/cli.js +0 -443
- package/dist/lib/agent-clients/adapters/codex-lifecycle/evidence.js +0 -236
- package/dist/lib/agent-clients/adapters/codex-lifecycle/recovery.js +0 -292
- package/dist/lib/agent-clients/adapters/codex-lifecycle/store.js +0 -267
- package/dist/lib/agent-clients/adapters/codex-orchestration.js +0 -466
- package/dist/lib/internal/task-orchestration.js +0 -71
- package/dist/lib/platform/verification.js +0 -6
- package/dist/lib/run/prompt.js +0 -2
- package/dist/lib/sandbox/engines/authority.js +0 -289
- package/dist/lib/task/delegation-receipts.js +0 -410
- package/dist/lib/task/orchestration.js +0 -1233
- package/dist/lib/task/verification-checks.js +0 -9
- package/dist/lib/task/workspace-snapshot.js +0 -121
- package/dist/lifecycle-build-manifest.json +0 -6
- package/lib/agent-clients/adapters/codex-lifecycle/app-server.ts +0 -688
- package/lib/agent-clients/adapters/codex-lifecycle/binding.ts +0 -147
- package/lib/agent-clients/adapters/codex-lifecycle/build-identity.ts +0 -349
- package/lib/agent-clients/adapters/codex-lifecycle/cli.ts +0 -506
- package/lib/agent-clients/adapters/codex-lifecycle/evidence.ts +0 -385
- package/lib/agent-clients/adapters/codex-lifecycle/manifest-files.json +0 -41
- package/lib/agent-clients/adapters/codex-lifecycle/recovery.ts +0 -418
- package/lib/agent-clients/adapters/codex-lifecycle/store.ts +0 -354
- package/lib/agent-clients/adapters/codex-orchestration.ts +0 -630
- package/lib/internal/task-orchestration.ts +0 -74
- package/lib/platform/verification.ts +0 -11
- package/lib/run/prompt.ts +0 -1
- package/lib/sandbox/engines/authority.ts +0 -365
- package/lib/task/delegation-receipts.ts +0 -547
- package/lib/task/orchestration.ts +0 -1651
- package/lib/task/verification-checks.ts +0 -10
- package/lib/task/workspace-snapshot.ts +0 -144
- package/templates/.agents/hooks/lifecycle-delegation.js +0 -140
- package/templates/.agents/rules/lifecycle-orchestration.en.md +0 -44
- package/templates/.agents/rules/lifecycle-orchestration.zh-CN.md +0 -44
- package/templates/.agents/skills/run-task/SKILL.en.md +0 -29
- package/templates/.agents/skills/run-task/SKILL.zh-CN.md +0 -29
- package/templates/.agents/skills/run-task/config/verify.en.json +0 -10
- package/templates/.agents/skills/run-task/config/verify.zh-CN.json +0 -10
- package/templates/.agents/skills/run-task/reference/host-validation.en.md +0 -24
- package/templates/.agents/skills/run-task/reference/host-validation.zh-CN.md +0 -24
- package/templates/.claude/agents/agent-infra-lifecycle-executor.en.md +0 -6
- package/templates/.claude/agents/agent-infra-lifecycle-executor.zh-CN.md +0 -6
- package/templates/.claude/agents/agent-infra-lifecycle-reviewer.en.md +0 -6
- package/templates/.claude/agents/agent-infra-lifecycle-reviewer.zh-CN.md +0 -6
- package/templates/.claude/commands/run-task.en.md +0 -8
- package/templates/.claude/commands/run-task.zh-CN.md +0 -8
- package/templates/.codex/agents/agent-infra-lifecycle-executor.en.toml +0 -3
- package/templates/.codex/agents/agent-infra-lifecycle-executor.zh-CN.toml +0 -3
- package/templates/.codex/agents/agent-infra-lifecycle-reviewer.en.toml +0 -3
- package/templates/.codex/agents/agent-infra-lifecycle-reviewer.zh-CN.toml +0 -3
- package/templates/.opencode/commands/run-task.en.md +0 -11
- package/templates/.opencode/commands/run-task.zh-CN.md +0 -11
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { isAgentClientId } from '../agent-clients/types.js';
|
|
3
|
-
import { normalizeAgentToken } from '../agent-clients/tokens.js';
|
|
4
|
-
function isRecord(value) {
|
|
5
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
|
-
}
|
|
7
|
-
function hasExactKeys(value, required, optional = []) {
|
|
8
|
-
if (!isRecord(value))
|
|
9
|
-
return false;
|
|
10
|
-
const keys = Object.keys(value);
|
|
11
|
-
const allowed = new Set([...required, ...optional]);
|
|
12
|
-
return required.every((key) => Object.prototype.hasOwnProperty.call(value, key))
|
|
13
|
-
&& keys.every((key) => allowed.has(key));
|
|
14
|
-
}
|
|
15
|
-
function exactText(value) {
|
|
16
|
-
return typeof value === 'string' && value.length > 0 && value.trim() === value;
|
|
17
|
-
}
|
|
18
|
-
function nullableText(value) {
|
|
19
|
-
return value === null || exactText(value);
|
|
20
|
-
}
|
|
21
|
-
function nullableSafeInteger(value) {
|
|
22
|
-
return value === null || (Number.isSafeInteger(value) && value >= 0);
|
|
23
|
-
}
|
|
24
|
-
const RECEIPT_KEYS = [
|
|
25
|
-
'id', 'taskId', 'runId', 'role', 'stage', 'round', 'artifact', 'client',
|
|
26
|
-
'requestedModel', 'requestedReasoningEffort', 'actualModel', 'actualReasoningEffort',
|
|
27
|
-
'modelFallbackReason', 'reasoningEffortFallbackReason', 'parentId', 'childId',
|
|
28
|
-
'spawnMode', 'agent', 'status', 'workspaceSnapshotScope',
|
|
29
|
-
'beforeFingerprint', 'afterFingerprint', 'changedPaths', 'createdAt',
|
|
30
|
-
'preparedMonotonicMs', 'spawnDispatchMonotonicMs', 'activationDeadlineMonotonicMs',
|
|
31
|
-
'spawnDispatchedAt', 'activationDeadlineAt', 'startEvidenceMonotonicMs',
|
|
32
|
-
'activatedMonotonicMs', 'activatedAt', 'sealedAt', 'consumedAt'
|
|
33
|
-
];
|
|
34
|
-
const RECEIPT_OPTIONAL_KEYS = ['adapterEvidence'];
|
|
35
|
-
function isJsonRecord(value) {
|
|
36
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
37
|
-
return false;
|
|
38
|
-
try {
|
|
39
|
-
return JSON.parse(JSON.stringify(value)) !== null;
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function withClientEvidence(receipt, evidence) {
|
|
46
|
-
if (evidence === undefined)
|
|
47
|
-
return receipt.adapterEvidence ?? Object.freeze({});
|
|
48
|
-
if (!isJsonRecord(evidence))
|
|
49
|
-
return null;
|
|
50
|
-
return Object.freeze({
|
|
51
|
-
...(receipt.adapterEvidence ?? {}),
|
|
52
|
-
[receipt.client]: JSON.parse(JSON.stringify(evidence))
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function hasStatusBoundEvidence(receipt) {
|
|
56
|
-
const dispatchFields = [
|
|
57
|
-
receipt.spawnDispatchMonotonicMs,
|
|
58
|
-
receipt.activationDeadlineMonotonicMs,
|
|
59
|
-
receipt.spawnDispatchedAt,
|
|
60
|
-
receipt.activationDeadlineAt
|
|
61
|
-
];
|
|
62
|
-
const dispatchEmpty = dispatchFields.every((field) => field === null);
|
|
63
|
-
const dispatchComplete = dispatchFields.every((field) => field !== null);
|
|
64
|
-
if (!dispatchEmpty && !dispatchComplete)
|
|
65
|
-
return false;
|
|
66
|
-
const beforeActivation = ['prepared', 'expired'].includes(receipt.status)
|
|
67
|
-
|| (receipt.status === 'aborted' && receipt.activatedAt === null);
|
|
68
|
-
if (beforeActivation) {
|
|
69
|
-
return receipt.parentId === null
|
|
70
|
-
&& receipt.childId === null
|
|
71
|
-
&& receipt.spawnMode === null
|
|
72
|
-
&& receipt.actualModel === null
|
|
73
|
-
&& receipt.actualReasoningEffort === null
|
|
74
|
-
&& receipt.modelFallbackReason === null
|
|
75
|
-
&& receipt.reasoningEffortFallbackReason === null
|
|
76
|
-
&& receipt.agent === null
|
|
77
|
-
&& receipt.startEvidenceMonotonicMs === null
|
|
78
|
-
&& receipt.activatedMonotonicMs === null
|
|
79
|
-
&& receipt.activatedAt === null
|
|
80
|
-
&& receipt.afterFingerprint === null
|
|
81
|
-
&& receipt.changedPaths.length === 0
|
|
82
|
-
&& receipt.sealedAt === null
|
|
83
|
-
&& receipt.consumedAt === null;
|
|
84
|
-
}
|
|
85
|
-
if (!dispatchComplete
|
|
86
|
-
|| !exactText(receipt.parentId)
|
|
87
|
-
|| !exactText(receipt.childId)
|
|
88
|
-
|| receipt.parentId === receipt.childId
|
|
89
|
-
|| receipt.startEvidenceMonotonicMs === null
|
|
90
|
-
|| receipt.activatedMonotonicMs === null
|
|
91
|
-
|| !exactText(receipt.activatedAt))
|
|
92
|
-
return false;
|
|
93
|
-
if (receipt.status === 'activated') {
|
|
94
|
-
return receipt.agent === null
|
|
95
|
-
&& receipt.afterFingerprint === null
|
|
96
|
-
&& receipt.changedPaths.length === 0
|
|
97
|
-
&& receipt.sealedAt === null
|
|
98
|
-
&& receipt.consumedAt === null;
|
|
99
|
-
}
|
|
100
|
-
if (receipt.status === 'aborted') {
|
|
101
|
-
return receipt.agent === null
|
|
102
|
-
&& receipt.afterFingerprint === null
|
|
103
|
-
&& receipt.changedPaths.length === 0
|
|
104
|
-
&& receipt.sealedAt === null
|
|
105
|
-
&& receipt.consumedAt === null
|
|
106
|
-
&& receipt.childId !== null;
|
|
107
|
-
}
|
|
108
|
-
if (!exactText(receipt.agent)
|
|
109
|
-
|| normalizeAgentToken(receipt.agent) !== normalizeAgentToken(receipt.client))
|
|
110
|
-
return false;
|
|
111
|
-
if (receipt.status === 'stage-completed') {
|
|
112
|
-
return receipt.afterFingerprint === null
|
|
113
|
-
&& receipt.changedPaths.length === 0
|
|
114
|
-
&& receipt.sealedAt === null
|
|
115
|
-
&& receipt.consumedAt === null;
|
|
116
|
-
}
|
|
117
|
-
if (!exactText(receipt.afterFingerprint) || !exactText(receipt.sealedAt))
|
|
118
|
-
return false;
|
|
119
|
-
return receipt.status === 'sealed'
|
|
120
|
-
? receipt.consumedAt === null
|
|
121
|
-
: receipt.status === 'consumed' && exactText(receipt.consumedAt);
|
|
122
|
-
}
|
|
123
|
-
function isDelegationReceipt(value) {
|
|
124
|
-
if (!hasExactKeys(value, RECEIPT_KEYS, RECEIPT_OPTIONAL_KEYS))
|
|
125
|
-
return false;
|
|
126
|
-
const structurallyValid = exactText(value.id)
|
|
127
|
-
&& exactText(value.taskId)
|
|
128
|
-
&& exactText(value.runId)
|
|
129
|
-
&& ['executor', 'reviewer'].includes(value.role)
|
|
130
|
-
&& ['analysis', 'review-analysis', 'plan', 'review-plan', 'code', 'review-code', 'commit'].includes(value.stage)
|
|
131
|
-
&& Number.isSafeInteger(value.round)
|
|
132
|
-
&& value.round > 0
|
|
133
|
-
&& exactText(value.artifact)
|
|
134
|
-
&& isAgentClientId(value.client)
|
|
135
|
-
&& exactText(value.requestedModel)
|
|
136
|
-
&& exactText(value.requestedReasoningEffort)
|
|
137
|
-
&& nullableText(value.actualModel)
|
|
138
|
-
&& nullableText(value.actualReasoningEffort)
|
|
139
|
-
&& nullableText(value.modelFallbackReason)
|
|
140
|
-
&& nullableText(value.reasoningEffortFallbackReason)
|
|
141
|
-
&& nullableText(value.parentId)
|
|
142
|
-
&& nullableText(value.childId)
|
|
143
|
-
&& nullableText(value.spawnMode)
|
|
144
|
-
&& nullableText(value.agent)
|
|
145
|
-
&& ['prepared', 'activated', 'stage-completed', 'sealed', 'consumed', 'aborted', 'expired'].includes(value.status)
|
|
146
|
-
&& value.workspaceSnapshotScope === 'task'
|
|
147
|
-
&& (value.adapterEvidence === undefined || isJsonRecord(value.adapterEvidence))
|
|
148
|
-
&& exactText(value.beforeFingerprint)
|
|
149
|
-
&& nullableText(value.afterFingerprint)
|
|
150
|
-
&& Array.isArray(value.changedPaths)
|
|
151
|
-
&& value.changedPaths.every(exactText)
|
|
152
|
-
&& exactText(value.createdAt)
|
|
153
|
-
&& nullableSafeInteger(value.preparedMonotonicMs)
|
|
154
|
-
&& value.preparedMonotonicMs !== null
|
|
155
|
-
&& nullableSafeInteger(value.spawnDispatchMonotonicMs)
|
|
156
|
-
&& nullableSafeInteger(value.activationDeadlineMonotonicMs)
|
|
157
|
-
&& nullableText(value.spawnDispatchedAt)
|
|
158
|
-
&& nullableText(value.activationDeadlineAt)
|
|
159
|
-
&& nullableSafeInteger(value.startEvidenceMonotonicMs)
|
|
160
|
-
&& nullableSafeInteger(value.activatedMonotonicMs)
|
|
161
|
-
&& nullableText(value.activatedAt)
|
|
162
|
-
&& nullableText(value.sealedAt)
|
|
163
|
-
&& nullableText(value.consumedAt);
|
|
164
|
-
if (!structurallyValid)
|
|
165
|
-
return false;
|
|
166
|
-
const receipt = value;
|
|
167
|
-
if (!hasStatusBoundEvidence(receipt))
|
|
168
|
-
return false;
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
const MANAGED_AGENTS = {
|
|
172
|
-
'agent-infra-lifecycle-executor': 'executor',
|
|
173
|
-
'agent-infra-lifecycle-reviewer': 'reviewer'
|
|
174
|
-
};
|
|
175
|
-
function managedDelegationRole(nativeAgent) {
|
|
176
|
-
return MANAGED_AGENTS[nativeAgent] ?? null;
|
|
177
|
-
}
|
|
178
|
-
function fail(code, message) {
|
|
179
|
-
return { ok: false, code, message };
|
|
180
|
-
}
|
|
181
|
-
// 空白串折叠为 null,保持"缺失即 null"的单一表示(Start/Stop 两处共用,避免任一入口把 " " 当成已观察到的值入账)
|
|
182
|
-
function foldBlankToNull(value) {
|
|
183
|
-
return value?.trim() ? value : null;
|
|
184
|
-
}
|
|
185
|
-
function validateSealRequest(receipt, event) {
|
|
186
|
-
if (receipt.status !== 'stage-completed') {
|
|
187
|
-
return fail('DELEGATION_STATE_INVALID', `delegation ${receipt.id} is ${receipt.status}, expected stage-completed`);
|
|
188
|
-
}
|
|
189
|
-
if (event.childId !== receipt.childId || event.exitCode !== 0) {
|
|
190
|
-
return fail('DELEGATION_STOP_INVALID', 'native stop identity or exit status is invalid');
|
|
191
|
-
}
|
|
192
|
-
const reviewerPathFailure = validateReviewerSealPaths(receipt, event.changedPaths);
|
|
193
|
-
return reviewerPathFailure;
|
|
194
|
-
}
|
|
195
|
-
function validateReviewerSealPaths(receipt, changedPaths) {
|
|
196
|
-
if (receipt.role !== 'reviewer')
|
|
197
|
-
return null;
|
|
198
|
-
const taskRoot = `task-workspace/active/${receipt.taskId}/`;
|
|
199
|
-
const allowed = new Set([
|
|
200
|
-
`${taskRoot}${receipt.artifact}`,
|
|
201
|
-
`${taskRoot}task.md`,
|
|
202
|
-
`${taskRoot}.runtime/orchestration.json`
|
|
203
|
-
]);
|
|
204
|
-
const disallowed = changedPaths.find((entry) => !allowed.has(entry));
|
|
205
|
-
return disallowed
|
|
206
|
-
? fail('DELEGATION_REVIEWER_WRITE_FORBIDDEN', `reviewer changed forbidden path '${disallowed}'`)
|
|
207
|
-
: null;
|
|
208
|
-
}
|
|
209
|
-
function prepareDelegation(input, options = {}) {
|
|
210
|
-
const monotonic = (options.monotonicNow ?? (() => Number(process.hrtime.bigint() / 1000000n)))();
|
|
211
|
-
return Object.freeze({
|
|
212
|
-
...input,
|
|
213
|
-
adapterEvidence: Object.freeze({ ...(input.adapterEvidence ?? {}) }),
|
|
214
|
-
id: (options.id ?? randomUUID)(),
|
|
215
|
-
actualModel: null,
|
|
216
|
-
actualReasoningEffort: null,
|
|
217
|
-
modelFallbackReason: null,
|
|
218
|
-
reasoningEffortFallbackReason: null,
|
|
219
|
-
parentId: null,
|
|
220
|
-
childId: null,
|
|
221
|
-
spawnMode: null,
|
|
222
|
-
agent: null,
|
|
223
|
-
status: 'prepared',
|
|
224
|
-
afterFingerprint: null,
|
|
225
|
-
changedPaths: Object.freeze([]),
|
|
226
|
-
createdAt: (options.now ?? (() => new Date().toISOString()))(),
|
|
227
|
-
preparedMonotonicMs: monotonic,
|
|
228
|
-
spawnDispatchMonotonicMs: null,
|
|
229
|
-
activationDeadlineMonotonicMs: null,
|
|
230
|
-
spawnDispatchedAt: null,
|
|
231
|
-
activationDeadlineAt: null,
|
|
232
|
-
startEvidenceMonotonicMs: null,
|
|
233
|
-
activatedMonotonicMs: null,
|
|
234
|
-
activatedAt: null,
|
|
235
|
-
sealedAt: null,
|
|
236
|
-
consumedAt: null
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
function dispatchDelegation(receipt, options = {}) {
|
|
240
|
-
if (receipt.status !== 'prepared') {
|
|
241
|
-
return fail('DELEGATION_STATE_INVALID', `delegation ${receipt.id} is ${receipt.status}, expected prepared`);
|
|
242
|
-
}
|
|
243
|
-
if (receipt.spawnDispatchMonotonicMs != null || receipt.spawnDispatchedAt != null) {
|
|
244
|
-
return fail('DELEGATION_DISPATCH_REPLAY', `delegation ${receipt.id} was already dispatched`);
|
|
245
|
-
}
|
|
246
|
-
const monotonic = (options.monotonicNow ?? (() => Number(process.hrtime.bigint() / 1000000n)))();
|
|
247
|
-
const dispatchedAt = (options.now ?? (() => new Date().toISOString()))();
|
|
248
|
-
const window = options.activationWindowMs ?? 60_000;
|
|
249
|
-
return { ok: true, receipt: Object.freeze({
|
|
250
|
-
...receipt,
|
|
251
|
-
spawnDispatchMonotonicMs: monotonic,
|
|
252
|
-
activationDeadlineMonotonicMs: monotonic + window,
|
|
253
|
-
spawnDispatchedAt: dispatchedAt,
|
|
254
|
-
activationDeadlineAt: new Date(Date.parse(dispatchedAt) + window).toISOString()
|
|
255
|
-
}) };
|
|
256
|
-
}
|
|
257
|
-
function activateDelegation(receipt, event, options = {}) {
|
|
258
|
-
const managedRole = managedDelegationRole(event.nativeAgent);
|
|
259
|
-
if (!managedRole)
|
|
260
|
-
return fail('DELEGATION_IGNORED', `subagent '${event.nativeAgent}' is not lifecycle-managed`);
|
|
261
|
-
if (receipt.status !== 'prepared')
|
|
262
|
-
return fail('DELEGATION_STATE_INVALID', `delegation ${receipt.id} is ${receipt.status}, expected prepared`);
|
|
263
|
-
if (receipt.spawnDispatchMonotonicMs == null
|
|
264
|
-
|| receipt.spawnDispatchedAt == null
|
|
265
|
-
|| receipt.activationDeadlineAt == null
|
|
266
|
-
|| receipt.activationDeadlineMonotonicMs == null
|
|
267
|
-
|| !Number.isFinite(Date.parse(receipt.spawnDispatchedAt))
|
|
268
|
-
|| !Number.isFinite(Date.parse(receipt.activationDeadlineAt))) {
|
|
269
|
-
return fail('DELEGATION_NOT_DISPATCHED', `delegation ${receipt.id} has not reached the native spawn dispatch boundary`);
|
|
270
|
-
}
|
|
271
|
-
const monotonic = (options.monotonicNow ?? (() => Number(process.hrtime.bigint() / 1000000n)))();
|
|
272
|
-
const wallNow = Date.parse((options.now ?? (() => new Date().toISOString()))());
|
|
273
|
-
if (wallNow > Date.parse(receipt.activationDeadlineAt)) {
|
|
274
|
-
return fail('DELEGATION_ACTIVATION_TIMEOUT', `delegation ${receipt.id} activation evidence arrived after its deadline`);
|
|
275
|
-
}
|
|
276
|
-
if (managedRole !== receipt.role)
|
|
277
|
-
return fail('DELEGATION_ROLE_MISMATCH', `managed role ${managedRole} does not match ${receipt.role}`);
|
|
278
|
-
if (!event.parentId || (receipt.parentId !== null && event.parentId !== receipt.parentId) || !event.childId || event.childId === event.parentId) {
|
|
279
|
-
return fail('DELEGATION_IDENTITY_INVALID', 'native parent/child identity does not match the prepared delegation');
|
|
280
|
-
}
|
|
281
|
-
const evidencePolicy = options.evidencePolicy ?? {};
|
|
282
|
-
if (evidencePolicy.spawnModeRequired !== false && event.spawnMode !== 'fresh') {
|
|
283
|
-
return fail('DELEGATION_FORK_FORBIDDEN', `spawn mode '${event.spawnMode}' is not fresh`);
|
|
284
|
-
}
|
|
285
|
-
const actualModel = foldBlankToNull(event.actualModel);
|
|
286
|
-
const actualReasoningEffort = foldBlankToNull(event.actualReasoningEffort);
|
|
287
|
-
if (evidencePolicy.actualModelRequired !== false) {
|
|
288
|
-
if (!actualModel || actualModel.trim() !== actualModel) {
|
|
289
|
-
return fail('DELEGATION_MODEL_IDENTITY_MISSING', 'native start event must provide a non-empty actual model identity');
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
if (actualModel !== null && actualModel !== receipt.requestedModel) {
|
|
293
|
-
if (evidencePolicy.fallbackReasonRequired !== false && (!event.modelFallbackReason || event.modelFallbackReason.trim() === '')) {
|
|
294
|
-
return fail('DELEGATION_MODEL_FALLBACK_UNRECORDED', 'actual model differs from requested model without a fallback reason');
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (evidencePolicy.actualReasoningEffortRequired !== false) {
|
|
298
|
-
if (!actualReasoningEffort || actualReasoningEffort.trim() !== actualReasoningEffort) {
|
|
299
|
-
return fail('DELEGATION_REASONING_EFFORT_MISSING', 'native start event must provide a non-empty actual reasoning effort');
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
if (actualReasoningEffort !== null && actualReasoningEffort !== receipt.requestedReasoningEffort) {
|
|
303
|
-
if (evidencePolicy.fallbackReasonRequired !== false && (!event.reasoningEffortFallbackReason || event.reasoningEffortFallbackReason.trim() === '')) {
|
|
304
|
-
return fail('DELEGATION_REASONING_EFFORT_FALLBACK_UNRECORDED', 'actual reasoning effort differs from requested effort without a fallback reason');
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// "无关 fallback 理由"检查对所有 client 保持不变——防止编造理由的红线,不属于 HDR-2 放宽范围
|
|
308
|
-
// actualModel/actualReasoningEffort 为 null(未观察到)时同样没有"实际不同"这回事,理由一样是无关的
|
|
309
|
-
if ((actualModel === null || actualModel === receipt.requestedModel) && event.modelFallbackReason) {
|
|
310
|
-
return fail('DELEGATION_MODEL_FALLBACK_INVALID', 'model fallback reason is only valid when actual model differs');
|
|
311
|
-
}
|
|
312
|
-
if ((actualReasoningEffort === null || actualReasoningEffort === receipt.requestedReasoningEffort)
|
|
313
|
-
&& event.reasoningEffortFallbackReason) {
|
|
314
|
-
return fail('DELEGATION_REASONING_EFFORT_FALLBACK_INVALID', 'reasoning-effort fallback reason is only valid when actual effort differs');
|
|
315
|
-
}
|
|
316
|
-
const adapterEvidence = withClientEvidence(receipt, event.clientEvidence);
|
|
317
|
-
if (!adapterEvidence)
|
|
318
|
-
return fail('DELEGATION_ADAPTER_EVIDENCE_INVALID', 'adapter evidence must be a JSON object');
|
|
319
|
-
return { ok: true, receipt: Object.freeze({
|
|
320
|
-
...receipt,
|
|
321
|
-
status: 'activated',
|
|
322
|
-
parentId: event.parentId,
|
|
323
|
-
childId: event.childId,
|
|
324
|
-
spawnMode: event.spawnMode ?? null,
|
|
325
|
-
actualModel,
|
|
326
|
-
actualReasoningEffort,
|
|
327
|
-
modelFallbackReason: event.modelFallbackReason ?? null,
|
|
328
|
-
reasoningEffortFallbackReason: event.reasoningEffortFallbackReason ?? null,
|
|
329
|
-
adapterEvidence,
|
|
330
|
-
startEvidenceMonotonicMs: monotonic,
|
|
331
|
-
activatedMonotonicMs: (options.monotonicNow ?? (() => Number(process.hrtime.bigint() / 1000000n)))(),
|
|
332
|
-
activatedAt: new Date(wallNow).toISOString()
|
|
333
|
-
}) };
|
|
334
|
-
}
|
|
335
|
-
function abortPreparedDelegation(receipt) {
|
|
336
|
-
if (receipt.status !== 'prepared') {
|
|
337
|
-
return fail('DELEGATION_STATE_INVALID', `delegation ${receipt.id} is ${receipt.status}, expected prepared`);
|
|
338
|
-
}
|
|
339
|
-
return {
|
|
340
|
-
ok: true,
|
|
341
|
-
receipt: Object.freeze({ ...receipt, status: 'aborted' })
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
function abortActivatedDelegation(receipt, event) {
|
|
345
|
-
if (receipt.status !== 'activated') {
|
|
346
|
-
return fail('DELEGATION_STATE_INVALID', `delegation ${receipt.id} is ${receipt.status}, expected activated`);
|
|
347
|
-
}
|
|
348
|
-
if (event.childId !== receipt.childId)
|
|
349
|
-
return fail('DELEGATION_RECOVERY_EVIDENCE_INVALID', 'recovery child does not match the activated delegation');
|
|
350
|
-
const adapterEvidence = withClientEvidence(receipt, event.clientEvidence);
|
|
351
|
-
if (!adapterEvidence)
|
|
352
|
-
return fail('DELEGATION_ADAPTER_EVIDENCE_INVALID', 'adapter evidence must be a JSON object');
|
|
353
|
-
return {
|
|
354
|
-
ok: true,
|
|
355
|
-
receipt: Object.freeze({
|
|
356
|
-
...receipt,
|
|
357
|
-
status: 'aborted',
|
|
358
|
-
agent: null,
|
|
359
|
-
afterFingerprint: null,
|
|
360
|
-
changedPaths: Object.freeze([]),
|
|
361
|
-
sealedAt: null,
|
|
362
|
-
consumedAt: null,
|
|
363
|
-
adapterEvidence
|
|
364
|
-
})
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
function completeDelegationStage(receipt, event) {
|
|
368
|
-
if (receipt.status !== 'activated')
|
|
369
|
-
return fail('DELEGATION_STATE_INVALID', `delegation ${receipt.id} is ${receipt.status}, expected activated`);
|
|
370
|
-
if (event.stage !== receipt.stage || event.round !== receipt.round || event.artifact !== receipt.artifact) {
|
|
371
|
-
return fail('DELEGATION_STAGE_MISMATCH', 'stage completion identity does not match the active delegation');
|
|
372
|
-
}
|
|
373
|
-
if (normalizeAgentToken(event.agent) !== normalizeAgentToken(receipt.client)) {
|
|
374
|
-
return fail('DELEGATION_AGENT_MISMATCH', `stage agent '${event.agent}' does not match client '${receipt.client}'`);
|
|
375
|
-
}
|
|
376
|
-
return { ok: true, receipt: Object.freeze({ ...receipt, status: 'stage-completed', agent: event.agent }) };
|
|
377
|
-
}
|
|
378
|
-
function sealDelegation(receipt, event, options = {}) {
|
|
379
|
-
const validationFailure = validateSealRequest(receipt, event);
|
|
380
|
-
if (validationFailure)
|
|
381
|
-
return validationFailure;
|
|
382
|
-
const adapterEvidence = withClientEvidence(receipt, event.clientEvidence);
|
|
383
|
-
if (!adapterEvidence)
|
|
384
|
-
return fail('DELEGATION_ADAPTER_EVIDENCE_INVALID', 'adapter evidence must be a JSON object');
|
|
385
|
-
return { ok: true, receipt: Object.freeze({
|
|
386
|
-
...receipt,
|
|
387
|
-
status: 'sealed',
|
|
388
|
-
afterFingerprint: event.afterFingerprint,
|
|
389
|
-
changedPaths: Object.freeze([...event.changedPaths]),
|
|
390
|
-
actualModel: receipt.actualModel ?? foldBlankToNull(event.actualModel),
|
|
391
|
-
actualReasoningEffort: receipt.actualReasoningEffort ?? foldBlankToNull(event.actualReasoningEffort),
|
|
392
|
-
modelFallbackReason: receipt.modelFallbackReason ?? event.modelFallbackReason ?? null,
|
|
393
|
-
reasoningEffortFallbackReason: receipt.reasoningEffortFallbackReason ?? event.reasoningEffortFallbackReason ?? null,
|
|
394
|
-
adapterEvidence,
|
|
395
|
-
sealedAt: (options.now ?? (() => new Date().toISOString()))()
|
|
396
|
-
}) };
|
|
397
|
-
}
|
|
398
|
-
function consumeDelegation(receipt, options = {}) {
|
|
399
|
-
if (receipt.status === 'consumed')
|
|
400
|
-
return fail('DELEGATION_REPLAY', `delegation ${receipt.id} was already consumed`);
|
|
401
|
-
if (receipt.status !== 'sealed')
|
|
402
|
-
return fail('DELEGATION_STATE_INVALID', `delegation ${receipt.id} is ${receipt.status}, expected sealed`);
|
|
403
|
-
return { ok: true, receipt: Object.freeze({
|
|
404
|
-
...receipt,
|
|
405
|
-
status: 'consumed',
|
|
406
|
-
consumedAt: (options.now ?? (() => new Date().toISOString()))()
|
|
407
|
-
}) };
|
|
408
|
-
}
|
|
409
|
-
export { activateDelegation, abortActivatedDelegation, abortPreparedDelegation, completeDelegationStage, consumeDelegation, dispatchDelegation, foldBlankToNull, isDelegationReceipt, managedDelegationRole, prepareDelegation, sealDelegation };
|
|
410
|
-
//# sourceMappingURL=delegation-receipts.js.map
|