dsh-completion-guard 0.7.1 → 0.8.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 +11 -0
- package/CHANGELOG.zh-CN.md +11 -0
- package/README.md +11 -11
- package/README.zh-CN.md +11 -11
- package/dist/domain/index.d.ts +2 -2
- package/dist/domain/index.js +2 -2
- package/dist/{domain-DbPbaoXp.js → domain-D0zTh3O_.js} +18336 -18640
- package/dist/{index-hiUtfKJa.d.ts → index-DMr57AgL.d.ts} +48 -115
- package/dist/index.d.ts +15 -3
- package/dist/index.js +483 -318
- package/docs/COMPATIBILITY.md +14 -41
- package/docs/DEVELOPMENT_PLAN_DSH_0_1_7_RC2.md +283 -0
- package/docs/DSH_0_1_7_RC2_ACCEPTANCE.md +57 -0
- package/docs/HOST_LOCK_UPGRADE.md +11 -8
- package/docs/LOCAL_ACCEPTANCE.md +4 -0
- package/docs/PORTING_NOTES.md +5 -1
- package/docs/README.md +2 -0
- package/docs/dsh-0.1.7-rc.2-planning-evidence.json +585 -0
- package/manifests/rc017-rc2-byte-audit.json +637 -0
- package/manifests/supported-host.v1.json +126 -1314
- package/package.json +40 -36
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { $ as PROOF_KINDS, $i as BOUNDED_ARTIFACT_TYPES, $n as capabilityConsequence, $r as statefulActionsOfScope, $t as reservationFor, A as PROTOCOL_V4_NOTICE, Ai as DEFAULT_HOST_LOCK, An as isCurrentAcceptedBoundary, Ar as interpretMessage, At as carriesCleanupCondition, B as extractToolSubject, Bi as evaluateToolSurfaceCapability, Bn as replayRebindResult, Br as legacyQuestionReadingIsInformational, Bt as sourceItemForCoreRequirement, C as SESSION_EVENT_ENVELOPE_INVALID, Ci as resolveActiveProfileHostLock, Cn as hasCurrentCertificate, Cr as clauseIsProtected, Ct as CLEANUP_CONDITION_RULE_COMPACT, D as CAPTURE_V042_NOTICE, Di as ACTIVE_HOST_COHORT_IDS, Dn as BOUNDARY_RECORD_PREFIX, Dr as hasQuestionScope, Dt as V6_ORDINARY_COMPLETION_RULE, E as projectCoreV2, Ei as ACTIVE_HOST_COHORT_ID, En as unitDescendantIds, Er as hasOrderedCoordination, Et as MIN_RECOVERY_CHAR_BUDGET, F as legacyRecordsNeedingReview, Fi as bindExecutableIdentity, Fn as proposeRebind, Fr as isOpenObligation, Ft as recoveryTitle, G as isRunExecutable, Gi as SUPPORTED_HOST_RANGE, Gn as deriveItemDiagnosis, Gr as opensWithDirective, Gt as inFlightReservation, H as persistedToolResultStatus, Hi as selectHostCohort, Hn as isFrozenV042RebindResponse, Hr as maskQuotedSpans, Ht as RELEASE_OPERATIONS, I as rootLocatorFlavor, Ii as bindLiveGoalCapability, In as proposeRebindOutcome, Ir as isQuestionScopeNeedingReview, It as renderRecoveryPacket, J as authorityCaptureCounts, Ji as evaluateMinimumHostVersion, Jn as nativeFileTwoRole, Jr as questionHeadsClause, Jt as normalizeSettlement, K as parsePwshCommand, Ki as SUPPORTED_HOST_VERSIONS, Kn as evidenceAvailabilityReason, Kr as presentExplanationHead, Kt as normalizeReleaseContract, L as supersedeItem, Li as evaluateExternalWaitCapability, Ln as proposeRebindV042, Lr as isRestatement, Lt as v6CurrentRootBoundaries, M as PROTOCOL_V6_NOTICE, Mi as GOAL_HOST_PACKAGES, Mn as currentContractDigest, Mr as isExecutableItem, Mt as closingHint, N as applyUpgradeEligibility, Ni as HOST_CAPABILITY_PACKAGE_GROUPS, Nn as createProjection, Nr as isExplanationScope, Nt as openItems, O as DEFAULT_DELEGATION_TOOL_NAMES, Oi as ACTIVE_HOST_LAUNCHER_VERSION, On as availableBoundaryQualifications, Or as hasWorkPredicate, Ot as V6_ORDINARY_COMPLETION_RULE_COMPACT, P as deriveProjection, Pi as HOST_COHORTS, Pn as confirmRebind, Pr as isInformationalFragment, Pt as recoveryDigest, Q as PROOF_CAPABILITY_MATRIX, Qi as ACTION_MANIFEST_VERSION, Qn as admissibleForRemoval, Qr as splitTextFragments, Qt as releasePreEffectDecision, R as evidenceFromPersistedToolResult, Ri as evaluateHostCapability, Rn as rebindAttemptKey, Rr as itemHoldsExecutionAuthority, Rt as currentV6Feedback, S as SESSION_API_UNSUPPORTED, Si as readActiveHostGraph, Sn as goalCompletionDenial, Sr as clauseIsGoverned, St as CLEANUP_CONDITION_RULE, T as snapshotSessionEvents, Ti as verifyComposedHostLockDump, Tn as certificateClosure, Tr as governedClauseRestrictsExecution, Tt as DEFAULT_RECOVERY_CHAR_BUDGET, U as withDurability, Ui as LATEST_SUPPORTED_HOST_VERSION, Un as parseConfirmationMessage, Ur as namedActions, Ut as RELEASE_OPERATION_SURFACES, V as isDeterministicCheck, Vi as hostVersionFromPackages, Vn as CONFIRM_LINE_PATTERN, Vr as maskCodeSpans, Vt as OUTCOME_STRENGTH, W as canonicalArgvFromCommand, Wi as MIN_SUPPORTED_HOST_VERSION, Wn as capabilityRemedyPhrase, Wr as opensConditionLead, Wt as contractById, X as bindingIndividuallyAccepted, Xi as satisfiesSupportedHostRange, Xn as DEPENDENCY_FREE_ONLY_CONDITION, Xr as restatedContentOf, Xt as releaseContractFor, Y as segmentAuthorityBlocks, Yi as parseHostVersion, Yn as relevantEvidence, Yr as reportingHeadGoverns, Yt as readbackSettlesContract, Z as certifyCheckpoint, Zi as ACTION_MANIFEST, Zn as actionHasCertificationPath, Zr as semanticActionOfScope, Zt as releaseCoverage, _ as projectSessionCoreV2, _a as RC017_RC2_HOST_PACKAGES, _i as hostLockRowsFromComposedDump, _n as latestRootInstruction, _r as GRANTED_QUALIFICATION, _t as scopeCoverageDigest, a as createGitPrestateEnvelope, aa as STOP_PROTOCOL_VERSION_V2, ai as normalizeClause, an as NO_PROGRESS_RECORD_PREFIX, ar as captureItem, at as bindProofV2ToProjection, b as captureHostWorkdir, bi as packageRowsFromActiveGraph, bn as testOutcomePredicate, br as clarifiedSpanOf, bt as validateProofManifest, c as parseGitCommandManifest, ca as boundedArtifactChoiceMatches, ci as sha256, cn as assessmentOutcomePredicate, cr as extractArtifactPaths, ct as createProofManifestV2, d as FIRST_STEP_GUIDANCE, da as requestedTargetAuthorizesMutation, di as auditedDefaultWorkdirHost, dn as decideTurnBoundary, dr as isInformationalMessage, dt as proofDigestV2, ea as CERTIFICATE_VERSION, ei as verbIsNegated, en as bindingSatisfies, er as capabilityFactOf, et as PROOF_KINDS_V2, f as claimedBatchHasRealRootInput, fa as requestedTargetMatchesResolved, fi as auditedDefaultWorkdirProvider, fn as decideTurnStopping, fr as segmentClauses, ft as proofEvidenceConstraints, g as previewFirstStepInjection, ga as validateActionTarget, gi as hostLockContextFromComposedDump, gn as latestAssistantText, gr as classifyUserInteraction, gt as requiredSubjectsOf, h as lifecyclePhase, ha as validateActionManifest, hi as combineHostPolicy, hn as isWholeTaskCompletionClaim, hr as classifyTaskIntent, ht as proofV2Rejection, i as commitTreeSnapshotDigest, ia as STOP_PROTOCOL_VERSION, ii as digestStrings, in as CONTROL_RECORD_PREFIX, ir as captureClause, it as bindProofToProjection, j as PROTOCOL_V5_NOTICE, ji as EXPECTED_HOST_PACKAGES, jn as qualifyBoundary, jr as introducesActionClause, jt as cleanupConditionFor, k as PROTOCOL_V3_NOTICE, ki as BASE_HOST_PACKAGES, kn as effectuateBoundary, kr as interpretClause, kt as V6_ORDINARY_COMPLETION_RULE_SHORT, l as revalidateGitPrestate, la as isStatefulAction, li as HostProfileError, ln as classifyCompletionClaim, lr as extractMethod, lt as proofCapabilityReport, m as firstStepGuidanceV6, ma as semanticActionFromText, mi as auditedHostImplementation, mn as isRootPauseRequest, mr as npmEscapedPackageName, mt as proofOperationMatches, n as GIT_COMMAND_TEMPLATES, na as SEMANTIC_ACTIONS, ni as validateManifest, nn as evidenceMatchesItem, nr as removalIsComplete, nt as PROOF_PROTOCOL_VERSION, o as executeRevalidatedGitEffect, oa as SUPPORTED_EVIDENCE_ADAPTERS, oi as sanitizeClauseText, on as NO_PROGRESS_TURNS_BEFORE_STOP, or as classifyClause, ot as canonicalProjection, p as firstStepGuidance, pa as semanticActionFromCommand, pi as auditedForegroundRenderers, pn as decisionBoundaryKey, pr as canonicalRegistryBase, pt as proofHostSurfacesOf, q as parseShellCommand, qi as compareHostVersions, qn as itemDiagnosis, qr as qualificationOfClause, qt as normalizeReservation, r as commitIndexSnapshotDigest, ra as STATEFUL_ACTIONS, ri as canonicalizePath, rn as isVerifyingCapability, rr as removalIsPartiallyKnown, rt as PROOF_PROTOCOL_VERSION_V2, s as gitCommandMatchesTarget, sa as actionCompatible, si as sanitizeUrl, sn as assessmentAction, sr as environmentDefaultRepositoryTarget, st as createProofManifest, t as GIT_COMMAND_MANIFEST_IDS, ta as CERTIFICATE_VERSION_V2, ti as COMMAND_SURFACE_MANIFEST, tn as evidenceCoverage, tr as partialFailureOf, tt as PROOF_MANIFEST_DOMAIN_V2, u as verifiedLinearCommitReadback, ua as requestedIdentityKey, ui as activeRendererModule, un as currentActionBases, ur as extractOperation, ut as proofDigest, v as sessionCoreSnapshot, vi as injectActiveProfileHostLock, vn as observeAssistantOutcome, vr as LEGACY_QUALIFICATION, vt as sessionQuery, w as SessionApiError, wi as resolveInstalledHostLock, wn as certifiableOpenItems, wr as explanationHasActionResidue, wt as CLEANUP_CONDITION_RULE_SHORT, x as sourcedNamedTestRoot, xi as packageRowsFromPnpmLock, xn as v6TestPredicate, xr as clauseAsksOwnQuestion, xt as validateProofManifestV2, y as HOST_WORKDIR_PREFIX, yi as inspectTargetHostGraph, yn as progressFingerprint, yr as actionVerbMatches, yt as sessionQueryV2, z as extractTextContent, zi as evaluateHostLock, zn as rebindResponse, zr as kindOfScope, zt as isV6PendingRootWait } from "./domain-D0zTh3O_.js";
|
|
2
|
+
import { boundContextSummary, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { closeSync, constants, existsSync, fchmodSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, unlinkSync, writeSync } from "node:fs";
|
|
4
4
|
import { basename, delimiter, dirname, isAbsolute, join, posix, resolve, win32 } from "node:path";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { JobId } from "@deepseek-ai/dsh-jobs";
|
|
8
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
5
9
|
import { homedir, tmpdir } from "node:os";
|
|
6
|
-
import { boundContextSummary, createToolResultMessage, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
7
|
-
import { closeSync, constants, existsSync, fchmodSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, unlinkSync, writeSync } from "node:fs";
|
|
8
10
|
import { promisify } from "node:util";
|
|
9
11
|
import { execFile } from "node:child_process";
|
|
10
12
|
import { access, readFile, realpath } from "node:fs/promises";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
12
13
|
import { gunzip } from "node:zlib";
|
|
13
14
|
import { SESSION_FORMAT_VERSION, Session, SessionId } from "@deepseek-ai/dsh-session";
|
|
14
15
|
|
|
@@ -62,6 +63,18 @@ function createRebindTool(getProjection, prepare) {
|
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/tools/cursor-identity.ts
|
|
68
|
+
/** The Session observation watermark advances when a read-only Guard tool
|
|
69
|
+
* records its own result. It is not a change to the current business state.
|
|
70
|
+
* Keep every other core field in cursor identity so changed predicates,
|
|
71
|
+
* actions, coverage, and release state still invalidate a page. */
|
|
72
|
+
function semanticCoreCursorState(core) {
|
|
73
|
+
if (!core) return null;
|
|
74
|
+
const { as_of: _observationWatermark,...semantic } = core;
|
|
75
|
+
return semantic;
|
|
76
|
+
}
|
|
77
|
+
|
|
65
78
|
//#endregion
|
|
66
79
|
//#region src/tools/checkpoint-page.ts
|
|
67
80
|
const LANES = [
|
|
@@ -86,7 +99,7 @@ function checkpointPage(p, query, full) {
|
|
|
86
99
|
revision: p.contractRevision,
|
|
87
100
|
evidence: [...p.evidence.values()],
|
|
88
101
|
items: [...p.items.values()],
|
|
89
|
-
...full.current_feedback === true ? { current_core: p.coreV2 } : {},
|
|
102
|
+
...full.current_feedback === true ? { current_core: semanticCoreCursorState(p.coreV2) } : {},
|
|
90
103
|
item_ids,
|
|
91
104
|
evidence_ids,
|
|
92
105
|
evidence_scope,
|
|
@@ -292,38 +305,70 @@ function bindingTemplate(projection, item) {
|
|
|
292
305
|
const action = item.semanticAction;
|
|
293
306
|
if (!action || action === "generic_run") return void 0;
|
|
294
307
|
const evidence = evidenceForAction(projection, item);
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
resolution.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
308
|
+
const effects = evidence.filter((entry) => (entry.evidenceRole ?? "effect") === "effect");
|
|
309
|
+
for (const effect of effects.reverse()) {
|
|
310
|
+
if (!effect.resolvedTarget) continue;
|
|
311
|
+
const resolved = effect.resolvedTarget;
|
|
312
|
+
const nativeFile = projection.boundaryProtocol === 6 && action === "modify" && !item.legacyFlags?.length && ["edit", "edit_file"].includes(effect.toolName);
|
|
313
|
+
const states = nativeFile ? evidence.filter((entry) => entry.evidenceRole === "state" && entry.causedByCallId === effect.callId) : isStatefulAction(action) ? evidence.filter((entry) => entry.evidenceRole === "state" && sameTuple(entry.resolvedTarget, resolved)) : [];
|
|
314
|
+
const resolution = !nativeFile && isStatefulAction(action) ? evidence.find((entry) => entry.evidenceRole === "resolution" && sameTuple(entry.resolvedTarget, resolved)) : void 0;
|
|
315
|
+
if (isStatefulAction(action) && !nativeFile && (!resolution || states.length === 0 || !resolution.expectedTransition?.parameters || !resolution.expectedTransitionDigest)) continue;
|
|
316
|
+
const candidates = nativeFile ? states.map((state) => [state]) : [states];
|
|
317
|
+
for (const chosen of candidates) {
|
|
318
|
+
if (nativeFile && chosen.length !== 1) continue;
|
|
319
|
+
const observed = nativeFile ? { post_digest: chosen[0]?.observedState?.post_digest ?? "" } : isStatefulAction(action) ? Object.assign({}, ...chosen.map((entry) => entry.observedState ?? {})) : effect.observedState ?? {};
|
|
320
|
+
const expectedTransition = nativeFile ? {
|
|
321
|
+
predicateId: ACTION_MANIFEST.actions[action].predicateId,
|
|
322
|
+
version: 1,
|
|
323
|
+
predParamsKind: "inline",
|
|
324
|
+
parameters: observed
|
|
325
|
+
} : isStatefulAction(action) ? resolution.expectedTransition : {
|
|
326
|
+
predicateId: ACTION_MANIFEST.actions[action].predicateId,
|
|
327
|
+
version: 1,
|
|
328
|
+
predParamsKind: "inline",
|
|
329
|
+
parameters: expectedParameters(action, resolved, observed)
|
|
330
|
+
};
|
|
331
|
+
const binding = {
|
|
332
|
+
itemId: item.id,
|
|
333
|
+
evidenceIds: nativeFile ? [effect.id, chosen[0].id] : isStatefulAction(action) ? [
|
|
334
|
+
resolution.id,
|
|
335
|
+
effect.id,
|
|
336
|
+
...chosen.map((entry) => entry.id)
|
|
337
|
+
] : [effect.id],
|
|
338
|
+
semanticAction: action,
|
|
339
|
+
requestedTarget: item.requestedTarget,
|
|
340
|
+
resolvedTarget: resolved,
|
|
341
|
+
observedState: observed,
|
|
342
|
+
expectedTransition,
|
|
343
|
+
...nativeFile ? {
|
|
344
|
+
effectEvidenceId: effect.id,
|
|
345
|
+
stateEvidenceIds: [chosen[0].id]
|
|
346
|
+
} : isStatefulAction(action) ? {
|
|
347
|
+
resolutionEvidenceId: resolution.id,
|
|
348
|
+
effectEvidenceId: effect.id,
|
|
349
|
+
stateEvidenceIds: chosen.map((entry) => entry.id)
|
|
350
|
+
} : { effectEvidenceId: effect.id }
|
|
351
|
+
};
|
|
352
|
+
if (!bindingIndividuallyAccepted(projection, item, binding)) continue;
|
|
353
|
+
return {
|
|
354
|
+
item_id: item.id,
|
|
355
|
+
evidence_ids: binding.evidenceIds,
|
|
356
|
+
semantic_action: action,
|
|
357
|
+
requested_target: targetForTool(item.requestedTarget),
|
|
358
|
+
resolved_target: targetForTool(resolved),
|
|
359
|
+
observed_state: targetForTool(observed),
|
|
360
|
+
expected_transition: expectedTransitionForTool(expectedTransition),
|
|
361
|
+
...nativeFile ? {
|
|
362
|
+
effect_evidence_id: effect.id,
|
|
363
|
+
state_evidence_ids: [chosen[0].id]
|
|
364
|
+
} : isStatefulAction(action) ? {
|
|
365
|
+
resolution_evidence_id: resolution.id,
|
|
366
|
+
effect_evidence_id: effect.id,
|
|
367
|
+
state_evidence_ids: chosen.map((entry) => entry.id)
|
|
368
|
+
} : { effect_evidence_id: effect.id }
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
327
372
|
}
|
|
328
373
|
function openItemForTool(projection, item) {
|
|
329
374
|
const action = item.semanticAction ?? "generic_run";
|
|
@@ -357,7 +402,7 @@ function openItemForTool(projection, item) {
|
|
|
357
402
|
predicate: {
|
|
358
403
|
predicate_id: spec.predicateId,
|
|
359
404
|
version: 1,
|
|
360
|
-
parameters_source: isStatefulAction(action) ? "resolution_evidence_expected_transition" : "versioned_action_manifest",
|
|
405
|
+
parameters_source: nativeFileTwoRole(projection, item) ? "native_state_readback" : isStatefulAction(action) ? "resolution_evidence_expected_transition" : "versioned_action_manifest",
|
|
361
406
|
resolved_target_keys: spec.resolvedTargetKeys,
|
|
362
407
|
observed_state_keys: spec.observedStateKeys,
|
|
363
408
|
pred_params_kind: "inline"
|
|
@@ -1495,7 +1540,6 @@ function createPrepareTool(options) {
|
|
|
1495
1540
|
}
|
|
1496
1541
|
if (args.item_id === void 0) {
|
|
1497
1542
|
const filter = args.semantic_action ?? null;
|
|
1498
|
-
const coreIdentity = currentFeedback ? sha256(JSON.stringify(p.coreV2 ?? null)) : void 0;
|
|
1499
1543
|
const invalidCursor = (reason_code, note) => ({
|
|
1500
1544
|
status: "rejected",
|
|
1501
1545
|
reason_code,
|
|
@@ -1503,6 +1547,15 @@ function createPrepareTool(options) {
|
|
|
1503
1547
|
contract_revision: p.contractRevision,
|
|
1504
1548
|
...note !== void 0 ? { note } : { note: "Re-run discovery without page_cursor to list from the first page." }
|
|
1505
1549
|
});
|
|
1550
|
+
const eligible = discoveryItemIds(p).map((id) => ({
|
|
1551
|
+
id,
|
|
1552
|
+
sourced: currentFeedback ? sourceItemForCoreRequirement(p, id) : void 0,
|
|
1553
|
+
item: currentFeedback ? sourceItemForCoreRequirement(p, id)?.item : p.items.get(id)
|
|
1554
|
+
})).filter((entry) => entry.item !== void 0).filter(({ item: item$1, sourced }) => filter === null || (sourced?.origin?.action ?? item$1.semanticAction ?? "generic_run") === filter);
|
|
1555
|
+
const coreIdentity = currentFeedback ? sha256(JSON.stringify({
|
|
1556
|
+
core: semanticCoreCursorState(p.coreV2),
|
|
1557
|
+
listing: eligible.map(({ id, item: item$1 }) => [id, item$1.revision])
|
|
1558
|
+
})) : void 0;
|
|
1506
1559
|
let startAfter;
|
|
1507
1560
|
if (args.page_cursor !== void 0) {
|
|
1508
1561
|
let parsed;
|
|
@@ -1520,11 +1573,6 @@ function createPrepareTool(options) {
|
|
|
1520
1573
|
if ((parsed.f ?? null) !== (filter ?? null)) return invalidCursor("discovery_cursor_filter_mismatch");
|
|
1521
1574
|
startAfter = parsed.k;
|
|
1522
1575
|
}
|
|
1523
|
-
const eligible = discoveryItemIds(p).map((id) => ({
|
|
1524
|
-
id,
|
|
1525
|
-
sourced: currentFeedback ? sourceItemForCoreRequirement(p, id) : void 0,
|
|
1526
|
-
item: currentFeedback ? sourceItemForCoreRequirement(p, id)?.item : p.items.get(id)
|
|
1527
|
-
})).filter((entry) => entry.item !== void 0).filter(({ item: item$1, sourced }) => filter === null || (sourced?.origin?.action ?? item$1.semanticAction ?? "generic_run") === filter);
|
|
1528
1576
|
const startIndex = startAfter === void 0 ? 0 : eligible.findIndex(({ id, item: item$1 }) => item$1.revision === startAfter[0] && id === startAfter[1]) + 1;
|
|
1529
1577
|
if (startAfter !== void 0 && startIndex <= 0) return invalidCursor("discovery_cursor_stale", "The cursor names an item no longer in the current listing. Re-run discovery without page_cursor.");
|
|
1530
1578
|
const page = eligible.slice(startIndex, startIndex + DISCOVERY_ITEM_LIMIT);
|
|
@@ -1654,7 +1702,7 @@ function createPrepareTool(options) {
|
|
|
1654
1702
|
resolved_target: evidence.resolvedTarget,
|
|
1655
1703
|
tool_result_seq: evidence.toolResultSeq
|
|
1656
1704
|
}));
|
|
1657
|
-
const requiredOrder = plannedAction && isStatefulAction(plannedAction) ? [
|
|
1705
|
+
const requiredOrder = nativeFileTwoRole(p, item) ? ["effect (the persisted native edit result)", "state (independent context_guard_observe_file readback)"] : plannedAction && isStatefulAction(plannedAction) ? [
|
|
1658
1706
|
"resolution (prestate facts from a trusted read)",
|
|
1659
1707
|
"effect (the exact planned change)",
|
|
1660
1708
|
"state (independent post-state readback)"
|
|
@@ -1867,7 +1915,7 @@ function restartIntent(events, resolutionCallId, target) {
|
|
|
1867
1915
|
if (!event || event.type !== "user/message") continue;
|
|
1868
1916
|
const data = record$1(event.data);
|
|
1869
1917
|
const source = record$1(data?.source);
|
|
1870
|
-
if (source?.kind !== "plugin" || source.plugin !== "context-guard" || source.form !== "notice") continue;
|
|
1918
|
+
if (source?.kind !== "plugin" && source?.kind !== "context-guard" || source.plugin !== "context-guard" || source.form !== "notice") continue;
|
|
1871
1919
|
const content = Array.isArray(data?.content) ? data.content : [];
|
|
1872
1920
|
const block = content.length === 1 ? record$1(content[0]) : void 0;
|
|
1873
1921
|
const text = typeof block?.text === "string" ? block.text : "";
|
|
@@ -4245,12 +4293,12 @@ function createExternalOperationTool(read, capability) {
|
|
|
4245
4293
|
reason_code: "host_jobs_capability_unavailable",
|
|
4246
4294
|
adapter_id: "dsh.jobs.v1"
|
|
4247
4295
|
});
|
|
4248
|
-
const snapshot = read(args.operation_id, exec.agent);
|
|
4249
|
-
return Promise.resolve(snapshot ? {
|
|
4250
|
-
status: snapshot.status,
|
|
4251
|
-
operation_id: snapshot.id,
|
|
4296
|
+
const snapshot$1 = read(args.operation_id, exec.agent);
|
|
4297
|
+
return Promise.resolve(snapshot$1 ? {
|
|
4298
|
+
status: snapshot$1.status,
|
|
4299
|
+
operation_id: snapshot$1.id,
|
|
4252
4300
|
reason_code: "external_operation_readback",
|
|
4253
|
-
adapter_id: snapshot.adapterId
|
|
4301
|
+
adapter_id: snapshot$1.adapterId
|
|
4254
4302
|
} : {
|
|
4255
4303
|
status: "unknown",
|
|
4256
4304
|
operation_id: args.operation_id,
|
|
@@ -4536,7 +4584,7 @@ function createContextGuardCommand(projectionFor, setEnabled, clearContract, lif
|
|
|
4536
4584
|
}
|
|
4537
4585
|
|
|
4538
4586
|
//#endregion
|
|
4539
|
-
//#region node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.
|
|
4587
|
+
//#region node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.5/node_modules/@deepseek-ai/cosmokit/lib/index.js
|
|
4540
4588
|
/** Return true when a value is `null` or `undefined`. */
|
|
4541
4589
|
function isNullable(value) {
|
|
4542
4590
|
return value === null || value === void 0;
|
|
@@ -4560,6 +4608,43 @@ function pick(source, keys, forced) {
|
|
|
4560
4608
|
for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
|
|
4561
4609
|
return result;
|
|
4562
4610
|
}
|
|
4611
|
+
/** Shared config references used by schema validators and plugin runtimes. */
|
|
4612
|
+
const write = Symbol.for("cosmokit.volatile.write");
|
|
4613
|
+
function snapshot(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
4614
|
+
if (typeof value === "function") throw new TypeError("volatile config cannot contain functions");
|
|
4615
|
+
if (value === null || typeof value !== "object") return value;
|
|
4616
|
+
if (ancestors.has(value)) throw new TypeError("volatile config cannot contain cycles");
|
|
4617
|
+
ancestors.add(value);
|
|
4618
|
+
try {
|
|
4619
|
+
if (Array.isArray(value)) return Object.freeze(value.map((item) => snapshot(item, ancestors)));
|
|
4620
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new TypeError("volatile config objects must be plain objects or arrays");
|
|
4621
|
+
return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])));
|
|
4622
|
+
} finally {
|
|
4623
|
+
ancestors.delete(value);
|
|
4624
|
+
}
|
|
4625
|
+
}
|
|
4626
|
+
/**
|
|
4627
|
+
* Create a detached reference containing an immutable copy of the supplied data.
|
|
4628
|
+
* @param value - validated config data; class instances and functions are unsupported.
|
|
4629
|
+
* @returns a reference whose value is updated only by its owning runtime.
|
|
4630
|
+
*/
|
|
4631
|
+
function createVolatile(value) {
|
|
4632
|
+
let current = snapshot(value);
|
|
4633
|
+
return Object.freeze({
|
|
4634
|
+
get: () => current,
|
|
4635
|
+
[write]: (value$1) => {
|
|
4636
|
+
current = value$1;
|
|
4637
|
+
}
|
|
4638
|
+
});
|
|
4639
|
+
}
|
|
4640
|
+
/**
|
|
4641
|
+
* Identify references across ESM/CJS copies of the shared library.
|
|
4642
|
+
* @param value - a parsed config value.
|
|
4643
|
+
* @returns whether the value implements the shared reference protocol.
|
|
4644
|
+
*/
|
|
4645
|
+
function isVolatile(value) {
|
|
4646
|
+
return typeof value === "object" && value !== null && write in value;
|
|
4647
|
+
}
|
|
4563
4648
|
/** Test values using `instanceof` with a `toStringTag` fallback. */
|
|
4564
4649
|
function is(type, value) {
|
|
4565
4650
|
if (arguments.length === 1) return (value$1) => is(type, value$1);
|
|
@@ -4644,26 +4729,47 @@ function clone(source, refs = /* @__PURE__ */ new Map()) {
|
|
|
4644
4729
|
}
|
|
4645
4730
|
return result;
|
|
4646
4731
|
}
|
|
4647
|
-
/**
|
|
4732
|
+
/**
|
|
4733
|
+
* Compare values recursively, treating two volatile references as equal regardless of value.
|
|
4734
|
+
* Strict comparison distinguishes null/undefined, treats opaque objects by identity,
|
|
4735
|
+
* compares URLs by normalized href, treats array holes as undefined, and considers distinct cyclic structures unequal.
|
|
4736
|
+
* @param a - first value.
|
|
4737
|
+
* @param b - second value.
|
|
4738
|
+
* @param strict - whether to require strict data equality outside volatile references.
|
|
4739
|
+
* @returns whether the values compare equal.
|
|
4740
|
+
*/
|
|
4648
4741
|
function deepEqual(a, b, strict) {
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4742
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
4743
|
+
function compare(a$1, b$1) {
|
|
4744
|
+
if (a$1 === b$1) return true;
|
|
4745
|
+
if (isVolatile(a$1) || isVolatile(b$1)) return isVolatile(a$1) && isVolatile(b$1);
|
|
4746
|
+
if (!strict && isNullable(a$1) && isNullable(b$1)) return true;
|
|
4747
|
+
if (typeof a$1 !== typeof b$1 || typeof a$1 !== "object" || !a$1 || !b$1) return false;
|
|
4748
|
+
if (ancestors.has(a$1)) return false;
|
|
4749
|
+
function check(test, then) {
|
|
4750
|
+
return test(a$1) ? test(b$1) ? then(a$1, b$1) : false : test(b$1) ? false : void 0;
|
|
4751
|
+
}
|
|
4752
|
+
ancestors.add(a$1);
|
|
4753
|
+
try {
|
|
4754
|
+
return check(Array.isArray, (a$2, b$2) => {
|
|
4755
|
+
if (a$2.length !== b$2.length) return false;
|
|
4756
|
+
for (let index = 0; index < a$2.length; index++) if (!compare(a$2[index], b$2[index])) return false;
|
|
4757
|
+
return true;
|
|
4758
|
+
}) ?? check(is("Date"), (a$2, b$2) => a$2.valueOf() === b$2.valueOf()) ?? check(is("URL"), (a$2, b$2) => a$2.href === b$2.href) ?? check(is("RegExp"), (a$2, b$2) => a$2.source === b$2.source && a$2.flags === b$2.flags) ?? check(isArrayBufferLike, (a$2, b$2) => {
|
|
4759
|
+
if (a$2.byteLength !== b$2.byteLength) return false;
|
|
4760
|
+
const viewA = new Uint8Array(a$2);
|
|
4761
|
+
const viewB = new Uint8Array(b$2);
|
|
4762
|
+
for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
|
|
4763
|
+
return true;
|
|
4764
|
+
}) ?? ((!strict || [a$1, b$1].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({
|
|
4765
|
+
...a$1,
|
|
4766
|
+
...b$1
|
|
4767
|
+
}).every((key) => compare(a$1[key], b$1[key])));
|
|
4768
|
+
} finally {
|
|
4769
|
+
ancestors.delete(a$1);
|
|
4770
|
+
}
|
|
4656
4771
|
}
|
|
4657
|
-
return
|
|
4658
|
-
if (a$1.byteLength !== b$1.byteLength) return false;
|
|
4659
|
-
const viewA = new Uint8Array(a$1);
|
|
4660
|
-
const viewB = new Uint8Array(b$1);
|
|
4661
|
-
for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
|
|
4662
|
-
return true;
|
|
4663
|
-
}) ?? Object.keys({
|
|
4664
|
-
...a,
|
|
4665
|
-
...b
|
|
4666
|
-
}).every((key) => deepEqual(a[key], b[key], strict));
|
|
4772
|
+
return compare(a, b);
|
|
4667
4773
|
}
|
|
4668
4774
|
/** Time constants plus parsing and formatting helpers. */
|
|
4669
4775
|
var Time;
|
|
@@ -4737,7 +4843,7 @@ var Time;
|
|
|
4737
4843
|
})(Time || (Time = {}));
|
|
4738
4844
|
|
|
4739
4845
|
//#endregion
|
|
4740
|
-
//#region node_modules/.pnpm/@deepseek-ai+schemastery@3.18.
|
|
4846
|
+
//#region node_modules/.pnpm/@deepseek-ai+schemastery@3.18.4/node_modules/@deepseek-ai/schemastery/lib/index.mjs
|
|
4741
4847
|
const kSchema = Symbol.for("schemastery");
|
|
4742
4848
|
const kValidationError = Symbol.for("ValidationError");
|
|
4743
4849
|
globalThis.__schemastery_index__ ??= 0;
|
|
@@ -4913,6 +5019,7 @@ Schema.prototype.pattern = function pattern(regexp) {
|
|
|
4913
5019
|
return schema;
|
|
4914
5020
|
};
|
|
4915
5021
|
Schema.prototype.simplify = function simplify(value) {
|
|
5022
|
+
if (isVolatile(value)) value = value.get();
|
|
4916
5023
|
if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
|
|
4917
5024
|
if (isNullable(value)) return value;
|
|
4918
5025
|
if (this.type === "object" || this.type === "dict") {
|
|
@@ -4969,12 +5076,49 @@ for (const key of [
|
|
|
4969
5076
|
};
|
|
4970
5077
|
return schema;
|
|
4971
5078
|
} });
|
|
5079
|
+
Schema.prototype.volatile = function volatile() {
|
|
5080
|
+
if (this.meta.volatile) throw new TypeError("volatile schema is already wrapped");
|
|
5081
|
+
return this.extra("volatile", true);
|
|
5082
|
+
};
|
|
4972
5083
|
const resolvers = {};
|
|
5084
|
+
const checkedVolatile = Symbol("checked-volatile-schema");
|
|
5085
|
+
function validateVolatileSchema(schema, path = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
|
|
5086
|
+
const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
|
|
5087
|
+
if (states.has(blocked)) return;
|
|
5088
|
+
states.add(blocked);
|
|
5089
|
+
seen.set(schema, states);
|
|
5090
|
+
if (schema.meta?.volatile && blocked) throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path });
|
|
5091
|
+
const nested = blocked || !!schema.meta?.volatile;
|
|
5092
|
+
if (schema.dict) for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path, key], nested, seen);
|
|
5093
|
+
if (schema.sKey) validateVolatileSchema(schema.sKey, [...path, "<key>"], true, seen);
|
|
5094
|
+
if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) validateVolatileSchema(schema.inner, [...path, "*"], true, seen);
|
|
5095
|
+
if (schema.list) for (let index = 0; index < schema.list.length; index++) validateVolatileSchema(schema.list[index], [...path, String(index)], true, seen);
|
|
5096
|
+
}
|
|
4973
5097
|
Schema.extend = function extend(type, resolve$1) {
|
|
4974
5098
|
resolvers[type] = resolve$1;
|
|
4975
5099
|
};
|
|
4976
5100
|
Schema.resolve = function resolve$1(data, schema, options = {}, strict = false) {
|
|
4977
5101
|
if (!schema) return [data];
|
|
5102
|
+
if (!options[checkedVolatile]) {
|
|
5103
|
+
validateVolatileSchema(schema, options.path);
|
|
5104
|
+
options = {
|
|
5105
|
+
...options,
|
|
5106
|
+
[checkedVolatile]: true
|
|
5107
|
+
};
|
|
5108
|
+
}
|
|
5109
|
+
if (schema.meta?.volatile) {
|
|
5110
|
+
const inner = Schema(schema);
|
|
5111
|
+
inner.meta = {
|
|
5112
|
+
...schema.meta,
|
|
5113
|
+
volatile: false
|
|
5114
|
+
};
|
|
5115
|
+
const [value, adapted] = Schema.resolve(data, inner, options, strict);
|
|
5116
|
+
try {
|
|
5117
|
+
return [createVolatile(value), adapted];
|
|
5118
|
+
} catch (error) {
|
|
5119
|
+
throw new ValidationError(error instanceof Error ? error.message : String(error), options);
|
|
5120
|
+
}
|
|
5121
|
+
}
|
|
4978
5122
|
if (options.ignore?.(data, schema)) return [data];
|
|
4979
5123
|
if (isNullable(data) && schema.type !== "lazy") {
|
|
4980
5124
|
if (schema.meta.required) throw new ValidationError(`missing required value`, options);
|
|
@@ -5077,6 +5221,7 @@ Schema.extend("lazy", (data, schema, options, strict) => {
|
|
|
5077
5221
|
...schema.meta,
|
|
5078
5222
|
...schema.inner.meta
|
|
5079
5223
|
};
|
|
5224
|
+
validateVolatileSchema(schema.inner, options.path, true);
|
|
5080
5225
|
}
|
|
5081
5226
|
return Schema.resolve(data, schema.inner, options, strict);
|
|
5082
5227
|
});
|
|
@@ -5176,7 +5321,7 @@ function property(data, key, schema, options) {
|
|
|
5176
5321
|
} catch (e) {
|
|
5177
5322
|
if (!options?.autofix) throw e;
|
|
5178
5323
|
delete data[key];
|
|
5179
|
-
return schema.meta.default;
|
|
5324
|
+
return schema.meta.volatile ? createVolatile(schema.meta.default) : schema.meta.default;
|
|
5180
5325
|
}
|
|
5181
5326
|
}
|
|
5182
5327
|
Schema.extend("array", (data, { inner, meta }, options) => {
|
|
@@ -5633,11 +5778,11 @@ function appendPrivateLedger(root, input, kind, payload) {
|
|
|
5633
5778
|
const expectedContext = contextDigest(context, root);
|
|
5634
5779
|
const anchored = readAnchors(root).get(session);
|
|
5635
5780
|
if (anchored !== void 0 && anchored !== expectedContext) return false;
|
|
5636
|
-
const snapshot = anchored === void 0 ? {
|
|
5781
|
+
const snapshot$1 = anchored === void 0 ? {
|
|
5637
5782
|
records: [],
|
|
5638
5783
|
damaged: false
|
|
5639
5784
|
} : readPrivateLedger(root, context);
|
|
5640
|
-
if (snapshot.damaged) return false;
|
|
5785
|
+
if (snapshot$1.damaged) return false;
|
|
5641
5786
|
if (anchored === void 0) {
|
|
5642
5787
|
const unsignedAnchor = {
|
|
5643
5788
|
version: 1,
|
|
@@ -5658,7 +5803,7 @@ function appendPrivateLedger(root, input, kind, payload) {
|
|
|
5658
5803
|
}
|
|
5659
5804
|
if (kind === "release_settlement") {
|
|
5660
5805
|
const settlement = normalizeSettlement(payload);
|
|
5661
|
-
const reservation = settlement && [...snapshot.records].reverse().find((record$3) => record$3.kind === "release_reservation" && record$3.payload.contractId === settlement.contractId && record$3.payload.operation === settlement.operation && record$3.payload.callId === settlement.callId);
|
|
5806
|
+
const reservation = settlement && [...snapshot$1.records].reverse().find((record$3) => record$3.kind === "release_reservation" && record$3.payload.contractId === settlement.contractId && record$3.payload.operation === settlement.operation && record$3.payload.callId === settlement.callId);
|
|
5662
5807
|
if (!reservation) return false;
|
|
5663
5808
|
payload = {
|
|
5664
5809
|
...payload,
|
|
@@ -5671,8 +5816,8 @@ function appendPrivateLedger(root, input, kind, payload) {
|
|
|
5671
5816
|
version: 1,
|
|
5672
5817
|
session_sha256: session,
|
|
5673
5818
|
context_sha256: expectedContext,
|
|
5674
|
-
position: snapshot.records.length + 1,
|
|
5675
|
-
prior_sha256: snapshot.records.at(-1)?.record_sha256 ?? null,
|
|
5819
|
+
position: snapshot$1.records.length + 1,
|
|
5820
|
+
prior_sha256: snapshot$1.records.at(-1)?.record_sha256 ?? null,
|
|
5676
5821
|
kind,
|
|
5677
5822
|
payload
|
|
5678
5823
|
};
|
|
@@ -5702,8 +5847,8 @@ function appendPrivateLedger(root, input, kind, payload) {
|
|
|
5702
5847
|
}
|
|
5703
5848
|
}
|
|
5704
5849
|
}
|
|
5705
|
-
function applyPrivateLedger(projection, snapshot) {
|
|
5706
|
-
if (snapshot.damaged || projection.releaseContracts.length > 0 && snapshot.anchored === false) {
|
|
5850
|
+
function applyPrivateLedger(projection, snapshot$1) {
|
|
5851
|
+
if (snapshot$1.damaged || projection.releaseContracts.length > 0 && snapshot$1.anchored === false) {
|
|
5707
5852
|
projection.releaseStateDamaged = true;
|
|
5708
5853
|
if (!projection.releaseDiagnostics.some((row) => row.reasonCode === "private_ledger_damaged")) projection.releaseDiagnostics.push({
|
|
5709
5854
|
seq: 0,
|
|
@@ -5712,7 +5857,7 @@ function applyPrivateLedger(projection, snapshot) {
|
|
|
5712
5857
|
return;
|
|
5713
5858
|
}
|
|
5714
5859
|
const reservations = /* @__PURE__ */ new Map();
|
|
5715
|
-
for (const record$2 of snapshot.records) if (record$2.kind === "release_reservation") {
|
|
5860
|
+
for (const record$2 of snapshot$1.records) if (record$2.kind === "release_reservation") {
|
|
5716
5861
|
const normalized = normalizeReservation(record$2.payload);
|
|
5717
5862
|
const contract = normalized && projection.releaseContracts.find((entry) => entry.contractId === normalized.contractId);
|
|
5718
5863
|
if (!normalized || !contract || record$2.payload.contract_sha256 !== privateLedgerContractDigest(contract) || typeof record$2.payload.target_sha256 !== "string") {
|
|
@@ -5756,8 +5901,8 @@ function applyPrivateLedger(projection, snapshot) {
|
|
|
5756
5901
|
else if (OUTCOME_STRENGTH[pinned.outcome] >= OUTCOME_STRENGTH[projection.releaseSettlements[index].outcome]) projection.releaseSettlements[index] = pinned;
|
|
5757
5902
|
}
|
|
5758
5903
|
}
|
|
5759
|
-
function hasPrivateRestartIntent(snapshot, resolutionCallId, serviceId, preGeneration) {
|
|
5760
|
-
return !snapshot.damaged && snapshot.records.some((record$2) => record$2.kind === "restart_intent" && record$2.payload.resolution_call_id === resolutionCallId && record$2.payload.service_id === serviceId && record$2.payload.pre_generation === preGeneration);
|
|
5904
|
+
function hasPrivateRestartIntent(snapshot$1, resolutionCallId, serviceId, preGeneration) {
|
|
5905
|
+
return !snapshot$1.damaged && snapshot$1.records.some((record$2) => record$2.kind === "restart_intent" && record$2.payload.resolution_call_id === resolutionCallId && record$2.payload.service_id === serviceId && record$2.payload.pre_generation === preGeneration);
|
|
5761
5906
|
}
|
|
5762
5907
|
|
|
5763
5908
|
//#endregion
|
|
@@ -5893,13 +6038,9 @@ function authorizeMutationFromProjection(projection, request) {
|
|
|
5893
6038
|
}
|
|
5894
6039
|
const PROTOCOL_CORRECTION_NOTICE = "Context Guard protocol correction: root-authorized work remains pending; continue with tools or obtain a typed boundary.";
|
|
5895
6040
|
/**
|
|
5896
|
-
* Establish a boundary
|
|
5897
|
-
*
|
|
5898
|
-
*
|
|
5899
|
-
* Replay reads boundaries from the `context_guard_boundary` call/result pair, so
|
|
5900
|
-
* a Guard-created boundary is written in exactly that wire shape rather than in
|
|
5901
|
-
* a private side channel — otherwise it would not survive a reload, and a
|
|
5902
|
-
* boundary that only exists in memory is not a persisted wait or stop.
|
|
6041
|
+
* Establish a Guard-owned boundary as a durable producer notice. V4 Stop hooks
|
|
6042
|
+
* run outside tool steps, so replay requalifies the notice request and verifies
|
|
6043
|
+
* its candidate digest instead of inventing a tool call/result envelope.
|
|
5903
6044
|
*
|
|
5904
6045
|
* Returns the boundary only after the durable flush succeeded. A failed flush
|
|
5905
6046
|
* reports the failure instead of a boundary, because an unflushed record must
|
|
@@ -5909,35 +6050,10 @@ async function establishBoundary(agent, runtime, flush, request) {
|
|
|
5909
6050
|
const projection = runtime.projection;
|
|
5910
6051
|
const candidate = qualifyBoundary(projection, request);
|
|
5911
6052
|
if (candidate.persistedResult !== "accepted") return { reasonCode: candidate.reasonCode };
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
step: session.seq,
|
|
5917
|
-
callId,
|
|
5918
|
-
name: "context_guard_boundary",
|
|
5919
|
-
arguments: JSON.stringify({
|
|
5920
|
-
disposition: request.disposition,
|
|
5921
|
-
qualification_kind: request.qualificationKind,
|
|
5922
|
-
qualification_ids: request.qualificationIds
|
|
5923
|
-
})
|
|
5924
|
-
});
|
|
5925
|
-
session.append("tool/result", {
|
|
5926
|
-
turn: 0,
|
|
5927
|
-
step: session.seq,
|
|
5928
|
-
message: createToolResultMessage({
|
|
5929
|
-
callId,
|
|
5930
|
-
content: [{
|
|
5931
|
-
type: "text",
|
|
5932
|
-
text: JSON.stringify({
|
|
5933
|
-
status: candidate.persistedResult,
|
|
5934
|
-
reason_code: candidate.reasonCode,
|
|
5935
|
-
boundary: { candidate_sha256: candidate.candidateSha256 }
|
|
5936
|
-
})
|
|
5937
|
-
}],
|
|
5938
|
-
isError: false
|
|
5939
|
-
})
|
|
5940
|
-
}, { surfaceOp: "append" });
|
|
6053
|
+
agent.session.append("user/message", pluginNoticeMessage(`${BOUNDARY_RECORD_PREFIX}${JSON.stringify({
|
|
6054
|
+
request,
|
|
6055
|
+
candidate_sha256: candidate.candidateSha256
|
|
6056
|
+
})}`, "recording a qualified stop boundary"), { surfaceOp: "append" });
|
|
5941
6057
|
let durable = false;
|
|
5942
6058
|
try {
|
|
5943
6059
|
durable = await flush();
|
|
@@ -6004,7 +6120,7 @@ async function handleGuardTurnStopping(agent, runtime, access$1) {
|
|
|
6004
6120
|
})}`
|
|
6005
6121
|
}],
|
|
6006
6122
|
source: {
|
|
6007
|
-
kind: "
|
|
6123
|
+
kind: "context-guard",
|
|
6008
6124
|
plugin: "context-guard",
|
|
6009
6125
|
form: "notice",
|
|
6010
6126
|
summary: boundContextSummary("carrying the root pause request to the host")
|
|
@@ -6029,7 +6145,7 @@ async function handleGuardTurnStopping(agent, runtime, access$1) {
|
|
|
6029
6145
|
text: record$2
|
|
6030
6146
|
}],
|
|
6031
6147
|
source: {
|
|
6032
|
-
kind: "
|
|
6148
|
+
kind: "context-guard",
|
|
6033
6149
|
plugin: "context-guard",
|
|
6034
6150
|
form: "notice",
|
|
6035
6151
|
summary: boundContextSummary("recording a turn boundary without relevant progress")
|
|
@@ -6052,7 +6168,7 @@ async function handleGuardTurnStopping(agent, runtime, access$1) {
|
|
|
6052
6168
|
text: PROTOCOL_CORRECTION_NOTICE
|
|
6053
6169
|
}],
|
|
6054
6170
|
source: {
|
|
6055
|
-
kind: "
|
|
6171
|
+
kind: "context-guard",
|
|
6056
6172
|
plugin: "context-guard",
|
|
6057
6173
|
form: "notice",
|
|
6058
6174
|
summary: boundContextSummary("requesting the one allowed protocol correction step")
|
|
@@ -6337,6 +6453,12 @@ function revalidateCoreLock(config, expected) {
|
|
|
6337
6453
|
goalAvailable: false,
|
|
6338
6454
|
reasonCode: "host_lock_installed_graph_drift"
|
|
6339
6455
|
};
|
|
6456
|
+
if (!auditedHostImplementation(config.hostLockRuntimeRoot, config.hostLockProfileRoot)) return {
|
|
6457
|
+
...actual,
|
|
6458
|
+
status: "unsupported",
|
|
6459
|
+
goalAvailable: false,
|
|
6460
|
+
reasonCode: "host_lock_installed_graph_drift"
|
|
6461
|
+
};
|
|
6340
6462
|
const audited = auditedForegroundRenderers(config.hostLockRuntimeRoot, config.hostLockProfileRoot);
|
|
6341
6463
|
return audited.length ? {
|
|
6342
6464
|
...actual,
|
|
@@ -6354,17 +6476,17 @@ function revalidateCoreLock(config, expected) {
|
|
|
6354
6476
|
}
|
|
6355
6477
|
/** Observe one actual Host dispatch through Cordis without joining its gate. */
|
|
6356
6478
|
function registerPassiveHostWorkdirObserver(agent, hostLockAtCall, attestedRouteAtCall, sourcedRootAtCall) {
|
|
6357
|
-
if (typeof agent.ctx.on !== "function") return;
|
|
6479
|
+
if (typeof agent.ctx.on !== "function") return () => {};
|
|
6358
6480
|
const pending = /* @__PURE__ */ new WeakMap();
|
|
6359
|
-
agent.ctx.on("tools/pre-execute", async (exec, next) => {
|
|
6481
|
+
const pre = agent.ctx.on("tools/pre-execute", async (exec, next) => {
|
|
6360
6482
|
if (exec.agent === agent && (exec.name === "bash" || exec.name === "pwsh")) try {
|
|
6361
6483
|
const policy = agent.ctx.get("sandboxPolicy");
|
|
6362
|
-
const receipt = captureHostWorkdir(agent.session, exec, hostLockAtCall(), policy, await attestedRouteAtCall(exec.name, agent.ctx.get("shell"), policy), sourcedRootAtCall?.(exec) ?? null);
|
|
6484
|
+
const receipt = captureHostWorkdir(agent.session, exec, hostLockAtCall(), policy, await attestedRouteAtCall(exec.name, agent.ctx.get("shell"), policy), sourcedRootAtCall?.(exec) ?? null, SESSION_FORMAT_VERSION);
|
|
6363
6485
|
if (receipt) pending.set(exec, receipt);
|
|
6364
6486
|
} catch {}
|
|
6365
6487
|
return next();
|
|
6366
6488
|
});
|
|
6367
|
-
agent.ctx.on("tools/post-execute", async (exec, _result, next) => {
|
|
6489
|
+
const post = agent.ctx.on("tools/post-execute", async (exec, _result, next) => {
|
|
6368
6490
|
const decision = await next();
|
|
6369
6491
|
const receipt = pending.get(exec);
|
|
6370
6492
|
pending.delete(exec);
|
|
@@ -6375,7 +6497,7 @@ function registerPassiveHostWorkdirObserver(agent, hostLockAtCall, attestedRoute
|
|
|
6375
6497
|
text: `${HOST_WORKDIR_PREFIX}${JSON.stringify(receipt)}`
|
|
6376
6498
|
}],
|
|
6377
6499
|
source: {
|
|
6378
|
-
kind: "
|
|
6500
|
+
kind: "context-guard",
|
|
6379
6501
|
plugin: "context-guard",
|
|
6380
6502
|
form: "notice",
|
|
6381
6503
|
summary: "read-only Host workdir observation"
|
|
@@ -6386,6 +6508,10 @@ function registerPassiveHostWorkdirObserver(agent, hostLockAtCall, attestedRoute
|
|
|
6386
6508
|
additionalContexts: [...decision.additionalContexts ?? [], context]
|
|
6387
6509
|
};
|
|
6388
6510
|
});
|
|
6511
|
+
return () => {
|
|
6512
|
+
pre();
|
|
6513
|
+
post();
|
|
6514
|
+
};
|
|
6389
6515
|
}
|
|
6390
6516
|
function apply(ctx, rawConfig = {}, seams = {}) {
|
|
6391
6517
|
const config = resolveConfig(rawConfig);
|
|
@@ -6402,7 +6528,20 @@ function apply(ctx, rawConfig = {}, seams = {}) {
|
|
|
6402
6528
|
cwd: sessionCwd(agent.session) ?? "",
|
|
6403
6529
|
hostLockDigest: (hostLocks.get(agent) ?? fallback).digest
|
|
6404
6530
|
});
|
|
6405
|
-
const
|
|
6531
|
+
const registrations = /* @__PURE__ */ new Map();
|
|
6532
|
+
const detach = (agent) => {
|
|
6533
|
+
const disposers = registrations.get(agent);
|
|
6534
|
+
registrations.delete(agent);
|
|
6535
|
+
for (const dispose of disposers?.slice().reverse() ?? []) dispose();
|
|
6536
|
+
runtimes.delete(agent);
|
|
6537
|
+
hostLocks.delete(agent);
|
|
6538
|
+
};
|
|
6539
|
+
ctx.effect?.(() => () => {
|
|
6540
|
+
for (const agent of registrations.keys()) detach(agent);
|
|
6541
|
+
});
|
|
6542
|
+
ctx.on("agent/disposed", ({ agent }) => {
|
|
6543
|
+
detach(agent);
|
|
6544
|
+
});
|
|
6406
6545
|
const ensure = (agent) => {
|
|
6407
6546
|
let runtime = runtimes.get(agent);
|
|
6408
6547
|
if (!runtime) {
|
|
@@ -6420,197 +6559,223 @@ function apply(ctx, rawConfig = {}, seams = {}) {
|
|
|
6420
6559
|
return runtime;
|
|
6421
6560
|
};
|
|
6422
6561
|
ctx.commands.register(createContextGuardCommand((agent) => ensure(agent).projection, (agent, enabled) => ensure(agent).setEnabled(enabled), (agent) => ensure(agent).sync(), (agent) => ensure(agent).lifecycle));
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6562
|
+
const attach = (agent, source) => {
|
|
6563
|
+
if (registrations.has(agent)) {
|
|
6564
|
+
if (source === "resume" || source === "compact") {
|
|
6565
|
+
const runtime = ensure(agent);
|
|
6566
|
+
runtime.sync();
|
|
6567
|
+
runtime.projection.lastRecoveryDigest = void 0;
|
|
6568
|
+
runtime.markRecoveryNeeded(source === "resume" ? "resume" : "compaction");
|
|
6569
|
+
}
|
|
6570
|
+
return;
|
|
6429
6571
|
}
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
return sourcedNamedTestRoot(runtime.projection, agent.session, exec.arguments);
|
|
6435
|
-
});
|
|
6436
|
-
agent.ctx.tools.register(createRebindTool(() => runtime.projection, async () => {
|
|
6437
|
-
const durable = await ctx.sessions.flush(agent.session);
|
|
6438
|
-
runtime.setDurability(durable);
|
|
6439
|
-
runtime.sync();
|
|
6440
|
-
return durable;
|
|
6441
|
-
}));
|
|
6442
|
-
agent.ctx.tools.register(createCheckpointTool(() => runtime.projection, () => runtime.markRecoveryNeeded("checkpoint_followup"), async () => {
|
|
6443
|
-
const durable = await ctx.sessions.flush(agent.session);
|
|
6444
|
-
runtime.setDurability(durable);
|
|
6445
|
-
runtime.sync();
|
|
6446
|
-
return durable;
|
|
6447
|
-
}));
|
|
6448
|
-
agent.ctx.tools.register(createBoundaryTool(() => runtime.projection, async () => {
|
|
6449
|
-
const durable = await ctx.sessions.flush(agent.session);
|
|
6450
|
-
runtime.setDurability(durable);
|
|
6451
|
-
runtime.sync();
|
|
6452
|
-
return durable;
|
|
6453
|
-
}, () => runtime.markRecoveryNeeded("boundary_update")));
|
|
6454
|
-
/** Persist release state outside provider-visible Session history. */
|
|
6455
|
-
const persistReleaseRecord = async (toolAgent, kind, payload) => {
|
|
6456
|
-
if (toolAgent.session !== agent.session) return false;
|
|
6457
|
-
if (!sessionCwd(agent.session)) return false;
|
|
6458
|
-
const durable = appendPrivateLedger(privateLedgerRoot, ledgerContext(agent), kind, payload);
|
|
6459
|
-
runtime.sync();
|
|
6460
|
-
return durable;
|
|
6572
|
+
const disposers = [];
|
|
6573
|
+
registrations.set(agent, disposers);
|
|
6574
|
+
const own = (dispose) => {
|
|
6575
|
+
if (dispose) disposers.push(dispose);
|
|
6461
6576
|
};
|
|
6462
|
-
const
|
|
6463
|
-
|
|
6464
|
-
...
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6577
|
+
const ownedTools = {
|
|
6578
|
+
register: (...args) => own(agent.ctx.tools.register(...args)),
|
|
6579
|
+
guard: (...args) => own(agent.ctx.tools.guard(...args))
|
|
6580
|
+
};
|
|
6581
|
+
try {
|
|
6582
|
+
const runtime = ensure(agent);
|
|
6583
|
+
runtime.sync();
|
|
6584
|
+
if (source === "resume" || source === "compact") {
|
|
6585
|
+
runtime.projection.lastRecoveryDigest = void 0;
|
|
6586
|
+
runtime.markRecoveryNeeded(source === "resume" ? "resume" : "compaction");
|
|
6587
|
+
}
|
|
6588
|
+
own(registerPassiveHostWorkdirObserver(agent, () => seams.hostLock ?? revalidateCoreLock(config, installedHostLock), (tool, provider, policy) => config.hostLockRuntimeRoot && config.hostLockProfileRoot ? auditedDefaultWorkdirProvider(config.hostLockRuntimeRoot, config.hostLockProfileRoot, tool, provider, policy) : false, (exec) => {
|
|
6589
|
+
runtime.sync();
|
|
6590
|
+
return sourcedNamedTestRoot(runtime.projection, agent.session, exec.arguments);
|
|
6591
|
+
}));
|
|
6592
|
+
ownedTools.register(createRebindTool(() => runtime.projection, async () => {
|
|
6469
6593
|
const durable = await ctx.sessions.flush(agent.session);
|
|
6470
6594
|
runtime.setDurability(durable);
|
|
6471
6595
|
runtime.sync();
|
|
6472
6596
|
return durable;
|
|
6473
|
-
}
|
|
6474
|
-
|
|
6475
|
-
runtime.sync();
|
|
6476
|
-
return authorizeMutationFromProjection(runtime.projection, request);
|
|
6477
|
-
},
|
|
6478
|
-
marketOrigin: optionalMarketOrigin(ctx, agent),
|
|
6479
|
-
hasRestartIntent: (resolutionCallId, serviceId, preGeneration) => hasPrivateRestartIntent(readPrivateLedger(privateLedgerRoot, ledgerContext(agent)), resolutionCallId, serviceId, preGeneration),
|
|
6480
|
-
releaseGate: async (request) => {
|
|
6481
|
-
runtime.sync();
|
|
6482
|
-
const projection = runtime.projection;
|
|
6483
|
-
if (!(projection.policy === "release" || projection.releaseContracts.length > 0)) return {
|
|
6484
|
-
status: "denied",
|
|
6485
|
-
reasonCode: "release_contract_not_adopted"
|
|
6486
|
-
};
|
|
6487
|
-
const observed = { ...request.observed };
|
|
6488
|
-
const declaredRef = releaseContractFor(projection, request.operation)?.candidate.ref;
|
|
6489
|
-
if (declaredRef !== void 0 && observed.ref === void 0) {
|
|
6490
|
-
const refSha = await resolveAuditedRef(sessionCwd(runtime.session), declaredRef, evidenceOptions, requestSignal());
|
|
6491
|
-
if (refSha !== void 0) {
|
|
6492
|
-
observed.ref = declaredRef;
|
|
6493
|
-
observed.refSha = refSha;
|
|
6494
|
-
}
|
|
6495
|
-
}
|
|
6496
|
-
const decision = releasePreEffectDecision(projection, {
|
|
6497
|
-
operation: request.operation,
|
|
6498
|
-
observed,
|
|
6499
|
-
resolvedTarget: request.resolvedTarget,
|
|
6500
|
-
nowEpochMs: Date.now()
|
|
6501
|
-
});
|
|
6502
|
-
if (decision.status !== "granted" || decision.contractId === void 0) return {
|
|
6503
|
-
status: "denied",
|
|
6504
|
-
reasonCode: decision.reasonCode
|
|
6505
|
-
};
|
|
6506
|
-
const grantedContract = projection.releaseContracts.find((entry) => entry.contractId === decision.contractId);
|
|
6507
|
-
if (!grantedContract) return {
|
|
6508
|
-
status: "denied",
|
|
6509
|
-
reasonCode: "release_state_damaged"
|
|
6510
|
-
};
|
|
6511
|
-
return await persistReleaseRecord(agent, "release_reservation", {
|
|
6512
|
-
contractId: decision.contractId,
|
|
6513
|
-
operation: request.operation,
|
|
6514
|
-
callId: request.callId,
|
|
6515
|
-
startedAtSeq: 0,
|
|
6516
|
-
status: "in_flight",
|
|
6517
|
-
contract_sha256: privateLedgerContractDigest(grantedContract),
|
|
6518
|
-
target_sha256: privateLedgerTargetDigest(request.resolvedTarget),
|
|
6519
|
-
...observed.artifactSri !== void 0 ? { observedArtifactSri: observed.artifactSri } : {}
|
|
6520
|
-
}) ? {
|
|
6521
|
-
status: "granted",
|
|
6522
|
-
reasonCode: decision.reasonCode,
|
|
6523
|
-
contractId: decision.contractId
|
|
6524
|
-
} : {
|
|
6525
|
-
status: "denied",
|
|
6526
|
-
reasonCode: "release_reservation_not_durable"
|
|
6527
|
-
};
|
|
6528
|
-
},
|
|
6529
|
-
releaseSettle: async (request) => {
|
|
6530
|
-
const contractId = request.contractId ?? releaseContractFor(runtime.projection, request.operation)?.contractId ?? "unknown";
|
|
6531
|
-
const contract = runtime.projection.releaseContracts.find((entry) => entry.contractId === contractId);
|
|
6532
|
-
const reservation = reservationFor(runtime.projection, contractId, request.callId);
|
|
6533
|
-
let outcome = request.effect === "not_effected" ? "not_effected" : "unknown";
|
|
6534
|
-
if (request.effect === "completed" && contract) outcome = readbackSettlesContract(contract, request.readback, reservation?.observedArtifactSri) === "settled" ? "settled" : "unknown";
|
|
6535
|
-
await persistReleaseRecord(agent, "release_settlement", {
|
|
6536
|
-
contractId,
|
|
6537
|
-
operation: request.operation,
|
|
6538
|
-
callId: request.callId,
|
|
6539
|
-
settledAtSeq: 0,
|
|
6540
|
-
readback: request.readback,
|
|
6541
|
-
outcome,
|
|
6542
|
-
settlement_source: "effect"
|
|
6543
|
-
});
|
|
6544
|
-
},
|
|
6545
|
-
persistRestartIntent: async (toolAgent, intent) => {
|
|
6546
|
-
if (toolAgent.session !== agent.session) return false;
|
|
6547
|
-
if (!sessionCwd(agent.session)) return false;
|
|
6548
|
-
const snapshot = readPrivateLedger(privateLedgerRoot, ledgerContext(agent));
|
|
6549
|
-
if (snapshot.damaged || !snapshot.anchored) return false;
|
|
6550
|
-
const durable = appendPrivateLedger(privateLedgerRoot, ledgerContext(agent), "restart_intent", {
|
|
6551
|
-
resolution_call_id: intent.resolutionCallId,
|
|
6552
|
-
service_id: intent.serviceId,
|
|
6553
|
-
pre_generation: intent.preGeneration
|
|
6554
|
-
});
|
|
6555
|
-
runtime.sync();
|
|
6556
|
-
return durable;
|
|
6557
|
-
}
|
|
6558
|
-
};
|
|
6559
|
-
agent.ctx.tools.register(createEvidenceTool(evidenceOptions));
|
|
6560
|
-
agent.ctx.tools.register(createNativeFileObserver({
|
|
6561
|
-
fs: ctx.fs,
|
|
6562
|
-
flush: (session) => ctx.sessions.flush(session)
|
|
6563
|
-
}));
|
|
6564
|
-
agent.ctx.tools.register(createNativeGitObserver({ flush: (session) => ctx.sessions.flush(session) }));
|
|
6565
|
-
agent.ctx.tools.register(createTestReadinessObserver({
|
|
6566
|
-
getProjection: () => runtime.projection,
|
|
6567
|
-
fs: ctx.fs,
|
|
6568
|
-
flush: (session) => ctx.sessions.flush(session)
|
|
6569
|
-
}));
|
|
6570
|
-
agent.ctx.tools.register(createActionTool(evidenceOptions));
|
|
6571
|
-
agent.ctx.tools.register(createPrepareTool({
|
|
6572
|
-
getProjection: () => runtime.projection,
|
|
6573
|
-
hostCapability: (action) => {
|
|
6574
|
-
const evaluation = createHostCapabilityEvaluator(hostLocks.get(agent) ?? installedHostLock)(action);
|
|
6575
|
-
return {
|
|
6576
|
-
status: evaluation.status,
|
|
6577
|
-
reasonCode: evaluation.reasonCode
|
|
6578
|
-
};
|
|
6579
|
-
},
|
|
6580
|
-
commandTemplate: (action) => GIT_COMMAND_TEMPLATES[action],
|
|
6581
|
-
refreshProjection: async () => {
|
|
6597
|
+
}));
|
|
6598
|
+
ownedTools.register(createCheckpointTool(() => runtime.projection, () => runtime.markRecoveryNeeded("checkpoint_followup"), async () => {
|
|
6582
6599
|
const durable = await ctx.sessions.flush(agent.session);
|
|
6583
6600
|
runtime.setDurability(durable);
|
|
6584
6601
|
runtime.sync();
|
|
6585
6602
|
return durable;
|
|
6586
|
-
}
|
|
6587
|
-
|
|
6588
|
-
agent.ctx.tools.register(createInterpretTool({
|
|
6589
|
-
getProjection: () => runtime.projection,
|
|
6590
|
-
refreshProjection: async () => {
|
|
6603
|
+
}));
|
|
6604
|
+
ownedTools.register(createBoundaryTool(() => runtime.projection, async () => {
|
|
6591
6605
|
const durable = await ctx.sessions.flush(agent.session);
|
|
6592
6606
|
runtime.setDurability(durable);
|
|
6593
6607
|
runtime.sync();
|
|
6594
6608
|
return durable;
|
|
6595
|
-
}
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6609
|
+
}, () => runtime.markRecoveryNeeded("boundary_update")));
|
|
6610
|
+
/** Persist release state outside provider-visible Session history. */
|
|
6611
|
+
const persistReleaseRecord = async (toolAgent, kind, payload) => {
|
|
6612
|
+
if (toolAgent.session !== agent.session) return false;
|
|
6613
|
+
if (!sessionCwd(agent.session)) return false;
|
|
6614
|
+
const durable = appendPrivateLedger(privateLedgerRoot, ledgerContext(agent), kind, payload);
|
|
6615
|
+
runtime.sync();
|
|
6616
|
+
return durable;
|
|
6617
|
+
};
|
|
6618
|
+
const evidenceOptions = {
|
|
6619
|
+
hostCapability: createHostCapabilityEvaluator(hostLocks.get(agent) ?? installedHostLock),
|
|
6620
|
+
...seams.commandRunner ? { commandRunner: seams.commandRunner } : {},
|
|
6621
|
+
...seams.fetcher ? { fetcher: seams.fetcher } : {},
|
|
6622
|
+
...seams.allowLoopbackHttpRegistry ? { allowLoopbackHttpRegistry: true } : {},
|
|
6623
|
+
prepareMutation: async (toolAgent) => {
|
|
6624
|
+
if (toolAgent.session !== agent.session) return false;
|
|
6625
|
+
const durable = await ctx.sessions.flush(agent.session);
|
|
6626
|
+
runtime.setDurability(durable);
|
|
6627
|
+
runtime.sync();
|
|
6628
|
+
return durable;
|
|
6629
|
+
},
|
|
6630
|
+
authorizeMutation: (request) => {
|
|
6631
|
+
runtime.sync();
|
|
6632
|
+
return authorizeMutationFromProjection(runtime.projection, request);
|
|
6633
|
+
},
|
|
6634
|
+
marketOrigin: optionalMarketOrigin(ctx, agent),
|
|
6635
|
+
hasRestartIntent: (resolutionCallId, serviceId, preGeneration) => hasPrivateRestartIntent(readPrivateLedger(privateLedgerRoot, ledgerContext(agent)), resolutionCallId, serviceId, preGeneration),
|
|
6636
|
+
releaseGate: async (request) => {
|
|
6637
|
+
runtime.sync();
|
|
6638
|
+
const projection = runtime.projection;
|
|
6639
|
+
if (!(projection.policy === "release" || projection.releaseContracts.length > 0)) return {
|
|
6640
|
+
status: "denied",
|
|
6641
|
+
reasonCode: "release_contract_not_adopted"
|
|
6642
|
+
};
|
|
6643
|
+
const observed = { ...request.observed };
|
|
6644
|
+
const declaredRef = releaseContractFor(projection, request.operation)?.candidate.ref;
|
|
6645
|
+
if (declaredRef !== void 0 && observed.ref === void 0) {
|
|
6646
|
+
const refSha = await resolveAuditedRef(sessionCwd(runtime.session), declaredRef, evidenceOptions, requestSignal());
|
|
6647
|
+
if (refSha !== void 0) {
|
|
6648
|
+
observed.ref = declaredRef;
|
|
6649
|
+
observed.refSha = refSha;
|
|
6650
|
+
}
|
|
6651
|
+
}
|
|
6652
|
+
const decision = releasePreEffectDecision(projection, {
|
|
6653
|
+
operation: request.operation,
|
|
6654
|
+
observed,
|
|
6655
|
+
resolvedTarget: request.resolvedTarget,
|
|
6656
|
+
nowEpochMs: Date.now()
|
|
6657
|
+
});
|
|
6658
|
+
if (decision.status !== "granted" || decision.contractId === void 0) return {
|
|
6659
|
+
status: "denied",
|
|
6660
|
+
reasonCode: decision.reasonCode
|
|
6661
|
+
};
|
|
6662
|
+
const grantedContract = projection.releaseContracts.find((entry) => entry.contractId === decision.contractId);
|
|
6663
|
+
if (!grantedContract) return {
|
|
6664
|
+
status: "denied",
|
|
6665
|
+
reasonCode: "release_state_damaged"
|
|
6666
|
+
};
|
|
6667
|
+
return await persistReleaseRecord(agent, "release_reservation", {
|
|
6668
|
+
contractId: decision.contractId,
|
|
6669
|
+
operation: request.operation,
|
|
6670
|
+
callId: request.callId,
|
|
6671
|
+
startedAtSeq: 0,
|
|
6672
|
+
status: "in_flight",
|
|
6673
|
+
contract_sha256: privateLedgerContractDigest(grantedContract),
|
|
6674
|
+
target_sha256: privateLedgerTargetDigest(request.resolvedTarget),
|
|
6675
|
+
...observed.artifactSri !== void 0 ? { observedArtifactSri: observed.artifactSri } : {}
|
|
6676
|
+
}) ? {
|
|
6677
|
+
status: "granted",
|
|
6678
|
+
reasonCode: decision.reasonCode,
|
|
6679
|
+
contractId: decision.contractId
|
|
6680
|
+
} : {
|
|
6681
|
+
status: "denied",
|
|
6682
|
+
reasonCode: "release_reservation_not_durable"
|
|
6683
|
+
};
|
|
6684
|
+
},
|
|
6685
|
+
releaseSettle: async (request) => {
|
|
6686
|
+
const contractId = request.contractId ?? releaseContractFor(runtime.projection, request.operation)?.contractId ?? "unknown";
|
|
6687
|
+
const contract = runtime.projection.releaseContracts.find((entry) => entry.contractId === contractId);
|
|
6688
|
+
const reservation = reservationFor(runtime.projection, contractId, request.callId);
|
|
6689
|
+
let outcome = request.effect === "not_effected" ? "not_effected" : "unknown";
|
|
6690
|
+
if (request.effect === "completed" && contract) outcome = readbackSettlesContract(contract, request.readback, reservation?.observedArtifactSri) === "settled" ? "settled" : "unknown";
|
|
6691
|
+
await persistReleaseRecord(agent, "release_settlement", {
|
|
6692
|
+
contractId,
|
|
6693
|
+
operation: request.operation,
|
|
6694
|
+
callId: request.callId,
|
|
6695
|
+
settledAtSeq: 0,
|
|
6696
|
+
readback: request.readback,
|
|
6697
|
+
outcome,
|
|
6698
|
+
settlement_source: "effect"
|
|
6699
|
+
});
|
|
6700
|
+
},
|
|
6701
|
+
persistRestartIntent: async (toolAgent, intent) => {
|
|
6702
|
+
if (toolAgent.session !== agent.session) return false;
|
|
6703
|
+
if (!sessionCwd(agent.session)) return false;
|
|
6704
|
+
const snapshot$1 = readPrivateLedger(privateLedgerRoot, ledgerContext(agent));
|
|
6705
|
+
if (snapshot$1.damaged || !snapshot$1.anchored) return false;
|
|
6706
|
+
const durable = appendPrivateLedger(privateLedgerRoot, ledgerContext(agent), "restart_intent", {
|
|
6707
|
+
resolution_call_id: intent.resolutionCallId,
|
|
6708
|
+
service_id: intent.serviceId,
|
|
6709
|
+
pre_generation: intent.preGeneration
|
|
6710
|
+
});
|
|
6711
|
+
runtime.sync();
|
|
6712
|
+
return durable;
|
|
6713
|
+
}
|
|
6714
|
+
};
|
|
6715
|
+
ownedTools.register(createEvidenceTool(evidenceOptions));
|
|
6716
|
+
ownedTools.register(createNativeFileObserver({
|
|
6717
|
+
fs: ctx.fs,
|
|
6718
|
+
flush: (session) => ctx.sessions.flush(session)
|
|
6719
|
+
}));
|
|
6720
|
+
ownedTools.register(createNativeGitObserver({ flush: (session) => ctx.sessions.flush(session) }));
|
|
6721
|
+
ownedTools.register(createTestReadinessObserver({
|
|
6722
|
+
getProjection: () => runtime.projection,
|
|
6723
|
+
fs: ctx.fs,
|
|
6724
|
+
flush: (session) => ctx.sessions.flush(session)
|
|
6725
|
+
}));
|
|
6726
|
+
ownedTools.register(createActionTool(evidenceOptions));
|
|
6727
|
+
ownedTools.register(createPrepareTool({
|
|
6728
|
+
getProjection: () => runtime.projection,
|
|
6729
|
+
hostCapability: (action) => {
|
|
6730
|
+
const evaluation = createHostCapabilityEvaluator(hostLocks.get(agent) ?? installedHostLock)(action);
|
|
6731
|
+
return {
|
|
6732
|
+
status: evaluation.status,
|
|
6733
|
+
reasonCode: evaluation.reasonCode
|
|
6734
|
+
};
|
|
6735
|
+
},
|
|
6736
|
+
commandTemplate: (action) => GIT_COMMAND_TEMPLATES[action],
|
|
6737
|
+
refreshProjection: async () => {
|
|
6738
|
+
const durable = await ctx.sessions.flush(agent.session);
|
|
6739
|
+
runtime.setDurability(durable);
|
|
6740
|
+
runtime.sync();
|
|
6741
|
+
return durable;
|
|
6742
|
+
}
|
|
6743
|
+
}));
|
|
6744
|
+
ownedTools.register(createInterpretTool({
|
|
6745
|
+
getProjection: () => runtime.projection,
|
|
6746
|
+
refreshProjection: async () => {
|
|
6747
|
+
const durable = await ctx.sessions.flush(agent.session);
|
|
6748
|
+
runtime.setDurability(durable);
|
|
6749
|
+
runtime.sync();
|
|
6750
|
+
return durable;
|
|
6751
|
+
}
|
|
6752
|
+
}));
|
|
6753
|
+
ownedTools.register(createReleaseTool({
|
|
6754
|
+
getProjection: () => runtime.projection,
|
|
6755
|
+
fetcher: evidenceOptions.fetcher,
|
|
6756
|
+
...evidenceOptions.allowLoopbackHttpRegistry ? { allowLoopbackHttpRegistry: true } : {},
|
|
6757
|
+
persistSettlement: async (request) => persistReleaseRecord(request.agent, "release_settlement", {
|
|
6758
|
+
contractId: request.contractId,
|
|
6759
|
+
operation: request.operation,
|
|
6760
|
+
callId: request.callId,
|
|
6761
|
+
settledAtSeq: 0,
|
|
6762
|
+
readback: request.readback,
|
|
6763
|
+
outcome: request.outcome,
|
|
6764
|
+
settlement_source: "reconcile"
|
|
6765
|
+
})
|
|
6766
|
+
}));
|
|
6767
|
+
ownedTools.register(createExternalOperationTool((id, toolAgent) => readExternalOperation(ctx, toolAgent, id), () => evaluateExternalWaitCapability(hostLocks.get(agent) ?? installedHostLock)));
|
|
6768
|
+
ownedTools.guard((exec) => goalCompletionDenial(runtime.projection, exec.name, exec.arguments));
|
|
6769
|
+
} catch (error) {
|
|
6770
|
+
detach(agent);
|
|
6771
|
+
throw error;
|
|
6772
|
+
}
|
|
6773
|
+
};
|
|
6774
|
+
ctx.on("agent/created", ({ agent, source, signal }) => {
|
|
6775
|
+
signal?.throwIfAborted();
|
|
6776
|
+
return attach(agent, source);
|
|
6613
6777
|
});
|
|
6778
|
+
for (const agent of ctx.get?.("agents")?.list() ?? []) attach(agent);
|
|
6614
6779
|
ctx.on("agent/pre-step", async ({ agent }, next) => {
|
|
6615
6780
|
const durability = await ctx.sessions.flush(agent.session);
|
|
6616
6781
|
const runtime = ensure(agent);
|
|
@@ -6657,7 +6822,7 @@ function apply(ctx, rawConfig = {}, seams = {}) {
|
|
|
6657
6822
|
text: `${title}\n${recovery}`
|
|
6658
6823
|
}],
|
|
6659
6824
|
source: {
|
|
6660
|
-
kind: "
|
|
6825
|
+
kind: "context-guard",
|
|
6661
6826
|
plugin: "context-guard",
|
|
6662
6827
|
form: "notice",
|
|
6663
6828
|
summary: boundContextSummary("recovering open task requirements")
|
|
@@ -6685,15 +6850,15 @@ function apply(ctx, rawConfig = {}, seams = {}) {
|
|
|
6685
6850
|
}
|
|
6686
6851
|
function readExternalOperation(ctx, agent, id) {
|
|
6687
6852
|
if (!agent || !id) return void 0;
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6853
|
+
if (!agent.session || agent.id !== agent.session.id) return void 0;
|
|
6854
|
+
try {
|
|
6855
|
+
const service = agent.ctx.get("jobs") ?? ctx.get("jobs");
|
|
6856
|
+
if (!service) return void 0;
|
|
6857
|
+
const row = service.get(JobId(id), agent.id);
|
|
6858
|
+
if (!row || row.id !== id) return void 0;
|
|
6694
6859
|
return {
|
|
6695
6860
|
id,
|
|
6696
|
-
status:
|
|
6861
|
+
status: row.status === "running" ? "running" : row.status === "stopping" ? "pending" : row.status === "completed" ? "completed" : row.status === "killed" || row.status === "failed" ? "failed" : "unknown",
|
|
6697
6862
|
adapterId: "dsh.jobs.v1"
|
|
6698
6863
|
};
|
|
6699
6864
|
} catch {
|
|
@@ -6715,7 +6880,7 @@ function pluginNoticeMessage(text, summaryLabel) {
|
|
|
6715
6880
|
text
|
|
6716
6881
|
}],
|
|
6717
6882
|
source: {
|
|
6718
|
-
kind: "
|
|
6883
|
+
kind: "context-guard",
|
|
6719
6884
|
plugin: "context-guard",
|
|
6720
6885
|
form: "notice",
|
|
6721
6886
|
summary: boundContextSummary(summaryLabel)
|
|
@@ -6811,7 +6976,7 @@ async function replayRawV2(input) {
|
|
|
6811
6976
|
text: PROTOCOL_V6_NOTICE
|
|
6812
6977
|
}],
|
|
6813
6978
|
source: {
|
|
6814
|
-
kind: "
|
|
6979
|
+
kind: "context-guard",
|
|
6815
6980
|
plugin: "context-guard",
|
|
6816
6981
|
form: "notice",
|
|
6817
6982
|
summary: "v6 replay boundary"
|
|
@@ -6855,7 +7020,7 @@ async function replayRawV2(input) {
|
|
|
6855
7020
|
const runtime = createRuntime(agent, { activation: "always" }, lock, () => void 0);
|
|
6856
7021
|
runtime.setDurability(true);
|
|
6857
7022
|
runtime.sync();
|
|
6858
|
-
const snapshot = sessionCoreSnapshot(session.snapshotEvents(), runtime.projection);
|
|
7023
|
+
const snapshot$1 = sessionCoreSnapshot(session.snapshotEvents(), runtime.projection);
|
|
6859
7024
|
const stopCore = runtime.projection.coreV2 ?? null;
|
|
6860
7025
|
const stop = await handleGuardTurnStopping(agent, runtime, {
|
|
6861
7026
|
flush: async () => true,
|
|
@@ -6870,7 +7035,7 @@ async function replayRawV2(input) {
|
|
|
6870
7035
|
const projection = runtime.projection;
|
|
6871
7036
|
const postSnapshot = sessionCoreSnapshot(session.snapshotEvents(), projection);
|
|
6872
7037
|
return {
|
|
6873
|
-
stop_core_snapshot: snapshot ?? null,
|
|
7038
|
+
stop_core_snapshot: snapshot$1 ?? null,
|
|
6874
7039
|
stop_core_projection: stopCore,
|
|
6875
7040
|
stop,
|
|
6876
7041
|
post_turn_core_snapshot: postSnapshot ?? null,
|
|
@@ -6900,4 +7065,4 @@ async function replayRawV2(input) {
|
|
|
6900
7065
|
}
|
|
6901
7066
|
|
|
6902
7067
|
//#endregion
|
|
6903
|
-
export { ACTION_MANIFEST, ACTION_MANIFEST_VERSION, ACTIVE_HOST_COHORT_ID, ACTIVE_HOST_COHORT_IDS, ACTIVE_HOST_LAUNCHER_VERSION,
|
|
7068
|
+
export { ACTION_MANIFEST, ACTION_MANIFEST_VERSION, ACTIVE_HOST_COHORT_ID, ACTIVE_HOST_COHORT_IDS, ACTIVE_HOST_LAUNCHER_VERSION, BASE_HOST_PACKAGES, BOUNDARY_RECORD_PREFIX, BOUNDED_ARTIFACT_TYPES, CAPTURE_V042_NOTICE, CERTIFICATE_VERSION, CERTIFICATE_VERSION_V2, CLEANUP_CONDITION_RULE, CLEANUP_CONDITION_RULE_COMPACT, CLEANUP_CONDITION_RULE_SHORT, COMMAND_SURFACE_MANIFEST, CONFIRM_LINE_PATTERN, CONTROL_RECORD_PREFIX, Config, DEFAULT_DELEGATION_TOOL_NAMES, DEFAULT_HOST_LOCK, DEFAULT_RECOVERY_CHAR_BUDGET, DEPENDENCY_FREE_ONLY_CONDITION, EXPECTED_HOST_PACKAGES, FIRST_STEP_GUIDANCE, GIT_COMMAND_MANIFEST_IDS, GIT_COMMAND_TEMPLATES, GOAL_HOST_PACKAGES, GRANTED_QUALIFICATION, HOST_CAPABILITY_PACKAGE_GROUPS, HOST_COHORTS, HostProfileError, LATEST_SUPPORTED_HOST_VERSION, LEGACY_QUALIFICATION, MIN_RECOVERY_CHAR_BUDGET, MIN_SUPPORTED_HOST_VERSION, NO_PROGRESS_RECORD_PREFIX, NO_PROGRESS_TURNS_BEFORE_STOP, PROOF_CAPABILITY_MATRIX, PROOF_KINDS, PROOF_KINDS_V2, PROOF_MANIFEST_DOMAIN_V2, PROOF_PROTOCOL_VERSION, PROOF_PROTOCOL_VERSION_V2, PROTOCOL_V3_NOTICE, PROTOCOL_V4_NOTICE, PROTOCOL_V5_NOTICE, PROTOCOL_V6_NOTICE, RC017_RC2_HOST_PACKAGES, SEMANTIC_ACTIONS, SESSION_API_UNSUPPORTED, SESSION_EVENT_ENVELOPE_INVALID, STATEFUL_ACTIONS, STOP_PROTOCOL_VERSION, STOP_PROTOCOL_VERSION_V2, SUPPORTED_EVIDENCE_ADAPTERS, SUPPORTED_HOST_RANGE, SUPPORTED_HOST_VERSIONS, SessionApiError, V6_ORDINARY_COMPLETION_RULE, V6_ORDINARY_COMPLETION_RULE_COMPACT, V6_ORDINARY_COMPLETION_RULE_SHORT, actionCompatible, actionHasCertificationPath, actionVerbMatches, activeRendererModule, admissibleForRemoval, apply, applyUpgradeEligibility, assessmentAction, assessmentOutcomePredicate, auditedDefaultWorkdirHost, auditedDefaultWorkdirProvider, auditedForegroundRenderers, auditedHostImplementation, authorityCaptureCounts, availableBoundaryQualifications, bindExecutableIdentity, bindLiveGoalCapability, bindProofToProjection, bindProofV2ToProjection, bindingIndividuallyAccepted, bindingSatisfies, boundedArtifactChoiceMatches, canonicalArgvFromCommand, canonicalProjection, canonicalizePath, capabilityConsequence, capabilityFactOf, capabilityRemedyPhrase, captureClause, captureItem, carriesCleanupCondition, certifyCheckpoint, claimedBatchHasRealRootInput, clarifiedSpanOf, classifyClause, classifyCompletionClaim, classifyTaskIntent, classifyUserInteraction, clauseAsksOwnQuestion, clauseIsGoverned, clauseIsProtected, cleanupConditionFor, closingHint, combineHostPolicy, commitIndexSnapshotDigest, commitTreeSnapshotDigest, compareHostVersions, confirmRebind, createGitPrestateEnvelope, createProjection, createProofManifest, createProofManifestV2, currentActionBases, currentContractDigest, decideTurnBoundary, decideTurnStopping, decisionBoundaryKey, deriveItemDiagnosis, deriveProjection, digestStrings, effectuateBoundary, environmentDefaultRepositoryTarget, evaluateExternalWaitCapability, evaluateHostCapability, evaluateHostLock, evaluateMinimumHostVersion, evaluateToolSurfaceCapability, evidenceAvailabilityReason, evidenceCoverage, evidenceFromPersistedToolResult, evidenceMatchesItem, executeRevalidatedGitEffect, explanationHasActionResidue, extractArtifactPaths, extractMethod, extractOperation, extractTextContent, extractToolSubject, firstStepGuidance, firstStepGuidanceV6, gitCommandMatchesTarget, goalCompletionDenial, governedClauseRestrictsExecution, hasCurrentCertificate, hasOrderedCoordination, hasQuestionScope, hasWorkPredicate, hostLockContextFromComposedDump, hostLockRowsFromComposedDump, hostVersionFromPackages, inject, injectActiveProfileHostLock, inspectTargetHostGraph, interpretClause, interpretMessage, introducesActionClause, isCurrentAcceptedBoundary, isDeterministicCheck, isExecutableItem, isExplanationScope, isFrozenV042RebindResponse, isInformationalFragment, isInformationalMessage, isOpenObligation, isQuestionScopeNeedingReview, isRestatement, isRootPauseRequest, isRunExecutable, isStatefulAction, isVerifyingCapability, isWholeTaskCompletionClaim, itemDiagnosis, itemHoldsExecutionAuthority, kindOfScope, latestAssistantText, latestRootInstruction, legacyQuestionReadingIsInformational, legacyRecordsNeedingReview, lifecyclePhase, maskCodeSpans, maskQuotedSpans, name, namedActions, nativeFileTwoRole, normalizeClause, observeAssistantOutcome, openItems, opensConditionLead, opensWithDirective, packageRowsFromActiveGraph, packageRowsFromPnpmLock, parseConfirmationMessage, parseGitCommandManifest, parseHostVersion, parsePwshCommand, parseShellCommand, partialFailureOf, persistedToolResultStatus, presentExplanationHead, previewFirstStepInjection, progressFingerprint, projectCoreV2, projectSessionCoreV2, proofCapabilityReport, proofDigest, proofDigestV2, proofEvidenceConstraints, proofHostSurfacesOf, proofOperationMatches, proofV2Rejection, proposeRebind, proposeRebindOutcome, proposeRebindV042, qualificationOfClause, qualifyBoundary, questionHeadsClause, readActiveHostGraph, rebindAttemptKey, rebindResponse, recoveryDigest, recoveryTitle, relevantEvidence, removalIsComplete, removalIsPartiallyKnown, renderRecoveryPacket, replayRawV2, replayRebindResult, reportingHeadGoverns, requestedIdentityKey, requestedTargetAuthorizesMutation, requestedTargetMatchesResolved, requiredSubjectsOf, resolveActiveProfileHostLock, resolveInstalledHostLock, restatedContentOf, revalidateGitPrestate, rootLocatorFlavor, sanitizeClauseText, sanitizeUrl, satisfiesSupportedHostRange, scopeCoverageDigest, segmentAuthorityBlocks, segmentClauses, selectHostCohort, semanticActionFromCommand, semanticActionFromText, semanticActionOfScope, sessionQuery, sessionQueryV2, sha256, snapshotSessionEvents, splitTextFragments, statefulActionsOfScope, supersedeItem, testOutcomePredicate, v6CurrentRootBoundaries, v6TestPredicate, validateActionManifest, validateActionTarget, validateManifest, validateProofManifest, validateProofManifestV2, verbIsNegated, verifiedLinearCommitReadback, verifyComposedHostLockDump, withDurability };
|