@mono-lit/utility 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +54 -0
- package/README.md +156 -2
- package/dist/app-roots-BJsIxzjk.d.ts +91 -0
- package/dist/app-roots-CvJnmXcs.js +128 -0
- package/dist/config-node-UzJrXg0Z.js +76 -0
- package/dist/config-node.d.ts +977 -0
- package/dist/config-node.js +7 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +3 -0
- package/dist/create-config-D3m6xTaQ.d.ts +733 -0
- package/dist/create-config-DdL3Fh6T.js +357 -0
- package/dist/fetching.d.ts +239 -0
- package/dist/fetching.js +867 -0
- package/dist/generate-CJ7MtcDd.js +291 -0
- package/dist/index-C2hZeNkq.d.ts +365 -0
- package/dist/index-ClrZbU7n.d.ts +518 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +939 -0
- package/dist/merge-file-C5nzi_MY.d.ts +122 -0
- package/dist/merge-file-CtyKTu5L.js +133 -0
- package/dist/mock-db-5mJTObSC.js +1282 -0
- package/dist/mock-db.d.ts +2 -0
- package/dist/mock-db.js +4 -0
- package/dist/mono-alias-DNDm-jB_.js +508 -0
- package/dist/mono-clone.mjs +958 -0
- package/dist/mono-db.d.ts +1 -0
- package/dist/mono-db.js +151 -0
- package/dist/mono-env.mjs +231 -0
- package/dist/mono-git.mjs +798 -0
- package/dist/mono-link-YlOQ2PVS.js +488 -0
- package/dist/mono-prepare.d.ts +1 -0
- package/dist/mono-prepare.js +27 -0
- package/dist/mono-skills.d.ts +1 -0
- package/dist/mono-skills.js +830 -0
- package/dist/mono-tsconfig-D2qRL9_R.js +204 -0
- package/dist/mono.mjs +34 -0
- package/dist/nuxt-layers-DP1m7f1-.js +176 -0
- package/dist/nuxt-layers.d.ts +34 -0
- package/dist/nuxt-layers.js +3 -0
- package/dist/nuxt-runtime.d.ts +18 -0
- package/dist/nuxt-runtime.js +102 -0
- package/dist/nuxt.d.ts +386 -0
- package/dist/nuxt.js +590 -0
- package/dist/runtime-C_IWNrAG.js +5817 -0
- package/dist/runtime.d.ts +2583 -0
- package/dist/runtime.js +4 -0
- package/dist/session-Bk985AIM.js +1721 -0
- package/dist/types-B6FdB7LJ.d.ts +57 -0
- package/dist/universal-B2eD9xho.d.ts +97 -0
- package/dist/universal-BNTo_83u.js +599 -0
- package/dist/virtual-mono-apps.d.ts +16 -0
- package/dist/vite.d.ts +940 -0
- package/dist/vite.js +1132 -0
- package/package.json +141 -3
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
import { J as loadSkillsEnv, K as isGenericAppName, O as resolveRemote, R as redactUrl, S as SkillsAccessError, U as ALLOWED_FLAGS, Y as resolveSkillTarget, _ as stagingRoot, b as resolveAppId, i as runSearch, n as runCheck, o as buildSavePlan, p as listSessions, q as loadSkillConfig, r as runRead, s as runSave, t as runSessionShow, w as ensureRepo, x as detectActor } from "./session-Bk985AIM.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { defineCommand, runMain } from "citty";
|
|
5
|
+
|
|
6
|
+
//#region pkg/cli/skills/_shared.ts
|
|
7
|
+
/** Print a single JSON object to stdout (pretty, machine-parseable). */
|
|
8
|
+
function printJson(value) {
|
|
9
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
10
|
+
}
|
|
11
|
+
/** Print a failure payload and exit 1. Use for every error exit. */
|
|
12
|
+
function fail(error, extra = {}) {
|
|
13
|
+
printJson({
|
|
14
|
+
success: false,
|
|
15
|
+
error: redactUrl(error),
|
|
16
|
+
...extra
|
|
17
|
+
});
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reject any CLI flag that isn't in the approved allowlist. Scans the RAW args
|
|
22
|
+
* so even flags citty would silently accept are caught. Call this first in
|
|
23
|
+
* every command's `run`, passing `ctx.rawArgs`.
|
|
24
|
+
*/
|
|
25
|
+
function guardArgs(rawArgs) {
|
|
26
|
+
for (const arg of rawArgs) {
|
|
27
|
+
if (!arg.startsWith("--")) continue;
|
|
28
|
+
const name = arg.slice(2).split("=")[0];
|
|
29
|
+
if (name === "help" || name === "version") continue;
|
|
30
|
+
if (!ALLOWED_FLAGS.includes(name)) fail(`Disallowed flag '--${name}'. The mono skills CLI accepts only: ${ALLOWED_FLAGS.map((f) => "--" + f).join(", ")}. The repository target comes from \`skill\` in mono.config.ts and cannot be overridden.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Load `.env` so `skill.envToken` can resolve, then return cwd. */
|
|
34
|
+
function prelude() {
|
|
35
|
+
const cwd = process.cwd();
|
|
36
|
+
loadSkillsEnv(cwd);
|
|
37
|
+
return cwd;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* For commands that touch the repository: read `skill` from mono.config.ts.
|
|
41
|
+
* Absent → print the skipped result (NOT an error) and exit 0. Present but
|
|
42
|
+
* broken → fail. Returns the parsed config + target when the caller should
|
|
43
|
+
* continue. `check` does NOT use this — it always runs and reports the state.
|
|
44
|
+
*/
|
|
45
|
+
function requireSkillConfig(cwd) {
|
|
46
|
+
let cfg;
|
|
47
|
+
try {
|
|
48
|
+
cfg = loadSkillConfig(cwd);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return fail(e.message);
|
|
51
|
+
}
|
|
52
|
+
if (!cfg) {
|
|
53
|
+
printJson({
|
|
54
|
+
success: true,
|
|
55
|
+
skipped: true,
|
|
56
|
+
reason: "MONO_SKILLS_NOT_CONFIGURED",
|
|
57
|
+
hint: "Add `skill: { url, envToken? }` to mono.config.ts to enable the skills workflow."
|
|
58
|
+
});
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
return {
|
|
63
|
+
cfg,
|
|
64
|
+
target: resolveSkillTarget(cfg)
|
|
65
|
+
};
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return fail(e.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Reach the repository (git first, token second) and make sure the local clone
|
|
72
|
+
* exists / is fresh enough. Access failures become a JSON failure carrying the
|
|
73
|
+
* classified cause; the message is already redacted.
|
|
74
|
+
*/
|
|
75
|
+
function connect(cwd, target, refresh) {
|
|
76
|
+
let remote;
|
|
77
|
+
try {
|
|
78
|
+
remote = resolveRemote({ target });
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (e instanceof SkillsAccessError) return fail(e.message, {
|
|
81
|
+
kind: e.kind,
|
|
82
|
+
why: e.why ?? null,
|
|
83
|
+
transportTried: e.transportTried
|
|
84
|
+
});
|
|
85
|
+
return fail(e.message);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return {
|
|
89
|
+
remote,
|
|
90
|
+
repo: ensureRepo({
|
|
91
|
+
cwd,
|
|
92
|
+
remote,
|
|
93
|
+
refresh
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
} catch (e) {
|
|
97
|
+
return fail(e.message, { repository: redactUrl(target.remoteUrl) });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* For `save` / `retry`: if the resolved app id is still a default/generic
|
|
102
|
+
* template name, print a skipped result (NOT an error) and exit 0. This stops
|
|
103
|
+
* session history from being filed under a placeholder app id — the user must
|
|
104
|
+
* rename the app first (Template Rule 1). Other commands are unaffected.
|
|
105
|
+
*/
|
|
106
|
+
function skipIfGenericApp(appId) {
|
|
107
|
+
if (isGenericAppName(appId)) {
|
|
108
|
+
printJson({
|
|
109
|
+
success: true,
|
|
110
|
+
skipped: true,
|
|
111
|
+
reason: "MONO_SKILLS_GENERIC_APP_NAME",
|
|
112
|
+
app: appId,
|
|
113
|
+
hint: `App '${appId}' still uses a default template name, so skills are not generated. Rename the app in mono.config.ts (and package.json) to a project-specific name first — see Template Rule 1.`
|
|
114
|
+
});
|
|
115
|
+
process.exit(0);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** `<repo>@<ref>[/<dir>]` for human-facing stderr lines. */
|
|
119
|
+
function describeRemote(remote) {
|
|
120
|
+
const base = `${redactUrl(remote.target.remoteUrl)}@${remote.ref}`;
|
|
121
|
+
return remote.dir ? `${base}/${remote.dir}` : base;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region pkg/cli/skills/commands/check.ts
|
|
126
|
+
/**
|
|
127
|
+
* `mono skills check` — diagnostic. Always runs (even when `skill` is not
|
|
128
|
+
* configured) so it can report the state. Never prints a token.
|
|
129
|
+
*/
|
|
130
|
+
const checkCommand = defineCommand({
|
|
131
|
+
meta: {
|
|
132
|
+
name: "check",
|
|
133
|
+
description: "Verify MONO Skills setup: `skill` config, repository access (git credentials, then envToken), branch/folder, push permission, local clone, and git identity. Never prints a token."
|
|
134
|
+
},
|
|
135
|
+
async run({ rawArgs }) {
|
|
136
|
+
guardArgs(rawArgs);
|
|
137
|
+
const cwd = prelude();
|
|
138
|
+
try {
|
|
139
|
+
printJson({
|
|
140
|
+
success: true,
|
|
141
|
+
...runCheck({ cwd })
|
|
142
|
+
});
|
|
143
|
+
} catch (e) {
|
|
144
|
+
fail(e.message);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region pkg/cli/skills/commands/whoami.ts
|
|
151
|
+
/**
|
|
152
|
+
* `mono skills whoami` — print the effective local git identity used for
|
|
153
|
+
* attribution: `{ name, email, actorFolder }`. The identity is detected, never
|
|
154
|
+
* supplied by the caller. Local-only, so it runs whether or not `skill` is set.
|
|
155
|
+
*/
|
|
156
|
+
const whoamiCommand = defineCommand({
|
|
157
|
+
meta: {
|
|
158
|
+
name: "whoami",
|
|
159
|
+
description: "Show the local git identity used for attribution (name, email, actorFolder)."
|
|
160
|
+
},
|
|
161
|
+
async run({ rawArgs }) {
|
|
162
|
+
guardArgs(rawArgs);
|
|
163
|
+
printJson({
|
|
164
|
+
success: true,
|
|
165
|
+
...detectActor(prelude())
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region pkg/cli/skills/commands/read.ts
|
|
172
|
+
/**
|
|
173
|
+
* `mono skills read` — read centralized knowledge or skills for an app, or a
|
|
174
|
+
* single safe file via `--path`, from the local clone (refreshed when stale).
|
|
175
|
+
* Path traversal (`../`) is rejected.
|
|
176
|
+
*/
|
|
177
|
+
const readCommand = defineCommand({
|
|
178
|
+
meta: {
|
|
179
|
+
name: "read",
|
|
180
|
+
description: "Read centralized knowledge/skills for an app (--type), or one file (--path)."
|
|
181
|
+
},
|
|
182
|
+
args: {
|
|
183
|
+
app: {
|
|
184
|
+
type: "string",
|
|
185
|
+
description: "App id (defaults to the current app)."
|
|
186
|
+
},
|
|
187
|
+
type: {
|
|
188
|
+
type: "string",
|
|
189
|
+
description: "'knowledge' or 'skills'."
|
|
190
|
+
},
|
|
191
|
+
path: {
|
|
192
|
+
type: "string",
|
|
193
|
+
description: "A specific safe file under the app, e.g. knowledge/business-rules.md."
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
async run({ args, rawArgs }) {
|
|
197
|
+
guardArgs(rawArgs);
|
|
198
|
+
const cwd = prelude();
|
|
199
|
+
const { target } = requireSkillConfig(cwd);
|
|
200
|
+
const { remote } = connect(cwd, target, "if-stale");
|
|
201
|
+
try {
|
|
202
|
+
const type = args.type === "knowledge" || args.type === "skills" ? args.type : void 0;
|
|
203
|
+
printJson({
|
|
204
|
+
success: true,
|
|
205
|
+
...runRead({
|
|
206
|
+
cwd,
|
|
207
|
+
app: args.app,
|
|
208
|
+
type,
|
|
209
|
+
path: args.path,
|
|
210
|
+
remote
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
} catch (e) {
|
|
214
|
+
fail(e.message);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region pkg/cli/skills/commands/search.ts
|
|
221
|
+
/**
|
|
222
|
+
* `mono skills search` — find relevant knowledge/skills/history for a query in
|
|
223
|
+
* the local clone. Returns ranked snippets; never bulk-loads all conversations.
|
|
224
|
+
*/
|
|
225
|
+
const searchCommand = defineCommand({
|
|
226
|
+
meta: {
|
|
227
|
+
name: "search",
|
|
228
|
+
description: "Search an app's knowledge, skills, and history summaries for relevant matches."
|
|
229
|
+
},
|
|
230
|
+
args: {
|
|
231
|
+
app: {
|
|
232
|
+
type: "string",
|
|
233
|
+
description: "App id (defaults to the current app)."
|
|
234
|
+
},
|
|
235
|
+
query: {
|
|
236
|
+
type: "string",
|
|
237
|
+
description: "Search text."
|
|
238
|
+
},
|
|
239
|
+
limit: {
|
|
240
|
+
type: "string",
|
|
241
|
+
description: "Max results (default 10)."
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
async run({ args, rawArgs }) {
|
|
245
|
+
guardArgs(rawArgs);
|
|
246
|
+
const cwd = prelude();
|
|
247
|
+
if (!args.query) fail("--query is required.");
|
|
248
|
+
const { target } = requireSkillConfig(cwd);
|
|
249
|
+
const { remote } = connect(cwd, target, "if-stale");
|
|
250
|
+
const limit = args.limit ? Math.max(1, parseInt(args.limit, 10) || 10) : 10;
|
|
251
|
+
try {
|
|
252
|
+
printJson({
|
|
253
|
+
success: true,
|
|
254
|
+
...runSearch({
|
|
255
|
+
cwd,
|
|
256
|
+
app: args.app,
|
|
257
|
+
query: args.query,
|
|
258
|
+
limit,
|
|
259
|
+
remote
|
|
260
|
+
})
|
|
261
|
+
});
|
|
262
|
+
} catch (e) {
|
|
263
|
+
fail(e.message);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region pkg/cli/skills/commands/save.ts
|
|
270
|
+
/** Human-facing report on stderr so stdout stays pure JSON. Shared with `retry`. */
|
|
271
|
+
function reportSaved(result, remote) {
|
|
272
|
+
process.stderr.write(`\nSession history saved to ${describeRemote(remote)}:\n\n${result.repoPath}\n` + (result.pushAttempts > 1 ? `(replayed after a concurrent save — ${result.pushAttempts} attempts)\n` : ""));
|
|
273
|
+
}
|
|
274
|
+
/** Failure report for `save`/`retry`: JSON to stdout, one honest line to stderr, exit 1. */
|
|
275
|
+
function reportNotSaved(e, repository, sessionId) {
|
|
276
|
+
printJson({
|
|
277
|
+
success: false,
|
|
278
|
+
error: redactUrl(e.message),
|
|
279
|
+
repository: redactUrl(repository)
|
|
280
|
+
});
|
|
281
|
+
process.stderr.write(`\nSession history was NOT saved to ${redactUrl(repository)}.\nLocal staging data was preserved${sessionId ? ` under .mono/skills/failed/${sessionId}` : ""} — fix the cause and run \`mono skills retry\`.\n`);
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* `mono skills save` — the primary command. Commits a completed, staged session
|
|
286
|
+
* to the repository configured in `skill` (one commit, pushed). With `--dry-run`
|
|
287
|
+
* it validates + redacts + reports the planned immutable path WITHOUT touching
|
|
288
|
+
* the network. On failure the local staging directory is preserved (moved to
|
|
289
|
+
* `failed/`) and the error is reported honestly.
|
|
290
|
+
*/
|
|
291
|
+
const saveCommand = defineCommand({
|
|
292
|
+
meta: {
|
|
293
|
+
name: "save",
|
|
294
|
+
description: "Save a staged session (from .mono/skills/pending/<id>) to the configured skills repository. Use --dry-run to validate without pushing."
|
|
295
|
+
},
|
|
296
|
+
args: {
|
|
297
|
+
app: {
|
|
298
|
+
type: "string",
|
|
299
|
+
description: "App id (defaults to the current app)."
|
|
300
|
+
},
|
|
301
|
+
dir: {
|
|
302
|
+
type: "string",
|
|
303
|
+
description: "Staging directory, e.g. .mono/skills/pending/<session-id>."
|
|
304
|
+
},
|
|
305
|
+
"dry-run": {
|
|
306
|
+
type: "boolean",
|
|
307
|
+
description: "Validate and report the planned path without pushing."
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
async run({ args, rawArgs }) {
|
|
311
|
+
guardArgs(rawArgs);
|
|
312
|
+
const cwd = prelude();
|
|
313
|
+
const { target } = requireSkillConfig(cwd);
|
|
314
|
+
const dir = args.dir;
|
|
315
|
+
if (!dir) fail("--dir is required (path to the staged session under .mono/skills/pending/).");
|
|
316
|
+
const app = args.app;
|
|
317
|
+
skipIfGenericApp(resolveAppId({
|
|
318
|
+
app,
|
|
319
|
+
cwd
|
|
320
|
+
}));
|
|
321
|
+
if (args["dry-run"]) {
|
|
322
|
+
try {
|
|
323
|
+
const plan = buildSavePlan({
|
|
324
|
+
cwd,
|
|
325
|
+
app,
|
|
326
|
+
dir,
|
|
327
|
+
target
|
|
328
|
+
});
|
|
329
|
+
printJson({
|
|
330
|
+
success: true,
|
|
331
|
+
dryRun: true,
|
|
332
|
+
repository: redactUrl(plan.repository),
|
|
333
|
+
appId: plan.appId,
|
|
334
|
+
sessionId: plan.sessionId,
|
|
335
|
+
savedPath: plan.savedPath,
|
|
336
|
+
filesPlanned: plan.files.length,
|
|
337
|
+
files: plan.files.map((f) => f.repoPath)
|
|
338
|
+
});
|
|
339
|
+
} catch (e) {
|
|
340
|
+
fail(e.message);
|
|
341
|
+
}
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const { remote } = connect(cwd, target, "always");
|
|
345
|
+
try {
|
|
346
|
+
const result = runSave({
|
|
347
|
+
cwd,
|
|
348
|
+
app,
|
|
349
|
+
dir,
|
|
350
|
+
remote
|
|
351
|
+
});
|
|
352
|
+
printJson(result);
|
|
353
|
+
reportSaved(result, remote);
|
|
354
|
+
} catch (e) {
|
|
355
|
+
reportNotSaved(e, target.remoteUrl, e?.sessionId);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region pkg/cli/skills/commands/retry.ts
|
|
362
|
+
/**
|
|
363
|
+
* `mono skills retry` — re-save a previously failed session from
|
|
364
|
+
* `.mono/skills/failed/<id>`. Same path as `save`; on success the local copy is
|
|
365
|
+
* cleaned up, on failure it is preserved.
|
|
366
|
+
*/
|
|
367
|
+
const retryCommand = defineCommand({
|
|
368
|
+
meta: {
|
|
369
|
+
name: "retry",
|
|
370
|
+
description: "Retry saving a failed session from .mono/skills/failed/<session-id>."
|
|
371
|
+
},
|
|
372
|
+
args: {
|
|
373
|
+
app: {
|
|
374
|
+
type: "string",
|
|
375
|
+
description: "App id (defaults to the current app)."
|
|
376
|
+
},
|
|
377
|
+
dir: {
|
|
378
|
+
type: "string",
|
|
379
|
+
description: "Failed staging directory, e.g. .mono/skills/failed/<session-id>."
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
async run({ args, rawArgs }) {
|
|
383
|
+
guardArgs(rawArgs);
|
|
384
|
+
const cwd = prelude();
|
|
385
|
+
const { target } = requireSkillConfig(cwd);
|
|
386
|
+
const dir = args.dir;
|
|
387
|
+
if (!dir) fail("--dir is required (path to the failed session under .mono/skills/failed/).");
|
|
388
|
+
skipIfGenericApp(resolveAppId({
|
|
389
|
+
app: args.app,
|
|
390
|
+
cwd
|
|
391
|
+
}));
|
|
392
|
+
const { remote } = connect(cwd, target, "always");
|
|
393
|
+
try {
|
|
394
|
+
const result = runSave({
|
|
395
|
+
cwd,
|
|
396
|
+
app: args.app,
|
|
397
|
+
dir,
|
|
398
|
+
remote
|
|
399
|
+
});
|
|
400
|
+
printJson(result);
|
|
401
|
+
reportSaved(result, remote);
|
|
402
|
+
} catch (e) {
|
|
403
|
+
reportNotSaved(e, target.remoteUrl, e?.sessionId);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region pkg/cli/skills/commands/pending.ts
|
|
410
|
+
/** `mono skills pending` — list locally-staged sessions awaiting upload. Local-only. */
|
|
411
|
+
const pendingCommand = defineCommand({
|
|
412
|
+
meta: {
|
|
413
|
+
name: "pending",
|
|
414
|
+
description: "List staged sessions in .mono/skills/pending/."
|
|
415
|
+
},
|
|
416
|
+
args: { app: {
|
|
417
|
+
type: "string",
|
|
418
|
+
description: "App id (defaults to the current app)."
|
|
419
|
+
} },
|
|
420
|
+
async run({ args, rawArgs }) {
|
|
421
|
+
guardArgs(rawArgs);
|
|
422
|
+
const cwd = prelude();
|
|
423
|
+
printJson({
|
|
424
|
+
success: true,
|
|
425
|
+
app: resolveAppId({
|
|
426
|
+
app: args.app,
|
|
427
|
+
cwd
|
|
428
|
+
}),
|
|
429
|
+
kind: "pending",
|
|
430
|
+
sessions: listSessions(cwd, "pending")
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region pkg/cli/skills/commands/failed.ts
|
|
437
|
+
/** `mono skills failed` — list sessions whose upload failed (kept for retry). Local-only. */
|
|
438
|
+
const failedCommand = defineCommand({
|
|
439
|
+
meta: {
|
|
440
|
+
name: "failed",
|
|
441
|
+
description: "List failed sessions in .mono/skills/failed/."
|
|
442
|
+
},
|
|
443
|
+
args: { app: {
|
|
444
|
+
type: "string",
|
|
445
|
+
description: "App id (defaults to the current app)."
|
|
446
|
+
} },
|
|
447
|
+
async run({ args, rawArgs }) {
|
|
448
|
+
guardArgs(rawArgs);
|
|
449
|
+
const cwd = prelude();
|
|
450
|
+
printJson({
|
|
451
|
+
success: true,
|
|
452
|
+
app: resolveAppId({
|
|
453
|
+
app: args.app,
|
|
454
|
+
cwd
|
|
455
|
+
}),
|
|
456
|
+
kind: "failed",
|
|
457
|
+
sessions: listSessions(cwd, "failed")
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region pkg/cli/skills/commands/session.ts
|
|
464
|
+
/** `mono skills session show --app <id> --session-id <id>` */
|
|
465
|
+
const showCommand = defineCommand({
|
|
466
|
+
meta: {
|
|
467
|
+
name: "show",
|
|
468
|
+
description: "Show a saved session's metadata + summary (no conversation)."
|
|
469
|
+
},
|
|
470
|
+
args: {
|
|
471
|
+
app: {
|
|
472
|
+
type: "string",
|
|
473
|
+
description: "App id (defaults to the current app)."
|
|
474
|
+
},
|
|
475
|
+
"session-id": {
|
|
476
|
+
type: "string",
|
|
477
|
+
description: "The session id to display."
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
async run({ args, rawArgs }) {
|
|
481
|
+
guardArgs(rawArgs);
|
|
482
|
+
const cwd = prelude();
|
|
483
|
+
const sessionId = args["session-id"];
|
|
484
|
+
if (!sessionId) fail("--session-id is required.");
|
|
485
|
+
const { target } = requireSkillConfig(cwd);
|
|
486
|
+
const { remote } = connect(cwd, target, "if-stale");
|
|
487
|
+
try {
|
|
488
|
+
printJson({
|
|
489
|
+
success: true,
|
|
490
|
+
...runSessionShow({
|
|
491
|
+
cwd,
|
|
492
|
+
app: args.app,
|
|
493
|
+
sessionId,
|
|
494
|
+
remote
|
|
495
|
+
})
|
|
496
|
+
});
|
|
497
|
+
} catch (e) {
|
|
498
|
+
fail(e.message);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
/** `mono skills session <subcommand>` — currently just `show`. */
|
|
503
|
+
const sessionCommand = defineCommand({
|
|
504
|
+
meta: {
|
|
505
|
+
name: "session",
|
|
506
|
+
description: "Inspect saved sessions."
|
|
507
|
+
},
|
|
508
|
+
subCommands: { show: showCommand }
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region pkg/cli/skills/standard.ts
|
|
513
|
+
/** Example `metadata.json` (required). Typed, so it can't drift from `SessionMetadata`. */
|
|
514
|
+
const METADATA_EXAMPLE = {
|
|
515
|
+
schemaVersion: 1,
|
|
516
|
+
sessionId: "gallery-image-lightbox",
|
|
517
|
+
status: "completed",
|
|
518
|
+
startedAt: "2026-07-02T15:40:00.000Z",
|
|
519
|
+
finishedAt: "2026-07-02T15:53:00.000Z",
|
|
520
|
+
title: "gallery-apps: image-only lightbox on the Picsum gallery",
|
|
521
|
+
topics: [
|
|
522
|
+
"image lightbox",
|
|
523
|
+
"gallery",
|
|
524
|
+
"Picsum"
|
|
525
|
+
],
|
|
526
|
+
userRequests: ["Clicking a thumbnail should open an image-only popup…"],
|
|
527
|
+
commandsRun: [
|
|
528
|
+
"mono skills check",
|
|
529
|
+
"npx vue-tsc --noEmit",
|
|
530
|
+
"npm run dev"
|
|
531
|
+
],
|
|
532
|
+
validation: {
|
|
533
|
+
testsRun: false,
|
|
534
|
+
testsPassed: null,
|
|
535
|
+
buildRun: true,
|
|
536
|
+
buildPassed: true
|
|
537
|
+
},
|
|
538
|
+
outcome: {
|
|
539
|
+
result: "shipped",
|
|
540
|
+
notes: "Added GalleryLightbox.vue; vue-tsc clean."
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
/** Example `files-changed.json` (optional). The reader also honours an optional `note` per file. */
|
|
544
|
+
const FILES_CHANGED_EXAMPLE = { files: [{
|
|
545
|
+
path: "src/components/GalleryLightbox.vue",
|
|
546
|
+
operation: "added"
|
|
547
|
+
}, {
|
|
548
|
+
path: "src/pages/gallery/index.vue",
|
|
549
|
+
operation: "modified"
|
|
550
|
+
}] };
|
|
551
|
+
/** Example `decisions.json` (optional). */
|
|
552
|
+
const DECISIONS_EXAMPLE = { decisions: [{
|
|
553
|
+
title: "Custom Teleport lightbox over mono-modal",
|
|
554
|
+
decision: "Built a custom Teleport overlay component instead of reusing mono-modal.",
|
|
555
|
+
reason: "mono-modal always renders a padded card; the design needed an edge-to-edge image-only view."
|
|
556
|
+
}] };
|
|
557
|
+
/**
|
|
558
|
+
* The canonical staged-session file standard. Frozen so callers can print it but
|
|
559
|
+
* never mutate it. Mirrors the narrative reference in the VitePress docs
|
|
560
|
+
* (`docs/ai/skills.md` → "Session file formats").
|
|
561
|
+
*/
|
|
562
|
+
const SESSION_FILE_STANDARD = Object.freeze({
|
|
563
|
+
version: 1,
|
|
564
|
+
layout: "<app>/history/<actor>/YYYY-MM-DD/HH-mm-ss_<sessionId>/",
|
|
565
|
+
stagingDir: ".mono/skills/pending/<id>/",
|
|
566
|
+
required: ["metadata.json", "summary.md"],
|
|
567
|
+
files: {
|
|
568
|
+
"metadata.json": {
|
|
569
|
+
required: true,
|
|
570
|
+
description: "Session metadata. `finishedAt` drives the destination HH-mm-ss (local time), else save time. The uploaded copy is augmented by the CLI (see `generated.metadataAugmentedWith`).",
|
|
571
|
+
fields: [
|
|
572
|
+
"schemaVersion: number",
|
|
573
|
+
"sessionId: string",
|
|
574
|
+
"status: \"completed\" | \"partial\" | \"failed\"",
|
|
575
|
+
"startedAt?: string (ISO 8601)",
|
|
576
|
+
"finishedAt?: string (ISO 8601)",
|
|
577
|
+
"topics?: string[]",
|
|
578
|
+
"userRequests?: string[]",
|
|
579
|
+
"commandsRun?: string[]",
|
|
580
|
+
"validation?: { testsRun?, testsPassed?, buildRun?, buildPassed? }",
|
|
581
|
+
"outcome?: { result?: string, notes?: string }",
|
|
582
|
+
"title?: string (read by the history browser)"
|
|
583
|
+
],
|
|
584
|
+
example: METADATA_EXAMPLE
|
|
585
|
+
},
|
|
586
|
+
"summary.md": {
|
|
587
|
+
required: true,
|
|
588
|
+
description: "A concise, reusable \"what changed and why\" — the highest-value artifact for the next session.",
|
|
589
|
+
format: "markdown"
|
|
590
|
+
},
|
|
591
|
+
"files-changed.json": {
|
|
592
|
+
required: false,
|
|
593
|
+
description: "Path + operation metadata only (never file contents). Wrapper object `{ files: [...] }`; operation ∈ added | modified | deleted | renamed; an optional `note` per file is honoured by the reader.",
|
|
594
|
+
example: FILES_CHANGED_EXAMPLE
|
|
595
|
+
},
|
|
596
|
+
"decisions.json": {
|
|
597
|
+
required: false,
|
|
598
|
+
description: "Technical/business decisions. Wrapper object `{ decisions: [...] }`; element `{ title, decision, reason }`.",
|
|
599
|
+
example: DECISIONS_EXAMPLE
|
|
600
|
+
},
|
|
601
|
+
"conversation.jsonl": {
|
|
602
|
+
required: false,
|
|
603
|
+
description: "One JSON object per line (user / assistant / tool). Stage a single file; the CLI redacts secrets and chunks it into conversation/part-0001.jsonl, part-0002.jsonl, … (≤ 750 KB per part, never splitting a line). Do not pre-chunk."
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
generated: {
|
|
607
|
+
description: "Written by the CLI — never stage these.",
|
|
608
|
+
"index.json": { example: {
|
|
609
|
+
schemaVersion: 1,
|
|
610
|
+
sessionId: "gallery-image-lightbox",
|
|
611
|
+
format: "jsonl",
|
|
612
|
+
files: [
|
|
613
|
+
"metadata.json",
|
|
614
|
+
"summary.md",
|
|
615
|
+
"files-changed.json",
|
|
616
|
+
"decisions.json"
|
|
617
|
+
]
|
|
618
|
+
} },
|
|
619
|
+
"app.json": { example: {
|
|
620
|
+
schemaVersion: 1,
|
|
621
|
+
app: "<appId>",
|
|
622
|
+
createdAt: "<ISO>"
|
|
623
|
+
} },
|
|
624
|
+
"user.json": { example: {
|
|
625
|
+
name: "<git user.name>",
|
|
626
|
+
email: "<git user.email>",
|
|
627
|
+
actorFolder: "<slug>__<6-hex>"
|
|
628
|
+
} },
|
|
629
|
+
metadataAugmentedWith: [
|
|
630
|
+
"app",
|
|
631
|
+
"actor",
|
|
632
|
+
"actorFolder",
|
|
633
|
+
"repository",
|
|
634
|
+
"savedPath",
|
|
635
|
+
"uploadedAt"
|
|
636
|
+
]
|
|
637
|
+
},
|
|
638
|
+
notes: [
|
|
639
|
+
"Only metadata.json + summary.md are required; the sidecars are optional. `mono skills init --session-id <id>` writes a skeleton that already passes validation.",
|
|
640
|
+
"save/retry validate every staged file against this standard BEFORE committing — a mismatch (bad status, wrong decisions/files-changed shape, invalid conversation line) fails in the CLI and nothing is pushed. --dry-run runs the same checks.",
|
|
641
|
+
"The destination is the git repository configured as `skill` in mono.config.ts (optionally a branch + subfolder via a GitHub /tree/<ref>/<dir> URL). The layout above sits under that folder.",
|
|
642
|
+
"One session = ONE git commit (`feat(<app>): session <id>`), pushed to the configured branch. A concurrent save by someone else is handled by replaying onto their tip — the folder-per-user/session layout can never conflict.",
|
|
643
|
+
"finishedAt drives the destination HH-mm-ss (local time), else save time.",
|
|
644
|
+
"Saves are immutable — a save refuses to overwrite an existing session folder.",
|
|
645
|
+
"The uploaded metadata.json `repository` field is the plain configured URL — never a token.",
|
|
646
|
+
"The date and time_session are two separate path segments; GitHub collapses single-child date folders in its tree view (cosmetic, not a merged folder)."
|
|
647
|
+
]
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region pkg/cli/skills/commands/template.ts
|
|
652
|
+
/**
|
|
653
|
+
* `mono skills template` — print the canonical staged-session file JSON standard
|
|
654
|
+
* (schemas + examples). Pure reference: needs no config, no repo, no env.
|
|
655
|
+
*/
|
|
656
|
+
const templateCommand = defineCommand({
|
|
657
|
+
meta: {
|
|
658
|
+
name: "template",
|
|
659
|
+
description: "Print the canonical staged-session file JSON standard (schemas + examples)."
|
|
660
|
+
},
|
|
661
|
+
async run({ rawArgs }) {
|
|
662
|
+
guardArgs(rawArgs);
|
|
663
|
+
printJson({
|
|
664
|
+
success: true,
|
|
665
|
+
standard: SESSION_FILE_STANDARD
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region pkg/cli/skills/commands/init.ts
|
|
672
|
+
/** A session id usable as a folder name: `[a-z0-9._-]`, no traversal. */
|
|
673
|
+
function assertSessionId(id) {
|
|
674
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id) || id.includes("..")) fail(`Invalid --session-id '${id}': use letters, digits, '.', '_' or '-' (e.g. gallery-image-lightbox).`);
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* `mono skills init --session-id <id>` — seed `.mono/skills/pending/<id>/` with
|
|
678
|
+
* a skeleton that already passes validation, so a human can fill in
|
|
679
|
+
* `summary.md` (and optionally `decisions.json` / `files-changed.json`) and run
|
|
680
|
+
* `mono skills save`. Refuses to touch an existing directory. Local-only.
|
|
681
|
+
*/
|
|
682
|
+
const initCommand = defineCommand({
|
|
683
|
+
meta: {
|
|
684
|
+
name: "init",
|
|
685
|
+
description: "Create a staged-session skeleton under .mono/skills/pending/<session-id>/ for manual editing."
|
|
686
|
+
},
|
|
687
|
+
args: {
|
|
688
|
+
app: {
|
|
689
|
+
type: "string",
|
|
690
|
+
description: "App id (defaults to the current app)."
|
|
691
|
+
},
|
|
692
|
+
"session-id": {
|
|
693
|
+
type: "string",
|
|
694
|
+
description: "Folder name + metadata.sessionId, e.g. fix-login-redirect."
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
async run({ args, rawArgs }) {
|
|
698
|
+
guardArgs(rawArgs);
|
|
699
|
+
const cwd = prelude();
|
|
700
|
+
const sessionId = args["session-id"];
|
|
701
|
+
if (!sessionId) fail("--session-id is required (e.g. --session-id fix-login-redirect).");
|
|
702
|
+
assertSessionId(sessionId);
|
|
703
|
+
const app = resolveAppId({
|
|
704
|
+
app: args.app,
|
|
705
|
+
cwd
|
|
706
|
+
});
|
|
707
|
+
const dir = path.join(stagingRoot(cwd), "pending", sessionId);
|
|
708
|
+
if (fs.existsSync(dir)) fail(`Staging directory already exists: ${dir}`);
|
|
709
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
710
|
+
const metadata = {
|
|
711
|
+
schemaVersion: 1,
|
|
712
|
+
sessionId,
|
|
713
|
+
status: "completed",
|
|
714
|
+
startedAt: now,
|
|
715
|
+
finishedAt: now,
|
|
716
|
+
title: "",
|
|
717
|
+
topics: [],
|
|
718
|
+
userRequests: [],
|
|
719
|
+
commandsRun: [],
|
|
720
|
+
validation: {
|
|
721
|
+
testsRun: false,
|
|
722
|
+
testsPassed: null,
|
|
723
|
+
buildRun: false,
|
|
724
|
+
buildPassed: null
|
|
725
|
+
},
|
|
726
|
+
outcome: {
|
|
727
|
+
result: "",
|
|
728
|
+
notes: ""
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
const summary = [
|
|
732
|
+
`# ${sessionId}`,
|
|
733
|
+
"",
|
|
734
|
+
"## What changed",
|
|
735
|
+
"",
|
|
736
|
+
"- ",
|
|
737
|
+
"",
|
|
738
|
+
"## Why",
|
|
739
|
+
"",
|
|
740
|
+
"- ",
|
|
741
|
+
"",
|
|
742
|
+
"## What the next session should know",
|
|
743
|
+
"",
|
|
744
|
+
"- ",
|
|
745
|
+
""
|
|
746
|
+
].join("\n");
|
|
747
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
748
|
+
const files = {
|
|
749
|
+
"metadata.json": JSON.stringify(metadata, null, 2) + "\n",
|
|
750
|
+
"summary.md": summary,
|
|
751
|
+
"decisions.json": JSON.stringify({ decisions: [] }, null, 2) + "\n",
|
|
752
|
+
"files-changed.json": JSON.stringify({ files: [] }, null, 2) + "\n"
|
|
753
|
+
};
|
|
754
|
+
for (const [name, text] of Object.entries(files)) fs.writeFileSync(path.join(dir, name), text);
|
|
755
|
+
const rel = (path.relative(cwd, dir) || dir).split(path.sep).join("/");
|
|
756
|
+
printJson({
|
|
757
|
+
success: true,
|
|
758
|
+
app,
|
|
759
|
+
sessionId,
|
|
760
|
+
dir,
|
|
761
|
+
files: Object.keys(files),
|
|
762
|
+
next: [
|
|
763
|
+
`Edit ${rel}/summary.md (required) and ${rel}/metadata.json (title, topics, finishedAt).`,
|
|
764
|
+
"Optionally fill decisions.json / files-changed.json, or delete them.",
|
|
765
|
+
`mono skills save --dir ${rel} --dry-run`,
|
|
766
|
+
`mono skills save --dir ${rel}`
|
|
767
|
+
]
|
|
768
|
+
});
|
|
769
|
+
process.stderr.write(`\nStaged session skeleton created at ${dir}\n`);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
//#endregion
|
|
774
|
+
//#region pkg/cli/skills/commands/sync.ts
|
|
775
|
+
/**
|
|
776
|
+
* `mono skills sync` — fetch the configured repository into the local clone
|
|
777
|
+
* (`.mono/skills/repo/`) right now, regardless of staleness. `read`/`search`
|
|
778
|
+
* refresh on their own when stale; this is for a human who wants to browse the
|
|
779
|
+
* clone, or to verify access end-to-end.
|
|
780
|
+
*/
|
|
781
|
+
const syncCommand = defineCommand({
|
|
782
|
+
meta: {
|
|
783
|
+
name: "sync",
|
|
784
|
+
description: "Refresh the local clone of the skills repository (.mono/skills/repo/) now."
|
|
785
|
+
},
|
|
786
|
+
async run({ rawArgs }) {
|
|
787
|
+
guardArgs(rawArgs);
|
|
788
|
+
const cwd = prelude();
|
|
789
|
+
const { target } = requireSkillConfig(cwd);
|
|
790
|
+
const { remote, repo } = connect(cwd, target, "always");
|
|
791
|
+
printJson({
|
|
792
|
+
success: true,
|
|
793
|
+
repository: redactUrl(target.remoteUrl),
|
|
794
|
+
ref: remote.ref,
|
|
795
|
+
dir: remote.dir,
|
|
796
|
+
transport: remote.transport,
|
|
797
|
+
emptyRemote: remote.emptyRemote,
|
|
798
|
+
headSha: repo.headSha,
|
|
799
|
+
path: repo.repoDir,
|
|
800
|
+
refreshed: repo.refreshed,
|
|
801
|
+
stale: repo.stale
|
|
802
|
+
});
|
|
803
|
+
process.stderr.write(`\nSkills repo ${repo.refreshed ? "refreshed" : repo.stale ? "NOT refreshed (serving the stale clone)" : "up to date"}: ${describeRemote(remote)}${repo.headSha ? ` @ ${repo.headSha.slice(0, 7)}` : " (empty)"}\n${repo.repoDir}\n`);
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
//#endregion
|
|
808
|
+
//#region pkg/cli/skills/index.ts
|
|
809
|
+
runMain(defineCommand({
|
|
810
|
+
meta: {
|
|
811
|
+
name: "skills",
|
|
812
|
+
description: "MONO Skills: read app knowledge/skills and save AI session history to the git repository configured as `skill` in mono.config.ts. Off unless `skill` is set; git credentials first, `envToken` as fallback."
|
|
813
|
+
},
|
|
814
|
+
subCommands: {
|
|
815
|
+
check: checkCommand,
|
|
816
|
+
whoami: whoamiCommand,
|
|
817
|
+
init: initCommand,
|
|
818
|
+
read: readCommand,
|
|
819
|
+
search: searchCommand,
|
|
820
|
+
save: saveCommand,
|
|
821
|
+
retry: retryCommand,
|
|
822
|
+
pending: pendingCommand,
|
|
823
|
+
failed: failedCommand,
|
|
824
|
+
session: sessionCommand,
|
|
825
|
+
sync: syncCommand,
|
|
826
|
+
template: templateCommand
|
|
827
|
+
}
|
|
828
|
+
}));
|
|
829
|
+
|
|
830
|
+
//#endregion
|