@awebai/oats 0.25.1 → 0.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/oats.mjs +151 -35
- package/docs/configuration.md +3 -3
- package/docs/design/2026-09-20-redesign-program-board.md +1 -1
- package/docs/design/2026-09-20-workspace-and-portable-adoption-plan.md +1 -1
- package/docs/design/2026-09-23-simplified-workspace-model.md +4 -4
- package/docs/design/2026-09-23-workspace-module-contracts.md +108 -2
- package/docs/design/2026-09-23-workspace-v2-implementation-plan.md +3 -3
- package/docs/desktop-cli-api.md +1 -1
- package/docs/desktop.md +1 -1
- package/docs/first-team.md +3 -3
- package/docs/knowledge.md +14 -7
- package/docs/rebuild-to-v2.md +182 -26
- package/docs/release-notes/v0.25.2.md +80 -0
- package/docs/souls-and-instances.md +34 -16
- package/docs/workspaces.md +65 -26
- package/lib/core.mjs +33 -4
- package/lib/instance-resolution.mjs +132 -2
- package/lib/materialize.mjs +29 -0
- package/package.json +1 -1
package/docs/workspaces.md
CHANGED
|
@@ -122,9 +122,8 @@ capabilities:
|
|
|
122
122
|
acme-deploy: { from: package } # provided by acme.tools, pinned in packages:
|
|
123
123
|
acme-house-style: off # removes a workspace default
|
|
124
124
|
|
|
125
|
-
knowledge: # provider payload, opaque to the kernel
|
|
126
|
-
|
|
127
|
-
reads: [platform-engineer]
|
|
125
|
+
knowledge: # provider payload, opaque to the kernel — the slot capability's BINDING keys
|
|
126
|
+
harvest-runtime: claude # (oats.okf 2.1.3: what this soul owns/reads is in souls/<name>/okf.json, not here — see below)
|
|
128
127
|
messaging:
|
|
129
128
|
channels: [acme-eng]
|
|
130
129
|
tasks: none # empties the slot
|
|
@@ -133,7 +132,15 @@ compatibility: # optional FLOORS on package versions
|
|
|
133
132
|
oats.okf: ">=2.1"
|
|
134
133
|
```
|
|
135
134
|
|
|
136
|
-
Beside it: `AGENTS.md` (canonical), `CLAUDE.md → AGENTS.md`, `skills
|
|
135
|
+
Beside it: `AGENTS.md` (canonical), `CLAUDE.md → AGENTS.md`, `skills/`, and
|
|
136
|
+
whatever the slot providers read from the soul directory — for `oats.okf`
|
|
137
|
+
2.1.3 that is **`okf.json`** (`{ version: 1, owner, owns: ["<base>/<node>"],
|
|
138
|
+
reads: […] }`, written by `oats okf init|migrate`), the soul's knowledge
|
|
139
|
+
declaration; it travels with the soul into the per-commit soul cache. The
|
|
140
|
+
`knowledge:` payload on `soul.yaml` reaches OKF as `OATS_SETTINGS` and may
|
|
141
|
+
carry only the binding's settings keys (`bindings-file`, `state-dir`,
|
|
142
|
+
`harvest-runtime`, `harvest-model`); `owns`/`reads`/`root` there are refused by
|
|
143
|
+
the provider, not read (a soul payload grammar is an OKF follow-up). Every
|
|
137
144
|
`souls/*/soul.yaml` in a member is discoverable; one that wants to stay
|
|
138
145
|
internal says `private: true` (spawnable only from its own repo). A soul's
|
|
139
146
|
`name` must equal its directory name; the first of two souls declaring one
|
|
@@ -257,8 +264,11 @@ integrity on the next `oats sync` and asks again.
|
|
|
257
264
|
|
|
258
265
|
`oats sync` confirms membership, resolves every `packages:` entry to a commit +
|
|
259
266
|
content digest, asks (on a terminal) for any missing per-version executable
|
|
260
|
-
approval
|
|
261
|
-
|
|
267
|
+
approval — or takes it from repeatable `--approve <id>@<version>` flags for
|
|
268
|
+
unattended runs (each approves exactly the entry the resolution contains; the
|
|
269
|
+
digest is always computed, never typed; Ctrl+D at the prompt is a decline,
|
|
270
|
+
exit `2`) — writes `oats-lock.json` (lockfileVersion 3), creates `agents/` if
|
|
271
|
+
absent and reports what changed. `oats package add <id> <version|git:…@…>` / `oats package remove <id>` edit
|
|
262
272
|
`packages:` in the workspace file when it is tracked by the current checkout,
|
|
263
273
|
else print the line to add — the workspace file is shared through Git. Details:
|
|
264
274
|
[packages.md](packages.md).
|
|
@@ -298,6 +308,7 @@ Nothing is symlinked, nothing is shared between instances.
|
|
|
298
308
|
```
|
|
299
309
|
<agents-root>/<soul>/instances/<instance>/
|
|
300
310
|
├── AGENTS.md # composed: soul AGENTS.md + kernel/work-mode blocks + each module's inject
|
|
311
|
+
│ # (with oats.core resolved, the module's "You run on OATS" block is the only one — the kernel's legacy copy is suppressed)
|
|
301
312
|
├── CLAUDE.md → AGENTS.md
|
|
302
313
|
├── .agents/skills/<capability>/<skill>/SKILL.md # full copies; where pi/codex look
|
|
303
314
|
├── .claude/skills → ../.agents/skills
|
|
@@ -317,10 +328,14 @@ bumped affects only new spawns. Details and DTOs:
|
|
|
317
328
|
[souls-and-instances.md](souls-and-instances.md), [desktop-cli-api.md](desktop-cli-api.md).
|
|
318
329
|
|
|
319
330
|
**Drift is shown, not prevented.** `oats status` compares each instance's
|
|
320
|
-
recorded modules
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
331
|
+
recorded modules — and its recorded **soul source** (`instance.json.workspace.soul`)
|
|
332
|
+
— with the workspace's current picture: `current`, `moved` (member or package
|
|
333
|
+
now at another commit) or `missing` (capability no longer present, member
|
|
334
|
+
unconfirmed, package no longer locked). The text form is `soul: <name> from
|
|
335
|
+
<member> @ <c7> [member moved since …]` above the module rows; `--json`
|
|
336
|
+
carries `instances[].soul`. `oats spawn --preview` lists `changedSince` the
|
|
337
|
+
newest previous instance of the same soul, plus `providers` (the `--provider`
|
|
338
|
+
map as given) and `settings.<cap>` (the merged payload each provider receives).
|
|
324
339
|
|
|
325
340
|
**Harnesses start normally.** OATS is a skill contributor, not a skill sandbox:
|
|
326
341
|
cwd = the instance home, the harness's own skill discovery intact
|
|
@@ -344,7 +359,7 @@ store** — it organises and can supply defaults. The messaging provider's paylo
|
|
|
344
359
|
|
|
345
360
|
| What it is | Where | Example |
|
|
346
361
|
|---|---|---|
|
|
347
|
-
| True of every instance of the soul | `soul.yaml` → `knowledge:` / `messaging:` / `tasks:` | `
|
|
362
|
+
| True of every instance of the soul | `soul.yaml` → `knowledge:` / `messaging:` / `tasks:` | `messaging: { channels: [acme-eng] }`; `knowledge: { harvest-runtime: claude }` |
|
|
348
363
|
| A fact about this machine | `oats-local.yaml` → `settings.<cap>.<key>` (absolute paths are refused in the workspace file) | `settings.oats.okf.state-dir: /Users/ana/.oats/okf` |
|
|
349
364
|
| A fact about **this spawn** | `oats spawn … --provider <cap> key=value` (repeatable; dotted keys nest) → `instance.json.providers.<cap>` | `--provider oats.aweb identity.source=/abs/path/to/retained/.aw` |
|
|
350
365
|
|
|
@@ -365,14 +380,26 @@ messaging:
|
|
|
365
380
|
|
|
366
381
|
A soul with `team: cloud` hands its messaging provider `{ team: aweb:example.cloud, … }`;
|
|
367
382
|
a label under `byTeam` that is not declared in `teams:` is `E_WORKSPACE_SCHEMA`.
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
383
|
+
**`byTeam` is kernel-merged; whether a provider honours what arrives is the
|
|
384
|
+
provider's.** `spawn --preview` shows the merged `settings.<cap>` so the
|
|
385
|
+
delivery is verifiable, and `instance.json.providers.<cap>` records it — but
|
|
386
|
+
oats.aweb **1.11.2 does not read `team` from its payload** (it resolves the
|
|
387
|
+
team from the removed `oats-config.yaml` `team:` block, else the active team at
|
|
388
|
+
the `.aw` root it finds), so for 1.11.2 `byTeam` is a recorded intent, not a
|
|
389
|
+
per-label identity; the per-repo `.aw` placement in
|
|
390
|
+
[rebuild-to-v2.md §8b](rebuild-to-v2.md#8b-where-the-team-aw-lives-now-oatsaweb-1112-and-what-byteam-does-today)
|
|
391
|
+
is the working alternative. An oats.aweb release that reads `team` from the
|
|
392
|
+
payload closes the gap without a workspace edit (release notes will name it).
|
|
393
|
+
A store (`stores: { <name>: <repo ref> }`) names a repository; where a
|
|
394
|
+
knowledge base lives inside it is the knowledge provider's own concern — for
|
|
395
|
+
OKF 2.1.3 that is the **bindings file** (`bases.<alias>.repository` + `root`,
|
|
396
|
+
`oats-local.yaml settings.oats.okf.bindings-file`), not a soul payload key; a
|
|
397
|
+
repo ref never carries a `#path`.
|
|
371
398
|
|
|
372
399
|
`--provider` for a capability the soul does not resolve is `E_CAPABILITY_MISSING`;
|
|
373
400
|
`__proto__`/`constructor`/`prototype` as a key at any depth is refused.
|
|
374
401
|
|
|
375
|
-
## Discovery over remotes and the
|
|
402
|
+
## Discovery over remotes and the deployment directory
|
|
376
403
|
|
|
377
404
|
Discovery and resolution work against **Git remotes, never local clones**. The
|
|
378
405
|
kernel fetches `oats-workspace.yaml`, each member's `oats-membership.yaml`,
|
|
@@ -382,25 +409,35 @@ BatchMode: nothing ever prompts). Neither the repo that defines a capability nor
|
|
|
382
409
|
the repo that hosts the workspace needs to be cloned.
|
|
383
410
|
|
|
384
411
|
**The only thing that needs a clone is a soul's work target** (`work:
|
|
385
|
-
worktree | checkout`).
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
412
|
+
worktree | checkout`). The kernel finds it, first hit wins: (1) `oats spawn
|
|
413
|
+
… --repo <abs path>`; (2) `oats-local.yaml` `clones: { <repo key>: <abs
|
|
414
|
+
path> }` (keys are canonical repo keys — any ref spelling is normalised through
|
|
415
|
+
`parseRepoRef`); (3) the convention `<deployment>/<member name>` (the last
|
|
416
|
+
segment of the repo key; a member named `agents` is looked for at
|
|
417
|
+
`<deployment>/agents-repo`, since `agents/` is the instance root). None →
|
|
418
|
+
`E_CLONE_MISSING` naming the three remedies; a directory whose `origin` is a
|
|
419
|
+
different repo → `E_CLONE_MISMATCH`. Spawning a soul whose repo is not yet
|
|
420
|
+
cloned is a guided clone-then-spawn, a job for the onboarding skill, not the
|
|
421
|
+
kernel.
|
|
422
|
+
|
|
423
|
+
The deployment directory is **yours to choose** (decision 9) — an existing folder that already holds your member clones is the usual case; `oats onboard <dir>` adds what the kernel needs and nothing else:
|
|
389
424
|
|
|
390
425
|
```
|
|
391
|
-
~/acme
|
|
426
|
+
~/acme/ ← the directory you chose
|
|
392
427
|
├── oats-local.yaml ← which workspace this machine realizes + host paths + disabled souls
|
|
393
428
|
├── oats-lock.json ← exact commit + integrity + per-version approval per package
|
|
394
429
|
├── agents/ ← instance homes (each self-contained) + fetched soul sources
|
|
395
|
-
├── platform/ ← clone of github.com/acme/platform (only if someone works IN it)
|
|
430
|
+
├── platform/ ← clone of github.com/acme/platform (only if someone works IN it; may live elsewhere — see clones:)
|
|
396
431
|
└── tools/
|
|
397
432
|
```
|
|
398
433
|
|
|
399
434
|
The kernel never depends on this shape: `oats-local.yaml` is found by walking
|
|
400
|
-
up from the current directory (`E_LOCAL_MISSING` otherwise);
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
435
|
+
up from the current directory (`E_LOCAL_MISSING` otherwise); `agents/` is
|
|
436
|
+
created by `oats sync` when absent; clones are found through `--repo`,
|
|
437
|
+
`clones:` or the convention, in that order. A soul that lives in a member repo
|
|
438
|
+
is fetched into `<agents-root>/<soul>/souls/<commit12>/` at its discovered
|
|
439
|
+
commit before its first spawn (idempotent per commit; `<agents-root>/<soul>/soul`
|
|
440
|
+
points at the current one); its instances then materialize as above.
|
|
404
441
|
|
|
405
442
|
## The standalone case
|
|
406
443
|
|
|
@@ -419,7 +456,9 @@ approved like any package (a soul may say `oats.core: off`); and the
|
|
|
419
456
|
operator's `oats-local.yaml` may name the repo directly (`workspace: <member
|
|
420
457
|
ref>` — the kernel notices it is a member whose workspace it cannot read and
|
|
421
458
|
falls back to the standalone view — or `standalone: <repo ref>` to ask for
|
|
422
|
-
that view explicitly).
|
|
459
|
+
that view explicitly). `oats onboard` lists the host among the clones to make
|
|
460
|
+
like any member (the host is a member; its souls may need a work clone); under
|
|
461
|
+
an explicit `standalone:` header its next steps say so and name that one repo.
|
|
423
462
|
|
|
424
463
|
**Executables from public members.** Membership is the trust (decision 2): a
|
|
425
464
|
member capability's hooks and command scripts run on every operator's machine at
|
package/lib/core.mjs
CHANGED
|
@@ -594,6 +594,15 @@ export function ensureRoot(cwd) {
|
|
|
594
594
|
const root = findRoot(cwd);
|
|
595
595
|
if (!root) {
|
|
596
596
|
const from = resolve(cwd ?? process.cwd());
|
|
597
|
+
// Workspace model: an oats-local.yaml above `from` IS a deployment whose instance
|
|
598
|
+
// root (<deployment>/agents/) was never created — name that remedy, not a v1 verb.
|
|
599
|
+
let localDeployment = null;
|
|
600
|
+
for (let d = from; ; d = dirname(d)) { if (existsSync(join(d, "oats-local.yaml"))) { localDeployment = d; break; } if (dirname(d) === d) break; }
|
|
601
|
+
if (localDeployment) {
|
|
602
|
+
throw oatsError("E_NO_DEPLOYMENT",
|
|
603
|
+
`no instance root walking up from ${from}: ${join(localDeployment, "oats-local.yaml")} names this deployment but ${join(localDeployment, "agents")} does not exist — mkdir ${join(localDeployment, "agents")} (or run \`oats sync --dir ${localDeployment}\`, which creates it)`,
|
|
604
|
+
{ from, looked: ["agents/", "local-agents/"], deployment: localDeployment, local: join(localDeployment, "oats-local.yaml"), remedy: `mkdir ${join(localDeployment, "agents")} (or run oats sync)` });
|
|
605
|
+
}
|
|
597
606
|
throw oatsError("E_NO_DEPLOYMENT",
|
|
598
607
|
`no deployment found walking up from ${from}: no agents/ or local-agents/ directory — create one (mkdir agents, or \`oats create <name> --local\`), run from the deployment (where oats-local.yaml lives), or set PI_AGENTS_ROOT`,
|
|
599
608
|
{ from, looked: ["agents/", "local-agents/"] });
|
|
@@ -4287,10 +4296,22 @@ export function composeInstanceAgentsMd(soulDir, contextDir, soulName, workMode,
|
|
|
4287
4296
|
resolved.layers = Object.fromEntries(Object.entries(prepared.resolution.slots || {}).map(([slot, mod]) => [slot, mod ? { capability: mod } : null]));
|
|
4288
4297
|
}
|
|
4289
4298
|
const wanted = [];
|
|
4290
|
-
|
|
4299
|
+
// Kernel "You run on OATS" block (R3, 0.25.2). Workspace model: the RESOLUTION
|
|
4300
|
+
// decides — when it carries oats.core / oats.setup as a module, that module's
|
|
4301
|
+
// inject and skills are the operational essentials and the kernel's legacy
|
|
4302
|
+
// block (which names the bundled `oats` skill no such home has) is suppressed,
|
|
4303
|
+
// whatever the soul's v1 `requires:` block says. A soul that resolves NO such
|
|
4304
|
+
// module (`oats.core: off`) still gets the kernel block: the instance needs the
|
|
4305
|
+
// essentials from somewhere. The classic path keeps reading `requires`.
|
|
4306
|
+
const resolvedOperations = prepared
|
|
4307
|
+
? ["oats.core", "oats.setup"].filter((id) => (prepared.resolution?.modules || []).some((m) => m.name === id))
|
|
4308
|
+
: null;
|
|
4309
|
+
const declaredOperations = prepared ? resolvedOperations : declaredOperationalCapabilities(soulDir);
|
|
4291
4310
|
const oatsCoreDeclared = declaredOperations.includes("oats.core");
|
|
4292
4311
|
if (declaredOperations.length) resolved.kernelInjection = { inject: undefined,
|
|
4293
|
-
provenance:
|
|
4312
|
+
provenance: prepared
|
|
4313
|
+
? `declared ${declaredOperations.join(", ")} (workspace module)`
|
|
4314
|
+
: `declared ${declaredOperations.join(", ")} ${declaredOperations.length === 1 ? "capability" : "capabilities"}` };
|
|
4294
4315
|
const kernelInject = resolved.kernelInjection?.inject;
|
|
4295
4316
|
if (kernelInject && existsSync(kernelInject)) wanted.push(["kernel:oats", kernelInject]);
|
|
4296
4317
|
if (kind === "local") {
|
|
@@ -6569,8 +6590,16 @@ function* spawnBody(root, agent, o = {}) {
|
|
|
6569
6590
|
// directory basename with a `module:<cap>` source — not the classic chain's view.
|
|
6570
6591
|
const preparedCapabilities = o.prepared ? o.prepared.resolution.modules.map((m) => ({ name: m.name, origin: m.from.kind === "package" ? `package:${m.from.package}@${m.from.version}` : `member:${m.from.repoKey}@${m.from.commit}` })) : null;
|
|
6571
6592
|
const preparedSkills = o.prepared ? o.prepared.resolution.modules.flatMap((m) => (m.manifest?.skills || []).filter((s) => typeof s === "string" && s).map((s) => ({ name: basename(s.replace(/\/+$/, "")), source: `module:${m.name}` }))) : [];
|
|
6593
|
+
// R5 (0.25.2, decision 14): the preview shows the provider payloads the apply
|
|
6594
|
+
// will record — `providers` is the --provider map exactly as parsed (what the
|
|
6595
|
+
// operator typed; prepareInstance keeps it on prepared.spawn.providers) and
|
|
6596
|
+
// `settings.<cap>` is the MERGED payload per module (soul ⊕ workspace byTeam ⊕
|
|
6597
|
+
// local.settings ⊕ --provider), i.e. what the provider receives. Reserved and
|
|
6598
|
+
// poison keys were refused by resolveSoul before this point (E_WORKSPACE_SCHEMA).
|
|
6599
|
+
const preparedProviders = o.prepared ? structuredClone(o.prepared.spawn?.providers && typeof o.prepared.spawn.providers === "object" ? o.prepared.spawn.providers : {}) : null;
|
|
6600
|
+
const preparedSettings = o.prepared ? Object.fromEntries(o.prepared.resolution.modules.map((m) => [m.name, structuredClone(o.prepared.resolution.payloads?.[m.name] && typeof o.prepared.resolution.payloads[m.name] === "object" ? o.prepared.resolution.payloads[m.name] : {})])) : null;
|
|
6572
6601
|
return deliver({
|
|
6573
|
-
...(o.prepared ? { modules: o.prepared.preview ?? null, team: o.prepared.soulEntry?.team ?? null, resolution: o.prepared.resolution.revision, declRevision: o.prepared.resolution.declRevision ?? null, payloadRevision: o.prepared.resolution.payloadRevision ?? null, workspace: o.prepared.discovery?.key ?? null, standalone: o.prepared.discovery?.standalone === true } : {}),
|
|
6602
|
+
...(o.prepared ? { modules: o.prepared.preview ?? null, team: o.prepared.soulEntry?.team ?? null, resolution: o.prepared.resolution.revision, declRevision: o.prepared.resolution.declRevision ?? null, payloadRevision: o.prepared.resolution.payloadRevision ?? null, workspace: o.prepared.discovery?.key ?? null, standalone: o.prepared.discovery?.standalone === true, providers: preparedProviders, settings: preparedSettings } : {}),
|
|
6574
6603
|
spawnPreviewApi: 2, preview: true, agent: agent.name, kind: agent.kind || "persistent", instance, home, repo: repoAbs, work,
|
|
6575
6604
|
subject: o.subject ?? { soul: agent.name, agentsRoot: root, context: null },
|
|
6576
6605
|
decision, preflight,
|
|
@@ -6870,7 +6899,7 @@ function* spawnBody(root, agent, o = {}) {
|
|
|
6870
6899
|
// Cross-repo coordinator: ./work is the deployment boundary, not a repo — member
|
|
6871
6900
|
// repos are read-context; repo edits are routed, not made.
|
|
6872
6901
|
// workspace model (o.prepared): the directory holding oats-local.yaml
|
|
6873
|
-
// (prepared.deployment — the
|
|
6902
|
+
// (prepared.deployment — the directory holding oats-local.yaml, whatever it is named);
|
|
6874
6903
|
// classic: config team: scope, else the workspace-scope oats-config.yaml.
|
|
6875
6904
|
const resolvedCfgEarly = composition.resolved;
|
|
6876
6905
|
const wsRoot = preparedDeployment
|
|
@@ -23,7 +23,8 @@ import { loadLocal, discoverWorkspace, discoverRepo, standaloneRepo } from "./wo
|
|
|
23
23
|
import { resolveSoul, packageRef } from "./resolve.mjs";
|
|
24
24
|
import { materialize, MODULES_DIR, SKILLS_DIR } from "./materialize.mjs";
|
|
25
25
|
import { fetchRemoteTree } from "./remote.mjs";
|
|
26
|
-
import { mkdirSync, renameSync, rmSync, writeFileSync, symlinkSync } from "node:fs";
|
|
26
|
+
import { mkdirSync, renameSync, rmSync, writeFileSync, symlinkSync, statSync } from "node:fs";
|
|
27
|
+
import { spawnSync } from "node:child_process";
|
|
27
28
|
import { randomBytes } from "node:crypto";
|
|
28
29
|
import { readLock, LOCK_FILE, readPackageManifests } from "./packages.mjs";
|
|
29
30
|
import * as defaultRemote from "./remote.mjs";
|
|
@@ -198,6 +199,135 @@ export async function ensureWorkspaceSoul(prepared, agentsRoot) {
|
|
|
198
199
|
return target;
|
|
199
200
|
}
|
|
200
201
|
|
|
202
|
+
// ---------------------------------------------------------------------------
|
|
203
|
+
// Member clones — where a workspace soul's `work: worktree|checkout` target lives
|
|
204
|
+
// ---------------------------------------------------------------------------
|
|
205
|
+
|
|
206
|
+
/** The taught member name of a repo key: the last path segment without `.git`
|
|
207
|
+
* (`github.com/northwind/platform` → `platform`). The same rule `oats onboard`
|
|
208
|
+
* and `oats sync` print (memberLabel). */
|
|
209
|
+
export function memberNameOf(key) {
|
|
210
|
+
return String(key).split("/").filter(Boolean).pop()?.replace(/\.git$/i, "") || String(key);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** The convention path of a member's clone: `<deployment>/<member name>` — except a
|
|
214
|
+
* member called `agents`, which is cloned as `agents-repo/` because `<deployment>/agents/`
|
|
215
|
+
* is the instance root (design doc §4; matches onboard's cloneDirOf). */
|
|
216
|
+
export function conventionCloneDir(deployment, key) {
|
|
217
|
+
const name = memberNameOf(key);
|
|
218
|
+
return join(deployment, name === "agents" ? "agents-repo" : name);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Normalise a key an operator may have WRITTEN in `clones:` — the canonical key
|
|
222
|
+
* (`github.com/org/repo`), or any ref form parseRepoRef understands (`git:…`,
|
|
223
|
+
* `https://…`, `git@host:…`, `/abs/bare.git`) — to the canonical key. A key that
|
|
224
|
+
* parses no way is returned as written (it can then only match literally). */
|
|
225
|
+
function canonicalCloneKey(written) {
|
|
226
|
+
const s = String(written).trim();
|
|
227
|
+
if (s.startsWith("local/")) return s; // a local key is already canonical
|
|
228
|
+
for (const candidate of [s, `git:${s}`]) {
|
|
229
|
+
try { return parseRepoRef(candidate).key; } catch { /* next form */ }
|
|
230
|
+
}
|
|
231
|
+
return s;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The remote urls a clone carries (any remote, not only origin), parsed to their
|
|
235
|
+
* repo keys. Not a git repo → null. */
|
|
236
|
+
function cloneRemoteKeys(path) {
|
|
237
|
+
const git = (argv) => spawnSync("git", ["-C", path, ...argv], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 10_000, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
|
|
238
|
+
const inside = git(["rev-parse", "--git-dir"]);
|
|
239
|
+
if (inside.status !== 0) return null;
|
|
240
|
+
const cfg = git(["config", "--get-regexp", "^remote\\..*\\.url$"]);
|
|
241
|
+
const keys = [];
|
|
242
|
+
if (cfg.status === 0) {
|
|
243
|
+
for (const line of cfg.stdout.split("\n")) {
|
|
244
|
+
const url = line.replace(/^\S+\s+/, "").trim();
|
|
245
|
+
if (!url) continue;
|
|
246
|
+
try { keys.push(parseRepoRef(url).key); } catch { keys.push(`?/${url}`); }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return keys;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Two repo keys name the same repository. Hosted keys compare literally; `local/<abs>`
|
|
253
|
+
* keys compare by realpath when the path exists (macOS tmpdir → /private/var…). */
|
|
254
|
+
function sameRepoKey(a, b) {
|
|
255
|
+
if (a === b) return true;
|
|
256
|
+
if (!a.startsWith("local/") || !b.startsWith("local/")) return false;
|
|
257
|
+
const real = (k) => { try { return realpathSync(k.slice("local/".length)); } catch { return k.slice("local/".length); } };
|
|
258
|
+
return real(a) === real(b);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Verify `path` is the clone of `key`: it exists, is a directory, is a Git repo, and
|
|
262
|
+
* one of its remotes parses to `key`. Anything else → E_CLONE_MISMATCH { path, expected,
|
|
263
|
+
* found } — the operator pointed the kernel at the wrong place; it never works there. */
|
|
264
|
+
export function verifyMemberClone(path, key, { via } = {}) {
|
|
265
|
+
const mismatch = (found, why) => err("E_CLONE_MISMATCH", `${via ? `${via}: ` : ""}${path} is not a clone of ${key}${why ? ` (${why})` : ""}${found && found.length ? ` — its remotes point at ${found.join(", ")}` : ""}`, { path, expected: key, found, via: via ?? null });
|
|
266
|
+
let st; try { st = statSync(path); } catch { throw mismatch(null, "the path does not exist"); }
|
|
267
|
+
if (!st.isDirectory()) throw mismatch(null, "not a directory");
|
|
268
|
+
const found = cloneRemoteKeys(path);
|
|
269
|
+
if (found === null) throw mismatch(null, "not a Git repository");
|
|
270
|
+
if (!found.some((k) => sameRepoKey(k, key))) throw mismatch(found, found.length ? "no remote names it" : "it has no remotes");
|
|
271
|
+
return path;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Where the work target of a PREPARED spawn lives — the member clone of the soul's
|
|
276
|
+
* repo on this machine (design doc §4; decision 9: the work target is the only thing
|
|
277
|
+
* that needs a clone). In order:
|
|
278
|
+
* 1. `explicit` (`--repo`) — the operator's word; relative to the deployment; not
|
|
279
|
+
* verified against the member (an explicit --repo may deliberately point elsewhere);
|
|
280
|
+
* 2. `oats-local.yaml` `clones: { <repo key>: <path> }` — the key as written is
|
|
281
|
+
* normalised through parseRepoRef so `git:…`, `https://…`, `git@…` spellings match;
|
|
282
|
+
* 3. `<deployment>/<member name>` (`agents` → `agents-repo`);
|
|
283
|
+
* 4. null — nothing on this machine.
|
|
284
|
+
* A path found by (2) or (3) is VERIFIED: a directory, a Git repo, one remote parsing to
|
|
285
|
+
* the member's key → else E_CLONE_MISMATCH. A `clones:` entry whose path is absent is a
|
|
286
|
+
* mismatch too (the operator named it; "missing" would hide the typo).
|
|
287
|
+
* Returns an absolute path or null.
|
|
288
|
+
*/
|
|
289
|
+
export function resolveMemberClone(prepared, { explicit } = {}) {
|
|
290
|
+
const deployment = resolvePath(prepared?.deployment ?? process.cwd());
|
|
291
|
+
if (typeof explicit === "string" && explicit.trim()) return isAbsolute(explicit) ? resolvePath(explicit) : resolvePath(deployment, explicit);
|
|
292
|
+
const key = prepared?.soulEntry?.repoKey;
|
|
293
|
+
if (typeof key !== "string" || !key) return null;
|
|
294
|
+
const clones = prepared?.local?.clones;
|
|
295
|
+
if (clones && typeof clones === "object") {
|
|
296
|
+
for (const [written, value] of Object.entries(clones)) {
|
|
297
|
+
if (!sameRepoKey(canonicalCloneKey(written), key)) continue;
|
|
298
|
+
if (typeof value !== "string" || !value.trim()) throw err("E_CLONE_MISMATCH", `oats-local.yaml clones: ${written} must be a path`, { path: value, expected: key, found: null, via: "oats-local.yaml clones:" });
|
|
299
|
+
const path = isAbsolute(value) ? resolvePath(value) : resolvePath(deployment, value);
|
|
300
|
+
return verifyMemberClone(path, key, { via: `oats-local.yaml clones: ${written}` });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const convention = conventionCloneDir(deployment, key);
|
|
304
|
+
if (!existsSync(convention)) return null;
|
|
305
|
+
return verifyMemberClone(convention, key, { via: "convention path" });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** The clone url of the soul's member as the workspace names it (for remedies). */
|
|
309
|
+
function memberUrlOf(prepared, key) {
|
|
310
|
+
for (const ref of prepared?.discovery?.workspace?.members || []) {
|
|
311
|
+
try { const p = parseRepoRef(ref); if (sameRepoKey(p.key, key)) return p.url; } catch { /* validated already */ }
|
|
312
|
+
}
|
|
313
|
+
if (prepared?.discovery?.standalone === true && prepared.discovery.key === key) return prepared.discovery.url ?? null;
|
|
314
|
+
return key.startsWith("local/") ? key.slice("local/".length) : `https://${key}.git`;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** resolveMemberClone, or E_CLONE_MISSING naming BOTH ways to provide the clone
|
|
318
|
+
* (the convention path and a `clones:` entry) plus `--repo` for a one-off. */
|
|
319
|
+
export function requireMemberClone(prepared, { explicit } = {}) {
|
|
320
|
+
const found = resolveMemberClone(prepared, { explicit });
|
|
321
|
+
if (found) return found;
|
|
322
|
+
const key = prepared?.soulEntry?.repoKey ?? "<repo>";
|
|
323
|
+
const deployment = resolvePath(prepared?.deployment ?? process.cwd());
|
|
324
|
+
const convention = conventionCloneDir(deployment, key);
|
|
325
|
+
const url = memberUrlOf(prepared, key);
|
|
326
|
+
const soul = prepared?.soulEntry?.name ?? "<soul>";
|
|
327
|
+
const work = prepared?.soulEntry?.definition?.work ?? "worktree";
|
|
328
|
+
throw err("E_CLONE_MISSING", `soul ${soul} works in a ${work} of ${key}, and this machine has no clone of it — either \`git clone ${url} ${convention}\` (the convention: <deployment>/<member name>) or point oats-local.yaml at an existing clone: \`clones: { ${key}: <abs path> }\`; for a one-off pass --repo <path>`, { soul, repoKey: key, work, deployment, convention, url, remedies: { clone: `git clone ${url} ${convention}`, local: { clones: { [key]: "<abs path>" } }, flag: "--repo <path>" } });
|
|
329
|
+
}
|
|
330
|
+
|
|
201
331
|
/** The async half of a spawn: everything that touches the network. Returns a
|
|
202
332
|
* PREPARED object that `spawnInstance` consumes synchronously. */
|
|
203
333
|
export async function prepareInstance(contextDir, soulName, { spawn = {}, remoteOptions, remote, local: localOverride, discovery: discoveryOverride } = {}) {
|
|
@@ -208,7 +338,7 @@ export async function prepareInstance(contextDir, soulName, { spawn = {}, remote
|
|
|
208
338
|
const discovery = discoveryOverride ?? await discoverOrStandalone(local, { remoteOptions, remote });
|
|
209
339
|
const soulEntry = findSoulEntry(discovery, soulName);
|
|
210
340
|
const resolution = await resolveSoul(discovery, soulEntry, { local, lock, spawn, remoteOptions, remote });
|
|
211
|
-
return { local, deployment, lock, discovery, soulEntry, resolution, remoteOptions };
|
|
341
|
+
return { local, deployment, lock, discovery, soulEntry, resolution, remoteOptions, spawn };
|
|
212
342
|
}
|
|
213
343
|
|
|
214
344
|
/** E_REMOTE_UNREADABLE reasons (lib/remote.mjs classifyRemoteFailure) that mean "the
|
package/lib/materialize.mjs
CHANGED
|
@@ -571,6 +571,35 @@ export function driftOf(instanceJson, discovery, { lock } = {}) {
|
|
|
571
571
|
return rows;
|
|
572
572
|
}
|
|
573
573
|
|
|
574
|
+
/**
|
|
575
|
+
* soulDriftOf(instanceJson, discovery)
|
|
576
|
+
* → { name, repoKey, commit, current: { commit } | null, status: "current"|"moved"|"missing", reason? } | null
|
|
577
|
+
*
|
|
578
|
+
* Decision 17 for the SOUL SOURCE: a workspace spawn records `instance.json.workspace.soul =
|
|
579
|
+
* { repoKey, commit, team }` (the member and commit the soul was fetched from). The member row
|
|
580
|
+
* for `repoKey` in `discovery.members` is the current state: a different commit → "moved", the
|
|
581
|
+
* soul gone from the member → "missing" (reason "soul-absent"), no usable row → "missing"
|
|
582
|
+
* (reason "unconfirmed" / the row's reason). A standalone view's own member row is unconfirmed
|
|
583
|
+
* by construction (reason "cannot-read") yet carries the repo's current commit — it is compared,
|
|
584
|
+
* not reported missing. Returns null for a home without a recorded workspace soul (classic).
|
|
585
|
+
*/
|
|
586
|
+
export function soulDriftOf(instanceJson, discovery) {
|
|
587
|
+
const soul = plainObject(instanceJson?.workspace) && plainObject(instanceJson.workspace.soul) ? instanceJson.workspace.soul : null;
|
|
588
|
+
if (!soul || typeof soul.repoKey !== "string") return null;
|
|
589
|
+
const name = typeof instanceJson.agent === "string" ? instanceJson.agent : (typeof instanceJson.soul === "string" ? instanceJson.soul : null);
|
|
590
|
+
const commit = typeof soul.commit === "string" ? soul.commit : null;
|
|
591
|
+
const members = Array.isArray(discovery?.members) ? discovery.members : [];
|
|
592
|
+
const member = members.find((m) => m && m.key === soul.repoKey) || null;
|
|
593
|
+
const standaloneOwn = discovery?.standalone === true && member && member.key === discovery.key && typeof member.commit === "string";
|
|
594
|
+
const base = { name, repoKey: soul.repoKey, commit, team: soul.team ?? null };
|
|
595
|
+
if (!member || (!member.confirmed && !standaloneOwn) || typeof member.commit !== "string") {
|
|
596
|
+
return { ...base, current: null, status: "missing", reason: member ? (member.reason || "unconfirmed") : "unconfirmed" };
|
|
597
|
+
}
|
|
598
|
+
const present = name === null || (Array.isArray(member.souls) && member.souls.some((s) => s && s.name === name));
|
|
599
|
+
if (!present) return { ...base, current: { commit: member.commit }, status: "missing", reason: "soul-absent" };
|
|
600
|
+
return { ...base, current: { commit: member.commit }, status: member.commit === commit ? "current" : "moved" };
|
|
601
|
+
}
|
|
602
|
+
|
|
574
603
|
/** Read the modules recorded in an instance home (→ {} when absent). */
|
|
575
604
|
export function recordedModules(home) {
|
|
576
605
|
const file = join(resolve(home), "instance.json");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awebai/oats",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.2",
|
|
4
4
|
"description": "OATS (Open Agent Team Specification) — durable souls, disposable instances, targetable capability packages, and the runtime-neutral oats CLI/kernel.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|