@melite/estate-queue 0.1.5-pre-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.
- package/LICENSE +561 -457
- package/README.md +0 -5
- package/lib/cardsArmError.d.ts +52 -3
- package/lib/cardsArmError.js +7 -1
- package/lib/cardsCompose.d.ts +31 -0
- package/lib/cardsCompose.js +98 -7
- package/lib/cardsFacts.d.ts +16 -0
- package/lib/cardsFacts.js +25 -1
- package/lib/cardsLanes.d.ts +51 -3
- package/lib/cardsLanes.js +337 -13
- package/lib/cardsLanesCopy.d.ts +21 -0
- package/lib/cardsLanesCopy.js +22 -0
- package/lib/cardsRegistry.d.ts +105 -5
- package/lib/cardsRegistry.js +826 -46
- package/lib/cardsVariant.d.ts +12 -7
- package/lib/cardsVariant.js +196 -58
- package/lib/discloseRegistry.d.ts +41 -6
- package/lib/discloseRegistry.js +155 -17
- package/lib/filmLead.js +5 -3
- package/lib/flowsData.d.ts +77 -21
- package/lib/flowsData.js +159 -21
- package/lib/flowsFamilyCompose.js +12 -1
- package/lib/flowsRegistryRows.d.ts +0 -3
- package/lib/flowsRegistryRows.js +166 -222
- package/lib/index.d.ts +1 -1
- package/lib/index.js +6 -4
- package/lib/loadPlane.d.ts +46 -4
- package/lib/loadPlane.js +116 -7
- package/lib/loadRegistry.js +9 -2
- package/lib/manageOps.js +2 -1
- package/lib/managePlane.d.ts +16 -1
- package/lib/managePlane.js +955 -65
- package/lib/managePreflight.d.ts +26 -0
- package/lib/managePreflight.js +211 -0
- package/lib/manageProbe.d.ts +52 -0
- package/lib/manageProbe.js +171 -1
- package/lib/queueCore.d.ts +14 -1
- package/lib/queueCore.js +13 -0
- package/lib/queueLock.js +19 -10
- package/lib/queueResurrect.d.ts +7 -5
- package/lib/queueResurrect.js +25 -9
- package/lib/queueRetry.d.ts +12 -10
- package/lib/queueRetry.js +2 -4
- package/lib/queueSidecar.d.ts +122 -1
- package/lib/queueSidecar.js +192 -7
- package/lib/queueSubmit.d.ts +70 -4
- package/lib/queueSubmit.js +159 -7
- package/lib/runsErrorCodes.js +5 -3
- package/lib/runsExecute.d.ts +16 -1
- package/lib/runsExecute.js +97 -39
- package/lib/runsGates.d.ts +16 -4
- package/lib/runsGates.js +17 -5
- package/lib/runsList.d.ts +100 -4
- package/lib/runsList.js +364 -63
- package/lib/runsRefusalVoices.js +50 -1
- package/lib/runsRegistry.d.ts +142 -9
- package/lib/runsRegistry.js +960 -163
- package/lib/runsStart.d.ts +30 -7
- package/lib/runsStart.js +136 -14
- package/lib/runsTypes.d.ts +46 -3
- package/lib/runsTypes.js +63 -9
- package/lib/runsValidate.d.ts +1 -0
- package/lib/runsValidate.js +5 -0
- package/lib/runsValidateArms.js +25 -0
- package/lib/runsValidateServe.js +25 -12
- package/lib/runsValidateShared.d.ts +8 -1
- package/lib/runsValidateShared.js +44 -4
- package/lib/runsValidateStages.d.ts +1 -1
- package/lib/runsValidateStages.js +107 -55
- package/lib/runtimeProvision.d.ts +119 -0
- package/lib/runtimeProvision.js +243 -0
- package/lib/skillAuthored.d.ts +50 -0
- package/lib/skillAuthored.js +178 -0
- package/lib/skillPlane.d.ts +40 -2
- package/lib/skillPlane.js +63 -13
- package/lib/skillRegistry.d.ts +24 -1
- package/lib/skillRegistry.js +69 -5
- package/lib/skillRows.d.ts +13 -3
- package/lib/skillRows.js +49 -5
- package/package.json +33 -23
- package/lib/resurrect.d.ts +0 -6
- package/lib/resurrect.js +0 -18
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// runtimeProvision.ts — THE RUNTIME PROVISION DECISION CORE (E2-2
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// lanes.env leg — ONE module so gate and verb can never disagree.
|
|
5
|
+
//
|
|
6
|
+
|
|
7
|
+
// the estimator is broken — the chain files are placed by hand — so
|
|
8
|
+
// this core never re-provisions and never copies bytes. The ONLY
|
|
9
|
+
// materialize arm is a SYMLINK from the engine tree's
|
|
10
|
+
// data/runtime/<name> to the repo's healthy seed (instant, nothing
|
|
11
|
+
// to wedge; the seed stays the source of truth). Everything else is
|
|
12
|
+
// already-present or a named refusal.
|
|
13
|
+
//
|
|
14
|
+
// The module is pure over injected fs deps: the walls run it on tmp
|
|
15
|
+
// fixtures (fixture seed + fixture sentinel files, never the real
|
|
16
|
+
// 7.4G tree; symlink creation against tmp dirs is fine).
|
|
17
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, symlinkSync } from "node:fs";
|
|
18
|
+
import { dirname, join, resolve } from "node:path";
|
|
19
|
+
import { loadEndpointConfig } from "@melite/comfyui-cordis";
|
|
20
|
+
/** One sentinel's safe join: a sentinel escaping its home (.. or
|
|
21
|
+
* empty) is a declaration bug — false, never a filesystem escape. */
|
|
22
|
+
export function sentinelHit(home, sentinel) {
|
|
23
|
+
const clean = sentinel.trim().replace(/^\/+|\/+$/gu, "");
|
|
24
|
+
if (clean === "" || clean.split("/").some((part) => part === ".."))
|
|
25
|
+
return false;
|
|
26
|
+
return existsSync(join(home, clean));
|
|
27
|
+
}
|
|
28
|
+
/** Every sentinel stands under `home` (through a symlink when the
|
|
29
|
+
* home is one — existsSync follows links). */
|
|
30
|
+
export function runtimeHealthy(home, sentinels) {
|
|
31
|
+
return sentinels.every((s) => sentinelHit(home, s));
|
|
32
|
+
}
|
|
33
|
+
/** The engine's own walk-up, mirrored (nodes_anny.py:885-935): the
|
|
34
|
+
* first ancestor of the output dir holding the rel dir decides — a
|
|
35
|
+
* chipped first hit is the miss, never a cue to walk on. Walk-up
|
|
36
|
+
* only: the caller owns the env leg, so this never re-checks it. */
|
|
37
|
+
export function resolveRuntimeHome(outputDir, rt) {
|
|
38
|
+
let dir = resolve(outputDir);
|
|
39
|
+
for (;;) {
|
|
40
|
+
const home = join(dir, ...rt.rel);
|
|
41
|
+
if (existsSync(home)) {
|
|
42
|
+
return runtimeHealthy(home, rt.sentinel) ? home : null;
|
|
43
|
+
}
|
|
44
|
+
const parent = dirname(dir);
|
|
45
|
+
if (parent === dir)
|
|
46
|
+
return null;
|
|
47
|
+
dir = parent;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** THE DECLARED ENGINE ROOT (E2-2 Piece A): where the live engine
|
|
51
|
+
* lives on this box, stated in the endpoint machine statement
|
|
52
|
+
* (`engine_root`). Additive key, unknown to every other reader. */
|
|
53
|
+
export function engineRootOf() {
|
|
54
|
+
let cfg;
|
|
55
|
+
try {
|
|
56
|
+
cfg = loadEndpointConfig();
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const raw = cfg["engine_root"];
|
|
62
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
63
|
+
return null;
|
|
64
|
+
return raw.trim();
|
|
65
|
+
}
|
|
66
|
+
/** The engine's output dir: the endpoint's output_dir when stated
|
|
67
|
+
* (absolute as-is, relative resolved under the declared engine
|
|
68
|
+
* root — the managed "data/temp" spelling), else the ComfyUI
|
|
69
|
+
* default (<root>/output). The walk-up only moves UP, so
|
|
70
|
+
* starting deep is safe. */
|
|
71
|
+
export function engineOutputDir(root) {
|
|
72
|
+
let cfg;
|
|
73
|
+
try {
|
|
74
|
+
cfg = loadEndpointConfig();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return join(root, "output");
|
|
78
|
+
}
|
|
79
|
+
const raw = cfg["output_dir"];
|
|
80
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
81
|
+
return join(root, "output");
|
|
82
|
+
const v = raw.trim();
|
|
83
|
+
return v.startsWith("/") ? v : join(root, v);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
export function lanesEnvFileOf() {
|
|
97
|
+
let cfg;
|
|
98
|
+
try {
|
|
99
|
+
cfg = loadEndpointConfig();
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const raw = cfg["lanes_env_file"];
|
|
105
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
106
|
+
return null;
|
|
107
|
+
return raw.trim();
|
|
108
|
+
}
|
|
109
|
+
/** Parse ONE key out of a systemd EnvironmentFile spelling: KEY=VALUE
|
|
110
|
+
* lines; blank lines and `#`/`;` comments (indented or not) are
|
|
111
|
+
* skipped; inline `#` text stays part of the value (systemd does not
|
|
112
|
+
* strip trailing comments in this mode, so neither do we — a quoted
|
|
113
|
+
* or commented value surfaces verbatim in the named-source answer
|
|
114
|
+
* and fails its sentinels loudly, never silently). ORDER: LAST-WINS —
|
|
115
|
+
* a later assignment overrides an earlier one, matching systemd's
|
|
116
|
+
* EnvironmentFile read order (later settings override earlier
|
|
117
|
+
* settings) and shell source semantics. The walls pin this with a
|
|
118
|
+
* first-dead/last-healthy fixture. */
|
|
119
|
+
export function lanesEnvValue(file, key, read) {
|
|
120
|
+
let text;
|
|
121
|
+
try {
|
|
122
|
+
text = read(file);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return { value: "", present: false };
|
|
126
|
+
}
|
|
127
|
+
let found = null;
|
|
128
|
+
for (const line of text.split("\n")) {
|
|
129
|
+
const trimmed = line.trim();
|
|
130
|
+
if (trimmed === "" || trimmed.startsWith("#") || trimmed.startsWith(";"))
|
|
131
|
+
continue;
|
|
132
|
+
const eq = trimmed.indexOf("=");
|
|
133
|
+
if (eq <= 0)
|
|
134
|
+
continue;
|
|
135
|
+
if (trimmed.slice(0, eq).trim() !== key)
|
|
136
|
+
continue;
|
|
137
|
+
found = trimmed.slice(eq + 1).trim();
|
|
138
|
+
}
|
|
139
|
+
return found === null ? { value: "", present: false } : { value: found, present: true };
|
|
140
|
+
}
|
|
141
|
+
export function runtimeEnvView(envKey, env = process.env) {
|
|
142
|
+
const file = lanesEnvFileOf();
|
|
143
|
+
if (file !== null) {
|
|
144
|
+
const lane = lanesEnvValue(file, envKey, (p) => readFileSync(p, "utf8"));
|
|
145
|
+
if (lane.present && lane.value !== "")
|
|
146
|
+
return { value: lane.value, source: "lanes.env" };
|
|
147
|
+
}
|
|
148
|
+
const value = (env[envKey] ?? "").trim();
|
|
149
|
+
return { value, source: value === "" ? "absent" : "process" };
|
|
150
|
+
}
|
|
151
|
+
export const nodeRuntimeFs = {
|
|
152
|
+
exists: (p) => existsSync(p),
|
|
153
|
+
isSymlink: (p) => {
|
|
154
|
+
try {
|
|
155
|
+
return lstatSync(p).isSymbolicLink();
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
readlink: (p) => {
|
|
162
|
+
try {
|
|
163
|
+
return readlinkSync(p);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
mkdir: (p) => {
|
|
170
|
+
mkdirSync(p, { recursive: true });
|
|
171
|
+
},
|
|
172
|
+
symlink: (target, path) => {
|
|
173
|
+
symlinkSync(target, path, "dir");
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
/** THE DECISION CORE (pure). Order is the law:
|
|
177
|
+
* 1. a stated env override (process or lanes.env) — valid counts as
|
|
178
|
+
* present (source env / lanes.env), invalid refuses naming it
|
|
179
|
+
* (the press gate refuses the same run: gate+verb agreement);
|
|
180
|
+
* 2. no engine root refuses (the estate cannot see that tree);
|
|
181
|
+
* 3. the walk-up from the engine's output — a hit is present
|
|
182
|
+
* (the managed-engine arm: the verb never double-seats);
|
|
183
|
+
* 4. an existing healthy target (real dir or live symlink) is
|
|
184
|
+
* present; a real CHIPPED or foreign one refuses target-blocked
|
|
185
|
+
* — never clobbered;
|
|
186
|
+
* 5. a healthy seed with an absent target is linkable; a chipped
|
|
187
|
+
* seed refuses broken-seed voicing the DECL's provision command. */
|
|
188
|
+
export function resolveRuntimeProvision(rt, deps) {
|
|
189
|
+
if (deps.env.value !== "") {
|
|
190
|
+
if (runtimeHealthy(deps.env.value, rt.sentinel)) {
|
|
191
|
+
return {
|
|
192
|
+
kind: "already-present",
|
|
193
|
+
home: deps.env.value,
|
|
194
|
+
source: deps.env.source === "lanes.env" ? "lanes.env" : "env",
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
kind: "refused",
|
|
199
|
+
reason: "env-invalid",
|
|
200
|
+
detail: "provision_runtime: the " + rt.env + " override ('" + deps.env.value + "' from " +
|
|
201
|
+
deps.env.source + ") does not hold every sentinel (" + rt.sentinel.join(", ") +
|
|
202
|
+
") — fix the path or clear the override; the press gate refuses this run until then",
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (deps.engineRoot === null) {
|
|
206
|
+
return {
|
|
207
|
+
kind: "refused",
|
|
208
|
+
reason: "no-engine-root",
|
|
209
|
+
detail: "provision_runtime: the endpoint states no engine_root — the estate cannot see the engine tree, " +
|
|
210
|
+
"so it refuses to guess where " + rt.name + " should link. Declare engine_root in the endpoint config first.",
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const walked = resolveRuntimeHome(deps.walkStart, rt);
|
|
214
|
+
if (walked !== null)
|
|
215
|
+
return { kind: "already-present", home: walked, source: "walk-up" };
|
|
216
|
+
const target = join(deps.engineRoot, "data", "runtime", rt.name);
|
|
217
|
+
if (deps.fs.exists(target)) {
|
|
218
|
+
if (runtimeHealthy(target, rt.sentinel)) {
|
|
219
|
+
return { kind: "already-present", home: target, source: "target" };
|
|
220
|
+
}
|
|
221
|
+
const linked = deps.fs.isSymlink(target) ? deps.fs.readlink(target) : null;
|
|
222
|
+
return {
|
|
223
|
+
kind: "refused",
|
|
224
|
+
reason: "target-blocked",
|
|
225
|
+
detail: "provision_runtime: " + target + " already exists" +
|
|
226
|
+
(linked !== null ? " (a symlink to " + linked + ")" : " as a real dir") +
|
|
227
|
+
" but does not hold every sentinel (" + rt.sentinel.join(", ") +
|
|
228
|
+
") — the verb never clobbers it; remove the chipped copy by hand and press again",
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const seed = deps.repoSeedHome;
|
|
232
|
+
if (!runtimeHealthy(seed, rt.sentinel)) {
|
|
233
|
+
return {
|
|
234
|
+
kind: "refused",
|
|
235
|
+
reason: "broken-seed",
|
|
236
|
+
detail: "provision_runtime: the repo seed " + seed + " does not hold every sentinel (" +
|
|
237
|
+
rt.sentinel.join(", ") + ") — the fresh provision script is not a cure here (the chain files are " +
|
|
238
|
+
"placed by hand); repair the seed with " + rt.command + " and its documented hand steps first",
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return { kind: "linkable", seed, target };
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=runtimeProvision.js.map
|
|
@@ -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/skillPlane.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
74
|
-
// tree
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
const
|
|
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
|