@cohortapp/agent-sdk 2.3.2 → 2.4.1
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/framework-features.json +30 -0
- package/lib/backlog.mjs +136 -0
- package/lib/cadences.mjs +63 -2
- package/lib/cadences.test.mjs +105 -0
- package/lib/capability/inventory.mjs +542 -0
- package/lib/capability/inventory.test.mjs +232 -0
- package/lib/capability/probe.mjs +255 -0
- package/lib/channels/contract.mjs +37 -1
- package/lib/channels/contract.test.mjs +25 -1
- package/lib/claude-bin.mjs +37 -3
- package/lib/claude-bin.test.mjs +42 -8
- package/lib/execution/disposition.mjs +501 -0
- package/lib/execution/disposition.test.mjs +482 -0
- package/lib/execution/drive.mjs +352 -0
- package/lib/execution/drive.test.mjs +270 -0
- package/lib/execution/effects.mjs +340 -0
- package/lib/execution/effects.test.mjs +193 -0
- package/lib/execution/index.mjs +152 -0
- package/lib/execution/intake.mjs +581 -0
- package/lib/execution/intake.test.mjs +343 -0
- package/lib/execution/journal.mjs +374 -0
- package/lib/execution/journal.test.mjs +261 -0
- package/lib/execution/match.mjs +331 -0
- package/lib/execution/match.test.mjs +235 -0
- package/lib/execution/pipeline.mjs +341 -0
- package/lib/execution/pipeline.test.mjs +389 -0
- package/lib/execution/route.mjs +332 -0
- package/lib/execution/route.test.mjs +186 -0
- package/lib/execution/surface-policy.mjs +446 -0
- package/lib/execution/surface-policy.test.mjs +162 -0
- package/lib/goals/admission.mjs +209 -0
- package/lib/goals/admission.test.mjs +139 -0
- package/lib/goals/classify.mjs +206 -0
- package/lib/goals/classify.test.mjs +109 -0
- package/lib/goals/collaborate.mjs +415 -0
- package/lib/goals/collaborate.test.mjs +324 -0
- package/lib/goals/gaps.mjs +111 -0
- package/lib/goals/gaps.test.mjs +284 -0
- package/lib/goals/loop.mjs +537 -0
- package/lib/goals/loop.test.mjs +719 -0
- package/lib/identity/persona.mjs +247 -0
- package/lib/identity/persona.test.mjs +117 -0
- package/lib/kpi.mjs +469 -0
- package/lib/kpi.test.mjs +244 -0
- package/lib/mandate/audit.mjs +168 -0
- package/lib/mandate/audit.test.mjs +195 -0
- package/lib/mandate/cache.mjs +162 -0
- package/lib/mandate/derive.mjs +317 -0
- package/lib/mandate/derive.test.mjs +224 -0
- package/lib/mandate/model.mjs +352 -0
- package/lib/mandate/model.test.mjs +145 -0
- package/lib/mandate/refresh.mjs +187 -0
- package/lib/mandate/refresh.test.mjs +293 -0
- package/lib/mcp/server.test.mjs +4 -4
- package/lib/org/approvals.mjs +14 -2
- package/lib/org/client.mjs +58 -22
- package/lib/org/client.test.mjs +3 -1
- package/lib/org/inbound/directedness.mjs +720 -0
- package/lib/org/inbound/directedness.test.mjs +543 -0
- package/lib/org/inbound/facts.mjs +501 -0
- package/lib/org/inbound/facts.test.mjs +375 -0
- package/lib/org/inbound/hydrate.mjs +535 -0
- package/lib/org/inbound/hydrate.test.mjs +326 -0
- package/lib/org/inbound/index.mjs +233 -0
- package/lib/org/inbound/index.test.mjs +324 -0
- package/lib/org/inbound/io.mjs +141 -0
- package/lib/org/inbound/project.mjs +201 -0
- package/lib/org/inbound/project.test.mjs +287 -0
- package/lib/org/inbound/surfaces.mjs +257 -0
- package/lib/org/knowledge.mjs +10 -1
- package/lib/org/knowledge.test.mjs +8 -1
- package/lib/org/leases.mjs +5 -0
- package/lib/org/mesh.mjs +17 -2
- package/lib/org/messaging.mjs +40 -4
- package/lib/org/messaging.test.mjs +40 -0
- package/lib/org/param-contract.mjs +694 -0
- package/lib/org/param-contract.test.mjs +451 -0
- package/lib/org/protocol.checksum +1 -1
- package/lib/org/protocol.mjs +8 -0
- package/lib/org/protocol.test.mjs +5 -1
- package/lib/org/push.mjs +1025 -0
- package/lib/org/push.test.mjs +690 -0
- package/lib/org/tool-surface.mjs +138 -38
- package/lib/org/tool-surface.test.mjs +13 -8
- package/lib/org/typing.mjs +341 -0
- package/lib/org/typing.test.mjs +291 -0
- package/lib/plan/compile.mjs +510 -0
- package/lib/plan/compile.test.mjs +286 -0
- package/lib/plan/emit.mjs +256 -0
- package/lib/plan/emit.test.mjs +246 -0
- package/lib/plan/explain.mjs +226 -0
- package/lib/plan/explain.test.mjs +188 -0
- package/lib/plan/schema.mjs +140 -0
- package/lib/resource-governor.mjs +47 -1
- package/lib/resource-governor.test.mjs +21 -1
- package/lib/setup/enroll-from-cohort.mjs +105 -17
- package/lib/setup/enroll-from-cohort.test.mjs +68 -1
- package/lib/setup/sections/identity.mjs +15 -4
- package/lib/setup/sections/identity.test.mjs +94 -0
- package/lib/setup/sections/inventory.mjs +178 -0
- package/lib/setup/sections/inventory.test.mjs +198 -0
- package/lib/setup/sections/mandate.mjs +392 -0
- package/lib/setup/sections/mandate.test.mjs +373 -0
- package/lib/setup/sections/subagents.mjs +427 -0
- package/lib/setup/sections/subagents.test.mjs +429 -0
- package/lib/setup/sections/verify.mjs +121 -0
- package/lib/setup/sections/verify.test.mjs +175 -0
- package/lib/setup/sot.mjs +2 -0
- package/lib/subagents/cli.mjs +463 -0
- package/lib/subagents/cli.test.mjs +389 -0
- package/lib/subagents/client.mjs +373 -0
- package/lib/subagents/client.test.mjs +309 -0
- package/lib/subagents/gap.mjs +268 -0
- package/lib/subagents/gap.test.mjs +234 -0
- package/lib/subagents/lock.mjs +296 -0
- package/lib/subagents/lock.test.mjs +248 -0
- package/lib/subagents/manifest.mjs +224 -0
- package/lib/subagents/manifest.test.mjs +175 -0
- package/lib/subagents/refs.mjs +274 -0
- package/lib/subagents/refs.test.mjs +204 -0
- package/lib/subagents/resolve.mjs +455 -0
- package/lib/subagents/resolve.test.mjs +422 -0
- package/lib/subagents/schema.mjs +467 -0
- package/lib/subagents/schema.test.mjs +306 -0
- package/package.json +8 -3
- package/plugins/maestro-skills/.claude-plugin/marketplace.json +16 -0
- package/policies/ai-disclosure.yaml +42 -2
- package/scaffold/CLAUDE.md +16 -2
- package/schedules/triggers/goal-steward.md +79 -0
- package/scripts/ci/conformance-org-api.mjs +792 -0
- package/scripts/ci/conformance-org-api.test.mjs +417 -0
- package/scripts/daemon/agent-daemon.mjs +36 -4
- package/scripts/daemon/cadence-handlers.mjs +145 -1
- package/scripts/daemon/goal-steward-cadence.test.mjs +243 -0
- package/scripts/daemon/inbox-deferral.mjs +45 -2
- package/scripts/daemon/inbox-deferral.test.mjs +56 -0
- package/scripts/daemon/inbox-wake.mjs +282 -0
- package/scripts/daemon/inbox-wake.test.mjs +199 -0
- package/scripts/daemon/prompt-builder.mjs +41 -1
- package/scripts/daemon/typing-registry.mjs +55 -2
- package/scripts/daemon/typing-registry.test.mjs +25 -0
- package/scripts/local-triggers/generate-plists.test.mjs +5 -5
- package/scripts/setup/gen-subagent-manifest.mjs +95 -0
- package/scripts/setup/gen-subagent-manifest.test.mjs +124 -0
- package/scripts/setup/generate-plan.mjs +108 -0
- package/scripts/setup/init-capability-manifest.mjs +70 -0
- package/scripts/setup/init-skill-marketplace.mjs +155 -0
- package/scripts/setup/init-skill-marketplace.test.mjs +193 -0
|
@@ -138,3 +138,97 @@ test("pull is fail-open: a fetch error leaves config untouched", async () => {
|
|
|
138
138
|
);
|
|
139
139
|
assert.equal(readAgentJson(root).firstName, "UNCONFIGURED");
|
|
140
140
|
});
|
|
141
|
+
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
// ARCHETYPE AXES (the fatal apply() regression).
|
|
144
|
+
//
|
|
145
|
+
// The wizard used to offer `people-leader` and `compliance-leader`, neither of
|
|
146
|
+
// which has an archetype file on disk. Picking either resolved to nothing and
|
|
147
|
+
// made apply() throw — and because the whole init pipeline downstream
|
|
148
|
+
// (capability pack -> cadences -> plan compiler) keys off this value, a bad axis
|
|
149
|
+
// poisons everything after it. These assert the invariant against the real
|
|
150
|
+
// filesystem, so adding an archetype without offering it (or offering one that
|
|
151
|
+
// does not exist) fails here rather than in a user's setup run.
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
|
|
154
|
+
import { FUNCTIONS, ALTITUDES } from "./identity.mjs";
|
|
155
|
+
import { listFunctions, listAltitudes, resolveArchetype } from "../../archetype.mjs";
|
|
156
|
+
import { FUNCTIONS as ENROLL_FUNCTIONS, ALTITUDES as ENROLL_ALTITUDES, deriveFunction, deriveAltitude } from "../enroll-from-cohort.mjs";
|
|
157
|
+
import { loadSections } from "../runner.mjs";
|
|
158
|
+
|
|
159
|
+
test("every function the wizard offers has an archetype file on disk", () => {
|
|
160
|
+
const onDisk = listFunctions();
|
|
161
|
+
for (const f of FUNCTIONS) {
|
|
162
|
+
assert.ok(onDisk.includes(f.value), `wizard offers "${f.value}" but archetypes/functions/${f.value}.yaml does not exist`);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("every archetype on disk is offered by the wizard (no orphaned archetype)", () => {
|
|
167
|
+
const offered = new Set(FUNCTIONS.map((f) => f.value));
|
|
168
|
+
for (const f of listFunctions()) {
|
|
169
|
+
assert.ok(offered.has(f), `archetypes/functions/${f}.yaml exists but the wizard never offers it`);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("every altitude the wizard offers has an archetype file, and vice versa", () => {
|
|
174
|
+
const onDisk = listAltitudes();
|
|
175
|
+
for (const a of ALTITUDES) assert.ok(onDisk.includes(a.value), `wizard offers altitude "${a.value}" with no archetypes/altitudes/${a.value}.yaml`);
|
|
176
|
+
const offered = new Set(ALTITUDES.map((a) => a.value));
|
|
177
|
+
for (const a of onDisk) assert.ok(offered.has(a), `archetypes/altitudes/${a}.yaml exists but the wizard never offers it`);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("`founder` is reachable from the wizard (it owns runway + investor cadences)", () => {
|
|
181
|
+
assert.ok(ALTITUDES.some((a) => a.value === "founder"), "founder altitude is offered");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("the pull path can only derive an axis the wizard can render", () => {
|
|
185
|
+
// enroll-from-cohort writes function/altitude straight into config/agent.json,
|
|
186
|
+
// so a value it can derive but the wizard cannot render is an un-resolvable seat.
|
|
187
|
+
const offeredFns = new Set(FUNCTIONS.map((f) => f.value));
|
|
188
|
+
for (const f of ENROLL_FUNCTIONS) assert.ok(offeredFns.has(f), `enroll can derive "${f}" which the wizard cannot render`);
|
|
189
|
+
const offeredAlts = new Set(ALTITUDES.map((a) => a.value));
|
|
190
|
+
for (const a of ENROLL_ALTITUDES) assert.ok(offeredAlts.has(a), `enroll can derive altitude "${a}" which the wizard cannot render`);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("the retired axes are gone from BOTH lists", () => {
|
|
194
|
+
for (const dead of ["people-leader", "compliance-leader"]) {
|
|
195
|
+
assert.ok(!FUNCTIONS.some((f) => f.value === dead), `wizard still offers the non-existent "${dead}"`);
|
|
196
|
+
assert.ok(!ENROLL_FUNCTIONS.includes(dead), `enroll can still derive the non-existent "${dead}"`);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("the roles that used to derive a dead axis now derive a real one", () => {
|
|
201
|
+
assert.equal(deriveFunction({ role: "Head of People", team: "HR" }), "operations-leader");
|
|
202
|
+
assert.equal(deriveFunction({ role: "general counsel", team: "Legal" }), "compliance-officer");
|
|
203
|
+
assert.equal(deriveFunction({ role: "Head of Product", team: "Product" }), "product-leader");
|
|
204
|
+
assert.equal(deriveAltitude({ title: "Co-Founder & CEO" }), "founder");
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("every offered (function, altitude) pair actually resolves to an archetype", async () => {
|
|
208
|
+
// The real end-to-end guarantee: no combination the wizard can produce throws.
|
|
209
|
+
for (const f of FUNCTIONS) {
|
|
210
|
+
for (const a of ALTITUDES) {
|
|
211
|
+
const arch = await resolveArchetype({ function: f.value, altitude: a.value });
|
|
212
|
+
assert.ok(arch && typeof arch === "object", `resolveArchetype failed for ${f.value}/${a.value}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("every derivable pull result resolves to an archetype too", async () => {
|
|
218
|
+
for (const f of ENROLL_FUNCTIONS) {
|
|
219
|
+
for (const a of ENROLL_ALTITUDES) {
|
|
220
|
+
const arch = await resolveArchetype({ function: f, altitude: a });
|
|
221
|
+
assert.ok(arch && typeof arch === "object", `resolveArchetype failed for pulled ${f}/${a}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("the identity section is registered by the directory glob at order 10", async () => {
|
|
227
|
+
const sections = await loadSections();
|
|
228
|
+
const s = sections.find((x) => x.id === "identity");
|
|
229
|
+
assert.ok(s, "identity is discovered by loadSections()");
|
|
230
|
+
assert.equal(s.order, 10);
|
|
231
|
+
assert.equal(s.order, identity.order);
|
|
232
|
+
// It must run before the capability inventory, which reads its archetype.
|
|
233
|
+
assert.ok(s.order < sections.find((x) => x.id === "inventory").order);
|
|
234
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sections/inventory.mjs — the CAPABILITY INVENTORY step. (order 55)
|
|
3
|
+
*
|
|
4
|
+
* Registered the same way every other cross-workstream section is: by dropping
|
|
5
|
+
* this file into `lib/setup/sections/`. `runner.mjs` globs the directory and
|
|
6
|
+
* sorts by `order` — no dispatcher edit, no import to add.
|
|
7
|
+
*
|
|
8
|
+
* Order 55 sits between `tools` (50, which RECORDS what the operator selected)
|
|
9
|
+
* and `operating-model` (60, which GENERATES the cadence set). That position is
|
|
10
|
+
* the whole point: the operating model, and later the plan compiler at 78, must
|
|
11
|
+
* be built on capabilities that were actually PROBED, not on a wish-list. The
|
|
12
|
+
* law this section establishes and `lib/plan/compile.mjs` enforces:
|
|
13
|
+
*
|
|
14
|
+
* an entry with `reachable:false` may not be cited by any obligation.
|
|
15
|
+
*
|
|
16
|
+
* What it discovers (SPEC §5.1), across four planes:
|
|
17
|
+
* builtin — Claude Code's own tools
|
|
18
|
+
* skill — plugins/<plugin>/skills/*.md (with the marketplace + enabledPlugins
|
|
19
|
+
* probe, and an optional REPAIR that registers them — rung 1 of the
|
|
20
|
+
* execution ladder is a lie while 40-odd skill files are orphaned),
|
|
21
|
+
* plus archetype workflows and the sub-agent roster
|
|
22
|
+
* mcp — .mcp.json cross-read with config/mcp-servers.yaml
|
|
23
|
+
* org — the curated Cohort protocol tools + granted integration tools
|
|
24
|
+
*
|
|
25
|
+
* Output: `config/capability-manifest.json` — tracked in git, so a capability
|
|
26
|
+
* appearing or disappearing is a reviewable diff, and queryable by every session,
|
|
27
|
+
* schedule and router that follows.
|
|
28
|
+
*
|
|
29
|
+
* Every hook is non-blocking under --headless; detect/apply/verify never read the
|
|
30
|
+
* TTY. apply() is idempotent. Degradations are recorded AND logged, never
|
|
31
|
+
* swallowed.
|
|
32
|
+
*
|
|
33
|
+
* @module lib/setup/sections/inventory
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
"use strict";
|
|
37
|
+
|
|
38
|
+
import { join } from "node:path";
|
|
39
|
+
import { existsSync } from "node:fs";
|
|
40
|
+
import * as io from "../io.mjs";
|
|
41
|
+
import { buildInventory, writeManifest, readManifest, MANIFEST_REL, MANIFEST_VERSION } from "../../capability/inventory.mjs";
|
|
42
|
+
import { readAgentJson } from "../sot.mjs";
|
|
43
|
+
|
|
44
|
+
/** Resolve { function, altitude } from the on-disk SoT (null when unset). */
|
|
45
|
+
export function archetypeOf(agentRoot) {
|
|
46
|
+
try {
|
|
47
|
+
const cfg = readAgentJson(agentRoot) || {};
|
|
48
|
+
if (cfg.function && cfg.altitude) return { function: cfg.function, altitude: cfg.altitude };
|
|
49
|
+
} catch { /* fall through — the identity section owns this gap */ }
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Post the manifest to hq (`mandate.declareCapability`). Fail-open and NEVER
|
|
55
|
+
* silent: an un-enrolled agent, an old server without the mandate family, or an
|
|
56
|
+
* unreachable network all degrade to a logged note — the local manifest is the
|
|
57
|
+
* authority for planning either way.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} agentRoot @param {object} manifest
|
|
60
|
+
* @param {{callImpl?:Function, logImpl?:Function}} [deps]
|
|
61
|
+
* @returns {Promise<{posted:boolean, reason?:string}>}
|
|
62
|
+
*/
|
|
63
|
+
export async function declareCapability(agentRoot, manifest, deps = {}) {
|
|
64
|
+
const log = deps.logImpl || ((m) => io.note(m, { dim: true }));
|
|
65
|
+
try {
|
|
66
|
+
let call = deps.callImpl;
|
|
67
|
+
if (!call) {
|
|
68
|
+
const client = await import("../../org/client.mjs");
|
|
69
|
+
const cfg = client.loadOrgConfig(agentRoot);
|
|
70
|
+
if (!client.isEnabled(cfg)) {
|
|
71
|
+
log("[inventory] not enrolled in an org — capability manifest kept local only");
|
|
72
|
+
return { posted: false, reason: "not-enrolled" };
|
|
73
|
+
}
|
|
74
|
+
const o = client.configFromAgent(cfg);
|
|
75
|
+
call = (m, p) => client.call(m, p, o);
|
|
76
|
+
}
|
|
77
|
+
const body = (manifest.entries || []).map((e) => ({
|
|
78
|
+
id: e.id, plane: e.plane, kind: e.kind, reachable: e.reachable,
|
|
79
|
+
probedAt: e.probedAt, blastRadius: e.blastRadius, costHint: e.costHint,
|
|
80
|
+
}));
|
|
81
|
+
const r = await call("mandate.declareCapability", { version: manifest.schemaVersion, body });
|
|
82
|
+
if (r && r.ok) return { posted: true };
|
|
83
|
+
const reason = (r && r.error && r.error.code) || "unknown";
|
|
84
|
+
log(`[inventory] mandate.declareCapability not accepted (${reason}) — manifest kept local only`);
|
|
85
|
+
return { posted: false, reason };
|
|
86
|
+
} catch (e) {
|
|
87
|
+
log(`[inventory] mandate.declareCapability failed: ${e && e.message ? e.message : e} — manifest kept local only`);
|
|
88
|
+
return { posted: false, reason: "threw" };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default {
|
|
93
|
+
id: "inventory",
|
|
94
|
+
label: "Capability inventory (skills, plugins, MCP, org tools)",
|
|
95
|
+
order: 55,
|
|
96
|
+
|
|
97
|
+
async detect(ctx) {
|
|
98
|
+
const m = readManifest(ctx.agentRoot);
|
|
99
|
+
if (!m) return { status: "unconfigured", missing: [MANIFEST_REL] };
|
|
100
|
+
if (m.schemaVersion !== MANIFEST_VERSION) {
|
|
101
|
+
return { status: "partial", summary: `manifest schema v${m.schemaVersion} (expected v${MANIFEST_VERSION})`, missing: ["stale manifest schema"] };
|
|
102
|
+
}
|
|
103
|
+
const total = Array.isArray(m.entries) ? m.entries.length : 0;
|
|
104
|
+
if (total === 0) return { status: "partial", summary: "manifest present but empty", missing: ["no capabilities discovered"] };
|
|
105
|
+
const c = m.counts || {};
|
|
106
|
+
return {
|
|
107
|
+
status: "complete",
|
|
108
|
+
summary: `${total} capabilities (${c.reachable ?? "?"} reachable) — builtin ${c.builtin ?? 0} · skill ${c.skill ?? 0} · mcp ${c.mcp ?? 0} · org ${c.org ?? 0}`,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
async prompt(ctx) {
|
|
113
|
+
// One question only, and it is a REPAIR consent: registering the skill
|
|
114
|
+
// marketplaces writes to the plugin dirs and ~/.claude/settings.json.
|
|
115
|
+
const repair = await io.confirm(ctx, {
|
|
116
|
+
message: "Register maestro's skill marketplaces and enable them, so the agent's skills are actually invocable?",
|
|
117
|
+
key: "capabilityRepair",
|
|
118
|
+
default: true,
|
|
119
|
+
});
|
|
120
|
+
ctx.answers.capabilityRepair = repair;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
async apply(ctx) {
|
|
124
|
+
const repair = ctx.answers && typeof ctx.answers.capabilityRepair === "boolean" ? ctx.answers.capabilityRepair : true;
|
|
125
|
+
const deps = (ctx.capabilityDeps && typeof ctx.capabilityDeps === "object") ? ctx.capabilityDeps : {};
|
|
126
|
+
const log = deps.logImpl || ((m) => io.note(m, { dim: true }));
|
|
127
|
+
|
|
128
|
+
const manifest = await buildInventory(
|
|
129
|
+
{ agentRoot: ctx.agentRoot, maestroRoot: ctx.maestroRoot, archetype: archetypeOf(ctx.agentRoot), repair, env: (ctx.flags && ctx.flags.env) || process.env },
|
|
130
|
+
{ ...deps, logImpl: log },
|
|
131
|
+
);
|
|
132
|
+
writeManifest(ctx.agentRoot, manifest, deps);
|
|
133
|
+
|
|
134
|
+
const c = manifest.counts || {};
|
|
135
|
+
io.note(`[inventory] ${c.reachable ?? 0}/${(manifest.entries || []).length} capabilities reachable — builtin ${c.builtin ?? 0} · skill ${c.skill ?? 0} · mcp ${c.mcp ?? 0} · org ${c.org ?? 0}`);
|
|
136
|
+
if ((manifest.degradations || []).length) {
|
|
137
|
+
io.note(`[inventory] ${manifest.degradations.length} degradation(s) recorded in ${MANIFEST_REL} — unreachable capabilities cannot back any obligation.`, { dim: true });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
await declareCapability(ctx.agentRoot, manifest, { ...deps, logImpl: log });
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
async verify(ctx) {
|
|
144
|
+
const checks = [];
|
|
145
|
+
const m = readManifest(ctx.agentRoot);
|
|
146
|
+
checks.push({ name: `${MANIFEST_REL} present`, ok: !!m, remedy: m ? undefined : "run `maestro setup --only inventory`" });
|
|
147
|
+
if (!m) return { ok: false, checks };
|
|
148
|
+
|
|
149
|
+
const entries = Array.isArray(m.entries) ? m.entries : [];
|
|
150
|
+
const wellFormed = entries.every((e) => e && typeof e.id === "string" && typeof e.plane === "string" && typeof e.reachable === "boolean" && e.probedAt);
|
|
151
|
+
checks.push({ name: "every entry carries {id, plane, reachable, probedAt}", ok: wellFormed, remedy: wellFormed ? undefined : "re-run the inventory section" });
|
|
152
|
+
|
|
153
|
+
const anyReachable = entries.some((e) => e.reachable);
|
|
154
|
+
checks.push({ name: `at least one reachable capability (${(m.counts && m.counts.reachable) || 0})`, ok: anyReachable, remedy: anyReachable ? undefined : "no capability probed reachable — the agent cannot act" });
|
|
155
|
+
|
|
156
|
+
// SOFT checks: an un-enrolled agent or a laptop without MCP credentials is a
|
|
157
|
+
// legitimate state during init. Surface the remedy, never hard-fail setup —
|
|
158
|
+
// but say it out loud, because a silently empty plane is how rung 0/1 became
|
|
159
|
+
// a lie in the first place.
|
|
160
|
+
for (const plane of ["skill", "mcp", "org"]) {
|
|
161
|
+
const total = entries.filter((e) => e.plane === plane).length;
|
|
162
|
+
const reachable = entries.filter((e) => e.plane === plane && e.reachable).length;
|
|
163
|
+
checks.push({
|
|
164
|
+
name: `${plane} plane: ${reachable}/${total} reachable`,
|
|
165
|
+
ok: true,
|
|
166
|
+
remedy: total > 0 && reachable === 0 ? `nothing on the ${plane} plane is reachable — obligations may not cite it` : undefined,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const degraded = (m.degradations || []).length;
|
|
171
|
+
checks.push({ name: `degradations recorded: ${degraded}`, ok: true, remedy: degraded ? `see \`degradations\` in ${MANIFEST_REL}` : undefined });
|
|
172
|
+
|
|
173
|
+
return { ok: checks.every((c) => c.ok), checks };
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/** Exported for the standalone init script + tests. */
|
|
178
|
+
export { MANIFEST_REL, existsSync as _existsSync, join as _join };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* inventory.test.mjs — the capability-inventory setup section (order 55).
|
|
3
|
+
* Run: node --test lib/setup/sections/inventory.test.mjs
|
|
4
|
+
*
|
|
5
|
+
* Also asserts the REGISTRATION mechanism itself: runner.loadSections() globs
|
|
6
|
+
* this directory, so the section must be discoverable and correctly ordered
|
|
7
|
+
* without any core edit.
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
|
|
11
|
+
import { test } from "node:test";
|
|
12
|
+
import assert from "node:assert/strict";
|
|
13
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join, dirname } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
|
|
18
|
+
import inventory, { archetypeOf, declareCapability } from "./inventory.mjs";
|
|
19
|
+
import { loadSections } from "../runner.mjs";
|
|
20
|
+
import { MANIFEST_REL } from "../../capability/inventory.mjs";
|
|
21
|
+
import * as io from "../io.mjs";
|
|
22
|
+
|
|
23
|
+
const MAESTRO_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A tmp agent repo, a tmp HOME and a tmp MAESTRO_ROOT. The framework root is
|
|
27
|
+
* faked deliberately: `repair:true` writes marketplace manifests into the plugin
|
|
28
|
+
* dirs it scans, and a test must never mutate the real repo (or the operator's
|
|
29
|
+
* ~/.claude/settings.json).
|
|
30
|
+
*/
|
|
31
|
+
function tmpRoot({ archetype = true } = {}) {
|
|
32
|
+
const root = mkdtempSync(join(tmpdir(), "maestro-invsec-"));
|
|
33
|
+
const home = mkdtempSync(join(tmpdir(), "maestro-invhome-"));
|
|
34
|
+
const fakeMaestro = mkdtempSync(join(tmpdir(), "maestro-invfw-"));
|
|
35
|
+
mkdirSync(join(root, "config"), { recursive: true });
|
|
36
|
+
writeFileSync(join(root, "config", "agent.json"), JSON.stringify(
|
|
37
|
+
archetype ? { firstName: "Placeholder", function: "executive-operator", altitude: "c-suite" } : { firstName: "Placeholder" },
|
|
38
|
+
));
|
|
39
|
+
mkdirSync(join(root, "plugins", "agent-skills", "skills"), { recursive: true });
|
|
40
|
+
writeFileSync(join(root, "plugins", "agent-skills", "skills", "morning-brief.md"), "# morning-brief\n");
|
|
41
|
+
writeFileSync(join(root, ".mcp.json"), JSON.stringify({ mcpServers: { cohort: { command: "cohort-mcp" } } }));
|
|
42
|
+
return { root, home, fakeMaestro };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function ctxFor(root, home, answers = {}, extra = {}) {
|
|
46
|
+
return {
|
|
47
|
+
agentRoot: root,
|
|
48
|
+
maestroRoot: extra.maestroRoot || MAESTRO_ROOT,
|
|
49
|
+
flags: { headless: true },
|
|
50
|
+
answers,
|
|
51
|
+
io,
|
|
52
|
+
capabilityDeps: {
|
|
53
|
+
homeDir: home,
|
|
54
|
+
now: () => "2026-08-11T09:00:00.000Z",
|
|
55
|
+
logImpl: () => {},
|
|
56
|
+
orgToolsImpl: async () => [
|
|
57
|
+
{ name: "board_ready", access: "read", binding: { kind: "rpc" } },
|
|
58
|
+
{ name: "task_create", access: "write", binding: { kind: "rpc" } },
|
|
59
|
+
],
|
|
60
|
+
orgProbeImpl: async () => ({ ok: true, detail: "round-trip ok", mandateFamily: true }),
|
|
61
|
+
capabilitySurface: async () => ({ workflows: [{ id: "weekly-operating-review", cadence: "weekly" }] }),
|
|
62
|
+
wishlistImpl: async () => [],
|
|
63
|
+
callImpl: async () => ({ ok: true, result: {} }),
|
|
64
|
+
...(extra.capabilityDeps || {}),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
test("REGISTRATION: runner.loadSections() discovers `inventory` at order 55, between tools(50) and operating-model(60)", async () => {
|
|
70
|
+
const sections = await loadSections();
|
|
71
|
+
const ids = sections.map((s) => s.id);
|
|
72
|
+
assert.ok(ids.includes("inventory"), "section is auto-discovered by the directory glob — no dispatcher edit");
|
|
73
|
+
const idx = ids.indexOf("inventory");
|
|
74
|
+
assert.equal(sections[idx].order, 55);
|
|
75
|
+
assert.ok(ids.indexOf("tools") < idx, "runs after tools (50)");
|
|
76
|
+
assert.ok(ids.indexOf("operating-model") > idx, "runs before operating-model (60)");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("section shape: id/order/hooks", () => {
|
|
80
|
+
assert.equal(inventory.id, "inventory");
|
|
81
|
+
assert.equal(inventory.order, 55);
|
|
82
|
+
for (const h of ["detect", "prompt", "apply", "verify"]) assert.equal(typeof inventory[h], "function");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("detect: unconfigured → complete across apply()", async () => {
|
|
86
|
+
const { root, home, fakeMaestro } = tmpRoot();
|
|
87
|
+
const before = await inventory.detect(ctxFor(root, home, {}, { maestroRoot: fakeMaestro }));
|
|
88
|
+
assert.equal(before.status, "unconfigured");
|
|
89
|
+
assert.deepEqual(before.missing, [MANIFEST_REL]);
|
|
90
|
+
|
|
91
|
+
await inventory.apply(ctxFor(root, home, { capabilityRepair: false }, { maestroRoot: fakeMaestro }));
|
|
92
|
+
const after = await inventory.detect(ctxFor(root, home, {}, { maestroRoot: fakeMaestro }));
|
|
93
|
+
assert.equal(after.status, "complete");
|
|
94
|
+
assert.match(after.summary, /capabilities/);
|
|
95
|
+
assert.ok(existsSync(join(root, MANIFEST_REL)));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("apply writes a durable, queryable manifest with all four planes", async () => {
|
|
99
|
+
const { root, home, fakeMaestro } = tmpRoot();
|
|
100
|
+
await inventory.apply(ctxFor(root, home, { capabilityRepair: false }, { maestroRoot: fakeMaestro }));
|
|
101
|
+
const m = JSON.parse(readFileSync(join(root, MANIFEST_REL), "utf8"));
|
|
102
|
+
assert.equal(m.schemaVersion, 1);
|
|
103
|
+
for (const plane of ["builtin", "skill", "mcp", "org"]) {
|
|
104
|
+
assert.ok(m.counts[plane] > 0, `${plane} plane inventoried`);
|
|
105
|
+
}
|
|
106
|
+
assert.ok(m.entries.some((e) => e.id === "skill:agent-skills:morning-brief"));
|
|
107
|
+
assert.ok(m.entries.some((e) => e.id === "workflow:weekly-operating-review"));
|
|
108
|
+
assert.ok(m.entries.some((e) => e.id === "mcp:cohort"));
|
|
109
|
+
assert.ok(m.entries.some((e) => e.id === "board_ready"));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("apply is IDEMPOTENT — the checksum is stable across runs", async () => {
|
|
113
|
+
const { root, home, fakeMaestro } = tmpRoot();
|
|
114
|
+
await inventory.apply(ctxFor(root, home, { capabilityRepair: false }, { maestroRoot: fakeMaestro }));
|
|
115
|
+
const a = JSON.parse(readFileSync(join(root, MANIFEST_REL), "utf8")).checksum;
|
|
116
|
+
await inventory.apply(ctxFor(root, home, { capabilityRepair: false }, { maestroRoot: fakeMaestro }));
|
|
117
|
+
const b = JSON.parse(readFileSync(join(root, MANIFEST_REL), "utf8")).checksum;
|
|
118
|
+
assert.equal(a, b);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("apply with repair registers the marketplace so the skills become reachable", async () => {
|
|
122
|
+
const { root, home, fakeMaestro } = tmpRoot();
|
|
123
|
+
await inventory.apply(ctxFor(root, home, { capabilityRepair: true }, { maestroRoot: fakeMaestro }));
|
|
124
|
+
const m = JSON.parse(readFileSync(join(root, MANIFEST_REL), "utf8"));
|
|
125
|
+
const skill = m.entries.find((e) => e.id === "skill:agent-skills:morning-brief");
|
|
126
|
+
assert.equal(skill.reachable, true);
|
|
127
|
+
assert.ok(existsSync(join(root, "plugins", "agent-skills", ".claude-plugin", "marketplace.json")));
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("verify: hard-fails only on a missing/empty manifest; plane emptiness is a SOFT remedy", async () => {
|
|
131
|
+
const { root, home, fakeMaestro } = tmpRoot();
|
|
132
|
+
const bad = await inventory.verify(ctxFor(root, home, {}, { maestroRoot: fakeMaestro }));
|
|
133
|
+
assert.equal(bad.ok, false);
|
|
134
|
+
|
|
135
|
+
await inventory.apply(ctxFor(root, home, { capabilityRepair: false }, { maestroRoot: fakeMaestro }));
|
|
136
|
+
const good = await inventory.verify(ctxFor(root, home, {}, { maestroRoot: fakeMaestro }));
|
|
137
|
+
assert.equal(good.ok, true, JSON.stringify(good.checks.filter((c) => !c.ok)));
|
|
138
|
+
const names = good.checks.map((c) => c.name);
|
|
139
|
+
assert.ok(names.some((n) => /every entry carries/.test(n)));
|
|
140
|
+
assert.ok(names.some((n) => /skill plane/.test(n)));
|
|
141
|
+
// The unregistered-marketplace state is reported (the archetype workflow IS
|
|
142
|
+
// reachable, the skill file is NOT), and it never hard-fails setup.
|
|
143
|
+
const skillCheck = good.checks.find((c) => /skill plane/.test(c.name));
|
|
144
|
+
assert.equal(skillCheck.ok, true);
|
|
145
|
+
assert.match(skillCheck.name, /skill plane: 1\/2 reachable/);
|
|
146
|
+
const degCheck = good.checks.find((c) => /degradations recorded/.test(c.name));
|
|
147
|
+
assert.equal(degCheck.ok, true);
|
|
148
|
+
assert.match(degCheck.remedy, /capability-manifest\.json/);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("verify: a plane with ZERO reachable entries surfaces an explicit remedy (never silent)", async () => {
|
|
152
|
+
const { root, home, fakeMaestro } = tmpRoot();
|
|
153
|
+
await inventory.apply(ctxFor(root, home, { capabilityRepair: false }, { maestroRoot: fakeMaestro,
|
|
154
|
+
capabilityDeps: { orgProbeImpl: async () => ({ ok: false, detail: "org.cohort is not enabled", degraded: "org-not-enrolled", mandateFamily: false }) },
|
|
155
|
+
}));
|
|
156
|
+
const v = await inventory.verify(ctxFor(root, home, {}, { maestroRoot: fakeMaestro }));
|
|
157
|
+
const orgCheck = v.checks.find((c) => /org plane/.test(c.name));
|
|
158
|
+
assert.equal(orgCheck.ok, true, "an un-enrolled agent is a legitimate init state");
|
|
159
|
+
assert.match(orgCheck.remedy, /nothing on the org plane is reachable/);
|
|
160
|
+
assert.equal(v.ok, true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("archetypeOf reads the SoT and returns null when unset", () => {
|
|
164
|
+
const { root } = tmpRoot();
|
|
165
|
+
assert.deepEqual(archetypeOf(root), { function: "executive-operator", altitude: "c-suite" });
|
|
166
|
+
const { root: bare } = tmpRoot({ archetype: false });
|
|
167
|
+
assert.equal(archetypeOf(bare), null);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("declareCapability fails OPEN and LOGS when hq rejects or is absent", async () => {
|
|
171
|
+
const { root } = tmpRoot();
|
|
172
|
+
const logs = [];
|
|
173
|
+
const rejected = await declareCapability(root, { schemaVersion: 1, entries: [] }, {
|
|
174
|
+
callImpl: async () => ({ ok: false, error: { code: "NOT_FOUND" } }),
|
|
175
|
+
logImpl: (m) => logs.push(m),
|
|
176
|
+
});
|
|
177
|
+
assert.equal(rejected.posted, false);
|
|
178
|
+
assert.equal(rejected.reason, "NOT_FOUND");
|
|
179
|
+
assert.ok(logs.some((l) => /kept local only/.test(l)), "the degradation is never silent");
|
|
180
|
+
|
|
181
|
+
const threw = await declareCapability(root, { schemaVersion: 1, entries: [] }, {
|
|
182
|
+
callImpl: async () => { throw new Error("ECONNREFUSED"); },
|
|
183
|
+
logImpl: (m) => logs.push(m),
|
|
184
|
+
});
|
|
185
|
+
assert.equal(threw.posted, false);
|
|
186
|
+
assert.ok(logs.some((l) => /ECONNREFUSED/.test(l)));
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("declareCapability sends ids + reachability only — never invocation details", async () => {
|
|
190
|
+
const { root } = tmpRoot();
|
|
191
|
+
let sent = null;
|
|
192
|
+
await declareCapability(root, {
|
|
193
|
+
schemaVersion: 1,
|
|
194
|
+
entries: [{ id: "board_ready", plane: "org", kind: "method_tool", reachable: true, probedAt: "t", blastRadius: "internal", costHint: "free", invocation: "board_ready", probe: { detail: "secret" } }],
|
|
195
|
+
}, { callImpl: async (m, p) => { sent = { m, p }; return { ok: true }; }, logImpl: () => {} });
|
|
196
|
+
assert.equal(sent.m, "mandate.declareCapability");
|
|
197
|
+
assert.deepEqual(Object.keys(sent.p.body[0]).sort(), ["blastRadius", "costHint", "id", "kind", "plane", "probedAt", "reachable"]);
|
|
198
|
+
});
|