@sema-agent/core 7.62.0 → 7.63.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 +528 -0
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.js +82 -51
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-queries.d.ts +47 -4
- package/dist/core/checkpoint-queries.js +36 -16
- package/dist/core/checkpoint-requirements.d.ts +3 -3
- package/dist/core/checkpoint-requirements.js +2 -1
- package/dist/core/checkpoint-row-verdict.d.ts +15 -4
- package/dist/core/checkpoint-row-verdict.js +22 -2
- package/dist/core/checkpoint-store.d.ts +23 -10
- package/dist/core/checkpoint-store.js +45 -4
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/engine-attestation.d.ts +1 -1
- package/dist/core/engine-notice.d.ts +19 -4
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +7 -3
- package/dist/core/governance-codes.js +13 -3
- package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +73 -10
- package/dist/core/memory-engine/consolidation.js +167 -11
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
- package/dist/core/memory-engine/delegation-settlement.js +53 -59
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +9 -5
- package/dist/core/memory-engine/engine.d.ts +98 -35
- package/dist/core/memory-engine/engine.js +477 -380
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +29 -3
- package/dist/core/memory-engine/file-backend.js +66 -35
- package/dist/core/memory-engine/index.d.ts +7 -7
- package/dist/core/memory-engine/index.js +6 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +121 -45
- package/dist/core/memory-engine/layout.js +252 -102
- package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
- package/dist/core/memory-engine/memory-backend-contract.js +320 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
- package/dist/core/memory-engine/memory-deployment.js +26 -12
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +3 -1
- package/dist/core/memory-engine/session-write-home.js +1 -1
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +118 -19
- package/dist/core/memory-engine/types.js +1 -0
- package/dist/core/memory.js +15 -6
- package/dist/core/mods/stations.d.ts +20 -1
- package/dist/core/mods/stations.js +21 -2
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/permission-rule-consent.d.ts +10 -3
- package/dist/core/permission-rule-consent.js +37 -24
- package/dist/core/permission-rule-store.d.ts +35 -1
- package/dist/core/permission-rule-store.js +27 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/contracts.d.ts +18 -9
- package/dist/core/runner/gate-exit.js +2 -2
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/person-path-rows.d.ts +8 -3
- package/dist/core/runner/person-path-rows.js +5 -1
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-ask-lane.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +5 -2
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
- package/dist/core/runner/prepare-hands-readface.js +4 -3
- package/dist/core/runner/prepare-inherited-gate.d.ts +10 -8
- package/dist/core/runner/prepare-inherited-gate.js +8 -4
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +3 -2
- package/dist/core/runner/prepare-memory.js +28 -20
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-task.js +15 -12
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/run-leg.js +1 -1
- package/dist/core/runner/run-settle-and-teardown.js +3 -2
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner-deps.d.ts +6 -2
- package/dist/core/secret-env.d.ts +1 -1
- package/dist/core/secret-env.js +4 -4
- package/dist/core/session-checkout.d.ts +108 -0
- package/dist/core/session-checkout.js +485 -0
- package/dist/core/session-store.d.ts +12 -4
- package/dist/core/session-store.js +23 -3
- package/dist/core/session.d.ts +16 -2
- package/dist/core/session.js +3 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
- package/dist/core/store-contracts/session-store-contract.js +39 -0
- package/dist/core/task-event.d.ts +21 -0
- package/dist/core/task-notification.d.ts +9 -1
- package/dist/core/task-notification.js +6 -0
- package/dist/core/task-registry-agent.d.ts +14 -2
- package/dist/core/task-registry-agent.js +45 -19
- package/dist/core/task-registry-shared.d.ts +26 -11
- package/dist/core/task-registry.d.ts +15 -9
- package/dist/core/task-registry.js +9 -10
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +20 -0
- package/dist/core/tool-policy.d.ts +14 -12
- package/dist/core/tool-policy.js +11 -10
- package/dist/core/tool-spec.d.ts +38 -19
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/harness/types.d.ts +66 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +24 -1
- package/dist/engine/session/session.js +45 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +7 -4
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +4 -1
- package/dist/orchestration/run-workflow-tool.js +1 -0
- package/dist/orchestration/workflow.d.ts +3 -0
- package/dist/orchestration/workflow.js +3 -1
- package/dist/stores/file/session-store.js +2 -1
- package/dist/tools/fs/bash-program-position.js +3 -3
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +13 -1
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/removal-targets.js +3 -3
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +8 -1
- package/dist/tools/fs/shell-read-argv.js +34 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
- package/dist/tools/fs/shell-read-bindings.js +5 -1
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.js +10 -8
- package/dist/tools/fs/shell-read-establish.js +23 -16
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-plan.d.ts +10 -0
- package/dist/tools/fs/shell-read-plan.js +189 -93
- package/dist/tools/fs/shell-read-start.d.ts +19 -9
- package/dist/tools/fs/shell-read-start.js +20 -12
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
- package/dist/tools/fs/shell-read-workdir.js +73 -12
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +73 -11
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExecutionEnv, ReadFloor } from "../internal/harness-types.js";
|
|
2
|
+
import { type RepositoryProbe } from "../tools/fs/shell-read-object-path.js";
|
|
2
3
|
/** The managed parent (under the repository root) that holds every managed worktree — the reference implementation's
|
|
3
4
|
* `.claude/worktrees/` under this project's brand — so {@link pruneWorktrees} and a userland reaper find orphans by one known
|
|
4
5
|
* location. Every tree the engine mints lives at `<repoRoot>/.sema/worktrees/<slug>` (see {@link managedWorktreeDir}). */
|
|
@@ -11,11 +12,33 @@ export declare function managedWorktreeDir(repoRoot: string, name: string): stri
|
|
|
11
12
|
* when `dir` is not shaped as a managed tree. Literal, byte-exact segments (no case fold): this answer EXEMPTS, and a fold
|
|
12
13
|
* would widen an exemption. */
|
|
13
14
|
export declare function managedWorktreeBaseOf(dir: string): string | undefined;
|
|
15
|
+
/** The managed tree `dir` is in — `dir` itself, or its nearest ancestor shaped as one (a task root in `pkg/` of a session's tree
|
|
16
|
+
* sits at `<tree>/pkg`) — as its root and the checkout it was minted under; `undefined` when no level is a managed tree or a
|
|
17
|
+
* level below the tree is `.` / `..` (where that lands is not decided lexically, and this answer exempts). */
|
|
18
|
+
export declare function managedTreeAt(dir: string): {
|
|
19
|
+
readonly root: string;
|
|
20
|
+
readonly base: string;
|
|
21
|
+
} | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* THE repository root the managed parent is anchored at (the path law): the root of the checkout `dir` belongs
|
|
24
|
+
* to, read through the one repository-top reader ({@link repositoryTopOf} — no second walk). A managed tree is checked out
|
|
25
|
+
* BELOW the repository root it was minted under and its `.git` is a `gitdir:` file, which the top reader answers `undefined`
|
|
26
|
+
* for; so a `dir` at or below a managed tree (its root, a subdirectory of it, a symlink alias of either — read on the
|
|
27
|
+
* canonical spelling) is first peeled to the root before the marker's outermost occurrence (a tree minted by an older engine
|
|
28
|
+
* under another tree peels all the way out). `undefined` where the reader has no answer — not a repository, a linked work tree
|
|
29
|
+
* of the person's own, a submodule, a lookup the environment did not answer; the caller then stays at the root it was given.
|
|
30
|
+
*/
|
|
31
|
+
export declare function repositoryRootOf(env: RepositoryProbe, dir: string, signal?: AbortSignal): Promise<string | undefined>;
|
|
32
|
+
/** Where the managed parent hangs for a mint asked at `root`: the repository root when the reader names one, spelled as the
|
|
33
|
+
* caller spelled `root` whenever that is the same directory (a consumer comparing the tree's path with its own root's keeps
|
|
34
|
+
* one spelling); `root` itself when no repository root is named. */
|
|
35
|
+
export declare function managedAnchorOf(env: ExecutionEnv, root: string): Promise<string>;
|
|
14
36
|
/** The branch the path law gives the managed tree at `dir` (`sema/<slug>`), or `undefined` when `dir` is not a managed tree —
|
|
15
37
|
* what a recorded branch must equal before anything deletes it (a record cannot name some other branch for removal). */
|
|
16
38
|
export declare function managedWorktreeBranchOf(dir: string): string | undefined;
|
|
17
39
|
export interface AddWorktreeOptions {
|
|
18
|
-
/**
|
|
40
|
+
/** Where the mint is asked (the caller's task root — a checkout of the repository, typically its root). The managed parent
|
|
41
|
+
* hangs at the REPOSITORY root that checkout belongs to ({@link repositoryRootOf}); with no repository root named, here. */
|
|
19
42
|
repoRoot: string;
|
|
20
43
|
/** Stable per-task identity: with no {@link name}, the tree's name is this (sanitized) plus a random suffix — a fresh name
|
|
21
44
|
* per mint, for the lanes that mint one tree per child. */
|
|
@@ -36,6 +59,14 @@ export interface AddWorktreeOptions {
|
|
|
36
59
|
* step's failure (the add's refuses the mint before anything exists). Absent ⇒ the starts carry none (no run). */
|
|
37
60
|
readFloor?: () => ReadFloor | undefined;
|
|
38
61
|
}
|
|
62
|
+
/** Single-quote a path for the `exec` command STRING (the Shell API takes a command string, not argv). */
|
|
63
|
+
export declare function shq(s: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* THE path law's symlink half: from `.sema` down to the tree's own directory, NO level may be a symlink — a link committed to
|
|
66
|
+
* the repository at any of them would redirect the mint outside it. Three levels exactly (the slug is one directory, see
|
|
67
|
+
* {@link slugOf}); a level that does not exist yet is fine (git creates it), and a level whose kind cannot be read refuses.
|
|
68
|
+
*/
|
|
69
|
+
export declare function symlinkedLevel(env: ExecutionEnv, repoRoot: string, worktreeDir: string): Promise<string | undefined>;
|
|
39
70
|
/**
|
|
40
71
|
* Remove a managed worktree and — by the ONE branch rule — its branch: the branch is deleted only when its tip is still the
|
|
41
72
|
* commit the tree was minted at (it carries nothing the tree made); otherwise it is kept, so commits made in the tree stay
|
|
@@ -47,10 +78,13 @@ export interface AddWorktreeOptions {
|
|
|
47
78
|
* deregisters worktrees whose directory is gone). Check the result, retry once (the observed failures are transient),
|
|
48
79
|
* and report the outcome.
|
|
49
80
|
*/
|
|
50
|
-
export declare function removeManagedWorktree(baseEnv: ExecutionEnv, repoRoot: string, worktreeDir: string, branch
|
|
81
|
+
export declare function removeManagedWorktree(baseEnv: ExecutionEnv, repoRoot: string, worktreeDir: string, branch: {
|
|
51
82
|
readonly name: string;
|
|
52
83
|
readonly baseSha: string;
|
|
53
|
-
}, readFloor
|
|
84
|
+
} | undefined, readFloor: (() => ReadFloor | undefined) | undefined,
|
|
85
|
+
/** `"discard"` removes the tree whatever it holds (`--force`: the caller already decided its changes go); `"clean"` lets git
|
|
86
|
+
* refuse a tree with changes (no `--force`: whatever lands between the caller's own check and the removal keeps the tree). */
|
|
87
|
+
how: "discard" | "clean"): Promise<{
|
|
54
88
|
ok: true;
|
|
55
89
|
branchDeleted?: string;
|
|
56
90
|
branchKept?: string;
|
|
@@ -81,6 +115,31 @@ export declare function addWorktree(baseEnv: ExecutionEnv, opts: AddWorktreeOpti
|
|
|
81
115
|
branch: string;
|
|
82
116
|
baseSha?: string;
|
|
83
117
|
}>;
|
|
118
|
+
/**
|
|
119
|
+
* THE managed-tree mint with no environment attached: judges the name, anchors the managed parent at the repository root,
|
|
120
|
+
* refuses a symlinked level, runs `git worktree add` (a name whose directory or branch exists is refused) and registers the
|
|
121
|
+
* parent in the repository-local ignore file. {@link addWorktree} wraps it with a tree-rooted env whose destroy removes the
|
|
122
|
+
* tree; a session checkout keeps the tree past every env and removes it only on release.
|
|
123
|
+
*/
|
|
124
|
+
export declare function mintManagedWorktree(baseEnv: ExecutionEnv, opts: Pick<AddWorktreeOptions, "repoRoot" | "sessionId" | "name" | "commit" | "readFloor">): Promise<{
|
|
125
|
+
worktreeDir: string;
|
|
126
|
+
name: string;
|
|
127
|
+
branch: string;
|
|
128
|
+
anchor: string;
|
|
129
|
+
baseSha?: string;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* Resolve the commit a new tree starts from, by the base words EnterWorktree and the session declaration share: `"head"` =
|
|
133
|
+
* the current local HEAD; `"fresh"` = the default branch tip (origin's HEAD symbolic ref → local main → local master → HEAD,
|
|
134
|
+
* the fallback named in `note`). Run where the mint is asked (`repoRoot`).
|
|
135
|
+
*/
|
|
136
|
+
export declare function resolveBaseCommit(env: ExecutionEnv, repoRoot: string, baseRef: "fresh" | "head", readFloor: ReadFloor | undefined): Promise<{
|
|
137
|
+
sha: string;
|
|
138
|
+
label: string;
|
|
139
|
+
note?: string;
|
|
140
|
+
} | {
|
|
141
|
+
error: string;
|
|
142
|
+
}>;
|
|
84
143
|
/** Reap orphaned worktrees (after a crash removed their dirs) — `git worktree prune` deregisters them. A userland
|
|
85
144
|
* reaper calls this periodically against the base repo; core ships no post-kill Runner hook.
|
|
86
145
|
*
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { thrownLabel, thrownText } from "./thrown-value.js";
|
|
3
|
+
import { repositoryTopOf } from "../tools/fs/shell-read-object-path.js";
|
|
4
|
+
import { pathFamilyOf } from "../tools/fs/safety.js";
|
|
3
5
|
export const WORKTREE_PARENT = ".sema/worktrees";
|
|
4
6
|
const WORKTREE_BRANCH_PREFIX = "sema";
|
|
5
7
|
const NAME_SEGMENT = /^[a-zA-Z0-9._-]+$/;
|
|
@@ -33,15 +35,41 @@ export function managedWorktreeBaseOf(dir) {
|
|
|
33
35
|
const base = parts.slice(0, -3).join("/");
|
|
34
36
|
return base === "" ? "/" : base;
|
|
35
37
|
}
|
|
38
|
+
export function managedTreeAt(dir) {
|
|
39
|
+
const parts = dir.split("/");
|
|
40
|
+
for (let end = parts.length; end >= 4; end--) {
|
|
41
|
+
const root = parts.slice(0, end).join("/");
|
|
42
|
+
const base = managedWorktreeBaseOf(root);
|
|
43
|
+
if (base === undefined)
|
|
44
|
+
continue;
|
|
45
|
+
return parts.slice(end).some((s) => s === "." || s === "..") ? undefined : { root, base };
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const MANAGED_MARKER = `/${WORKTREE_PARENT}/`;
|
|
50
|
+
export async function repositoryRootOf(env, dir, signal) {
|
|
51
|
+
const canonical = await env.canonicalPath(dir, signal);
|
|
52
|
+
const spelled = canonical.ok ? canonical.value : dir;
|
|
53
|
+
const at = spelled.indexOf(MANAGED_MARKER);
|
|
54
|
+
const base = at < 0 ? dir : at === 0 ? "/" : spelled.slice(0, at);
|
|
55
|
+
return repositoryTopOf(env, base, pathFamilyOf({ root: base }), signal);
|
|
56
|
+
}
|
|
57
|
+
export async function managedAnchorOf(env, root) {
|
|
58
|
+
const top = await repositoryRootOf(env, root);
|
|
59
|
+
if (top === undefined)
|
|
60
|
+
return root;
|
|
61
|
+
const own = await env.canonicalPath(root);
|
|
62
|
+
return own.ok && own.value === top ? root : top;
|
|
63
|
+
}
|
|
36
64
|
export function managedWorktreeBranchOf(dir) {
|
|
37
65
|
if (managedWorktreeBaseOf(dir) === undefined)
|
|
38
66
|
return undefined;
|
|
39
67
|
return `${WORKTREE_BRANCH_PREFIX}/${dir.slice(dir.lastIndexOf("/") + 1)}`;
|
|
40
68
|
}
|
|
41
|
-
function shq(s) {
|
|
69
|
+
export function shq(s) {
|
|
42
70
|
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
43
71
|
}
|
|
44
|
-
async function symlinkedLevel(env, repoRoot, worktreeDir) {
|
|
72
|
+
export async function symlinkedLevel(env, repoRoot, worktreeDir) {
|
|
45
73
|
for (const level of [`${repoRoot}/.sema`, `${repoRoot}/${WORKTREE_PARENT}`, worktreeDir]) {
|
|
46
74
|
const info = await env.fileInfo(level);
|
|
47
75
|
if (!info.ok) {
|
|
@@ -55,13 +83,13 @@ async function symlinkedLevel(env, repoRoot, worktreeDir) {
|
|
|
55
83
|
}
|
|
56
84
|
return undefined;
|
|
57
85
|
}
|
|
58
|
-
export async function removeManagedWorktree(baseEnv, repoRoot, worktreeDir, branch, readFloor) {
|
|
86
|
+
export async function removeManagedWorktree(baseEnv, repoRoot, worktreeDir, branch, readFloor, how) {
|
|
59
87
|
const readFloorNow = () => { const f = readFloor?.(); return f !== undefined ? { readFloor: f } : {}; };
|
|
60
88
|
let detail = "";
|
|
61
89
|
let removed = false;
|
|
62
90
|
for (let attempt = 0; attempt < 2 && !removed; attempt++) {
|
|
63
91
|
try {
|
|
64
|
-
const r = await baseEnv.exec(`git worktree remove --force ${shq(worktreeDir)}`, { cwd: repoRoot, ...readFloorNow() });
|
|
92
|
+
const r = await baseEnv.exec(`git worktree remove ${how === "discard" ? "--force " : ""}${shq(worktreeDir)}`, { cwd: repoRoot, ...readFloorNow() });
|
|
65
93
|
if (r.ok && r.value.exitCode === 0)
|
|
66
94
|
removed = true;
|
|
67
95
|
else
|
|
@@ -93,13 +121,42 @@ export async function removeManagedWorktree(baseEnv, repoRoot, worktreeDir, bran
|
|
|
93
121
|
}
|
|
94
122
|
}
|
|
95
123
|
export async function addWorktree(baseEnv, opts) {
|
|
124
|
+
const { worktreeDir, name, branch, anchor, baseSha } = await mintManagedWorktree(baseEnv, opts);
|
|
125
|
+
const branchRule = baseSha !== undefined ? { name: branch, baseSha } : undefined;
|
|
126
|
+
let inner;
|
|
127
|
+
try {
|
|
128
|
+
inner = await opts.rootEnvAt(worktreeDir);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
await removeManagedWorktree(baseEnv, anchor, worktreeDir, branchRule, opts.readFloor, "discard");
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
const innerDestroy = inner.destroy;
|
|
135
|
+
const env = inner;
|
|
136
|
+
env.destroy = async () => {
|
|
137
|
+
try {
|
|
138
|
+
if (typeof innerDestroy === "function")
|
|
139
|
+
await innerDestroy.call(inner);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
const removed = await removeManagedWorktree(baseEnv, anchor, worktreeDir, branchRule, opts.readFloor, "discard");
|
|
143
|
+
if (!removed.ok) {
|
|
144
|
+
throw new Error(`git worktree remove failed twice — ${worktreeDir} is now an orphan (dir + registration remain; ` +
|
|
145
|
+
`\`git worktree prune\` cannot reclaim it while the dir exists — remove it manually): ${removed.detail}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return { env, worktreeDir, name, branch, ...(baseSha !== undefined ? { baseSha } : {}) };
|
|
150
|
+
}
|
|
151
|
+
export async function mintManagedWorktree(baseEnv, opts) {
|
|
96
152
|
const name = opts.name ?? `${(opts.sessionId || "task").replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 50)}-${randomUUID().slice(0, 8)}`;
|
|
97
153
|
const nameProblem = worktreeNameProblem(name);
|
|
98
154
|
if (nameProblem !== undefined)
|
|
99
155
|
throw new Error(nameProblem);
|
|
100
|
-
const
|
|
156
|
+
const anchor = await managedAnchorOf(baseEnv, opts.repoRoot);
|
|
157
|
+
const worktreeDir = managedWorktreeDir(anchor, name);
|
|
101
158
|
const branch = `${WORKTREE_BRANCH_PREFIX}/${slugOf(name)}`;
|
|
102
|
-
const symlinked = await symlinkedLevel(baseEnv,
|
|
159
|
+
const symlinked = await symlinkedLevel(baseEnv, anchor, worktreeDir);
|
|
103
160
|
if (symlinked !== undefined)
|
|
104
161
|
throw new Error(symlinked);
|
|
105
162
|
const readFloorNow = () => { const readFloor = opts.readFloor?.(); return readFloor !== undefined ? { readFloor } : {}; };
|
|
@@ -114,37 +171,41 @@ export async function addWorktree(baseEnv, opts) {
|
|
|
114
171
|
const excludeLine = shq(`/${WORKTREE_PARENT}/`);
|
|
115
172
|
await Promise.resolve()
|
|
116
173
|
.then(() => baseEnv.exec(`ex="$(git rev-parse --git-path info/exclude)" && mkdir -p "$(dirname "$ex")" && ` +
|
|
117
|
-
`{ grep -qxF ${excludeLine} "$ex" 2>/dev/null || printf '%s\\n' ${excludeLine} >> "$ex"; }`, { cwd:
|
|
174
|
+
`{ grep -qxF ${excludeLine} "$ex" 2>/dev/null || printf '%s\\n' ${excludeLine} >> "$ex"; }`, { cwd: anchor, ...readFloorNow() }))
|
|
118
175
|
.catch(() => undefined);
|
|
119
176
|
const baseSha = await Promise.resolve()
|
|
120
177
|
.then(() => baseEnv.exec("git rev-parse HEAD", { cwd: worktreeDir, ...readFloorNow() }))
|
|
121
178
|
.then((r) => (r.ok && r.value.exitCode === 0 && r.value.stdout.trim() !== "" ? r.value.stdout.trim() : undefined))
|
|
122
179
|
.catch(() => undefined);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
180
|
+
return { worktreeDir, name, branch, anchor, ...(baseSha !== undefined ? { baseSha } : {}) };
|
|
181
|
+
}
|
|
182
|
+
export async function resolveBaseCommit(env, repoRoot, baseRef, readFloor) {
|
|
183
|
+
const rev = async (ref) => {
|
|
184
|
+
const r = await env.exec(`git rev-parse --verify --quiet ${shq(`${ref}^{commit}`)}`, { cwd: repoRoot, ...(readFloor !== undefined ? { readFloor } : {}) });
|
|
185
|
+
return r.ok && r.value.exitCode === 0 ? r.value.stdout.trim() : undefined;
|
|
186
|
+
};
|
|
187
|
+
if (baseRef === "head") {
|
|
188
|
+
const sha = await rev("HEAD");
|
|
189
|
+
return sha ? { sha, label: "HEAD" } : { error: "cannot resolve HEAD (empty repository with no commits?)" };
|
|
131
190
|
}
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
191
|
+
const sym = await env.exec("git symbolic-ref --quiet refs/remotes/origin/HEAD", { cwd: repoRoot, ...(readFloor !== undefined ? { readFloor } : {}) });
|
|
192
|
+
if (sym.ok && sym.value.exitCode === 0) {
|
|
193
|
+
const branch = sym.value.stdout.trim().replace(/^refs\/remotes\//, "");
|
|
194
|
+
if (branch) {
|
|
195
|
+
const sha = await rev(branch);
|
|
196
|
+
if (sha)
|
|
197
|
+
return { sha, label: branch };
|
|
138
198
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
199
|
+
}
|
|
200
|
+
for (const candidate of ["main", "master"]) {
|
|
201
|
+
const sha = await rev(candidate);
|
|
202
|
+
if (sha)
|
|
203
|
+
return { sha, label: candidate };
|
|
204
|
+
}
|
|
205
|
+
const sha = await rev("HEAD");
|
|
206
|
+
return sha
|
|
207
|
+
? { sha, label: "HEAD", note: " (no remote default branch or local main/master found — fell back to HEAD)" }
|
|
208
|
+
: { error: "cannot resolve a fresh base (no default branch and no HEAD)" };
|
|
148
209
|
}
|
|
149
210
|
export async function pruneWorktrees(baseEnv, repoRoot, readFloor) {
|
|
150
211
|
try {
|
|
@@ -145,7 +145,7 @@ export type NoticeAudience = "user" | "operator";
|
|
|
145
145
|
* the union's catalog ({@link EngineNotice.code}). The groups below say only which family a row joins,
|
|
146
146
|
* so the catalog is not written a second time here and the two cannot drift.
|
|
147
147
|
*/
|
|
148
|
-
export declare const ENGINE_NOTICE_CODES: readonly ["config.autocompact_window_clamped", "config.env_timeout_discarded", "config.materialize_env_discarded", "config.models_swapped", "config.context_settings_swapped", "config.read_face_swapped", "config.read_face_deployment_clamped", "config.write_face_swapped", "config.write_face_deployment_clamped", "config.read_deny_swapped", "config.tool_model_gate_removed", "config.tool_model_gate_unknown_class", "config.tool_model_gate_env_invalid", "config.artifact_host_invalid", "config.task_root_not_canonical", "config.write_protection_target_view_absent", "config.path_view_unresolved", "config.execution_env_capability_invalid", "config.read_deny_floor_unkept", "config.read_floor_confinement_unavailable", "config.tool_card_undeclared", "config.tool_face_undeclared", "config.tool_face_invalid", "config.forward_sink_failed", "config.durable_gate_unavailable", "config.peer_admission_out_of_range", "config.peer_lane_unmounted", "config.secret_env_scrubbed", "inherit_env.names_withheld", "config.credential_not_withheld", "config.cross_boundary_posture_undeclared", "config.cross_boundary_record_unwritten", "config.permission_mode_unavailable", "permission.ask_released_by_mode", "permission.read_deny_unapplied", "permission.rule_store_unavailable", "permission.rule_row_dropped", "config.session_rules_earlier_grammar", "permission.allowed_tool_not_granted", "mods.registration_refused", "peer.inbound_disposition", "peer.held_settled", "peer.idle_subscription", "classifier.denial_limit", "classifier.fallback", "classifier.seat_rate_limited", "classifier.role_defaulted", "classifier.contract_broken", "classifier.unavailable", "checkpoint.execution_outcome_unrecorded", "delegation.transcript_integrity", "delegation.ask_unresolvable", "mcp.injection_dropped", "mcp.revocation_probe_failed", "mcp.server_redialed", "mcp.authorization_required", "mcp.credential_echoed", "workflow.governance_key_stripped", "workflow.agent_option_ignored", "memory.session_polluted", "memory.harvest_quarantined", "memory.delegation_static_mark_waived", "memory.content_class_declared", "memory.hold_opened", "memory.hold_released", "memory.hold_disposed", "memory.consolidation_recommended", "memory.consolidation_committed", "memory.consolidation_conflict", "memory.consolidation_incomplete", "memory.consolidation_refused", "memory.consolidation_withheld", "memory.restore_withheld", "memory.project_scope_absent", "route.fallback_to_primary", "route.classifier_unroutable", "route.seat_detached", "advisor.not_attached", "route.credential_origin_mismatch", "route.credential_rebound", "route.response_model_mismatch", "route.tool_call_id_folded", "route.finish_reason_unknown", "route.stream_end_ignored", "route.extra_body_reserved_dropped", "model.capability_downgraded", "model.role_defaulted", "context.tool_turn_repaired", "context.media_removed", "context.tool_schema_removed", "task.user_steer_undrained", "task.user_followup_undrained", "steering.parked_input_blocked", "task.turn_interrupted", "task.halt_unconsumed", "task.late_approval", "task.interrupt_unconsumed", "task.tool_turn_incomplete", "approval.read_root_granted", "approval.read_root_grant_rejected", "memory.capture_opted_out", "memory.capture_optout_unpersisted", "skills.listing_truncated", "agents.listing_truncated", "tool_result.offload_put_failed", "tool_result.media_refused", "config.image_processor_unavailable", "fs.staging_file_left", "fs.staging_file_swept", "session.lineage_rerooted", "instructions.source_changed", "
|
|
148
|
+
export declare const ENGINE_NOTICE_CODES: readonly ["config.autocompact_window_clamped", "config.env_timeout_discarded", "config.materialize_env_discarded", "config.models_swapped", "config.context_settings_swapped", "config.read_face_swapped", "config.read_face_deployment_clamped", "config.write_face_swapped", "config.write_face_deployment_clamped", "config.read_deny_swapped", "config.tool_model_gate_removed", "config.tool_model_gate_unknown_class", "config.tool_model_gate_env_invalid", "config.artifact_host_invalid", "config.task_root_not_canonical", "config.write_protection_target_view_absent", "config.path_view_unresolved", "config.execution_env_capability_invalid", "config.read_deny_floor_unkept", "config.read_floor_confinement_unavailable", "config.tool_card_undeclared", "config.tool_face_undeclared", "config.tool_face_invalid", "config.forward_sink_failed", "config.durable_gate_unavailable", "config.peer_admission_out_of_range", "config.peer_lane_unmounted", "config.secret_env_scrubbed", "inherit_env.names_withheld", "config.credential_not_withheld", "config.cross_boundary_posture_undeclared", "config.cross_boundary_record_unwritten", "config.permission_mode_unavailable", "permission.ask_released_by_mode", "permission.read_deny_unapplied", "permission.rule_store_unavailable", "permission.rule_row_dropped", "config.session_rules_earlier_grammar", "permission.allowed_tool_not_granted", "mods.registration_refused", "peer.inbound_disposition", "peer.held_settled", "peer.idle_subscription", "classifier.denial_limit", "classifier.fallback", "classifier.seat_rate_limited", "classifier.role_defaulted", "classifier.contract_broken", "classifier.unavailable", "checkpoint.execution_outcome_unrecorded", "delegation.transcript_integrity", "delegation.ask_unresolvable", "delegation.resume_lane_missing", "mcp.injection_dropped", "mcp.revocation_probe_failed", "mcp.server_redialed", "mcp.authorization_required", "mcp.credential_echoed", "workflow.governance_key_stripped", "workflow.agent_option_ignored", "memory.session_polluted", "memory.harvest_quarantined", "memory.harvest_refused", "memory.harvest_conflict", "memory.delegation_static_mark_waived", "memory.content_class_declared", "memory.hold_opened", "memory.hold_released", "memory.hold_disposed", "memory.consolidation_recommended", "memory.consolidation_committed", "memory.consolidation_conflict", "memory.consolidation_incomplete", "memory.consolidation_refused", "memory.consolidation_withheld", "memory.restore_withheld", "memory.project_scope_absent", "route.fallback_to_primary", "route.classifier_unroutable", "route.seat_detached", "advisor.not_attached", "route.credential_origin_mismatch", "route.credential_rebound", "route.response_model_mismatch", "route.tool_call_id_folded", "route.finish_reason_unknown", "route.stream_end_ignored", "route.extra_body_reserved_dropped", "model.capability_downgraded", "model.role_defaulted", "context.tool_turn_repaired", "context.media_removed", "context.tool_schema_removed", "task.user_steer_undrained", "task.user_followup_undrained", "steering.parked_input_blocked", "task.turn_interrupted", "task.halt_unconsumed", "task.late_approval", "task.interrupt_unconsumed", "task.tool_turn_incomplete", "approval.read_root_granted", "approval.read_root_grant_rejected", "memory.capture_opted_out", "memory.capture_optout_unpersisted", "skills.listing_truncated", "agents.listing_truncated", "tool_result.offload_put_failed", "tool_result.media_refused", "config.image_processor_unavailable", "fs.staging_file_left", "fs.staging_file_swept", "session.lineage_rerooted", "instructions.source_changed", "memory.layer_locked_legacy", "server.model_unreachable", "permission.entry_mode_clamped"];
|
|
149
149
|
/** A catalogued code (see {@link ENGINE_NOTICE_CODES}); {@link NOTICE_MINTER} says who mints it. NOT the type of
|
|
150
150
|
* `EngineNotice.code`, which stays `string` — a host forwarding its own notices through the same
|
|
151
151
|
* sink is a supported shape, and narrowing that field would break it. */
|
|
@@ -166,6 +166,8 @@ export type EngineNoticeCode = (typeof ENGINE_NOTICE_CODES)[number];
|
|
|
166
166
|
declare const NOTICE_AUDIENCE_TABLE: {
|
|
167
167
|
readonly "memory.session_polluted": "user";
|
|
168
168
|
readonly "memory.harvest_quarantined": "user";
|
|
169
|
+
readonly "memory.harvest_refused": "user";
|
|
170
|
+
readonly "memory.harvest_conflict": "user";
|
|
169
171
|
readonly "memory.delegation_static_mark_waived": "user";
|
|
170
172
|
readonly "memory.hold_opened": "user";
|
|
171
173
|
readonly "memory.hold_released": "user";
|
|
@@ -236,6 +238,7 @@ declare const NOTICE_AUDIENCE_TABLE: {
|
|
|
236
238
|
readonly "peer.held_settled": "user";
|
|
237
239
|
readonly "peer.idle_subscription": "user";
|
|
238
240
|
readonly "delegation.transcript_integrity": "operator";
|
|
241
|
+
readonly "delegation.resume_lane_missing": "operator";
|
|
239
242
|
readonly "checkpoint.execution_outcome_unrecorded": "operator";
|
|
240
243
|
readonly "mcp.injection_dropped": "user";
|
|
241
244
|
readonly "mcp.revocation_probe_failed": "operator";
|
|
@@ -275,7 +278,6 @@ declare const NOTICE_AUDIENCE_TABLE: {
|
|
|
275
278
|
readonly "session.lineage_rerooted": "user";
|
|
276
279
|
readonly "config.forward_sink_failed": "operator";
|
|
277
280
|
readonly "instructions.source_changed": "user";
|
|
278
|
-
readonly "session.records_skipped": "user";
|
|
279
281
|
readonly "server.model_unreachable": "user";
|
|
280
282
|
readonly "permission.entry_mode_clamped": "user";
|
|
281
283
|
readonly "memory.layer_locked_legacy": "operator";
|
|
@@ -356,6 +358,7 @@ declare const NOTICE_MINTER_TABLE: {
|
|
|
356
358
|
readonly "checkpoint.execution_outcome_unrecorded": "engine";
|
|
357
359
|
readonly "delegation.transcript_integrity": "engine";
|
|
358
360
|
readonly "delegation.ask_unresolvable": "engine";
|
|
361
|
+
readonly "delegation.resume_lane_missing": "engine";
|
|
359
362
|
readonly "mcp.injection_dropped": "engine";
|
|
360
363
|
readonly "mcp.revocation_probe_failed": "engine";
|
|
361
364
|
readonly "mcp.server_redialed": "engine";
|
|
@@ -365,6 +368,8 @@ declare const NOTICE_MINTER_TABLE: {
|
|
|
365
368
|
readonly "workflow.agent_option_ignored": "engine";
|
|
366
369
|
readonly "memory.session_polluted": "engine";
|
|
367
370
|
readonly "memory.harvest_quarantined": "engine";
|
|
371
|
+
readonly "memory.harvest_refused": "engine";
|
|
372
|
+
readonly "memory.harvest_conflict": "engine";
|
|
368
373
|
readonly "memory.delegation_static_mark_waived": "engine";
|
|
369
374
|
readonly "memory.content_class_declared": "engine";
|
|
370
375
|
readonly "memory.hold_opened": "engine";
|
|
@@ -415,7 +420,6 @@ declare const NOTICE_MINTER_TABLE: {
|
|
|
415
420
|
readonly "fs.staging_file_swept": "engine";
|
|
416
421
|
readonly "session.lineage_rerooted": "engine";
|
|
417
422
|
readonly "instructions.source_changed": "server";
|
|
418
|
-
readonly "session.records_skipped": "server";
|
|
419
423
|
readonly "memory.layer_locked_legacy": "server";
|
|
420
424
|
readonly "server.model_unreachable": "server";
|
|
421
425
|
readonly "permission.entry_mode_clamped": "server";
|
|
@@ -27,6 +27,8 @@ export const NON_GOVERNANCE_MEMORY_CODES = new Set([
|
|
|
27
27
|
"memory.session_incarnation_unreadable",
|
|
28
28
|
"memory.session_polluted",
|
|
29
29
|
"memory.harvest_quarantined",
|
|
30
|
+
"memory.harvest_refused",
|
|
31
|
+
"memory.harvest_conflict",
|
|
30
32
|
"memory.delegation_static_mark_waived",
|
|
31
33
|
"memory.content_class_declared",
|
|
32
34
|
"memory.consolidation_driver_superseded",
|
|
@@ -58,6 +60,8 @@ export const NON_GOVERNANCE_MEMORY_CODES = new Set([
|
|
|
58
60
|
"memory.challenge_ledger_oversize",
|
|
59
61
|
"memory.control_plane_rebuilt",
|
|
60
62
|
"memory.control_plane_not_corrupt",
|
|
63
|
+
"memory.control_plane_rebuild_unsupported",
|
|
64
|
+
"memory.governance_doc_unknown",
|
|
61
65
|
"memory.erasure_evidence_unavailable",
|
|
62
66
|
"memory.erasure_selector_mismatch",
|
|
63
67
|
"memory.erasure_census_incomplete",
|
|
@@ -176,6 +180,7 @@ export const ENGINE_NOTICE_CODES = Object.freeze([
|
|
|
176
180
|
"checkpoint.execution_outcome_unrecorded",
|
|
177
181
|
"delegation.transcript_integrity",
|
|
178
182
|
"delegation.ask_unresolvable",
|
|
183
|
+
"delegation.resume_lane_missing",
|
|
179
184
|
"mcp.injection_dropped",
|
|
180
185
|
"mcp.revocation_probe_failed",
|
|
181
186
|
"mcp.server_redialed",
|
|
@@ -185,6 +190,8 @@ export const ENGINE_NOTICE_CODES = Object.freeze([
|
|
|
185
190
|
"workflow.agent_option_ignored",
|
|
186
191
|
"memory.session_polluted",
|
|
187
192
|
"memory.harvest_quarantined",
|
|
193
|
+
"memory.harvest_refused",
|
|
194
|
+
"memory.harvest_conflict",
|
|
188
195
|
"memory.delegation_static_mark_waived",
|
|
189
196
|
"memory.content_class_declared",
|
|
190
197
|
"memory.hold_opened",
|
|
@@ -235,7 +242,6 @@ export const ENGINE_NOTICE_CODES = Object.freeze([
|
|
|
235
242
|
"fs.staging_file_swept",
|
|
236
243
|
"session.lineage_rerooted",
|
|
237
244
|
"instructions.source_changed",
|
|
238
|
-
"session.records_skipped",
|
|
239
245
|
"memory.layer_locked_legacy",
|
|
240
246
|
"server.model_unreachable",
|
|
241
247
|
"permission.entry_mode_clamped",
|
|
@@ -243,6 +249,8 @@ export const ENGINE_NOTICE_CODES = Object.freeze([
|
|
|
243
249
|
const NOTICE_AUDIENCE_TABLE = {
|
|
244
250
|
"memory.session_polluted": "user",
|
|
245
251
|
"memory.harvest_quarantined": "user",
|
|
252
|
+
"memory.harvest_refused": "user",
|
|
253
|
+
"memory.harvest_conflict": "user",
|
|
246
254
|
"memory.delegation_static_mark_waived": "user",
|
|
247
255
|
"memory.hold_opened": "user",
|
|
248
256
|
"memory.hold_released": "user",
|
|
@@ -313,6 +321,7 @@ const NOTICE_AUDIENCE_TABLE = {
|
|
|
313
321
|
"peer.held_settled": "user",
|
|
314
322
|
"peer.idle_subscription": "user",
|
|
315
323
|
"delegation.transcript_integrity": "operator",
|
|
324
|
+
"delegation.resume_lane_missing": "operator",
|
|
316
325
|
"checkpoint.execution_outcome_unrecorded": "operator",
|
|
317
326
|
"mcp.injection_dropped": "user",
|
|
318
327
|
"mcp.revocation_probe_failed": "operator",
|
|
@@ -352,7 +361,6 @@ const NOTICE_AUDIENCE_TABLE = {
|
|
|
352
361
|
"session.lineage_rerooted": "user",
|
|
353
362
|
"config.forward_sink_failed": "operator",
|
|
354
363
|
"instructions.source_changed": "user",
|
|
355
|
-
"session.records_skipped": "user",
|
|
356
364
|
"server.model_unreachable": "user",
|
|
357
365
|
"permission.entry_mode_clamped": "user",
|
|
358
366
|
"memory.layer_locked_legacy": "operator",
|
|
@@ -414,6 +422,7 @@ const NOTICE_MINTER_TABLE = {
|
|
|
414
422
|
"checkpoint.execution_outcome_unrecorded": "engine",
|
|
415
423
|
"delegation.transcript_integrity": "engine",
|
|
416
424
|
"delegation.ask_unresolvable": "engine",
|
|
425
|
+
"delegation.resume_lane_missing": "engine",
|
|
417
426
|
"mcp.injection_dropped": "engine",
|
|
418
427
|
"mcp.revocation_probe_failed": "engine",
|
|
419
428
|
"mcp.server_redialed": "engine",
|
|
@@ -423,6 +432,8 @@ const NOTICE_MINTER_TABLE = {
|
|
|
423
432
|
"workflow.agent_option_ignored": "engine",
|
|
424
433
|
"memory.session_polluted": "engine",
|
|
425
434
|
"memory.harvest_quarantined": "engine",
|
|
435
|
+
"memory.harvest_refused": "engine",
|
|
436
|
+
"memory.harvest_conflict": "engine",
|
|
426
437
|
"memory.delegation_static_mark_waived": "engine",
|
|
427
438
|
"memory.content_class_declared": "engine",
|
|
428
439
|
"memory.hold_opened": "engine",
|
|
@@ -473,7 +484,6 @@ const NOTICE_MINTER_TABLE = {
|
|
|
473
484
|
"fs.staging_file_swept": "engine",
|
|
474
485
|
"session.lineage_rerooted": "engine",
|
|
475
486
|
"instructions.source_changed": "server",
|
|
476
|
-
"session.records_skipped": "server",
|
|
477
487
|
"memory.layer_locked_legacy": "server",
|
|
478
488
|
"server.model_unreachable": "server",
|
|
479
489
|
"permission.entry_mode_clamped": "server",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
* auto lane's task-boundary tick), never on a background schedule of core's own.
|
|
22
22
|
*/
|
|
23
23
|
import type { EngineNotice } from "../types.js";
|
|
24
|
-
import
|
|
24
|
+
import type { MemoryGovernanceStore } from "./types.js";
|
|
25
|
+
import { type ConsolidationGateRow, CONSOLIDATION_WRITE_REFUSED_CODE, type ConsolidationRunStopReason, type MemoryConsolidationOptions } from "./consolidation.js";
|
|
25
26
|
import { type ConsolidationPlanFoldEvidence, type ConsolidationPlanSummary } from "./engine.js";
|
|
27
|
+
import { type ComplianceCapability, type CompliancePostureSeat } from "../compliance.js";
|
|
26
28
|
import type { SyntheticWriteVerdict } from "../synthetic-read-verdict.js";
|
|
27
|
-
import { mintLlmConsolidationPlan, type ConsolidationDriveCycleRow, type ConsolidationDriveEngine, type ConsolidationFoldState, type DistillerChatFn, type
|
|
28
|
-
export declare const CONSOLIDATION_DRIVER_RUNS_FILE = "distiller-runs.json";
|
|
29
|
-
export { CONSOLIDATION_DRIVER_PLANS_DIR };
|
|
29
|
+
import { mintLlmConsolidationPlan, type ConsolidationDriveCycleRow, type ConsolidationDriveEngine, type ConsolidationFoldState, type DistillerChatFn, type LlmConsolidationPlanProduct, type LlmDistillerContract } from "./distiller.js";
|
|
30
30
|
export interface ConsolidationDriverRunRow {
|
|
31
31
|
runId: string;
|
|
32
32
|
scope: string;
|
|
@@ -79,7 +79,7 @@ export interface ConsolidationDriverRunRow {
|
|
|
79
79
|
* dies with a discarded cache, and "your data never left this machine" must not become
|
|
80
80
|
* unanswerable because an unrelated guard fired. */
|
|
81
81
|
withheldNeverSent?: number;
|
|
82
|
-
/** The archived mint transcript's
|
|
82
|
+
/** The archived mint transcript's name in the consolidation store (`MemoryGovernanceStore.readMint`). */
|
|
83
83
|
planArchive?: string;
|
|
84
84
|
/** COMMITTED cycles only (the store moved): a refused/fuse-blocked/zero-delta cycle row does
|
|
85
85
|
* not count — the receipt's "committed cycle(s)" label and the incomplete notice's zero-cycle
|
|
@@ -124,26 +124,20 @@ export interface ConsolidationDriverRunRow {
|
|
|
124
124
|
/** The next moment a snapshot can pass the hard throttle (resume scheduling hint). */
|
|
125
125
|
nextEligibleAt?: number;
|
|
126
126
|
}
|
|
127
|
-
/** Host read face: the scope's latest driver run row (pending = resumable; settled = audit). */
|
|
128
|
-
export declare function readConsolidationDriverRun(controlDir: string, scope: string): ConsolidationDriverRunRow | undefined;
|
|
129
|
-
/** Archive one mint (prompts + transcript verbatim) beside the run account. The name carries the
|
|
130
|
-
* CLAIM (`attempt`): two invocations that raced onto one run each archive
|
|
131
|
-
* under their own name, so a superseded worker can never overwrite the winning transcript — the
|
|
132
|
-
* run row's `planArchive` (written under the attempt guard) names the one that counts. */
|
|
133
|
-
export declare function distillerPlanArchiveName(runId: string, attempt: number): string;
|
|
134
|
-
export declare function archiveDistillerPlan(controlDir: string, runId: string, plan: LlmConsolidationPlan, attempt?: number): string;
|
|
135
127
|
/** The engine face this verb consumes — `MemoryEngine` satisfies it structurally.
|
|
136
128
|
* (`readConsolidationPlanFoldEvidence` joined in design/376 slice ③, #436: the conservation
|
|
137
129
|
* wall's terminal witness is member-level, so the face is REQUIRED — an engine without it could
|
|
138
130
|
* only offer the store-delta counts an interleaved fold can numerically offset.) */
|
|
139
131
|
export interface ConsolidationDriverEngine extends ConsolidationDriveEngine {
|
|
140
|
-
readConsolidationGate(scope: string): ConsolidationGateRow | undefined
|
|
141
|
-
listConsolidationPlans(): ConsolidationPlanSummary[]
|
|
142
|
-
readConsolidationPlanFoldEvidence(planId: string): ConsolidationPlanFoldEvidence
|
|
132
|
+
readConsolidationGate(scope: string): Promise<ConsolidationGateRow | undefined>;
|
|
133
|
+
listConsolidationPlans(): Promise<ConsolidationPlanSummary[]>;
|
|
134
|
+
readConsolidationPlanFoldEvidence(planId: string): Promise<ConsolidationPlanFoldEvidence>;
|
|
143
135
|
readConsolidationFoldState(scope: string): Promise<ConsolidationFoldState>;
|
|
144
136
|
/** The canonical directory a commit lands the scope's products in (the write judge's early question). */
|
|
145
137
|
consolidationWriteHome(scope: string): string;
|
|
146
|
-
|
|
138
|
+
/** The store the engine keeps its consolidation state in (the run account, the mint archive and the run's
|
|
139
|
+
* announcements — its `announcements` document — are written through it). */
|
|
140
|
+
readonly governance: MemoryGovernanceStore;
|
|
147
141
|
}
|
|
148
142
|
/** One write the judge is asked about: `path` is a file (or the library directory) of `scope`'s library, absolute and canonical. */
|
|
149
143
|
export interface ConsolidationWriteTarget {
|
|
@@ -153,6 +147,24 @@ export interface ConsolidationWriteTarget {
|
|
|
153
147
|
/** The write judge's seat: one target in, the synthetic-write judge's verdict out (only `no_objection` permits the write). */
|
|
154
148
|
export type ConsolidationWriteJudge = (target: ConsolidationWriteTarget) => Promise<SyntheticWriteVerdict> | SyntheticWriteVerdict;
|
|
155
149
|
export { CONSOLIDATION_WRITE_REFUSED_CODE };
|
|
150
|
+
/**
|
|
151
|
+
* A consolidation run's compliance veto. The posture asked is the one of the scope's OWNER (`memoryScopeOwnerOf`, read
|
|
152
|
+
* under `scopeContract`): a principal's own layer asks `postureOf` with that principal; a tenant's layer and an opaque key
|
|
153
|
+
* ask it with no principal (the deployment's posture — the seat is keyed by principals). Outside the v2 contract the
|
|
154
|
+
* principal a key's spelling names is asked too, refuse-only (a stored `user:<P>` layer stays P's whichever contract a
|
|
155
|
+
* task declares). `denies` are the caller's own,
|
|
156
|
+
* added to the owner's (add-only: the Runner's automatic run passes the leg's `TaskSpec.complianceAdditionalDenies`).
|
|
157
|
+
* `memory_consolidation` among them refuses `config.compliance_denied`; a seat that throws or answers an unparseable
|
|
158
|
+
* posture refuses `config.compliance_required` (fail-closed). Both are {@link ConsolidationRefusedError}s, and nothing
|
|
159
|
+
* has been read or written.
|
|
160
|
+
*/
|
|
161
|
+
export interface ConsolidationCompliance {
|
|
162
|
+
/** The deployment's posture seat (`RunnerDeps.compliancePostureResolver`); absent ⇒ only `denies` apply. */
|
|
163
|
+
postureOf?: CompliancePostureSeat;
|
|
164
|
+
/** The scope contract the scope was minted under (`TaskSpec.memory.scopeContract`) — a required key. */
|
|
165
|
+
scopeContract: "v2" | undefined;
|
|
166
|
+
denies?: readonly ComplianceCapability[];
|
|
167
|
+
}
|
|
156
168
|
export interface RunMemoryConsolidationOptions {
|
|
157
169
|
/** The explicit model seat (design/339 §1.1: the ENGINE holds none). Build one with
|
|
158
170
|
* `openAiCompatChatSeat` or hand any JSON-only completion function. */
|
|
@@ -170,6 +182,9 @@ export interface RunMemoryConsolidationOptions {
|
|
|
170
182
|
* throw — refuses the run with `memory.consolidation_write_refused`, and nothing is written. A host that holds no rules
|
|
171
183
|
* says so by passing a judge that answers `no_objection`; an absent seat refuses, it never reads as "no rules". */
|
|
172
184
|
writeJudge: ConsolidationWriteJudge;
|
|
185
|
+
/** The compliance veto of the capability `memory_consolidation`, asked once per invocation and FIRST — before the write
|
|
186
|
+
* judge and before any read, seat, lock or model call. Absent ⇒ no posture applies (a deployment that holds none). */
|
|
187
|
+
compliance?: ConsolidationCompliance;
|
|
173
188
|
/** Audit locator recorded into the archive when the seat is endpoint-shaped. */
|
|
174
189
|
baseUrl?: string;
|
|
175
190
|
/** The frozen prompt contract; default = the product v1 (dl-3 byte-identical). A different
|