@cassiomc1/forgeloop 1.14.0 → 2.0.0-rc.4
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/CONTRIBUTING.md +11 -7
- package/DOCS_INDEX.md +2 -1
- package/ENG/c-development-eng.md +2 -2
- package/ENG/cpp-development-eng.md +2 -2
- package/ENG/dotnet-aspnetcore-development-eng.md +7 -1
- package/ENG/flutter-development-eng.md +4 -2
- package/ENG/go-development-eng.md +2 -2
- package/ENG/java-development-eng.md +3 -3
- package/ENG/nodejs-backend-development-eng.md +8 -4
- package/ENG/php-development-eng.md +3 -3
- package/ENG/python-development-eng.md +205 -0
- package/ENG/rust-development-eng.md +42 -1
- package/ENG/sql-development-eng.md +4 -4
- package/ENG/swift-development-eng.md +5 -4
- package/ENG/test-code-eng.md +1 -1
- package/ENG/typescript-development-eng.md +4 -4
- package/GUIDE_ROUTER.md +6 -0
- package/LICENSE +133 -21
- package/LOOP_SYSTEM_DESIGN.md +10 -10
- package/README.md +30 -40
- package/THIRD_PARTY_NOTICES.md +3 -4
- package/completions/_forgeloop +11 -3
- package/completions/forgeloop.bash +19 -3
- package/completions/forgeloop.fish +61 -1
- package/docs/AGENT_PROTOCOL_SUMMARY.md +50 -40
- package/docs/ARTIFACT_REFERENCE.md +50 -37
- package/docs/CLI_REFERENCE.md +147 -3
- package/docs/DOCUMENTATION_GUIDE.md +6 -4
- package/docs/GETTING_STARTED.md +3 -3
- package/docs/PACKAGE_CONTENTS.md +14 -13
- package/docs/RELEASE_CHECKLIST.md +110 -10
- package/docs/SELF_HOSTED_TESTS.md +121 -0
- package/docs/TROUBLESHOOTING.md +33 -0
- package/docs/documentation-manifest.json +25 -12
- package/package.json +15 -10
- package/schemas/task-bundle.schema.json +7 -2
- package/scripts/generate-agent-protocol-summary.mjs +2 -2
- package/scripts/run-mcp-clean-tests.mjs +30 -0
- package/src/adapters/agent-browser/provider.js +14 -11
- package/src/adapters/emulated-services/provider.js +11 -4
- package/src/adapters/temporary-paths.js +18 -0
- package/src/cli.js +146 -210
- package/src/commands/action-show.js +5 -2
- package/src/commands/advance.js +5 -1
- package/src/commands/baseline.js +13 -11
- package/src/commands/checkpoint-revalidate.js +24 -8
- package/src/commands/complete.js +19 -3
- package/src/commands/contract-create.js +3 -1
- package/src/commands/doctor.js +36 -13
- package/src/commands/gate-record.js +20 -31
- package/src/commands/gate-revalidate.js +11 -13
- package/src/commands/handoff-list.js +6 -1
- package/src/commands/handoff-show.js +6 -1
- package/src/commands/migrate-protocol.js +2 -2
- package/src/commands/model-route.js +9 -1
- package/src/commands/next.js +7 -1
- package/src/commands/policy-diff.js +25 -4
- package/src/commands/progress.js +17 -11
- package/src/commands/record-diagnosis.js +3 -0
- package/src/commands/semantic-plan.js +26 -2
- package/src/commands/status.js +6 -1
- package/src/commands/storage-backup.js +15 -0
- package/src/commands/storage-migrate.js +5 -0
- package/src/commands/storage-migration-resume.js +5 -0
- package/src/commands/storage-migration-status.js +44 -0
- package/src/commands/storage-restore-resume.js +7 -0
- package/src/commands/storage-restore.js +8 -0
- package/src/commands/task-abandon.js +1 -1
- package/src/commands/task-list.js +8 -43
- package/src/commands/task-migrate.js +3 -3
- package/src/commands/task-recover.js +10 -2
- package/src/commands/task-scope.js +18 -2
- package/src/commands/task-show.js +16 -2
- package/src/commands/validate-protocol.js +29 -14
- package/src/commands/validate-receipt.js +8 -1
- package/src/config/guides.json +4 -0
- package/src/core/action-ledger-projection.js +10 -3
- package/src/core/actions.js +38 -75
- package/src/core/activation.js +11 -3
- package/src/core/approvals.js +17 -51
- package/src/core/artifact-registry.js +59 -2
- package/src/core/artifacts.js +81 -27
- package/src/core/attachment-paths.js +45 -0
- package/src/core/attestation-coverage.js +6 -1
- package/src/core/attestation-verifier.js +21 -2
- package/src/core/attestation.js +17 -6
- package/src/core/audit.js +6 -1
- package/src/core/bundles.js +160 -66
- package/src/core/checkpoint-revalidation.js +12 -10
- package/src/core/cli-command-definitions.js +109 -7
- package/src/core/code-manifest.js +9 -3
- package/src/core/command-executors.js +182 -126
- package/src/core/command-input.js +21 -1
- package/src/core/completion-artifacts.js +85 -36
- package/src/core/completion-ownership.js +19 -8
- package/src/core/completion-recovery-rebind.js +11 -1
- package/src/core/completion.js +60 -9
- package/src/core/conformance.js +2 -1
- package/src/core/continuity-lint.js +13 -2
- package/src/core/continuity-reconciliation.js +16 -3
- package/src/core/continuity.js +16 -8
- package/src/core/contract-bootstrap-recovery.js +42 -41
- package/src/core/contract-revision.js +8 -9
- package/src/core/decision/artifact.js +2 -1
- package/src/core/decision/events.js +9 -6
- package/src/core/decision/resolver.js +19 -11
- package/src/core/decision/service.js +63 -38
- package/src/core/decision/task-bindings.js +6 -1
- package/src/core/diagnosis-model.js +11 -0
- package/src/core/diagnosis.js +10 -1
- package/src/core/diagnostic-projection.js +29 -12
- package/src/core/diagnostic-record.js +28 -3
- package/src/core/efficiency.js +6 -1
- package/src/core/events.js +316 -97
- package/src/core/execution-prerequisites.js +22 -13
- package/src/core/execution.js +26 -40
- package/src/core/filesystem.js +11 -0
- package/src/core/gate-artifact.js +105 -19
- package/src/core/gate-provenance.js +6 -5
- package/src/core/handoff.js +26 -14
- package/src/core/history.js +39 -35
- package/src/core/hypothesis-projection.js +32 -0
- package/src/core/information-gain-projection.js +104 -100
- package/src/core/inspect.js +12 -3
- package/src/core/integration-invocation-policy.js +10 -0
- package/src/core/integration-resources.js +41 -34
- package/src/core/ledger-event-collection.js +189 -0
- package/src/core/ledger-relations.js +23 -0
- package/src/core/native-storage.js +12 -0
- package/src/core/next-action-continuity.js +31 -9
- package/src/core/next-action-phases.js +1 -1
- package/src/core/next-action-review-phase.js +2 -2
- package/src/core/next-action-verification-phase.js +2 -1
- package/src/core/next-action.js +21 -2
- package/src/core/phase.js +138 -93
- package/src/core/policy-engine.js +12 -13
- package/src/core/preflight-consistency.js +72 -59
- package/src/core/preflight-loaders.js +19 -12
- package/src/core/preflight-model.js +6 -1
- package/src/core/preflight.js +29 -12
- package/src/core/progress.js +21 -10
- package/src/core/protocol-info.js +3 -0
- package/src/core/protocol-migration.js +7 -6
- package/src/core/reconcile-closure.js +162 -24
- package/src/core/recovery-history.js +66 -47
- package/src/core/reflection.js +72 -77
- package/src/core/responsibility.js +25 -13
- package/src/core/route-artifact.js +13 -3
- package/src/core/runtime-context.js +5 -0
- package/src/core/schema-validation.js +8 -3
- package/src/core/settlement.js +12 -1
- package/src/core/signing/bundle-file.js +53 -0
- package/src/core/signing/bundle-reference.js +15 -0
- package/src/core/signing/sigstore.js +60 -33
- package/src/core/signing/statement-file.js +27 -0
- package/src/core/storage-runtime-registry.js +41 -0
- package/src/core/structural-quality/artifacts.js +20 -14
- package/src/core/structural-quality/service.js +81 -56
- package/src/core/target-layout.js +1 -1
- package/src/core/task-claim-state.js +52 -18
- package/src/core/task-command.js +21 -1
- package/src/core/task-conflict-inspection.js +112 -107
- package/src/core/task-descriptor.js +29 -22
- package/src/core/task-discovery.js +288 -90
- package/src/core/task-lock.js +66 -306
- package/src/core/task-migration-validation.js +5 -5
- package/src/core/task-migration.js +17 -287
- package/src/core/task-snapshot.js +51 -8
- package/src/core/task-storage-migration.js +18 -0
- package/src/core/templates.js +20 -8
- package/src/core/test-intelligence/prune.js +5 -1
- package/src/core/trace.js +154 -99
- package/src/core/trajectory-evaluation.js +15 -3
- package/src/core/trajectory-metrics.js +47 -32
- package/src/core/transaction.js +16 -288
- package/src/core/verification-scope.js +20 -12
- package/src/core/work-state.js +100 -59
- package/src/repository-index/binary-manager.js +15 -7
- package/src/storage/artifact-bytes.js +22 -0
- package/src/storage/attachment-binding.js +11 -0
- package/src/storage/attachment-files.js +82 -0
- package/src/storage/attachment-references.js +36 -0
- package/src/storage/backup.js +53 -0
- package/src/storage/capabilities.js +31 -0
- package/src/storage/connection-owner.js +119 -0
- package/src/storage/connection.js +376 -0
- package/src/storage/existing-project-scope.js +45 -0
- package/src/storage/export-destination.js +44 -0
- package/src/storage/exporter.js +284 -0
- package/src/storage/file-durability.js +46 -0
- package/src/storage/importer.js +461 -0
- package/src/storage/index.js +74 -0
- package/src/storage/leases.js +63 -0
- package/src/storage/ledger-event-snapshot.js +150 -0
- package/src/storage/ledger-relations.js +220 -0
- package/src/storage/legacy-maintenance-boundary.js +18 -0
- package/src/storage/legacy-signature.js +115 -0
- package/src/storage/maintenance-handoff.js +129 -0
- package/src/storage/maintenance-owner.js +42 -0
- package/src/storage/maintenance.js +310 -0
- package/src/storage/metadata-json.js +35 -0
- package/src/storage/migration-activate.js +59 -0
- package/src/storage/migration-archive.js +57 -0
- package/src/storage/migration-attachment-root.js +61 -0
- package/src/storage/migration-candidate.js +398 -0
- package/src/storage/migration-publication.js +143 -0
- package/src/storage/migration-rollback-admission.js +54 -0
- package/src/storage/migration-rollback-preparation.js +132 -0
- package/src/storage/migration-rollback-publication.js +183 -0
- package/src/storage/migration-rollback-release.js +66 -0
- package/src/storage/migration-rollback-source-stage.js +103 -0
- package/src/storage/migration-rollback.js +43 -0
- package/src/storage/migration-source-partition.js +56 -0
- package/src/storage/migration-source.js +255 -0
- package/src/storage/migration-terminal.js +39 -0
- package/src/storage/migration-validation.js +75 -0
- package/src/storage/migration.js +43 -0
- package/src/storage/operational-attachments.js +49 -0
- package/src/storage/operational-context.js +50 -0
- package/src/storage/project-backup.js +98 -0
- package/src/storage/project-bootstrap.js +24 -0
- package/src/storage/project-boundary.js +79 -0
- package/src/storage/project-read-snapshot.js +18 -0
- package/src/storage/project-replacement.js +137 -0
- package/src/storage/project-restore.js +203 -0
- package/src/storage/record-definitions.js +45 -0
- package/src/storage/repository.js +507 -0
- package/src/storage/restore-execution-provenance.js +26 -0
- package/src/storage/restore-journal.js +62 -0
- package/src/storage/restore-layout.js +30 -0
- package/src/storage/restore-preparation.js +84 -0
- package/src/storage/restore-replacement-archive.js +162 -0
- package/src/storage/restore-replacement-owner.js +31 -0
- package/src/storage/restore-replacement-preparation.js +128 -0
- package/src/storage/restore-replacement.js +142 -0
- package/src/storage/restore-terminal.js +32 -0
- package/src/storage/runtime.js +31 -0
- package/src/storage/schema.js +214 -0
- package/src/storage/singleton-import.js +84 -0
- package/src/storage/snapshot-continuity.js +16 -0
- package/src/storage/snapshot.js +36 -0
- package/src/storage/storage-marker.js +79 -0
- package/src/storage/task-guards.js +107 -0
- package/src/storage/topology.js +42 -0
- package/src/storage/transaction.js +179 -0
- package/src/storage/unit-of-work.js +667 -0
- package/src/storage/windows-process-incarnation.js +206 -0
- package/.forgeloop/forgeloop.gitignore +0 -4
- package/LICENSE-DOCS.md +0 -13
- package/src/core/transaction-maintenance.js +0 -70
|
@@ -2,8 +2,9 @@ import { classifyLoadedWorkState, readWorkState } from "./work-state.js";
|
|
|
2
2
|
import { taskArtifactPath } from "./task-paths.js";
|
|
3
3
|
import { readLockInfo, classifyLockStaleness } from "./task-lock.js";
|
|
4
4
|
import { validateStateLedgerCoherence } from "./events.js";
|
|
5
|
+
import { ledgerEventAt, ledgerEventsOfTypes } from "./ledger-event-collection.js";
|
|
5
6
|
import { currentRepositoryFingerprint } from "./repository.js";
|
|
6
|
-
import {
|
|
7
|
+
import { withTaskClaimEvidence, classifyTaskClaimState } from "./task-claim-state.js";
|
|
7
8
|
|
|
8
9
|
export const TASK_CONFLICT_CLASSIFICATIONS = Object.freeze([
|
|
9
10
|
"ACTIVE",
|
|
@@ -55,22 +56,25 @@ function checkCount(state, status) {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
function lastMeaningfulActivity(state, events) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
let latest = state?.lastUpdated && Number.isFinite(Date.parse(state.lastUpdated))
|
|
60
|
+
? { at: state.lastUpdated, type: "WORK_STATE_UPDATED" }
|
|
61
|
+
: null;
|
|
62
|
+
for (const event of ledgerEventsOfTypes(events, [...MEANINGFUL_ACTIVITY_EVENTS])) {
|
|
63
|
+
const timestamp = Date.parse(event.at);
|
|
64
|
+
if (Number.isFinite(timestamp) && (!latest || timestamp > Date.parse(latest.at))) {
|
|
65
|
+
latest = { at: event.at, type: event.event };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return latest;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
function isInitialTaskLedger(events, taskId) {
|
|
68
72
|
return events.length >= 2
|
|
69
|
-
&& events
|
|
70
|
-
&& events
|
|
71
|
-
&& events
|
|
72
|
-
&& events
|
|
73
|
-
&& events
|
|
73
|
+
&& ledgerEventAt(events, 0)?.taskId === taskId
|
|
74
|
+
&& ledgerEventAt(events, 0)?.event === "TASK_RECEIVED"
|
|
75
|
+
&& ledgerEventAt(events, 1)?.taskId === taskId
|
|
76
|
+
&& ledgerEventAt(events, 1)?.event === "TRANSACTION_COMMITTED"
|
|
77
|
+
&& ledgerEventAt(events, 1)?.details?.operation === "task-create"
|
|
74
78
|
&& !events.slice(2).some((event) => [
|
|
75
79
|
"CONTRACT_VALIDATED", "ROUTE_VALIDATED", "PREFLIGHT_READY", "EXECUTION_STARTED",
|
|
76
80
|
"VERIFICATION_STARTED", "VERIFICATION_RECORDED", "REVIEW_STARTED", "COMPLETION_VALIDATED",
|
|
@@ -129,7 +133,7 @@ export function classifyConflictEvidence(evidence, {
|
|
|
129
133
|
};
|
|
130
134
|
}
|
|
131
135
|
const KNOWN_PHASES = new Set([
|
|
132
|
-
"RECEIVED", "DISCOVERING", "CONTRACT_READY", "ROUTED", "DESIGNING", "PLANNED",
|
|
136
|
+
"RECEIVED", "DISCOVERING", "CONTRACT_READY", "ROUTED", "DESIGNING", "PLANNED", "BLOCKED",
|
|
133
137
|
...POST_EXECUTION_PHASES,
|
|
134
138
|
]);
|
|
135
139
|
const effectivePhase = phase ?? earlyPhase;
|
|
@@ -247,101 +251,102 @@ export async function inspectTaskConflictState(target, {
|
|
|
247
251
|
now = Date.now(),
|
|
248
252
|
ignoredLockId = null,
|
|
249
253
|
} = {}) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
254
|
+
return withTaskClaimEvidence(target, { packageRoot, taskId }, async ownershipEvidence => {
|
|
255
|
+
const [lockInfo, stateResult] = await Promise.all([
|
|
256
|
+
readLockInfo(target, taskId),
|
|
257
|
+
readWorkState(target, { packageRoot, taskId })
|
|
258
|
+
.then((value) => ({ value, error: null }))
|
|
259
|
+
.catch((error) => ({ value: null, error })),
|
|
260
|
+
]);
|
|
261
|
+
const claimProjection = classifyTaskClaimState(ownershipEvidence);
|
|
262
|
+
const state = stateResult.value;
|
|
263
|
+
const recovery = claimProjection.recovery;
|
|
264
|
+
|
|
265
|
+
const lockClassification = ignoredLockId && lockInfo?.lockId === ignoredLockId
|
|
266
|
+
? { status: "NONE", stale: false }
|
|
267
|
+
: classifyLockStaleness(lockInfo, now);
|
|
268
|
+
|
|
269
|
+
let freshness = null;
|
|
270
|
+
if (state) {
|
|
271
|
+
try {
|
|
272
|
+
freshness = await classifyLoadedWorkState({
|
|
273
|
+
target,
|
|
274
|
+
state,
|
|
275
|
+
contractFile: taskArtifactPath(taskId, "contract"),
|
|
276
|
+
});
|
|
277
|
+
} catch {
|
|
278
|
+
freshness = { status: "UNKNOWN", reasons: ["E_STATE_UNREADABLE"] };
|
|
279
|
+
}
|
|
275
280
|
}
|
|
276
|
-
}
|
|
277
281
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
282
|
+
// Reuse the ownership snapshot's already-validated ledger; no second full
|
|
283
|
+
// ledger parse inside this immutable inspection.
|
|
284
|
+
const coherenceErrors = ownershipEvidence.state && ownershipEvidence.ledger
|
|
285
|
+
? validateStateLedgerCoherence(ownershipEvidence.state, ownershipEvidence.ledger.events)
|
|
286
|
+
: [];
|
|
287
|
+
const ledgerValid = ownershipEvidence.ledger.valid && coherenceErrors.length === 0;
|
|
288
|
+
const ledgerEvents = ownershipEvidence.ledger.events;
|
|
289
|
+
const ledgerErrors = [...ownershipEvidence.ledger.errors, ...coherenceErrors];
|
|
290
|
+
|
|
291
|
+
const repository = await currentRepositoryFingerprint(target);
|
|
292
|
+
const initialTask = !state && ledgerValid && ownershipEvidence.descriptor
|
|
293
|
+
&& isInitialTaskLedger(ledgerEvents, taskId)
|
|
294
|
+
&& !ownershipEvidence.recovery;
|
|
295
|
+
const meaningfulActivity = lastMeaningfulActivity(state, ledgerEvents);
|
|
296
|
+
const recoveryConsistencyErrors = claimProjection.ownershipErrors ?? claimProjection.errors ?? [];
|
|
297
|
+
const healthReasonCodes = [
|
|
298
|
+
...(stateResult.error ? ["E_STATE_UNREADABLE"] : []),
|
|
299
|
+
...(claimProjection.ownershipValid === false
|
|
300
|
+
? claimProjection.reasonCodes
|
|
301
|
+
: []),
|
|
302
|
+
];
|
|
303
|
+
|
|
304
|
+
const evidence = {
|
|
305
|
+
healthy: healthReasonCodes.length === 0,
|
|
306
|
+
healthReasonCodes,
|
|
307
|
+
descriptorHealthy: true,
|
|
308
|
+
phase: state?.phase ?? (initialTask ? deriveEarlyPhase(ledgerEvents, taskId) : null),
|
|
309
|
+
lastUpdated: state?.lastUpdated ?? null,
|
|
310
|
+
lastMeaningfulActivityAt: meaningfulActivity?.at ?? null,
|
|
311
|
+
lastMeaningfulEventType: meaningfulActivity?.type ?? null,
|
|
312
|
+
workStateRevision: state?.revision ?? 0,
|
|
313
|
+
lockStatus: lockClassification.status,
|
|
314
|
+
lockId: lockInfo?.lockId ?? null,
|
|
315
|
+
lockExpiresAt: lockClassification.expiresAt ?? null,
|
|
316
|
+
freshnessStatus: freshness?.status ?? (initialTask ? "FRESH" : "UNKNOWN"),
|
|
317
|
+
freshnessReasons: freshness?.reasons ?? [],
|
|
318
|
+
ledgerValid,
|
|
319
|
+
ledgerLastSeq: ledgerEvents.at(-1)?.seq ?? 0,
|
|
320
|
+
ledgerErrors,
|
|
321
|
+
recordedChecks: passedCheckCount(state),
|
|
322
|
+
passedCheckCount: passedCheckCount(state),
|
|
323
|
+
failedCheckCount: checkCount(state, "failed"),
|
|
324
|
+
blockedCheckCount: checkCount(state, "blocked"),
|
|
325
|
+
totalChecks: state?.checks?.length ?? 0,
|
|
326
|
+
verificationEvidenceCount: state?.verificationEvidence?.length ?? 0,
|
|
327
|
+
recoveryStatus: claimProjection.claimState === "RELEASED_BY_RECOVERY"
|
|
328
|
+
? "RECOVERED"
|
|
329
|
+
: recovery?.status ?? null,
|
|
330
|
+
recoveryConsistencyErrors,
|
|
331
|
+
claimState: claimProjection.claimState,
|
|
332
|
+
historicalWriteClaims: claimProjection.historicalWriteClaims,
|
|
333
|
+
effectiveWriteClaims: claimProjection.effectiveWriteClaims,
|
|
334
|
+
mutationAllowed: claimProjection.mutationAllowed,
|
|
335
|
+
ownershipValid: claimProjection.ownershipValid,
|
|
336
|
+
ownershipErrors: recoveryConsistencyErrors,
|
|
337
|
+
repositoryBranch: repository.branch,
|
|
338
|
+
repositoryHead: repository.head,
|
|
339
|
+
};
|
|
336
340
|
|
|
337
|
-
|
|
341
|
+
const verdict = classifyConflictEvidence(evidence, { now });
|
|
338
342
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
343
|
+
return {
|
|
344
|
+
taskId,
|
|
345
|
+
classification: verdict.classification,
|
|
346
|
+
reasonCodes: verdict.reasonCodes,
|
|
347
|
+
recoverable: verdict.recoverable ?? false,
|
|
348
|
+
...(verdict.recoveredBy ? { recoveredBy: verdict.recoveredBy } : {}),
|
|
349
|
+
evidence,
|
|
350
|
+
};
|
|
351
|
+
});
|
|
347
352
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PROTOCOL_VERSION } from "./protocol.js";
|
|
2
|
-
import { readJsonArtifact, writeJsonArtifact } from "./artifacts.js";
|
|
2
|
+
import { readJsonArtifact, readPortableJsonArtifact, writeJsonArtifact } from "./artifacts.js";
|
|
3
3
|
import { assertSchema, readSchema } from "./schema-validation.js";
|
|
4
4
|
import { getPackageRoot } from "./templates.js";
|
|
5
5
|
import { assertTaskDescriptorIdentity, assertTaskId, taskStorageKey } from "./task-identity.js";
|
|
@@ -7,6 +7,8 @@ import { normalizeWriteClaims } from "./task-scope.js";
|
|
|
7
7
|
import { taskArtifactPath, TASK_STATE_ROOT } from "./task-paths.js";
|
|
8
8
|
import { assertSafePath, ensureWithin, fileExists } from "./filesystem.js";
|
|
9
9
|
import { E_TASK_DESCRIPTOR_INVALID, E_TASK_NOT_FOUND } from "./error-codes.js";
|
|
10
|
+
import { operationalArtifactExists } from "../storage/operational-context.js";
|
|
11
|
+
import { withNativeReadScope } from "./native-storage.js";
|
|
10
12
|
|
|
11
13
|
export const TASK_DESCRIPTOR_SCHEMA_VERSION = 1;
|
|
12
14
|
|
|
@@ -42,29 +44,34 @@ export async function validateTaskDescriptor(descriptor, packageRoot = getPackag
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export async function readTaskDescriptor(target, taskIdOrKey, packageRoot = getPackageRoot()) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
return withNativeReadScope(target, async () => {
|
|
48
|
+
// If it's a 64-char key, use it directly; otherwise derive storage key
|
|
49
|
+
const isKey = typeof taskIdOrKey === "string" && /^[a-f0-9]{64}$/.test(taskIdOrKey);
|
|
50
|
+
const relativePath = isKey
|
|
51
|
+
? `${TASK_STATE_ROOT}/${taskIdOrKey}/task.json`
|
|
52
|
+
: taskArtifactPath(taskIdOrKey, "descriptor");
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const operationalExists = operationalArtifactExists(target, relativePath);
|
|
55
|
+
if (operationalExists === null) await assertSafePath(target, relativePath);
|
|
56
|
+
const fullPath = ensureWithin(target, relativePath);
|
|
57
|
+
if (operationalExists === false || (operationalExists === null && !(await fileExists(fullPath)))) {
|
|
58
|
+
const error = new Error(`Task descriptor not found: ${relativePath}`);
|
|
59
|
+
error.code = E_TASK_NOT_FOUND;
|
|
60
|
+
error.artifacts = [relativePath];
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
await
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
// An unselected legacy descriptor is inspection input, never writable authority.
|
|
65
|
+
const reader = operationalExists === null ? readPortableJsonArtifact : readJsonArtifact;
|
|
66
|
+
const artifact = await reader(target, relativePath, "task-descriptor", packageRoot);
|
|
67
|
+
try {
|
|
68
|
+
await validateTaskDescriptor(artifact.value, packageRoot);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
error.code = E_TASK_DESCRIPTOR_INVALID;
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
return { ...artifact, ...artifact.value, value: artifact.value };
|
|
74
|
+
});
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
export async function writeTaskDescriptor(target, descriptor, packageRoot = getPackageRoot(), options = {}) {
|