@melite/estate-queue 0.2.0-alpha → 0.2.2-alpha

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.
Files changed (61) hide show
  1. package/README.md +0 -5
  2. package/lib/cardsCompose.d.ts +31 -0
  3. package/lib/cardsCompose.js +55 -0
  4. package/lib/cardsRegistry.d.ts +5 -2
  5. package/lib/cardsRegistry.js +160 -3
  6. package/lib/discloseRegistry.d.ts +5 -0
  7. package/lib/discloseRegistry.js +3 -3
  8. package/lib/flowsData.d.ts +77 -21
  9. package/lib/flowsData.js +156 -21
  10. package/lib/flowsRegistryRows.d.ts +0 -4
  11. package/lib/flowsRegistryRows.js +137 -351
  12. package/lib/index.d.ts +0 -1
  13. package/lib/index.js +0 -4
  14. package/lib/loadPlane.d.ts +46 -4
  15. package/lib/loadPlane.js +107 -7
  16. package/lib/loadRegistry.js +9 -2
  17. package/lib/managePlane.d.ts +5 -0
  18. package/lib/managePlane.js +404 -49
  19. package/lib/managePreflight.js +38 -6
  20. package/lib/manageProbe.d.ts +35 -0
  21. package/lib/manageProbe.js +110 -0
  22. package/lib/queueLock.js +19 -10
  23. package/lib/queueResurrect.d.ts +0 -3
  24. package/lib/queueResurrect.js +0 -3
  25. package/lib/queueRetry.d.ts +12 -10
  26. package/lib/queueRetry.js +2 -4
  27. package/lib/queueSidecar.d.ts +12 -0
  28. package/lib/queueSidecar.js +15 -0
  29. package/lib/queueSubmit.d.ts +4 -1
  30. package/lib/queueSubmit.js +28 -5
  31. package/lib/runsExecute.d.ts +16 -1
  32. package/lib/runsExecute.js +63 -45
  33. package/lib/runsGates.d.ts +11 -3
  34. package/lib/runsGates.js +11 -3
  35. package/lib/runsList.d.ts +59 -3
  36. package/lib/runsList.js +217 -36
  37. package/lib/runsRegistry.d.ts +58 -3
  38. package/lib/runsRegistry.js +479 -92
  39. package/lib/runsStart.d.ts +6 -4
  40. package/lib/runsStart.js +32 -25
  41. package/lib/runsTypes.d.ts +19 -1
  42. package/lib/runsTypes.js +40 -3
  43. package/lib/runsValidate.d.ts +1 -0
  44. package/lib/runsValidate.js +5 -0
  45. package/lib/runsValidateArms.js +25 -0
  46. package/lib/runsValidateServe.js +15 -12
  47. package/lib/runsValidateShared.d.ts +8 -10
  48. package/lib/runsValidateShared.js +41 -15
  49. package/lib/runsValidateStages.d.ts +1 -1
  50. package/lib/runsValidateStages.js +90 -50
  51. package/lib/skillAuthored.d.ts +50 -0
  52. package/lib/skillAuthored.js +178 -0
  53. package/lib/skillPlane.d.ts +40 -2
  54. package/lib/skillPlane.js +63 -13
  55. package/lib/skillRegistry.d.ts +24 -1
  56. package/lib/skillRegistry.js +69 -5
  57. package/lib/skillRows.d.ts +13 -3
  58. package/lib/skillRows.js +42 -3
  59. package/package.json +24 -14
  60. package/lib/resurrect.d.ts +0 -6
  61. package/lib/resurrect.js +0 -18
@@ -3,7 +3,7 @@
3
3
  // stage rows, wires, the card gate, kinds, engines, flow_from_body.
4
4
  import { coerceWireArrays, coerceWireNumbers, unwrapItemArrays } from '@melite/comfyui-card-kit';
5
5
  import { checkStrictBody } from "./runsGates.js";
6
- import { FLOW_ID_RE, INLINE_TOP_SORTED, STAGE_KEYS_SORTED, FlowError, engineDefaultOutput, needCardRegistry, } from "./runsValidateShared.js";
6
+ import { FLOW_ID_RE, INLINE_TOP_SORTED, STAGE_KEYS_SORTED, FlowError, engineKnown, needCardRegistry, } from "./runsValidateShared.js";
7
7
  import { edgeRef, inlineEdge, inlineKind, inlineSkip } from "./runsValidateInline.js";
8
8
  import { KIND_VOCAB } from "./runsValidateShared.js";
9
9
  import { coerceRecord, minLengthRefusal } from "./runsValidateRefusals.js";
@@ -191,11 +191,26 @@ export function wiresResolve(flowId, stages) {
191
191
  export function cardGate(flowId, st, cards) {
192
192
  const defs = needCardRegistry(cards, "cardGate").defsSync();
193
193
  const def = defs.get(st.card);
194
- // requiresModel: false (pure-tool cards, boarded: []) skips the
195
- // {model:} demand — the row.requires_model. Unknown
196
- // cards still hit the model gate first (order preserved: the wall
197
- // pins the model-gate text verbatim).
198
- if (def?.requiresModel !== false) {
194
+
195
+ // UNKNOWN card refused with the model demand first named a param
196
+ // the card could never take ("card 'image-upscale' requires
197
+ // params.model" — the live receipt; the operator's agent then
198
+ // states a model to satisfy a nonsense demand and lands in a
199
+ // stranger's lane). Unknown cards hear the registration voice
200
+ // FIRST; a KNOWN card keeps the model-gate order (the wall pins
201
+ // that voice verbatim). requiresModel: false (pure-tool cards,
202
+ // boarded: []) skips the {model:} demand — the row.requires_model.
203
+ if (def === undefined) {
204
+ throw new FlowError("flow " +
205
+ JSON.stringify(flowId) +
206
+ " stage " +
207
+ JSON.stringify(st.id) +
208
+ ": card " +
209
+ JSON.stringify(st.card) +
210
+ " is not a registered card (the card set boots from " +
211
+ "src/cards — see GET /v1/tools for the served surface)");
212
+ }
213
+ if (def.requiresModel !== false) {
199
214
  const model = st.params["model"];
200
215
  if (!model || !String(model).trim()) {
201
216
  throw new FlowError("flow " +
@@ -209,16 +224,6 @@ export function cardGate(flowId, st, cards) {
209
224
  "of the {model:} door");
210
225
  }
211
226
  }
212
- if (def === undefined) {
213
- throw new FlowError("flow " +
214
- JSON.stringify(flowId) +
215
- " stage " +
216
- JSON.stringify(st.id) +
217
- ": card " +
218
- JSON.stringify(st.card) +
219
- " is not a registered card (the card set boots from " +
220
- "src/cards — see GET /v1/tools for the served surface)");
221
- }
222
227
  try {
223
228
  // THE WIRE-COERCION FAMILY AT THE LATTICE SEAT (attempt-035's
224
229
 
@@ -261,14 +266,43 @@ export function coerceSnapshotBody(def, body) {
261
266
  const carrier = (def.schemaCarrier ?? def.schema);
262
267
  return coerceWireNumbers(carrier, coerceWireArrays(carrier, unwrapItemArrays(body)));
263
268
  }
264
- // kindsOk with engineDefaults ({} at construction = deferred,
265
- // the ENGINE_TABLE at validate_engines = full).
266
- export function kindsOk(flowId, stages, engineDefaults, cards) {
269
+
270
+ // channels come from the stage's OWN tables — declared outputs,
271
+ // else card_io — else the card's declared output kinds (a card
272
+ // stage derives from its card's flowKinds.outputs, the same table
273
+ // the compose reads). The engine registry is membership-only: it
274
+ // names no kinds, so an output-less cardless stage refuses here
275
+ // instead of taking a fabricated {default: ...}. Deferred reads
276
+ // survive only for a card whose def declares no outputs at all
277
+ // (downstream reads skip it as upstream-unknown, never refused).
278
+ export function kindsOk(flowId, stages, cards) {
267
279
  // The lattice gate is its own pass BEFORE kinds (
268
280
  // docstring: "Runs BEFORE _validate_kinds").
269
281
  for (const st of stages) {
270
- if (st.card)
271
- cardGate(flowId, st, cards);
282
+ if (!st.card)
283
+ continue;
284
+ cardGate(flowId, st, cards);
285
+
286
+ // card stage that declares no channels of its own reads its
287
+ // output table from the CARD's declared ports — the same leg the
288
+ // run compose takes (runsRegistry composeCardStageRow's
289
+ // `cardDeclared`) and the same table the resolution below reads.
290
+
291
+ // default but left this walk reading only the ROW's own tables,
292
+ // so every bench card row — whose stored shape is outputs:{} by
293
+ // the card-ports law (benchStage normalizeBenchStage: absent on a
294
+ // card stage stays absent, compose fills from the ports) —
295
+ // refused the premint compose in the card-less voice. The fill
296
+ // rides the row the walk just judged: row-declared outputs and
297
+ // card_io always win, a card declaring no ports stays deferred.
298
+ if (st.outputs.length === 0 && st.cardIo.length === 0) {
299
+ const def = needCardRegistry(cards, "kindsOk").defsSync().get(st.card);
300
+ const declared = def?.flowKinds?.outputs ?? {};
301
+ for (const [name, kind] of Object.entries(declared)) {
302
+ if (typeof kind === "string")
303
+ st.cardIo.push({ name, kind });
304
+ }
305
+ }
272
306
  }
273
307
  // THE DERIVATION LAW (roadmap §12): a card stage's input kind
274
308
  // DERIVES from the card's own flowKinds.inputs when the port is
@@ -365,27 +399,33 @@ export function kindsOk(flowId, stages, engineDefaults, cards) {
365
399
  resolved.set(o.name, o.kind);
366
400
  for (const o of st.cardIo)
367
401
  resolved.set(o.name, o.kind);
368
- if (resolved.size === 0 && !st.card) {
369
- if (st.engine in engineDefaults) {
370
-
371
-
372
-
373
- const def = engineDefaults[st.engine] ?? null;
374
- if (def === null) {
375
- throw new FlowError("flow " +
376
- JSON.stringify(flowId) +
377
- " stage " +
378
- JSON.stringify(st.id) +
379
- ": engine " +
380
- JSON.stringify(st.engine) +
381
- " declares no default_output and stage declares no " +
382
- "outputs — add outputs={'default': <Kind>} on the stage, " +
383
- "or set DEFAULT_OUTPUT on the engine");
402
+ if (resolved.size === 0) {
403
+ if (st.card) {
404
+ // THE CARD'S OWN TABLE (the one-table cure): a card stage
405
+ // with no declared outputs derives them from the card's
406
+ // declared output kinds — cardGate above already proved the
407
+ // registry present and the card registered, so defsSync()
408
+ // reads loud, never silent. A card declaring no outputs at
409
+ // all stays deferred (the old shape: downstream reads skip
410
+ // it as upstream-unknown).
411
+ const defs = needCardRegistry(cards, "kindsOk").defsSync();
412
+ const declared = defs.get(st.card)?.flowKinds?.outputs ?? {};
413
+ for (const [name, kind] of Object.entries(declared)) {
414
+ if (typeof kind === "string")
415
+ resolved.set(name, kind);
384
416
  }
385
- /* v8 ignore stop */
386
- resolved.set("default", def);
387
417
  }
388
- // else: defer; the validate_engines() pass fills it in.
418
+ else {
419
+ throw new FlowError("flow " +
420
+ JSON.stringify(flowId) +
421
+ " stage " +
422
+ JSON.stringify(st.id) +
423
+ " declares no outputs and names no card — " +
424
+ "add outputs={'<channel>': <Kind>} (the closed Kind " +
425
+ "vocabulary is " +
426
+ JSON.stringify([...KIND_VOCAB]) +
427
+ ") or wire the stage to its card");
428
+ }
389
429
  }
390
430
  if (resolved.size > 0)
391
431
  outputsByStage.set(st.id, resolved);
@@ -443,9 +483,11 @@ export function kindsOk(flowId, stages, engineDefaults, cards) {
443
483
  }
444
484
  }
445
485
  // validateEngines: every stage's engine through the
446
- // bus — here the wall-pinned ENGINE_TABLE (existence + DEFAULT_OUTPUT);
447
- // then the FULL kind pass. Unknown-engine text mirrors
448
- // plugins.load_engine verbatim.
486
+ // bus — here the wall-pinned ENGINE_TABLE (existence ONLY — the
487
+ // kind-free registry: the one-table cure deleted the per-engine
488
+ // default kinds, so this pass judges membership and the FULL kind
489
+ // pass below judges declarations); then the FULL kind pass.
490
+ // Unknown-engine text mirrors plugins.load_engine verbatim.
449
491
  export function validateEngines(flow, cards,
450
492
 
451
493
 
@@ -454,7 +496,6 @@ export function validateEngines(flow, cards,
454
496
 
455
497
 
456
498
  knownEngines) {
457
- const engineDefaults = {};
458
499
  for (const st of flow.stages) {
459
500
  if (knownEngines !== undefined && !knownEngines.includes(st.engine)) {
460
501
  throw new FlowError("flow " +
@@ -469,8 +510,7 @@ knownEngines) {
469
510
  : knownEngines.slice().sort().join(", ")) +
470
511
  ")");
471
512
  }
472
- const def = engineDefaultOutput(st.engine);
473
- if (def === undefined) {
513
+ if (!engineKnown(st.engine)) {
474
514
  throw new FlowError("flow " +
475
515
  JSON.stringify(flow.id) +
476
516
  " stage " +
@@ -481,9 +521,8 @@ knownEngines) {
481
521
  JSON.stringify(st.engine) +
482
522
  " (no engine plugin declares it)");
483
523
  }
484
- engineDefaults[st.engine] = def;
485
524
  }
486
- kindsOk(flow.id, flow.stages, engineDefaults, cards);
525
+ kindsOk(flow.id, flow.stages, cards);
487
526
  return flow;
488
527
  }
489
528
  // flowFromBody: JSON body -> validated Flow.
@@ -511,12 +550,13 @@ export function flowFromBody(body, cards, knownEngines) {
511
550
  rows.push(buildStageRow(i, stagesIn[i]));
512
551
  }
513
552
  const flowId = String(rec["id"] ?? "");
514
- // Flow construction: wires + deferred kinds.
553
+ // Flow construction: wires + kinds (a cardless output-less stage
554
+ // refuses in kindsOk — no engine table to fill it from).
515
555
  if (flowId === "") {
516
556
  throw new FlowError(minLengthRefusal("Flow", "id"));
517
557
  }
518
558
  wiresResolve(flowId, rows);
519
- kindsOk(flowId, rows, {}, cards);
559
+ kindsOk(flowId, rows, cards);
520
560
  const flow = { id: flowId, description: String(rec["description"] ?? ""), stages: rows };
521
561
  return validateEngines(flow, cards, knownEngines);
522
562
  }
@@ -0,0 +1,50 @@
1
+ /** One authored skill as the door receives it. */
2
+ export interface SkillDraft {
3
+ /** The model family the skill serves ("krea-2"). */
4
+ readonly model: string;
5
+ /** The skill's name — its id leaf and its directory (SLUG_RE). */
6
+ readonly name: string;
7
+ /** One-line summary (rides every load verbatim; one line by law). */
8
+ readonly description: string;
9
+ /** The operator's trigger words, in their order. */
10
+ readonly trigger_words: readonly string[];
11
+ /** The operator's examples, verbatim. */
12
+ readonly examples: readonly string[];
13
+ /** Free markdown after the rendered sections ("" for none). */
14
+ readonly body: string;
15
+ /** The mod row this skill documents (a loras tray file name), or
16
+ * "" for a skill that names no file. */
17
+ readonly lora: string;
18
+ /** Rewrite an existing doc (the door refuses silently losing the
19
+ * previous trigger words: an update is an explicit call). */
20
+ readonly replace: boolean;
21
+ }
22
+ /** The served answer of one write. */
23
+ export interface SkillWritten {
24
+ readonly id: string;
25
+ readonly name: string;
26
+ readonly description: string;
27
+ readonly path: string;
28
+ readonly replaced: boolean;
29
+ }
30
+ /** THE ONE DERIVATION (writer and walker both spell this): the skill
31
+ * doc's directory under the estate's state root. */
32
+ export declare function authoredSkillDir(stateRoot: string, family: string, stem: string): string;
33
+ /** The doc file inside the authored skill's directory. */
34
+ export declare function authoredSkillDoc(stateRoot: string, family: string, stem: string): string;
35
+ /** The doc's text. Deterministic — no timestamps, so a rewrite of the
36
+ * same draft is byte-identical. */
37
+ export declare function renderAuthoredSkill(d: Omit<SkillDraft, "replace">): string;
38
+ /**
39
+ * Land one authored skill doc.
40
+ *
41
+ * @param repo the checkout root (the family seat is verified there)
42
+ * @param stateRoot the estate's state root (the authored plane)
43
+ * @param draft the skill as the door received it
44
+ * @returns the served answer (the id the read door answers with)
45
+ * @throws Error with the door's refusal voice when a field is missing,
46
+ * a leaf is not path-safe, the family is unseated, or an existing
47
+ * doc would be silently replaced
48
+ */
49
+ export declare function writeAuthoredSkill(repo: string, stateRoot: string, draft: SkillDraft): SkillWritten;
50
+ //# sourceMappingURL=skillAuthored.d.ts.map
@@ -0,0 +1,178 @@
1
+
2
+ // "we should also be able to get the agent to write skills. For
3
+ // example, it would be helpful that when we gave the lora to the
4
+ // model, that could also make the skill with examples, trigger
5
+ // words"). ONE ROOT, TWO ENDS: the agent's write door lands
6
+ // <stateRoot>/skills/<family>/<stem>/SKILL.md and the doc walk
7
+ // (skillRows.authoredRows) reads that same tree. The SOURCE plane
8
+ // (the tracked models tree) is never written at runtime.
9
+ //
10
+ // The trigger words are the OPERATOR's to state, never invented: an
11
+ // empty set renders as the explicit blank, so a doc that has not been
12
+ // told its triggers says so in its own body.
13
+ import { mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
14
+ import { join } from "node:path";
15
+ /** Path-safe leaf law for the skill's name (it is the served id leaf
16
+ * and the doc's directory — one spelling, never escaped later). */
17
+ const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
18
+ /** THE ONE DERIVATION (writer and walker both spell this): the skill
19
+ * doc's directory under the estate's state root. */
20
+ export function authoredSkillDir(stateRoot, family, stem) {
21
+ return join(stateRoot, "skills", family, stem);
22
+ }
23
+ /** The doc file inside the authored skill's directory. */
24
+ export function authoredSkillDoc(stateRoot, family, stem) {
25
+ return join(authoredSkillDir(stateRoot, family, stem), "SKILL.md");
26
+ }
27
+ /** The refusal voice (the door's own words, one spelling per arm). */
28
+ function refuse(what) {
29
+ throw new Error("skill write refusal: " + what);
30
+ }
31
+ /** A description rides the doc's frontmatter on ONE line (the
32
+ * frontmatter grammar is line-oriented); the author's newlines
33
+ * become spaces rather than being dropped. */
34
+ function oneLine(s) {
35
+ return s.replace(/\s*\n\s*/g, " ").trim();
36
+ }
37
+ /** The doc's text. Deterministic — no timestamps, so a rewrite of the
38
+ * same draft is byte-identical. */
39
+ export function renderAuthoredSkill(d) {
40
+ const lines = [];
41
+ lines.push("---");
42
+ lines.push("name: " + d.name);
43
+ lines.push("description: " + oneLine(d.description));
44
+ lines.push("---");
45
+ lines.push("");
46
+ if (d.lora !== "") {
47
+ // ONE PREFIX: the row's filename is `<family>/<file>` and the
48
+ // caller may state it with or without the family (the tray row's
49
+ // label is the bare stem) — both spell ONE path. The live burn
50
+
51
+ // the engine does not have.
52
+ const tail = d.lora.startsWith(d.model + "/")
53
+ ? d.lora.slice(d.model.length + 1)
54
+ : d.lora;
55
+ lines.push("## Applies to");
56
+ lines.push("");
57
+ lines.push("- lora: `" + d.model + "/" + tail + "` (the loras mod's row, label `" +
58
+ tail.split("/").pop().replace(/\.(safetensors|ckpt|pt|bin)$/i, "") + "`)");
59
+ lines.push("");
60
+ }
61
+ lines.push("## Trigger words");
62
+ lines.push("");
63
+ if (d.trigger_words.length === 0) {
64
+ lines.push("- None stated yet — the operator states them at hand-off and this doc is rewritten; " +
65
+ "run trigger-less and say so.");
66
+ }
67
+ else {
68
+ for (const w of d.trigger_words)
69
+ lines.push("- " + w);
70
+ }
71
+ lines.push("");
72
+ if (d.examples.length > 0) {
73
+ lines.push("## Examples");
74
+ lines.push("");
75
+ for (const e of d.examples)
76
+ lines.push("- " + e);
77
+ lines.push("");
78
+ }
79
+ if (d.body.trim() !== "") {
80
+ lines.push(d.body.trim());
81
+ lines.push("");
82
+ }
83
+ return lines.join("\n");
84
+ }
85
+ /** Whether the repo carries the family (the walk that serves the doc
86
+ * reads the same tree: a skill under a family nobody serves is a
87
+ * lie, so the door refuses it instead of landing an orphan). */
88
+ function familySeat(repo, family) {
89
+ const enginesRoot = join(repo, "packages", "engines");
90
+ let engines;
91
+ try {
92
+ engines = readdirSync(enginesRoot);
93
+ }
94
+ catch {
95
+ // no engines tree in this checkout: no family can be seated
96
+ return null;
97
+ }
98
+ for (const eng of engines) {
99
+ const modelsRoot = join(enginesRoot, eng, "models");
100
+ let genres;
101
+ try {
102
+ genres = readdirSync(modelsRoot);
103
+ }
104
+ catch {
105
+ // an engine with no models tree seats no family
106
+ continue;
107
+ }
108
+ for (const genre of genres) {
109
+ const mdir = join(modelsRoot, genre, family);
110
+ try {
111
+ // the family dir must exist (the same stat the walk takes)
112
+ readdirSync(mdir);
113
+ }
114
+ catch {
115
+ // not in this genre
116
+ continue;
117
+ }
118
+ return genre;
119
+ }
120
+ }
121
+ return null;
122
+ }
123
+ /**
124
+ * Land one authored skill doc.
125
+ *
126
+ * @param repo the checkout root (the family seat is verified there)
127
+ * @param stateRoot the estate's state root (the authored plane)
128
+ * @param draft the skill as the door received it
129
+ * @returns the served answer (the id the read door answers with)
130
+ * @throws Error with the door's refusal voice when a field is missing,
131
+ * a leaf is not path-safe, the family is unseated, or an existing
132
+ * doc would be silently replaced
133
+ */
134
+ export function writeAuthoredSkill(repo, stateRoot, draft) {
135
+ if (draft.model === "")
136
+ refuse("model: Field required — the model family the skill serves");
137
+ if (!SLUG_RE.test(draft.model)) {
138
+ refuse("model: " + JSON.stringify(draft.model) + " is not a path-safe family id");
139
+ }
140
+ if (familySeat(repo, draft.model) === null) {
141
+ refuse("model: no family " + JSON.stringify(draft.model) +
142
+ " under packages/engines/*/models/<genre>/ — a skill under a family nobody serves is a lie");
143
+ }
144
+ if (draft.name === "")
145
+ refuse("name: Field required — the skill is known by this name (melite_skill_read takes it)");
146
+ if (!SLUG_RE.test(draft.name)) {
147
+ refuse("name: " + JSON.stringify(draft.name) + " is not a path-safe skill id (letters, digits, . _ -)");
148
+ }
149
+ if (oneLine(draft.description) === "") {
150
+ refuse("description: Field required — the one-line summary every load prints");
151
+ }
152
+ if (draft.lora !== "" && draft.lora.includes("/.."))
153
+ refuse("lora: a file name, not a path");
154
+ const doc = authoredSkillDoc(stateRoot, draft.model, draft.name);
155
+ let existing = null;
156
+ try {
157
+ existing = readFileSync(doc, "utf8");
158
+ }
159
+ catch {
160
+ // the absent doc is the first write (never an error)
161
+ existing = null;
162
+ }
163
+ if (existing !== null && !draft.replace) {
164
+ refuse("model:" + draft.model + ":" + draft.name + " already exists at " + doc +
165
+ " — pass replace: true to rewrite it (the previous trigger words would otherwise be lost)");
166
+ }
167
+ const text = renderAuthoredSkill(draft);
168
+ mkdirSync(authoredSkillDir(stateRoot, draft.model, draft.name), { recursive: true });
169
+ writeFileSync(doc, text, "utf8");
170
+ return {
171
+ id: "model:" + draft.model + ":" + draft.name,
172
+ name: draft.name,
173
+ description: oneLine(draft.description),
174
+ path: doc,
175
+ replaced: existing !== null,
176
+ };
177
+ }
178
+ //# sourceMappingURL=skillAuthored.js.map
@@ -1,3 +1,4 @@
1
+ import type { SkillDraft } from "./skillAuthored.js";
1
2
  import type { FlowsSeat } from "./flowsData.js";
2
3
  import type { FamilyModelsSeat } from "./flowsFamilyCompose.js";
3
4
  export { disclosureRoot } from "./skillFs.js";
@@ -73,7 +74,28 @@ export interface BindingRow {
73
74
  readonly skills: number;
74
75
  readonly entrance: string | null;
75
76
  }
76
- export declare function buildSkillIndex(repo: string): Record<string, unknown>;
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+ export declare function buildSkillIndex(repo: string, queueStateRoot?: string): Record<string, unknown>;
77
99
  /** The inline agent block (lane_disclosure._agent_block 780-793):
78
100
 
79
101
  /** Skill lookup across flow + model + card rows
@@ -82,7 +104,7 @@ export declare function buildSkillIndex(repo: string): Record<string, unknown>;
82
104
  /** @param modelsSeat the context's models service when mounted — the
83
105
  * flow rows compose from the seat the runs doors thread (the
84
106
  * lane-seat law); the booted singleton otherwise */
85
- export declare function findSkill(repo: string, sid: string, modelsSeat?: FamilyModelsSeat | null, flowsSeat?: FlowsSeat | null): {
107
+ export declare function findSkill(repo: string, sid: string, modelsSeat?: FamilyModelsSeat | null, flowsSeat?: FlowsSeat | null, stateRoot?: string): {
86
108
  row: SkillRow;
87
109
  path: string | null;
88
110
  bodyText: string | null;
@@ -96,4 +118,20 @@ export declare function hSkillRead(repo: string, stateRoot: string, sid: string,
96
118
  status: number;
97
119
  payload: unknown;
98
120
  };
121
+ /** POST /v1/skills: land one authored skill doc (the agent's write
122
+ * door — melite_skill_write). The doc lands in the state root's
123
+ * authored plane and the same walk that serves tracked skills serves
124
+ * it: written and read are one law. The write ledgers skill.write,
125
+ * so which skills the agent authored is auditable exactly as which
126
+ * it read.
127
+ * @param repo the checkout root (the family seat is verified there)
128
+ * @param stateRoot the estate's state root
129
+ * @param draft the skill as the door's caller stated it
130
+ * @returns 200 with the served answer, or 400 carrying the refusal
131
+ * voice (missing field, unsafe leaf, unseated family, or an
132
+ * existing doc without replace) */
133
+ export declare function hSkillWrite(repo: string, stateRoot: string, draft: SkillDraft): {
134
+ status: number;
135
+ payload: unknown;
136
+ };
99
137
  //# sourceMappingURL=skillPlane.d.ts.map
package/lib/skillPlane.js CHANGED
@@ -18,6 +18,7 @@ import { readFileSync } from "node:fs";
18
18
  import { join } from "node:path";
19
19
  import { benchPicksSync } from "./bench.js";
20
20
  import { appendLedger } from "./queue.js";
21
+ import { writeAuthoredSkill } from "./skillAuthored.js";
21
22
  import { engineDirs, modelRows, cardRows, flowRows } from "./skillRows.js";
22
23
  // the extracted planes re-export through the skill plane's door
23
24
  export { disclosureRoot } from "./skillFs.js";
@@ -58,7 +59,28 @@ export function wireSkill(r) {
58
59
  out["step_count"] = r.stepCount;
59
60
  return out;
60
61
  }
61
- export function buildSkillIndex(repo) {
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+ export function buildSkillIndex(repo, queueStateRoot) {
62
84
  const engines = engineDirs(join(repo, "packages", "engines"));
63
85
  const families = new Map();
64
86
  const cards = new Map();
@@ -70,14 +92,17 @@ export function buildSkillIndex(repo) {
70
92
  // vocabulary door is melite_discover (a paid tool call), never
71
93
  // this index. The full-catalog dump below was the last leak —
72
94
  // it handed the agent every card entrance for one cheap scan.
73
- // ONE ROOT (audit 004/C1): the bench reader rides the WRITER's
74
- // tree — <repoRoot>/data/runs/storage/drafts/docs, the same
75
- // resolution as the estate's drafts mount (resolveStateRoot's
76
- // default law; a config.stateRoot override deployment pins the
77
- // same root on both sides through its own config). The
78
- // MELITE_BENCH_STORAGE seam (race-class rec 1, debt 11) moves
79
- // writer AND reader together — never the reader alone.
80
- const picks = benchPicksSync(process.env["MELITE_BENCH_STORAGE"] ?? join(repo, "data", "runs", "storage"));
95
+ // ONE ROOT (audit 004/C1; the §8.3 orphan cure): the bench
96
+ // reader rides the WRITER's tree, <queueStateRoot>/storage —
97
+ // the same derivation the composition hands the drafts row
98
+ // (one root spelled once per side, one identity behind both).
99
+ // The MELITE_BENCH_STORAGE seam (race-class rec 1, debt 11)
100
+ // still moves writer AND reader together — never the reader
101
+ // alone; the walls pin it over any caller root.
102
+ const writerRoot = queueStateRoot === undefined ? undefined : join(queueStateRoot, "storage");
103
+ const picks = benchPicksSync(process.env["MELITE_BENCH_STORAGE"] ??
104
+ writerRoot ??
105
+ join(repo, "data", "runs", "storage"));
81
106
  const pickedCards = new Set(picks.map((p) => p.card).filter((c) => c !== null));
82
107
  const pickedModels = new Set(picks.map((p) => p.model).filter((m) => m !== null));
83
108
  const selectionEmpty = pickedCards.size === 0 && pickedModels.size === 0;
@@ -93,7 +118,7 @@ export function buildSkillIndex(repo) {
93
118
  };
94
119
  }
95
120
  for (const engine of engines) {
96
- for (const r of modelRows(engine)) {
121
+ for (const r of modelRows(engine, queueStateRoot)) {
97
122
  if (r.row.scope.endsWith("-spawn"))
98
123
  continue;
99
124
  const mid = r.row.model;
@@ -162,7 +187,7 @@ export function buildSkillIndex(repo) {
162
187
  /** @param modelsSeat the context's models service when mounted — the
163
188
  * flow rows compose from the seat the runs doors thread (the
164
189
  * lane-seat law); the booted singleton otherwise */
165
- export function findSkill(repo, sid, modelsSeat, flowsSeat) {
190
+ export function findSkill(repo, sid, modelsSeat, flowsSeat, stateRoot) {
166
191
  for (const fr of flowRows(repo, modelsSeat, flowsSeat)) {
167
192
  if (fr.row.id === sid) {
168
193
  return { row: fr.row, path: fr.bodyPath, bodyText: fr.bodyText };
@@ -170,7 +195,7 @@ export function findSkill(repo, sid, modelsSeat, flowsSeat) {
170
195
  }
171
196
  const engines = engineDirs(join(repo, "packages", "engines"));
172
197
  for (const engine of engines) {
173
- for (const r of modelRows(engine)) {
198
+ for (const r of modelRows(engine, stateRoot)) {
174
199
  if (r.row.id === sid)
175
200
  return { row: r.row, path: r.bodyText === undefined ? r.path : null, bodyText: r.bodyText ?? null };
176
201
  }
@@ -188,7 +213,7 @@ export function findSkill(repo, sid, modelsSeat, flowsSeat) {
188
213
  * same seat-threading law as findSkill) */
189
214
  export function hSkillRead(repo, stateRoot, sid, modelsSeat, flowsSeat) {
190
215
  try {
191
- const found = findSkill(repo, sid, modelsSeat, flowsSeat);
216
+ const found = findSkill(repo, sid, modelsSeat, flowsSeat, stateRoot);
192
217
  if (found === null) {
193
218
  return { status: 404, payload: { error: "no such skill: " + JSON.stringify(sid) } };
194
219
  }
@@ -266,4 +291,29 @@ export function hSkillRead(repo, stateRoot, sid, modelsSeat, flowsSeat) {
266
291
  return { status: 500, payload: { error: e.message } };
267
292
  }
268
293
  }
294
+ /** POST /v1/skills: land one authored skill doc (the agent's write
295
+ * door — melite_skill_write). The doc lands in the state root's
296
+ * authored plane and the same walk that serves tracked skills serves
297
+ * it: written and read are one law. The write ledgers skill.write,
298
+ * so which skills the agent authored is auditable exactly as which
299
+ * it read.
300
+ * @param repo the checkout root (the family seat is verified there)
301
+ * @param stateRoot the estate's state root
302
+ * @param draft the skill as the door's caller stated it
303
+ * @returns 200 with the served answer, or 400 carrying the refusal
304
+ * voice (missing field, unsafe leaf, unseated family, or an
305
+ * existing doc without replace) */
306
+ export function hSkillWrite(repo, stateRoot, draft) {
307
+ try {
308
+ const written = writeAuthoredSkill(repo, stateRoot, draft);
309
+ appendLedger(stateRoot, "skill.write", { id: written.id, path: written.path, replaced: written.replaced });
310
+ return { status: 200, payload: written };
311
+ }
312
+ catch (e) {
313
+ return {
314
+ status: 400,
315
+ payload: { error: e instanceof Error ? e.message : String(e) },
316
+ };
317
+ }
318
+ }
269
319
  //# sourceMappingURL=skillPlane.js.map