@awebai/oats 0.69.19 → 0.69.20
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/bin/oats.mjs +2 -2
- package/docs/capabilities.md +26 -13
- package/docs/container.md +218 -18
- package/docs/desktop-cli-api.md +25 -11
- package/docs/desktop.md +16 -0
- package/docs/implementation.md +2 -1
- package/docs/integrations.md +1 -1
- package/docs/knowledge.md +5 -5
- package/docs/official-catalog.md +4 -4
- package/docs/packages.md +11 -11
- package/docs/release-notes/v0.69.20.md +325 -0
- package/docs/servers.md +4 -2
- package/docs/souls-and-instances.md +4 -2
- package/docs/upgrading.md +11 -5
- package/docs/workspaces.md +13 -7
- package/lib/core.mjs +31 -195
- package/lib/hook-outcome.mjs +6 -0
- package/lib/instance-lifecycle.mjs +3 -1
- package/lib/instance-listing.mjs +3 -2
- package/lib/launch-prompt-fixtures/README.md +6 -0
- package/lib/retire-admission.mjs +215 -0
- package/lib/servers.mjs +3 -0
- package/package-catalog.json +2 -2
- package/package.json +1 -1
- package/packages/client/attributed-human.mjs +13 -0
- package/packages/client/deployment-data.mjs +4 -0
- package/packages/client/deployment-panel.mjs +2 -0
- package/packages/client/instance-lifecycle.mjs +6 -4
- package/packages/client/lifecycle-confirmation.mjs +4 -2
- package/packages/client/lifecycle-contract.mjs +11 -6
- package/packages/client/remote-roster.mjs +4 -0
- package/packages/record/README.md +15 -2
- package/packages/record/docs/capture-service.md +14 -0
- package/packages/record/lib/canonical.mjs +2 -70
- package/packages/record/lib/capture-aw-unit.mjs +14 -3
- package/packages/record/lib/capture-aw.mjs +11 -5
- package/packages/record/lib/capture-health.mjs +16 -5
- package/skills/oats-getting-started/SKILL.md +2 -2
package/lib/core.mjs
CHANGED
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
* work (worktree|checkout|attached|workspace|directory), harness (pi|claude|codex), model (pi model pattern, optional)
|
|
28
28
|
* (attached as soul default is for service agents — spawn must supply workDir)
|
|
29
29
|
*/
|
|
30
|
+
import { hookCleanupComplete } from "./hook-outcome.mjs";
|
|
31
|
+
import { WORK_MODES, QUARANTINE_CLEANUP_VERSION, QUARANTINE_GIT_DEBT, capturedHomeCapabilities, identifiedHomeRecord, nonEmptyString, retireCleanupAdmission } from "./retire-admission.mjs";
|
|
32
|
+
export { WORK_MODES, QUARANTINE_CLEANUP_VERSION, QUARANTINE_GIT_DEBT, capturedHomeCapabilities, identifiedHomeRecord } from "./retire-admission.mjs";
|
|
30
33
|
import { assertHostRunAdmission } from "./host-run-admission.mjs";
|
|
31
34
|
import { isLaunchEnvReference, referenceSource, referenceValue, fileReferenceRemedy, launchEnvHandoff, LAUNCH_ENV_HANDOFF } from "./launch-env.mjs";
|
|
32
35
|
import { canonicalHomePath, realPathOrNearest } from "./real-path.mjs";
|
|
@@ -106,7 +109,7 @@ import { PKG_ROOT } from "./version.mjs";
|
|
|
106
109
|
import { canonicalDeploymentPath } from "./deployment-path.mjs";
|
|
107
110
|
import { INSTANCE_NAME_RE, RESERVED, capabilityAgentDirs, enclosingInstanceHome, findInstanceHomes, listAgents, logicalCwd, readSoul, soulOf, stripInternalAnnotations, withConfigFile, yamlKey } from "./soul-listing.mjs";
|
|
108
111
|
import { RETIRE_BASELINE_VERSION, authorityMismatch, findRetirementBaseline, inspectInstanceSession, instanceSessionTarget, instancesRetirementRoot, isPlainObject, launchStateAgrees, missingSessionReceipt, readJsonOrUndefined, receiptHomeIdentity, receiptRecordsHome, recordsHerdr, refuseHerdrHome, retirementBaselinePath, runtimeAuthorityOf, tmuxEndpointAgrees } from "./session-inspect.mjs";
|
|
109
|
-
import { CLAIM_VERBS, DEFAULT_TMUX_SESSION, LAUNCH_RECIPE_VERSION, claimAction, completionLiveness, defaultTmuxWindows, deferredRetireResultPath, directoryRollbackPath, hostProcesses, isCapturedHome, lookupOnPath, missingSocketUnestablished, namedProcesses, parseLaunchCommand, procReadable, processesWorkingIn, readHomeRecord, readRetirePending, redactLaunchCommand, redactLaunchRecipe, retireCarried, retireClaimPath, retirePendingMarkerPath, retireStateOf, subdirs, tmuxFailure, tmuxOn, tmuxServerAbsence,
|
|
112
|
+
import { CLAIM_VERBS, DEFAULT_TMUX_SESSION, LAUNCH_RECIPE_VERSION, claimAction, completionLiveness, defaultTmuxWindows, deferredRetireResultPath, directoryRollbackPath, hostProcesses, isCapturedHome, lookupOnPath, missingSocketUnestablished, namedProcesses, parseLaunchCommand, procReadable, processesWorkingIn, readHomeRecord, readRetirePending, redactLaunchCommand, redactLaunchRecipe, retireCarried, retireClaimPath, retirePendingMarkerPath, retireStateOf, subdirs, tmuxFailure, tmuxOn, tmuxServerAbsence, upgradeHomeMeta, upgradeLaunchRecipe } from "./instance-listing.mjs";
|
|
110
113
|
import { LAYERS, PACKAGE_ID_RE } from "./package-catalog.mjs";
|
|
111
114
|
import { RESERVED_LAUNCH_ENV } from "./reserved-launch-env.mjs";
|
|
112
115
|
import { workspaceOf } from "./agents-root.mjs";
|
|
@@ -122,9 +125,6 @@ export { OATS_VERSION, PKG_ROOT } from "./version.mjs";
|
|
|
122
125
|
export { oatsError } from "./errors.mjs";
|
|
123
126
|
export { copyTreeSafe } from "./tree-copy.mjs";
|
|
124
127
|
|
|
125
|
-
/** The work modes spawn accepts — also the enum a quarantine cleanup descriptor
|
|
126
|
-
* must satisfy, so the retry cannot skip Git cleanup on an unrecognised value. */
|
|
127
|
-
export const WORK_MODES = ["worktree", "checkout", "attached", "workspace", "directory"];
|
|
128
128
|
/** The instances directories under the agents root `root`: `<root>/<agent>/instances`, one per
|
|
129
129
|
* agent directory, whether or not it exists. */
|
|
130
130
|
export function instancesDirs(root) {
|
|
@@ -2645,23 +2645,6 @@ function verifyHarnessPackages(harness, resolved, contextDir, { bin, env } = {})
|
|
|
2645
2645
|
return found.filter((x) => (seen.has(x.identity) ? false : seen.add(x.identity))).sort((a, b) => a.identity.localeCompare(b.identity));
|
|
2646
2646
|
}
|
|
2647
2647
|
|
|
2648
|
-
/** The refusal of a lifecycle verb (retire, stop, session start) for a home whose record is there
|
|
2649
|
-
* and cannot be read: E_UNIDENTIFIED_INSTANCE_HOME, with the file, the reason, `nothing` (what the
|
|
2650
|
-
* verb had done by then: nothing; a spawn that names the home says "nothing was spawned") and the
|
|
2651
|
-
* one remedy that exists. Every caller raises it before any effect: a client reads this code from
|
|
2652
|
-
* a stop or a retire as "refused, nothing happened". `--force` does not apply to it: it removes a
|
|
2653
|
-
* home that has NO record, never, blind, one whose record cannot be read. */
|
|
2654
|
-
function unreadableRecordRefusal(record, nothing = "nothing was done") {
|
|
2655
|
-
return oatsError("E_UNIDENTIFIED_INSTANCE_HOME", `${unreadableRecordSaid(record)}; ${nothing}. Restoring the file from a copy makes the home usable again; removing such a home through OATS is not possible yet.`);
|
|
2656
|
-
}
|
|
2657
|
-
/** The one check a lifecycle verb makes when it has resolved its home, before it takes a claim or
|
|
2658
|
-
* reads anything of the home: a record that cannot be read refuses the verb (unreadableRecordRefusal).
|
|
2659
|
-
* → the record as read (readHomeRecord), a record or an absent one. */
|
|
2660
|
-
export function identifiedHomeRecord(home, nothing) {
|
|
2661
|
-
const record = readHomeRecord(home);
|
|
2662
|
-
if (record.state === "unreadable") throw unreadableRecordRefusal(record, nothing);
|
|
2663
|
-
return record;
|
|
2664
|
-
}
|
|
2665
2648
|
const LAUNCH_PROMPT = { kind: "task-file", file: "TASK.md" };
|
|
2666
2649
|
/** The fixed prompt a codex launch starts with: it names the task file, never its text (argv is
|
|
2667
2650
|
* readable by every local user). Codex reads the file with a tool. */
|
|
@@ -4687,7 +4670,7 @@ function* spawnBody(root, agent, o = {}) {
|
|
|
4687
4670
|
// must not be announced as clean while the local key that could delete it
|
|
4688
4671
|
// is about to be removed.
|
|
4689
4672
|
for (const [capId, m] of Object.entries(comp.meta || {})) {
|
|
4690
|
-
if (m
|
|
4673
|
+
if (!hookCleanupComplete(m)) {
|
|
4691
4674
|
incomplete.push(`retire hook ${capId}: reported incomplete cleanup${m.reason ? ` (${m.reason})` : ""} — external state may remain`);
|
|
4692
4675
|
outstandingHooks.add(capId);
|
|
4693
4676
|
}
|
|
@@ -5154,20 +5137,6 @@ export function findInstanceHome(root, name) {
|
|
|
5154
5137
|
}
|
|
5155
5138
|
|
|
5156
5139
|
|
|
5157
|
-
/** The quarantine cleanup-descriptor contract version. Bump when the shape the
|
|
5158
|
-
* retry consumes changes, so an older/newer marker fails closed instead of
|
|
5159
|
-
* driving a retry that cannot do what it claims.
|
|
5160
|
-
*
|
|
5161
|
-
* The rule applies from the first RELEASE of this shape onward. Markers are only
|
|
5162
|
-
* ever written when a `required` spawn hook fails, and required hooks do not
|
|
5163
|
-
* exist in any released kernel — so no deployment can hold a marker of an earlier
|
|
5164
|
-
* v1 shape, and there is nothing to migrate from. A migration path for a file
|
|
5165
|
-
* that has never existed would be dead code claiming to protect real data. */
|
|
5166
|
-
export const QUARANTINE_CLEANUP_VERSION = 1;
|
|
5167
|
-
/** The rollback-owned Git steps a quarantine can still owe. */
|
|
5168
|
-
export const QUARANTINE_GIT_DEBT = ["worktree", "branch"];
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
5140
|
function assertDirectoryHome(home, canonicalHome = realPathOrNearest(home)) {
|
|
5172
5141
|
let st;
|
|
5173
5142
|
try { st = lstatSync(home); } catch { /* fail closed below */ }
|
|
@@ -5379,43 +5348,6 @@ function quarantineInstanceHome({ home, instance, agent, soulDir, soulId, incomp
|
|
|
5379
5348
|
return ` — rollback INCOMPLETE. The instance home is RETAINED at ${home} because it holds the state needed to finish cleanup; it is not a live instance. Retry with \`oats retire ${instance}\`, then remove it once cleanup succeeds. Outstanding: ${incomplete.join("; ")}`;
|
|
5380
5349
|
}
|
|
5381
5350
|
|
|
5382
|
-
function nonEmptyString(v) { return typeof v === "string" && !!v.trim(); }
|
|
5383
|
-
function usableCleanupDescriptor(marker) {
|
|
5384
|
-
const c = marker?.cleanup;
|
|
5385
|
-
if (!isPlainObject(c)) return false;
|
|
5386
|
-
if (c.version !== QUARANTINE_CLEANUP_VERSION) return false;
|
|
5387
|
-
if (!nonEmptyString(c.repo)) return false;
|
|
5388
|
-
if (!WORK_MODES.includes(c.work)) return false;
|
|
5389
|
-
if (c.work === "worktree" && !nonEmptyString(c.branch)) return false;
|
|
5390
|
-
if (c.branch !== undefined && !nonEmptyString(c.branch)) return false;
|
|
5391
|
-
if (c.capabilityMeta !== undefined && !isPlainObject(c.capabilityMeta)) return false;
|
|
5392
|
-
const directoryDebt = c.outstanding?.directory === true && c.work === "directory";
|
|
5393
|
-
if (c.outstanding?.directory !== undefined && !directoryDebt) return false;
|
|
5394
|
-
// A worktree directory whose git admin entry is gone (awebai/oats#444) is debt too: the retry proves it
|
|
5395
|
-
// cleared when the directory is no longer there or has its admin entry back.
|
|
5396
|
-
const orphanDebt = c.outstanding?.orphanedWork === true && c.work === "worktree";
|
|
5397
|
-
if (c.outstanding?.orphanedWork !== undefined && !orphanDebt) return false;
|
|
5398
|
-
if (!Array.isArray(c.capabilityRuntime) || (!c.capabilityRuntime.length && !directoryDebt && !orphanDebt)) return false;
|
|
5399
|
-
if (!c.capabilityRuntime.every((cap) => isPlainObject(cap) && nonEmptyString(cap.id))) return false;
|
|
5400
|
-
if (!isPlainObject(c.outstanding) || !Array.isArray(c.outstanding.hooks) || !Array.isArray(c.outstanding.git)) return false;
|
|
5401
|
-
if (!c.outstanding.hooks.every(nonEmptyString)) return false;
|
|
5402
|
-
if (!c.outstanding.git.every((g) => QUARANTINE_GIT_DEBT.includes(g))) return false;
|
|
5403
|
-
// Git debt only exists where the rollback owns Git steps, so claiming it in any
|
|
5404
|
-
// other work mode describes a quarantine that could not have happened.
|
|
5405
|
-
if (c.outstanding.git.length && c.work !== "worktree") return false;
|
|
5406
|
-
// The decisive invariant: a quarantine with NOTHING outstanding is a proof
|
|
5407
|
-
// obligation of zero. Directory preservation is also real debt: the retry's
|
|
5408
|
-
// independent-authority inspection and verified snapshots must succeed even
|
|
5409
|
-
// when no capability has a retire hook. It is never a Git/shared-work escape.
|
|
5410
|
-
if (!c.outstanding.hooks.length && !c.outstanding.git.length && !directoryDebt && !orphanDebt) return false;
|
|
5411
|
-
// The retry must be ABLE to rerun what it must prove: an outstanding hook whose
|
|
5412
|
-
// capability is not in the set could never run, so the quarantine would never
|
|
5413
|
-
// clear — and the home would be unremovable without --force.
|
|
5414
|
-
const known = new Set(c.capabilityRuntime.map((cap) => cap.id));
|
|
5415
|
-
if (!c.outstanding.hooks.every((id) => known.has(id))) return false;
|
|
5416
|
-
return true;
|
|
5417
|
-
}
|
|
5418
|
-
|
|
5419
5351
|
/** The version of the stored digests a spawn baseline is written with (fingerprintTrees,
|
|
5420
5352
|
* generatedWorkDigest); a baseline without `digestVersion` holds the legacy ones, 1. */
|
|
5421
5353
|
const BASELINE_DIGEST_VERSION = 2;
|
|
@@ -6914,14 +6846,7 @@ export function isWorkspaceHome(meta) {
|
|
|
6914
6846
|
}
|
|
6915
6847
|
/** The refusal for a captured home: E_UNSUPPORTED_MODE (lead decisions on (e), D1). */
|
|
6916
6848
|
export function capturedHomeRefusal(home, what) {
|
|
6917
|
-
return Object.assign(oatsError("E_UNSUPPORTED_MODE", `${home} is a captured home (0.24–0.25; the captured/portable path was removed in 0.26): it has no 0.26 runtime —
|
|
6918
|
-
}
|
|
6919
|
-
/** The capabilities whose spawn hooks ran in a captured home (its identities, memberships):
|
|
6920
|
-
* retire cannot run their captured retire hooks, so it names them. */
|
|
6921
|
-
export function capturedHomeCapabilities(meta) {
|
|
6922
|
-
const order = Array.isArray(meta?.captured?.hookOrder) ? meta.captured.hookOrder.filter((id) => typeof id === "string") : [];
|
|
6923
|
-
const withMeta = meta?.capabilityMeta && typeof meta.capabilityMeta === "object" ? Object.keys(meta.capabilityMeta) : [];
|
|
6924
|
-
return [...new Set([...order, ...withMeta])].sort();
|
|
6849
|
+
return Object.assign(oatsError("E_UNSUPPORTED_MODE", `${home} is a captured home (0.24–0.25; the captured/portable path was removed in 0.26): it has no 0.26 runtime — inspect and clean up external state; a captured home without proof that no spawn hook ran needs \`oats retire ${basename(home)} --force\`; then re-spawn from the deployment; ${what}`), { details: { home, captured: true } });
|
|
6925
6850
|
}
|
|
6926
6851
|
/** The refusal for a home an earlier (0.25) kernel spawned: E_UNSUPPORTED_MODE. */
|
|
6927
6852
|
export function preWorkspaceHome(home, what) {
|
|
@@ -9243,7 +9168,7 @@ function scheduleDeferredSelfRetirement(root, found, name, o, session) {
|
|
|
9243
9168
|
instance: name, agent: found.agent.name, root: resolve(root),
|
|
9244
9169
|
requestedAt: new Date().toISOString(), requestedByPid: process.pid, delaySec,
|
|
9245
9170
|
// A confirmed plan's extra trees go with the intent, so the completion is bound by them as well.
|
|
9246
|
-
options: { home: found.home, ...(o.keepDir ? { keepDir: true } : {}), tmuxSession: session, ...(Array.isArray(o.plannedExtraWorktrees) ? { plannedExtraWorktrees: o.plannedExtraWorktrees } : {}),
|
|
9171
|
+
options: { home: found.home, ...(o.force ? { force: true } : {}), ...(o.keepDir ? { keepDir: true } : {}), tmuxSession: session, ...(Array.isArray(o.plannedExtraWorktrees) ? { plannedExtraWorktrees: o.plannedExtraWorktrees } : {}),
|
|
9247
9172
|
// The recorded children as they were when the retirement was scheduled: the completion stops them first.
|
|
9248
9173
|
...(Array.isArray(o.children) ? { children: o.children.map((c) => ({ instance: c.instance, home: c.home })) } : {}) }, resultPath,
|
|
9249
9174
|
};
|
|
@@ -9451,9 +9376,9 @@ export function completeDeferredRetirement(intentOrMarkerPath, opts = {}) {
|
|
|
9451
9376
|
if (!written.ok) console.error(`deferred retirement of ${intent.instance}: its retire-refused event could not be written: ${written.reason ?? (written.results ?? []).map((r) => `${r.path}: ${r.reason}`).join("; ")}`);
|
|
9452
9377
|
return false;
|
|
9453
9378
|
};
|
|
9454
|
-
const retry = `oats retire ${intent.instance}${intent.options?.home ? ` --home ${intent.options.home}` : ""}`;
|
|
9379
|
+
const retry = `oats retire ${intent.instance}${intent.options?.home ? ` --home ${intent.options.home}` : ""}${intent.options?.force ? " --force" : ""}`;
|
|
9455
9380
|
const retireOnce = (underClaim) => retireInstance(intent.root, intent.instance, {
|
|
9456
|
-
home: intent.options?.home, keepDir: !!intent.options?.keepDir, tmuxSession: intent.options?.tmuxSession,
|
|
9381
|
+
home: intent.options?.home, keepDir: !!intent.options?.keepDir, force: !!intent.options?.force, tmuxSession: intent.options?.tmuxSession,
|
|
9457
9382
|
...(Array.isArray(intent.options?.plannedExtraWorktrees) ? { plannedExtraWorktrees: intent.options.plannedExtraWorktrees } : {}),
|
|
9458
9383
|
...(Array.isArray(intent.options?.children) ? { children: intent.options.children } : {}),
|
|
9459
9384
|
...(obsoleteDeleteBranch ? { [OBSOLETE_DELETE_BRANCH]: true } : {}),
|
|
@@ -10019,62 +9944,13 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10019
9944
|
// retirement is deferred to a detached external completion (below); with
|
|
10020
9945
|
// --keep-dir the old in-process path runs and kills the window LAST.
|
|
10021
9946
|
const self = o.self === true;
|
|
10022
|
-
const metaPath = join(found.home, "instance.json");
|
|
10023
9947
|
// A QUARANTINED home (spawn failed after a required hook and compensation did
|
|
10024
9948
|
// not finish) has no instance.json — it never got that far. Its marker carries
|
|
10025
9949
|
// the cleanup descriptor in the same shape, so retire can rerun compensation
|
|
10026
9950
|
// instead of silently skipping every hook and deleting the credentials.
|
|
10027
|
-
const
|
|
10028
|
-
const
|
|
10029
|
-
let
|
|
10030
|
-
let markerUnusable = false;
|
|
10031
|
-
let rawMarker;
|
|
10032
|
-
// A marker means the home is quarantined, WHETHER OR NOT instance.json exists:
|
|
10033
|
-
// the post-launch rollback retains a home that already has one, and gating on
|
|
10034
|
-
// its absence meant that quarantine was silently ignored — retire took the
|
|
10035
|
-
// ordinary path, where hook failures do not retain, and deleted the credential
|
|
10036
|
-
// while the external state survived (reviewer-final0130bc8).
|
|
10037
|
-
if (existsSync(quarantinePath)) {
|
|
10038
|
-
// A marker without a USABLE cleanup descriptor is NOT a quarantine we can
|
|
10039
|
-
// retry — it is an unidentified home. Treating an unusable one as retryable
|
|
10040
|
-
// made --force unable to ever clear it: the retry could not run, so the home
|
|
10041
|
-
// was retained again, forever (reviewer-adff009). "Parses as JSON" is not
|
|
10042
|
-
// the bar; "can actually drive the retry" is, so the shape is checked
|
|
10043
|
-
// against what the retry below consumes (reviewer-45ff039r2).
|
|
10044
|
-
try {
|
|
10045
|
-
const parsed = JSON.parse(readFileSync(quarantinePath, "utf8"));
|
|
10046
|
-
rawMarker = parsed;
|
|
10047
|
-
if (isPlainObject(parsed) && usableCleanupDescriptor(parsed)) quarantine = parsed;
|
|
10048
|
-
else markerUnusable = true;
|
|
10049
|
-
} catch { markerUnusable = true; }
|
|
10050
|
-
}
|
|
10051
|
-
// #796: a marker a spawn wrote before its spawn or worktree hooks (`inProgress`). While that spawn's
|
|
10052
|
-
// process is verifiably alive it is a spawn in progress, never a quarantine to retry, --force
|
|
10053
|
-
// included. Once it is gone, the hook group it left is ended when its leader is alive at the
|
|
10054
|
-
// recorded start time; a group whose leader is gone is never signalled, only reported (its id may
|
|
10055
|
-
// be another group's by now). The retry below completes the rollback from the marker like any other.
|
|
10056
|
-
// Whether that process still runs may also be unreadable (no procfs and `ps` failing): that is never
|
|
10057
|
-
// taken for gone. Retire refuses it, naming the recorded pid and start for a check by hand, and the
|
|
10058
|
-
// existing forced path (`--force`) is the way out; a forced retry then keeps the spawn's branch.
|
|
10059
|
-
// The same holds for a hook group with members whose leader's start cannot be read.
|
|
10060
|
-
const spawnGroupWarnings = [];
|
|
10061
|
-
let inProgressUnverified = false;
|
|
10062
|
-
if (isPlainObject(rawMarker?.inProgress)) {
|
|
10063
|
-
const p = rawMarker.inProgress;
|
|
10064
|
-
const live = processLiveness(p);
|
|
10065
|
-
if (live.state === "alive") throw lifecycleBusy("running", `${name} is still being spawned (pid ${p.pid}, running its hooks since ${p.startedAt ?? "?"}); nothing was retired`, "wait for the spawn to end, or stop that process, then retire");
|
|
10066
|
-
if (live.state === "unknown") {
|
|
10067
|
-
if (!o.force) throw lifecycleBusy("unknown", `${name}: whether its spawn (pid ${p.pid}, recorded start ${p.processStart ?? "none"}, running its hooks since ${p.startedAt ?? "?"}) still runs cannot be read (${live.reason}); nothing was retired`,
|
|
10068
|
-
`check that pid by hand, and if it is not that spawn, run \`oats retire ${name} --force\``, { pid: p.pid, processStart: p.processStart ?? null, unknown: live.reason, remedy: `oats retire ${name} --force` });
|
|
10069
|
-
inProgressUnverified = true;
|
|
10070
|
-
spawnGroupWarnings.push(`retired with --force although whether its spawn (pid ${p.pid}) still runs could not be read (${live.reason}); its branch is kept`);
|
|
10071
|
-
}
|
|
10072
|
-
}
|
|
10073
|
-
// The retire's own read of the record, with the same reader as the resolution: one that became
|
|
10074
|
-
// unreadable since then refuses as there. It comes before the first signal a retire can send
|
|
10075
|
-
// (below), so that E_UNIDENTIFIED_INSTANCE_HOME for an unreadable record is only ever answered
|
|
10076
|
-
// while nothing was done: `reached` is untouched ("before-effects").
|
|
10077
|
-
const liveMeta = identifiedHomeRecord(found.home).meta;
|
|
9951
|
+
const admission = retireCleanupAdmission(found.home, name, o, instanceWork);
|
|
9952
|
+
const { meta, liveMeta, workIs, repoFromGit, hookRepo, directoryFallbackPath, quarantinePath, quarantine, hooksKnown, spawnGroupWarnings } = admission;
|
|
9953
|
+
let inProgressUnverified = admission.inProgressUnverified;
|
|
10078
9954
|
// What this retire did to the hook group an interrupted spawn left, when it signalled it. Ending
|
|
10079
9955
|
// that group is the first signal a retire can send: from that call on the retire is no longer
|
|
10080
9956
|
// "before-effects", and no answer says that nothing was stopped.
|
|
@@ -10102,53 +9978,9 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10102
9978
|
spawnGroupWarnings.push(`retired with --force although the worktree ${note}; its branch is kept`);
|
|
10103
9979
|
}
|
|
10104
9980
|
}
|
|
10105
|
-
// A quarantined home may carry an instance.json that is NOT the spawn record:
|
|
10106
|
-
// module materialization writes a pre-hook stub ({ modules, providers,
|
|
10107
|
-
// resolutionRevision }) before the spawn hooks run, and a required-hook
|
|
10108
|
-
// failure retains the home with that stub in place. Trusting it over the
|
|
10109
|
-
// cleanup descriptor left meta.repo undefined, so the retry never re-ran the
|
|
10110
|
-
// owed retire hook and reported "cleanup descriptor lost its context repo"
|
|
10111
|
-
// on every attempt — only --force could clear the home (found by an operator
|
|
10112
|
-
// rehearsal on 0.25.3). The descriptor is written FOR this retry; a live
|
|
10113
|
-
// record only wins when it is a complete spawn record (repo + work present).
|
|
10114
|
-
const liveIsSpawnRecord = !!liveMeta && nonEmptyString(liveMeta.repo) && WORK_MODES.includes(liveMeta.work);
|
|
10115
|
-
const meta = liveIsSpawnRecord || !quarantine ? (liveMeta || quarantine?.cleanup || {}) : { ...liveMeta, ...quarantine.cleanup };
|
|
10116
|
-
// Compensation metadata is the SPAWN's, from whichever record survived — never
|
|
10117
|
-
// a failed retry's report, which says nothing about what still needs undoing.
|
|
10118
|
-
if (!liveMeta?.capabilityMeta && quarantine?.cleanup?.capabilityMeta) meta.capabilityMeta = quarantine.cleanup.capabilityMeta;
|
|
10119
|
-
if (quarantine && typeof quarantine.cleanup.launched === "boolean") {
|
|
10120
|
-
meta.launched = quarantine.cleanup.launched;
|
|
10121
|
-
meta.tmux = quarantine.cleanup.tmux;
|
|
10122
|
-
meta.sessionTarget = quarantine.cleanup.sessionTarget;
|
|
10123
|
-
}
|
|
10124
|
-
// A home with NEITHER instance.json NOR a usable cleanup descriptor cannot be
|
|
10125
|
-
// retired safely: hooks would be skipped and the directory removed, which is
|
|
10126
|
-
// the credential deletion the quarantine exists to prevent — and the spawn
|
|
10127
|
-
// path tolerates a failed marker write, so this state is reachable. Fail
|
|
10128
|
-
// closed; `force` is the deliberate manual-cleanup escape.
|
|
10129
|
-
// A marker that cannot drive a retry is not "ignore me" — it is evidence that
|
|
10130
|
-
// cleanup was interrupted and OATS cannot tell what remains. Fail closed even
|
|
10131
|
-
// when instance.json is present; `--force` is the deliberate manual escape.
|
|
10132
|
-
if (markerUnusable && !o.force) {
|
|
10133
|
-
throw oatsError("E_UNIDENTIFIED_INSTANCE_HOME", `${found.home} carries a rollback marker that cannot drive a retry (unreadable, or missing the cleanup descriptor fields the retry consumes), so OATS cannot tell what external state still depends on this home. Inspect it, then re-run with \`--force\` to remove it anyway.`);
|
|
10134
|
-
}
|
|
10135
|
-
if (!existsSync(metaPath) && !quarantine && !o.force) {
|
|
10136
|
-
throw oatsError("E_UNIDENTIFIED_INSTANCE_HOME", `${found.home} has no instance.json and no cleanup descriptor, so OATS cannot tell whether external state (identities, worktrees) still depends on it. Retiring it would delete whatever it holds without running any cleanup. Inspect it, then re-run with \`--force\` to remove it anyway.`);
|
|
10137
|
-
}
|
|
10138
|
-
// The retire hooks run from the record: the repository they are run for (`repo`) and the
|
|
10139
|
-
// capabilities with their hooks (`capabilityRuntime`). A record with no repository runs none.
|
|
10140
|
-
// That is a retire with nothing left out only when the record says that no capability has a
|
|
10141
|
-
// retire hook. One that does not say (the stub lib/materialize.mjs writes, left by a spawn that
|
|
10142
|
-
// was killed before its record and wrote no marker before its hooks) may stand for an identity
|
|
10143
|
-
// registered outside the home: removing the home would leave it there with nothing that knows
|
|
10144
|
-
// of it. Fail closed, as for a home with no record; `--force` is the same deliberate escape.
|
|
10145
|
-
if (!o.force && !nonEmptyString(meta.repo) && !(Array.isArray(meta.capabilityRuntime) && !meta.capabilityRuntime.some((cap) => cap?.hooks?.retire))) {
|
|
10146
|
-
throw oatsError("E_UNIDENTIFIED_INSTANCE_HOME", `${metaPath} records neither a repository nor its capabilities' hooks (a spawn that was interrupted before it wrote its record leaves such a file), so OATS cannot tell which retire hooks to run, and what the spawn's hooks registered outside the home (an identity, a seat) may still be there. Retiring it would remove the home without running any of them. Nothing was stopped, run or removed. Inspect the home, clean up by hand what its capabilities registered, then remove it with \`oats retire ${name} --force\`.`);
|
|
10147
|
-
}
|
|
10148
9981
|
|
|
10149
9982
|
const workPath = join(found.home, "work");
|
|
10150
|
-
//
|
|
10151
|
-
const workIs = instanceWork(found.home, meta);
|
|
9983
|
+
// Admission read work/ with the same instanceWork reader as the plan (#962).
|
|
10152
9984
|
const directoryMode = workIs.is === "directory-mode";
|
|
10153
9985
|
// A real directory that is not the instance's own tree is bytes of the home: inspected, copied to
|
|
10154
9986
|
// recovery and checked as a directory instance's work is, and removed with the home. It never
|
|
@@ -10164,8 +9996,7 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10164
9996
|
// is the one Git names for the tree. A directory of the home is no worktree, whatever it holds,
|
|
10165
9997
|
// and neither is a link, under a record that says `worktree` too: every step that asks whether
|
|
10166
9998
|
// this home is a worktree's (the recovery's writers, the rollback retry) asks this record.
|
|
10167
|
-
const
|
|
10168
|
-
const workMeta = workIs.is === "own-tree" ? { ...meta, work: "worktree", repo: meta.repo || repoFromGit }
|
|
9999
|
+
const workMeta = workIs.is === "own-tree" ? { ...meta, work: "worktree", repo: hookRepo }
|
|
10169
10000
|
: homeDirectory || link ? { ...meta, work: undefined } : meta;
|
|
10170
10001
|
// A live harness cannot establish a stable final work inspection of itself,
|
|
10171
10002
|
// so self-retire never inspects, runs hooks, or removes anything here. It
|
|
@@ -10356,11 +10187,11 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10356
10187
|
// e.g. aweb signing keys) is removed. The knowledge integration harvests notes/ here;
|
|
10357
10188
|
// the kernel itself is memory-agnostic.
|
|
10358
10189
|
let hookResults;
|
|
10359
|
-
if (meta
|
|
10190
|
+
if (hookRepo && !isCapturedHome(meta)) {
|
|
10360
10191
|
// The hooks this home recorded at spawn. A home an earlier kernel spawned
|
|
10361
|
-
// without them
|
|
10362
|
-
//
|
|
10363
|
-
const resolved = { ...resolvedFromHome(found.home, meta), capabilities:
|
|
10192
|
+
// without them needs explicit --force (retireCleanupAdmission); a captured
|
|
10193
|
+
// home cannot run its hooks. Neither path infers cleanup from missing data.
|
|
10194
|
+
const resolved = { ...resolvedFromHome(found.home, meta), capabilities: hooksKnown ? meta.capabilityRuntime : [] };
|
|
10364
10195
|
// The soul this home was spawned from, as recorded (a workspace home records its
|
|
10365
10196
|
// per-commit directory; agents/<name>/soul may since point elsewhere) — the same
|
|
10366
10197
|
// value spawn's hook saw.
|
|
@@ -10384,7 +10215,7 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10384
10215
|
home: found.home, instance: name, agentName: found.agent.name,
|
|
10385
10216
|
soulDir: instanceSoulDir(found.home, meta) || found.agent._soulDir || join(found.agent._dir, "soul"),
|
|
10386
10217
|
...(nonEmptyString(meta.soulId) ? { soulId: meta.soulId } : {}),
|
|
10387
|
-
contextDir:
|
|
10218
|
+
contextDir: hookRepo, workspaceDir: workspaceOf(root), rootDir: root, resolved, priorMeta: meta.capabilityMeta || {},
|
|
10388
10219
|
finished, onFinished: (capability, answered) => { ended.push({ capability, ...(isPlainObject(answered) ? { meta: answered } : {}) }); recordEnded(); },
|
|
10389
10220
|
});
|
|
10390
10221
|
// The hooks ran: their warnings are events now, whatever the retire does
|
|
@@ -10414,7 +10245,7 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10414
10245
|
// A hook may exit 0 and still report it did not finish. Only an explicit
|
|
10415
10246
|
// "nothing to undo" counts as complete — same rule the rollback path uses.
|
|
10416
10247
|
for (const [capId, m] of Object.entries(hookResults?.meta || {})) {
|
|
10417
|
-
if (m
|
|
10248
|
+
if (!hookCleanupComplete(m)) {
|
|
10418
10249
|
ordinaryIncomplete.push(`retire hook ${capId}: reported incomplete cleanup${m.reason ? ` (${m.reason})` : ""} — external state may remain`);
|
|
10419
10250
|
}
|
|
10420
10251
|
}
|
|
@@ -10429,7 +10260,7 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10429
10260
|
if (quarantine) {
|
|
10430
10261
|
for (const f of hookResults?.failures || []) retryFailures.push(`retire hook ${f.capability}: ${f.message}`);
|
|
10431
10262
|
for (const [capId, m] of Object.entries(hookResults?.meta || {})) {
|
|
10432
|
-
if (m
|
|
10263
|
+
if (!hookCleanupComplete(m)) {
|
|
10433
10264
|
retryFailures.push(`retire hook ${capId}: reported incomplete cleanup${m.reason ? ` (${m.reason})` : ""}`);
|
|
10434
10265
|
}
|
|
10435
10266
|
}
|
|
@@ -10762,7 +10593,7 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10762
10593
|
const outstandingHooks = new Set();
|
|
10763
10594
|
for (const f of hookResults?.failures || []) outstandingHooks.add(f.capability);
|
|
10764
10595
|
for (const [capId, m] of Object.entries(hookResults?.meta || {})) {
|
|
10765
|
-
if (m
|
|
10596
|
+
if (!hookCleanupComplete(m)) outstandingHooks.add(capId);
|
|
10766
10597
|
}
|
|
10767
10598
|
// What the writer adds to the items is debt of its own: a descriptor kept outside the home, or
|
|
10768
10599
|
// one that could not be stored, owes a restoration no rerun of the hooks makes.
|
|
@@ -10928,12 +10759,17 @@ function retireSteps(root, name, o, found, at) {
|
|
|
10928
10759
|
if (linkLed) w.push(`${workPath} was a link though the record says work mode worktree: nothing was retained or removed as a work tree, and ${linkLed.path === null ? "it led nowhere that could be read" : `what it led to (${linkLed.path}) was not touched`}`);
|
|
10929
10760
|
if (o[OBSOLETE_DELETE_BRANCH]) w.push(OBSOLETE_DELETE_BRANCH_SENTENCE);
|
|
10930
10761
|
if (isCapturedHome(meta) && !quarantine) {
|
|
10931
|
-
// A captured home
|
|
10932
|
-
//
|
|
10762
|
+
// A captured home cannot run its pre-0.26 hooks. A forced removal names
|
|
10763
|
+
// each capability whose spawn hook ran, with the state it did not revoke.
|
|
10933
10764
|
const caps = capturedHomeCapabilities(meta);
|
|
10934
10765
|
for (const cap of caps) w.push(`${cap}: its retire hook did NOT run (captured home; the captured/portable path was removed in 0.26) — identities/memberships it created are not revoked; remove them with the provider's own tooling`);
|
|
10935
|
-
if (!caps.length) w.push("captured home: no retire hook ran (the captured/portable path was removed in 0.26) — any identities/memberships its capabilities created are not revoked; remove them with the provider's own tooling");
|
|
10936
|
-
} else if (!
|
|
10766
|
+
if (!caps.length && o.force) w.push("captured home: no retire hook ran (the captured/portable path was removed in 0.26) — any identities/memberships its capabilities created are not revoked; remove them with the provider's own tooling");
|
|
10767
|
+
} else if (!hooksKnown && !quarantine) {
|
|
10768
|
+
if (meta.capabilityRuntime === undefined) w.push("this home records no capability hooks (an earlier kernel spawned it): no retire hook ran; any external state its capabilities created is the operator's to clean up");
|
|
10769
|
+
else w.push("this home's recorded capability hooks cannot be identified: no retire hook ran; any identities/memberships its capabilities created are not revoked; remove them with the provider's own tooling");
|
|
10770
|
+
} else if (!nonEmptyString(hookRepo) && hooksKnown && o.force && !quarantine) {
|
|
10771
|
+
for (const cap of meta.capabilityRuntime.filter(cap => cap.hooks?.retire)) w.push(`${cap.id}: its retire hook did NOT run (no context repository) — identities/memberships it created are not revoked; remove them with the provider's own tooling`);
|
|
10772
|
+
}
|
|
10937
10773
|
return w.length ? w : undefined;
|
|
10938
10774
|
})() };
|
|
10939
10775
|
result[RETIRE_SELECTED_HOME] = found.home;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The lifecycle cleanup vocabulary belongs to the kernel (docs/capabilities.md).
|
|
2
|
+
// Missing metadata makes no claim of incomplete cleanup. An explicit refusal
|
|
3
|
+
// is complete only for the documented idempotent "nothing to delete" outcome.
|
|
4
|
+
export function hookCleanupComplete(meta) {
|
|
5
|
+
return !(meta && typeof meta === 'object' && meta.retired === false && meta.reason !== 'nothing-to-delete');
|
|
6
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* plan instead of acting on a world the human did not see. Idempotency keys
|
|
8
8
|
* make a retried apply return the first receipt rather than act twice.
|
|
9
9
|
* Unknown is reported as unknown — never as "clean" or "no children". */
|
|
10
|
+
import { retireCleanupAdmission } from "./retire-admission.mjs";
|
|
10
11
|
import { createHash } from "node:crypto";
|
|
11
12
|
import { existsSync, lstatSync, readFileSync, rmSync } from "node:fs";
|
|
12
13
|
import { join } from "node:path";
|
|
@@ -478,8 +479,9 @@ const PLAN_NOT_COPIED_CAP = 16;
|
|
|
478
479
|
* itself applies them: plain retire re-homes the worktree; --discard-worktree
|
|
479
480
|
* is the dialog's opt-in. No retire deletes a branch: `deleteBranch` is
|
|
480
481
|
* always false. */
|
|
481
|
-
export function planRetire(ctx, root, name, { home } = {}) {
|
|
482
|
+
export function planRetire(ctx, root, name, { home, force = false } = {}) {
|
|
482
483
|
const me = resolveTarget(ctx, root, name, { home });
|
|
484
|
+
retireCleanupAdmission(me.home, name, { force }, instanceWork);
|
|
483
485
|
const kids = descendantsOf(me.root, name);
|
|
484
486
|
// Read once, after the lineage: every fact of the plan that the record gives is of this read.
|
|
485
487
|
const recorded = targetRecord(me.home);
|
package/lib/instance-listing.mjs
CHANGED
|
@@ -53,7 +53,8 @@ export function legacyLocalAgents(root) {
|
|
|
53
53
|
|
|
54
54
|
/** The captured homes (the 0.24–0.25 captured/portable path, removed in 0.26) under the
|
|
55
55
|
* agents root `root`: one `legacy-captured-home` problem naming them, or null. They have
|
|
56
|
-
* no 0.26 runtime (start, inspect and in-home commands refuse them);
|
|
56
|
+
* no 0.26 runtime (start, inspect and in-home commands refuse them); captured homes
|
|
57
|
+
* without positive cleanup proof need manual cleanup and forced retirement.
|
|
57
58
|
* `records`: the records listInstances read in this same read (its `records`), each home's
|
|
58
59
|
* instance.json parsed once per read; a home it holds no record for is read here. */
|
|
59
60
|
export function legacyCapturedHomes(root, { records } = {}) {
|
|
@@ -70,7 +71,7 @@ export function legacyCapturedHomes(root, { records } = {}) {
|
|
|
70
71
|
homes.sort((a, b) => a.instance.localeCompare(b.instance));
|
|
71
72
|
const one = homes.length === 1;
|
|
72
73
|
return { code: "legacy-captured-home", instances: homes.map((h) => h.instance), homes: homes.map((h) => h.home),
|
|
73
|
-
message: `${homes.length} captured home${one ? "" : "s"} (0.24–0.25; the captured/portable path was removed in 0.26) ${one ? "has" : "have"} no 0.26 runtime: start, inspect and in-home commands refuse ${one ? "it" : "them"};
|
|
74
|
+
message: `${homes.length} captured home${one ? "" : "s"} (0.24–0.25; the captured/portable path was removed in 0.26) ${one ? "has" : "have"} no 0.26 runtime: start, inspect and in-home commands refuse ${one ? "it" : "them"}; inspect and clean up external state; a captured home without proof that no spawn hook ran needs \`oats retire <instance> --force\`; then re-spawn from the deployment (${homes.map((h) => h.instance).join(", ")})` };
|
|
74
75
|
}
|
|
75
76
|
// The tmux session a new tmux instance opens its window in, when oats-local.yaml session.tmuxSession
|
|
76
77
|
// names none (0.31). PI_AGENTS_TMUX_SESSION is the pre-0.31 variable, still honoured. The Desktop keeps
|
|
@@ -7,6 +7,12 @@ Enter only while the normalized screen EQUALS one `confirmation` entry's `text`.
|
|
|
7
7
|
It also holds the notice Claude shows when it ignores the development-channel
|
|
8
8
|
flag (`flag-ignored` entries), which ends a start with no key.
|
|
9
9
|
|
|
10
|
+
The engagement tests take the channel arguments from the pinned `oats.aweb`
|
|
11
|
+
mirror's `CLAUDE_CHANNEL_ARGUMENTS`. They check that the kernel engages for the
|
|
12
|
+
provider's development argument and stays disengaged for its approved argument,
|
|
13
|
+
so a provider argument change cannot silently bypass confirmation. The kernel
|
|
14
|
+
does not import the provider at runtime.
|
|
15
|
+
|
|
10
16
|
## Normalization, and only this
|
|
11
17
|
|
|
12
18
|
1. Split the captured screen into rows.
|