@melite/estate-queue 0.2.0-alpha → 0.2.3-rc.4

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 (87) hide show
  1. package/README.md +0 -5
  2. package/lib/bench.js +30 -3
  3. package/lib/cardsCompose.d.ts +31 -0
  4. package/lib/cardsCompose.js +65 -1
  5. package/lib/cardsDangling.js +17 -7
  6. package/lib/cardsDroppable.d.ts +11 -0
  7. package/lib/cardsDroppable.js +50 -0
  8. package/lib/cardsFacts.d.ts +37 -0
  9. package/lib/cardsFacts.js +47 -1
  10. package/lib/cardsLanes.d.ts +18 -0
  11. package/lib/cardsLanes.js +2 -1
  12. package/lib/cardsRegistry.d.ts +12 -20
  13. package/lib/cardsRegistry.js +288 -96
  14. package/lib/discloseRegistry.d.ts +5 -0
  15. package/lib/discloseRegistry.js +3 -3
  16. package/lib/filmLead.js +9 -1
  17. package/lib/filmMemoryWarn.js +1 -0
  18. package/lib/flowsData.d.ts +110 -21
  19. package/lib/flowsData.js +201 -23
  20. package/lib/flowsFamilyCompose.js +1 -0
  21. package/lib/flowsParamsOverlay.d.ts +8 -1
  22. package/lib/flowsParamsOverlay.js +47 -2
  23. package/lib/flowsRegistryRows.d.ts +0 -4
  24. package/lib/flowsRegistryRows.js +177 -371
  25. package/lib/index.d.ts +0 -1
  26. package/lib/index.js +0 -4
  27. package/lib/ledgerTail.js +1 -0
  28. package/lib/loadPlane.d.ts +46 -4
  29. package/lib/loadPlane.js +109 -7
  30. package/lib/loadRegistry.js +9 -2
  31. package/lib/managePlane.d.ts +5 -0
  32. package/lib/managePlane.js +412 -51
  33. package/lib/managePreflight.js +38 -6
  34. package/lib/manageProbe.d.ts +35 -0
  35. package/lib/manageProbe.js +141 -2
  36. package/lib/manageRegistry.d.ts +10 -0
  37. package/lib/manageRegistry.js +7 -1
  38. package/lib/managerRail.js +1 -0
  39. package/lib/queueCore.js +3 -1
  40. package/lib/queueLock.js +22 -10
  41. package/lib/queueResurrect.d.ts +0 -3
  42. package/lib/queueResurrect.js +5 -3
  43. package/lib/queueRetry.d.ts +12 -10
  44. package/lib/queueRetry.js +2 -4
  45. package/lib/queueSidecar.d.ts +36 -1
  46. package/lib/queueSidecar.js +30 -2
  47. package/lib/queueSubmit.d.ts +4 -1
  48. package/lib/queueSubmit.js +28 -5
  49. package/lib/queueSweep.d.ts +38 -11
  50. package/lib/queueSweep.js +73 -16
  51. package/lib/runsChange.d.ts +5 -4
  52. package/lib/runsExecute.d.ts +16 -1
  53. package/lib/runsExecute.js +102 -50
  54. package/lib/runsGates.d.ts +11 -3
  55. package/lib/runsGates.js +12 -3
  56. package/lib/runsList.d.ts +59 -3
  57. package/lib/runsList.js +228 -36
  58. package/lib/runsRegistry.d.ts +87 -6
  59. package/lib/runsRegistry.js +664 -98
  60. package/lib/runsSourceEcho.js +9 -3
  61. package/lib/runsStart.d.ts +6 -4
  62. package/lib/runsStart.js +32 -25
  63. package/lib/runsTypes.d.ts +54 -1
  64. package/lib/runsTypes.js +82 -3
  65. package/lib/runsValidate.d.ts +1 -0
  66. package/lib/runsValidate.js +5 -0
  67. package/lib/runsValidateArms.js +48 -2
  68. package/lib/runsValidateServe.js +15 -12
  69. package/lib/runsValidateShared.d.ts +8 -10
  70. package/lib/runsValidateShared.js +41 -15
  71. package/lib/runsValidateStages.d.ts +1 -1
  72. package/lib/runsValidateStages.js +90 -50
  73. package/lib/runtimeProvision.js +10 -2
  74. package/lib/skillAuthored.d.ts +50 -0
  75. package/lib/skillAuthored.js +178 -0
  76. package/lib/skillFs.js +3 -0
  77. package/lib/skillPlane.d.ts +40 -2
  78. package/lib/skillPlane.js +63 -13
  79. package/lib/skillRegistry.d.ts +24 -1
  80. package/lib/skillRegistry.js +69 -5
  81. package/lib/skillRows.d.ts +13 -3
  82. package/lib/skillRows.js +52 -9
  83. package/lib/vocab.d.ts +29 -0
  84. package/lib/vocab.js +78 -0
  85. package/package.json +24 -14
  86. package/lib/resurrect.d.ts +0 -6
  87. package/lib/resurrect.js +0 -18
@@ -4,7 +4,19 @@
4
4
  import { WIRE_STAGE_KEYS } from "@melite/contracts/benchStage";
5
5
  import { engineIdOk } from "@melite/engine-contract";
6
6
  import { INLINE_TOP_KEYS } from "./runsGates.js";
7
- // ENGINE_TABLE: engine_type -> {plugin_id, default_output kind}.
7
+ // ENGINE_TABLE: engine_type -> {plugin_id} — THE KIND-FREE
8
+
9
+ // engine ids exist, never what they produce. The old per-engine
10
+ // `def` output kind was the bench's SECOND output table —
11
+ // validate's lattice judged a stage by the table's kind while the
12
+ // card's own cardIo table declared another (the retired
13
+ // music-native wrapper's {default: "image"} mislabel over the
14
+
15
+ // flows-are-compositions),
16
+ // and start's empty-outputs fill bound yet a third. One table now:
17
+ // the stage's own declared outputs, else its card_io, else the
18
+ // card's declared output kinds. An engine row with none of those
19
+ // refuses — a missing declaration is never filled from here.
8
20
 
9
21
  // api caller for comfyui, not having engines anymore"): ComfyUI is
10
22
  // the only engine. The old engine tiers (cpp/audio-cpp,
@@ -14,31 +26,42 @@ import { INLINE_TOP_KEYS } from "./runsGates.js";
14
26
  // rebirth as vendored ComfyUI custom nodes. Probed live from
15
27
  // scan_engines(); re-derived per run.
16
28
  export const ENGINE_TABLE = {
17
- comfyui: { plugin: "comfyui", def: "image" },
29
+ comfyui: { plugin: "comfyui" },
18
30
  // Stroke 55 (the engine-generics seam): the craft loop engine +
19
31
  // the MCP grammar arm — any mcp:<server> id matching the seat's
20
32
  // grammar admits (membership stays the runs door's registry arm).
21
- craft: { plugin: "craft", def: "image" },
33
+ craft: { plugin: "craft" },
22
34
  // Stroke 60 (plan §5): the agent engine — the spawner loop. Its
23
35
  // stage is validated like any engine stage (params carry the four
24
36
  // pinned fields); outputs are arbitrary (artifacts land in the
25
37
  // run dir).
26
- agent: { plugin: "agent", def: "text" },
38
+ agent: { plugin: "agent" },
27
39
  };
28
- /** THE ENGINE TABLE'S DEFAULT READ (P7 latent): the lattice's own
29
- * rule, owned once — mcp:<server> grammar ids read the mcp-client
30
- * row ("image"), table rows read their def, anything else reads
31
- * undefined (unknown: no fill — the caller's door refuses, never
32
- * guesses). Both doors derive from this one read (validate's
33
- * lattice below, start's empty-outputs fill): a future grammar id
34
- * absent from the table makes BOTH refuse instead of splitting
35
- * validate-refuses/start-accepts. */
36
- export function engineDefaultOutput(engine) {
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ export function engineKnown(engine) {
37
48
  if (engine.startsWith("mcp:") && engineIdOk(engine))
38
- return "image";
39
- return ENGINE_TABLE[engine]?.def;
49
+ return true;
50
+ return engine in ENGINE_TABLE;
40
51
  }
41
52
  // ── closed vocabularies (Kind / SkipWhen order) ──────
53
+
54
+ // `_list` seats the naming law contracts (image_list ← image,
55
+ // video_list ← video, audio_list ← audio — runsValidateStages' list
56
+ // law and contract-law's LAW 9 edge pin are the same closed set) are
57
+ // Kind members here, not a derived suffix: a derived `k + "_list"`
58
+ // admission would open text_list/mesh_list — kinds no wire carries.
59
+ // The DECL is the truth: h3's ref_audios is an array seat (cap 3,
60
+ // per-producer window stamps ref_audio_i), so the connect door must
61
+ // be able to STATE its declared kind — before this, every spelling
62
+ // refused (audio_list here, audio at the card-contradiction sweep)
63
+ // and the tts→film conditioning wire was unkindable at every flow
64
+ // door. A new kind is a contract act.
42
65
  export const KIND_VOCAB = [
43
66
  "text",
44
67
  "image",
@@ -49,6 +72,9 @@ export const KIND_VOCAB = [
49
72
  "lora",
50
73
  "seg",
51
74
  "data",
75
+ "image_list",
76
+ "video_list",
77
+ "audio_list",
52
78
  ];
53
79
  export const SKIP_VOCAB = ["present", "absent"];
54
80
  // _INLINE_TOP_KEYS sorted (dead/allowed messages) — DERIVED, not
@@ -19,7 +19,7 @@ export declare function cardGate(flowId: string, st: FlowStageRow, cards?: CardR
19
19
 
20
20
 
21
21
  export declare function coerceSnapshotBody(def: CardDefinition | undefined, body: Record<string, unknown>): Record<string, unknown>;
22
- export declare function kindsOk(flowId: string, stages: FlowStageRow[], engineDefaults: Record<string, string | null>, cards?: CardRegistryLike | null): void;
22
+ export declare function kindsOk(flowId: string, stages: FlowStageRow[], cards?: CardRegistryLike | null): void;
23
23
  export declare function validateEngines(flow: Flow, cards?: CardRegistryLike | null,
24
24
 
25
25
 
@@ -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
  }
@@ -15,7 +15,7 @@
15
15
  // fixtures (fixture seed + fixture sentinel files, never the real
16
16
  // 7.4G tree; symlink creation against tmp dirs is fine).
17
17
  import { existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, symlinkSync } from "node:fs";
18
- import { dirname, join, resolve } from "node:path";
18
+ import { dirname, isAbsolute, join, resolve } from "node:path";
19
19
  import { loadEndpointConfig } from "@melite/comfyui-cordis";
20
20
  /** One sentinel's safe join: a sentinel escaping its home (.. or
21
21
  * empty) is a declaration bug — false, never a filesystem escape. */
@@ -54,6 +54,7 @@ export function engineRootOf() {
54
54
  let cfg;
55
55
  try {
56
56
  cfg = loadEndpointConfig();
57
+ // an unreadable endpoint machine statement declares no engine root — null is the not-declared answer and the decision core refuses loudly downstream
57
58
  }
58
59
  catch {
59
60
  return null;
@@ -80,7 +81,10 @@ export function engineOutputDir(root) {
80
81
  if (typeof raw !== "string" || raw.trim() === "")
81
82
  return join(root, "output");
82
83
  const v = raw.trim();
83
- return v.startsWith("/") ? v : join(root, v);
84
+ // (isAbsolute, not startsWith("/"): a win32-absolute output_dir
85
+ // carries a drive prefix and was resolved INTO the engine tree,
86
+ // putting the walk-up inside it)
87
+ return isAbsolute(v) ? v : join(root, v);
84
88
  }
85
89
 
86
90
 
@@ -97,6 +101,7 @@ export function lanesEnvFileOf() {
97
101
  let cfg;
98
102
  try {
99
103
  cfg = loadEndpointConfig();
104
+ // an unreadable endpoint config states no lanes_env_file — null is the key-absent behavior and the process env still answers the check
100
105
  }
101
106
  catch {
102
107
  return null;
@@ -120,6 +125,7 @@ export function lanesEnvValue(file, key, read) {
120
125
  let text;
121
126
  try {
122
127
  text = read(file);
128
+ // an unreadable env file arms no override — present: false is truthful and the caller still judges the process env leg
123
129
  }
124
130
  catch {
125
131
  return { value: "", present: false };
@@ -153,6 +159,7 @@ export const nodeRuntimeFs = {
153
159
  isSymlink: (p) => {
154
160
  try {
155
161
  return lstatSync(p).isSymbolicLink();
162
+ // lstatSync fails on a missing or unreadable path — a path that lstats as nothing is not a symlink, so false is the chipped-target check's exact answer
156
163
  }
157
164
  catch {
158
165
  return false;
@@ -161,6 +168,7 @@ export const nodeRuntimeFs = {
161
168
  readlink: (p) => {
162
169
  try {
163
170
  return readlinkSync(p);
171
+ // readlinkSync fails on a missing path or a non-symlink — null is the seam's not-a-symlink answer and the decision judges the real dir instead
164
172
  }
165
173
  catch {
166
174
  return null;
@@ -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
package/lib/skillFs.js CHANGED
@@ -37,6 +37,7 @@ export function disclosureRoot() {
37
37
  export function isDir(p) {
38
38
  try {
39
39
  return statSync(p).isDirectory();
40
+ // a missing or unreadable path is not a directory — false is the probe's whole answer
40
41
  }
41
42
  catch {
42
43
  return false;
@@ -45,6 +46,7 @@ export function isDir(p) {
45
46
  export function isFile(p) {
46
47
  try {
47
48
  return statSync(p).isFile();
49
+ // a missing or unreadable path is not a file — false is the probe's whole answer
48
50
  }
49
51
  catch {
50
52
  return false;
@@ -70,6 +72,7 @@ export function subdirs(parent) {
70
72
  export function readText(p) {
71
73
  try {
72
74
  return readFileSync(p, "utf8");
75
+ // a missing or unreadable file reads as null — the callers treat null as absent, so the failure is itself the answer
73
76
  }
74
77
  catch {
75
78
  return null;