@mono-lit/utility 0.0.0-stage → 0.0.2

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 (54) hide show
  1. package/LICENSE.md +54 -0
  2. package/README.md +157 -3
  3. package/dist/app-roots-CvJnmXcs.js +128 -0
  4. package/dist/app-roots-DK41xMWj.d.ts +90 -0
  5. package/dist/config-node-UzJrXg0Z.js +76 -0
  6. package/dist/config-node.d.ts +923 -0
  7. package/dist/config-node.js +7 -0
  8. package/dist/config.d.ts +2 -0
  9. package/dist/config.js +3 -0
  10. package/dist/create-config-B8IhX4ht.d.ts +735 -0
  11. package/dist/create-config-DdL3Fh6T.js +357 -0
  12. package/dist/fetching.d.ts +244 -0
  13. package/dist/fetching.js +1015 -0
  14. package/dist/generate-CJ7MtcDd.js +291 -0
  15. package/dist/index-BAy6tbOG.d.ts +371 -0
  16. package/dist/index-DYlzhHq7.d.ts +514 -0
  17. package/dist/index.d.ts +25 -0
  18. package/dist/index.js +941 -0
  19. package/dist/merge-file-CLc3wxY4.d.ts +99 -0
  20. package/dist/merge-file-CtyKTu5L.js +133 -0
  21. package/dist/mock-db-4tTWrF-P.js +1282 -0
  22. package/dist/mock-db.d.ts +2 -0
  23. package/dist/mock-db.js +4 -0
  24. package/dist/mono-alias-DNDm-jB_.js +508 -0
  25. package/dist/mono-clone.mjs +958 -0
  26. package/dist/mono-db.d.ts +1 -0
  27. package/dist/mono-db.js +158 -0
  28. package/dist/mono-env.mjs +231 -0
  29. package/dist/mono-git.mjs +798 -0
  30. package/dist/mono-link-YlOQ2PVS.js +488 -0
  31. package/dist/mono-prepare.d.ts +1 -0
  32. package/dist/mono-prepare.js +28 -0
  33. package/dist/mono-skills.d.ts +1 -0
  34. package/dist/mono-skills.js +837 -0
  35. package/dist/mono-tsconfig-D2qRL9_R.js +204 -0
  36. package/dist/mono.mjs +34 -0
  37. package/dist/nuxt-layers-DP1m7f1-.js +176 -0
  38. package/dist/nuxt-layers.d.ts +36 -0
  39. package/dist/nuxt-layers.js +3 -0
  40. package/dist/nuxt-runtime.d.ts +17 -0
  41. package/dist/nuxt-runtime.js +102 -0
  42. package/dist/nuxt.d.ts +390 -0
  43. package/dist/nuxt.js +737 -0
  44. package/dist/runtime-vs7U9Ed4.js +6054 -0
  45. package/dist/runtime.d.ts +2518 -0
  46. package/dist/runtime.js +4 -0
  47. package/dist/session-Bcig-rPi.js +1721 -0
  48. package/dist/types-B6FdB7LJ.d.ts +57 -0
  49. package/dist/universal-BR0O7Qwk.d.ts +59 -0
  50. package/dist/universal-DIVEzCvN.js +600 -0
  51. package/dist/virtual-mono-apps.d.ts +16 -0
  52. package/dist/vite.d.ts +943 -0
  53. package/dist/vite.js +1132 -0
  54. package/package.json +141 -3
@@ -0,0 +1,837 @@
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-Bcig-rPi.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
+ const cwd = prelude();
164
+ printJson({
165
+ success: true,
166
+ ...detectActor(cwd)
167
+ });
168
+ }
169
+ });
170
+
171
+ //#endregion
172
+ //#region pkg/cli/skills/commands/read.ts
173
+ /**
174
+ * `mono skills read` — read centralized knowledge or skills for an app, or a
175
+ * single safe file via `--path`, from the local clone (refreshed when stale).
176
+ * Path traversal (`../`) is rejected.
177
+ */
178
+ const readCommand = defineCommand({
179
+ meta: {
180
+ name: "read",
181
+ description: "Read centralized knowledge/skills for an app (--type), or one file (--path)."
182
+ },
183
+ args: {
184
+ app: {
185
+ type: "string",
186
+ description: "App id (defaults to the current app)."
187
+ },
188
+ type: {
189
+ type: "string",
190
+ description: "'knowledge' or 'skills'."
191
+ },
192
+ path: {
193
+ type: "string",
194
+ description: "A specific safe file under the app, e.g. knowledge/business-rules.md."
195
+ }
196
+ },
197
+ async run({ args, rawArgs }) {
198
+ guardArgs(rawArgs);
199
+ const cwd = prelude();
200
+ const { target } = requireSkillConfig(cwd);
201
+ const { remote } = connect(cwd, target, "if-stale");
202
+ try {
203
+ const type = args.type === "knowledge" || args.type === "skills" ? args.type : void 0;
204
+ const result = runRead({
205
+ cwd,
206
+ app: args.app,
207
+ type,
208
+ path: args.path,
209
+ remote
210
+ });
211
+ printJson({
212
+ success: true,
213
+ ...result
214
+ });
215
+ } catch (e) {
216
+ fail(e.message);
217
+ }
218
+ }
219
+ });
220
+
221
+ //#endregion
222
+ //#region pkg/cli/skills/commands/search.ts
223
+ /**
224
+ * `mono skills search` — find relevant knowledge/skills/history for a query in
225
+ * the local clone. Returns ranked snippets; never bulk-loads all conversations.
226
+ */
227
+ const searchCommand = defineCommand({
228
+ meta: {
229
+ name: "search",
230
+ description: "Search an app's knowledge, skills, and history summaries for relevant matches."
231
+ },
232
+ args: {
233
+ app: {
234
+ type: "string",
235
+ description: "App id (defaults to the current app)."
236
+ },
237
+ query: {
238
+ type: "string",
239
+ description: "Search text."
240
+ },
241
+ limit: {
242
+ type: "string",
243
+ description: "Max results (default 10)."
244
+ }
245
+ },
246
+ async run({ args, rawArgs }) {
247
+ guardArgs(rawArgs);
248
+ const cwd = prelude();
249
+ if (!args.query) fail("--query is required.");
250
+ const { target } = requireSkillConfig(cwd);
251
+ const { remote } = connect(cwd, target, "if-stale");
252
+ const limit = args.limit ? Math.max(1, parseInt(args.limit, 10) || 10) : 10;
253
+ try {
254
+ const result = runSearch({
255
+ cwd,
256
+ app: args.app,
257
+ query: args.query,
258
+ limit,
259
+ remote
260
+ });
261
+ printJson({
262
+ success: true,
263
+ ...result
264
+ });
265
+ } catch (e) {
266
+ fail(e.message);
267
+ }
268
+ }
269
+ });
270
+
271
+ //#endregion
272
+ //#region pkg/cli/skills/commands/save.ts
273
+ /** Human-facing report on stderr so stdout stays pure JSON. Shared with `retry`. */
274
+ function reportSaved(result, remote) {
275
+ 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` : ""));
276
+ }
277
+ /** Failure report for `save`/`retry`: JSON to stdout, one honest line to stderr, exit 1. */
278
+ function reportNotSaved(e, repository, sessionId) {
279
+ printJson({
280
+ success: false,
281
+ error: redactUrl(e.message),
282
+ repository: redactUrl(repository)
283
+ });
284
+ 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`);
285
+ process.exit(1);
286
+ }
287
+ /**
288
+ * `mono skills save` — the primary command. Commits a completed, staged session
289
+ * to the repository configured in `skill` (one commit, pushed). With `--dry-run`
290
+ * it validates + redacts + reports the planned immutable path WITHOUT touching
291
+ * the network. On failure the local staging directory is preserved (moved to
292
+ * `failed/`) and the error is reported honestly.
293
+ */
294
+ const saveCommand = defineCommand({
295
+ meta: {
296
+ name: "save",
297
+ description: "Save a staged session (from .mono/skills/pending/<id>) to the configured skills repository. Use --dry-run to validate without pushing."
298
+ },
299
+ args: {
300
+ app: {
301
+ type: "string",
302
+ description: "App id (defaults to the current app)."
303
+ },
304
+ dir: {
305
+ type: "string",
306
+ description: "Staging directory, e.g. .mono/skills/pending/<session-id>."
307
+ },
308
+ "dry-run": {
309
+ type: "boolean",
310
+ description: "Validate and report the planned path without pushing."
311
+ }
312
+ },
313
+ async run({ args, rawArgs }) {
314
+ guardArgs(rawArgs);
315
+ const cwd = prelude();
316
+ const { target } = requireSkillConfig(cwd);
317
+ const dir = args.dir;
318
+ if (!dir) fail("--dir is required (path to the staged session under .mono/skills/pending/).");
319
+ const app = args.app;
320
+ skipIfGenericApp(resolveAppId({
321
+ app,
322
+ cwd
323
+ }));
324
+ if (args["dry-run"]) {
325
+ try {
326
+ const plan = buildSavePlan({
327
+ cwd,
328
+ app,
329
+ dir,
330
+ target
331
+ });
332
+ printJson({
333
+ success: true,
334
+ dryRun: true,
335
+ repository: redactUrl(plan.repository),
336
+ appId: plan.appId,
337
+ sessionId: plan.sessionId,
338
+ savedPath: plan.savedPath,
339
+ filesPlanned: plan.files.length,
340
+ files: plan.files.map((f) => f.repoPath)
341
+ });
342
+ } catch (e) {
343
+ fail(e.message);
344
+ }
345
+ return;
346
+ }
347
+ const { remote } = connect(cwd, target, "always");
348
+ try {
349
+ const result = runSave({
350
+ cwd,
351
+ app,
352
+ dir,
353
+ remote
354
+ });
355
+ printJson(result);
356
+ reportSaved(result, remote);
357
+ } catch (e) {
358
+ reportNotSaved(e, target.remoteUrl, e?.sessionId);
359
+ }
360
+ }
361
+ });
362
+
363
+ //#endregion
364
+ //#region pkg/cli/skills/commands/retry.ts
365
+ /**
366
+ * `mono skills retry` — re-save a previously failed session from
367
+ * `.mono/skills/failed/<id>`. Same path as `save`; on success the local copy is
368
+ * cleaned up, on failure it is preserved.
369
+ */
370
+ const retryCommand = defineCommand({
371
+ meta: {
372
+ name: "retry",
373
+ description: "Retry saving a failed session from .mono/skills/failed/<session-id>."
374
+ },
375
+ args: {
376
+ app: {
377
+ type: "string",
378
+ description: "App id (defaults to the current app)."
379
+ },
380
+ dir: {
381
+ type: "string",
382
+ description: "Failed staging directory, e.g. .mono/skills/failed/<session-id>."
383
+ }
384
+ },
385
+ async run({ args, rawArgs }) {
386
+ guardArgs(rawArgs);
387
+ const cwd = prelude();
388
+ const { target } = requireSkillConfig(cwd);
389
+ const dir = args.dir;
390
+ if (!dir) fail("--dir is required (path to the failed session under .mono/skills/failed/).");
391
+ skipIfGenericApp(resolveAppId({
392
+ app: args.app,
393
+ cwd
394
+ }));
395
+ const { remote } = connect(cwd, target, "always");
396
+ try {
397
+ const result = runSave({
398
+ cwd,
399
+ app: args.app,
400
+ dir,
401
+ remote
402
+ });
403
+ printJson(result);
404
+ reportSaved(result, remote);
405
+ } catch (e) {
406
+ reportNotSaved(e, target.remoteUrl, e?.sessionId);
407
+ }
408
+ }
409
+ });
410
+
411
+ //#endregion
412
+ //#region pkg/cli/skills/commands/pending.ts
413
+ /** `mono skills pending` — list locally-staged sessions awaiting upload. Local-only. */
414
+ const pendingCommand = defineCommand({
415
+ meta: {
416
+ name: "pending",
417
+ description: "List staged sessions in .mono/skills/pending/."
418
+ },
419
+ args: { app: {
420
+ type: "string",
421
+ description: "App id (defaults to the current app)."
422
+ } },
423
+ async run({ args, rawArgs }) {
424
+ guardArgs(rawArgs);
425
+ const cwd = prelude();
426
+ const app = resolveAppId({
427
+ app: args.app,
428
+ cwd
429
+ });
430
+ printJson({
431
+ success: true,
432
+ app,
433
+ kind: "pending",
434
+ sessions: listSessions(cwd, "pending")
435
+ });
436
+ }
437
+ });
438
+
439
+ //#endregion
440
+ //#region pkg/cli/skills/commands/failed.ts
441
+ /** `mono skills failed` — list sessions whose upload failed (kept for retry). Local-only. */
442
+ const failedCommand = defineCommand({
443
+ meta: {
444
+ name: "failed",
445
+ description: "List failed sessions in .mono/skills/failed/."
446
+ },
447
+ args: { app: {
448
+ type: "string",
449
+ description: "App id (defaults to the current app)."
450
+ } },
451
+ async run({ args, rawArgs }) {
452
+ guardArgs(rawArgs);
453
+ const cwd = prelude();
454
+ const app = resolveAppId({
455
+ app: args.app,
456
+ cwd
457
+ });
458
+ printJson({
459
+ success: true,
460
+ app,
461
+ kind: "failed",
462
+ sessions: listSessions(cwd, "failed")
463
+ });
464
+ }
465
+ });
466
+
467
+ //#endregion
468
+ //#region pkg/cli/skills/commands/session.ts
469
+ /** `mono skills session show --app <id> --session-id <id>` */
470
+ const showCommand = defineCommand({
471
+ meta: {
472
+ name: "show",
473
+ description: "Show a saved session's metadata + summary (no conversation)."
474
+ },
475
+ args: {
476
+ app: {
477
+ type: "string",
478
+ description: "App id (defaults to the current app)."
479
+ },
480
+ "session-id": {
481
+ type: "string",
482
+ description: "The session id to display."
483
+ }
484
+ },
485
+ async run({ args, rawArgs }) {
486
+ guardArgs(rawArgs);
487
+ const cwd = prelude();
488
+ const sessionId = args["session-id"];
489
+ if (!sessionId) fail("--session-id is required.");
490
+ const { target } = requireSkillConfig(cwd);
491
+ const { remote } = connect(cwd, target, "if-stale");
492
+ try {
493
+ const result = runSessionShow({
494
+ cwd,
495
+ app: args.app,
496
+ sessionId,
497
+ remote
498
+ });
499
+ printJson({
500
+ success: true,
501
+ ...result
502
+ });
503
+ } catch (e) {
504
+ fail(e.message);
505
+ }
506
+ }
507
+ });
508
+ /** `mono skills session <subcommand>` — currently just `show`. */
509
+ const sessionCommand = defineCommand({
510
+ meta: {
511
+ name: "session",
512
+ description: "Inspect saved sessions."
513
+ },
514
+ subCommands: { show: showCommand }
515
+ });
516
+
517
+ //#endregion
518
+ //#region pkg/cli/skills/standard.ts
519
+ /** Example `metadata.json` (required). Typed, so it can't drift from `SessionMetadata`. */
520
+ const METADATA_EXAMPLE = {
521
+ schemaVersion: 1,
522
+ sessionId: "gallery-image-lightbox",
523
+ status: "completed",
524
+ startedAt: "2026-07-02T15:40:00.000Z",
525
+ finishedAt: "2026-07-02T15:53:00.000Z",
526
+ title: "gallery-apps: image-only lightbox on the Picsum gallery",
527
+ topics: [
528
+ "image lightbox",
529
+ "gallery",
530
+ "Picsum"
531
+ ],
532
+ userRequests: ["Clicking a thumbnail should open an image-only popup…"],
533
+ commandsRun: [
534
+ "mono skills check",
535
+ "npx vue-tsc --noEmit",
536
+ "npm run dev"
537
+ ],
538
+ validation: {
539
+ testsRun: false,
540
+ testsPassed: null,
541
+ buildRun: true,
542
+ buildPassed: true
543
+ },
544
+ outcome: {
545
+ result: "shipped",
546
+ notes: "Added GalleryLightbox.vue; vue-tsc clean."
547
+ }
548
+ };
549
+ /** Example `files-changed.json` (optional). The reader also honours an optional `note` per file. */
550
+ const FILES_CHANGED_EXAMPLE = { files: [{
551
+ path: "src/components/GalleryLightbox.vue",
552
+ operation: "added"
553
+ }, {
554
+ path: "src/pages/gallery/index.vue",
555
+ operation: "modified"
556
+ }] };
557
+ /** Example `decisions.json` (optional). */
558
+ const DECISIONS_EXAMPLE = { decisions: [{
559
+ title: "Custom Teleport lightbox over mono-modal",
560
+ decision: "Built a custom Teleport overlay component instead of reusing mono-modal.",
561
+ reason: "mono-modal always renders a padded card; the design needed an edge-to-edge image-only view."
562
+ }] };
563
+ /**
564
+ * The canonical staged-session file standard. Frozen so callers can print it but
565
+ * never mutate it. Mirrors the narrative reference in the VitePress docs
566
+ * (`docs/ai/skills.md` → "Session file formats").
567
+ */
568
+ const SESSION_FILE_STANDARD = Object.freeze({
569
+ version: 1,
570
+ layout: "<app>/history/<actor>/YYYY-MM-DD/HH-mm-ss_<sessionId>/",
571
+ stagingDir: ".mono/skills/pending/<id>/",
572
+ required: ["metadata.json", "summary.md"],
573
+ files: {
574
+ "metadata.json": {
575
+ required: true,
576
+ 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`).",
577
+ fields: [
578
+ "schemaVersion: number",
579
+ "sessionId: string",
580
+ "status: \"completed\" | \"partial\" | \"failed\"",
581
+ "startedAt?: string (ISO 8601)",
582
+ "finishedAt?: string (ISO 8601)",
583
+ "topics?: string[]",
584
+ "userRequests?: string[]",
585
+ "commandsRun?: string[]",
586
+ "validation?: { testsRun?, testsPassed?, buildRun?, buildPassed? }",
587
+ "outcome?: { result?: string, notes?: string }",
588
+ "title?: string (read by the history browser)"
589
+ ],
590
+ example: METADATA_EXAMPLE
591
+ },
592
+ "summary.md": {
593
+ required: true,
594
+ description: "A concise, reusable \"what changed and why\" — the highest-value artifact for the next session.",
595
+ format: "markdown"
596
+ },
597
+ "files-changed.json": {
598
+ required: false,
599
+ 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.",
600
+ example: FILES_CHANGED_EXAMPLE
601
+ },
602
+ "decisions.json": {
603
+ required: false,
604
+ description: "Technical/business decisions. Wrapper object `{ decisions: [...] }`; element `{ title, decision, reason }`.",
605
+ example: DECISIONS_EXAMPLE
606
+ },
607
+ "conversation.jsonl": {
608
+ required: false,
609
+ 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."
610
+ }
611
+ },
612
+ generated: {
613
+ description: "Written by the CLI — never stage these.",
614
+ "index.json": { example: {
615
+ schemaVersion: 1,
616
+ sessionId: "gallery-image-lightbox",
617
+ format: "jsonl",
618
+ files: [
619
+ "metadata.json",
620
+ "summary.md",
621
+ "files-changed.json",
622
+ "decisions.json"
623
+ ]
624
+ } },
625
+ "app.json": { example: {
626
+ schemaVersion: 1,
627
+ app: "<appId>",
628
+ createdAt: "<ISO>"
629
+ } },
630
+ "user.json": { example: {
631
+ name: "<git user.name>",
632
+ email: "<git user.email>",
633
+ actorFolder: "<slug>__<6-hex>"
634
+ } },
635
+ metadataAugmentedWith: [
636
+ "app",
637
+ "actor",
638
+ "actorFolder",
639
+ "repository",
640
+ "savedPath",
641
+ "uploadedAt"
642
+ ]
643
+ },
644
+ notes: [
645
+ "Only metadata.json + summary.md are required; the sidecars are optional. `mono skills init --session-id <id>` writes a skeleton that already passes validation.",
646
+ "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.",
647
+ "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.",
648
+ "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.",
649
+ "finishedAt drives the destination HH-mm-ss (local time), else save time.",
650
+ "Saves are immutable — a save refuses to overwrite an existing session folder.",
651
+ "The uploaded metadata.json `repository` field is the plain configured URL — never a token.",
652
+ "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)."
653
+ ]
654
+ });
655
+
656
+ //#endregion
657
+ //#region pkg/cli/skills/commands/template.ts
658
+ /**
659
+ * `mono skills template` — print the canonical staged-session file JSON standard
660
+ * (schemas + examples). Pure reference: needs no config, no repo, no env.
661
+ */
662
+ const templateCommand = defineCommand({
663
+ meta: {
664
+ name: "template",
665
+ description: "Print the canonical staged-session file JSON standard (schemas + examples)."
666
+ },
667
+ async run({ rawArgs }) {
668
+ guardArgs(rawArgs);
669
+ printJson({
670
+ success: true,
671
+ standard: SESSION_FILE_STANDARD
672
+ });
673
+ }
674
+ });
675
+
676
+ //#endregion
677
+ //#region pkg/cli/skills/commands/init.ts
678
+ /** A session id usable as a folder name: `[a-z0-9._-]`, no traversal. */
679
+ function assertSessionId(id) {
680
+ 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).`);
681
+ }
682
+ /**
683
+ * `mono skills init --session-id <id>` — seed `.mono/skills/pending/<id>/` with
684
+ * a skeleton that already passes validation, so a human can fill in
685
+ * `summary.md` (and optionally `decisions.json` / `files-changed.json`) and run
686
+ * `mono skills save`. Refuses to touch an existing directory. Local-only.
687
+ */
688
+ const initCommand = defineCommand({
689
+ meta: {
690
+ name: "init",
691
+ description: "Create a staged-session skeleton under .mono/skills/pending/<session-id>/ for manual editing."
692
+ },
693
+ args: {
694
+ app: {
695
+ type: "string",
696
+ description: "App id (defaults to the current app)."
697
+ },
698
+ "session-id": {
699
+ type: "string",
700
+ description: "Folder name + metadata.sessionId, e.g. fix-login-redirect."
701
+ }
702
+ },
703
+ async run({ args, rawArgs }) {
704
+ guardArgs(rawArgs);
705
+ const cwd = prelude();
706
+ const sessionId = args["session-id"];
707
+ if (!sessionId) fail("--session-id is required (e.g. --session-id fix-login-redirect).");
708
+ assertSessionId(sessionId);
709
+ const app = resolveAppId({
710
+ app: args.app,
711
+ cwd
712
+ });
713
+ const dir = path.join(stagingRoot(cwd), "pending", sessionId);
714
+ if (fs.existsSync(dir)) fail(`Staging directory already exists: ${dir}`);
715
+ const now = (/* @__PURE__ */ new Date()).toISOString();
716
+ const metadata = {
717
+ schemaVersion: 1,
718
+ sessionId,
719
+ status: "completed",
720
+ startedAt: now,
721
+ finishedAt: now,
722
+ title: "",
723
+ topics: [],
724
+ userRequests: [],
725
+ commandsRun: [],
726
+ validation: {
727
+ testsRun: false,
728
+ testsPassed: null,
729
+ buildRun: false,
730
+ buildPassed: null
731
+ },
732
+ outcome: {
733
+ result: "",
734
+ notes: ""
735
+ }
736
+ };
737
+ const summary = [
738
+ `# ${sessionId}`,
739
+ "",
740
+ "## What changed",
741
+ "",
742
+ "- ",
743
+ "",
744
+ "## Why",
745
+ "",
746
+ "- ",
747
+ "",
748
+ "## What the next session should know",
749
+ "",
750
+ "- ",
751
+ ""
752
+ ].join("\n");
753
+ fs.mkdirSync(dir, { recursive: true });
754
+ const files = {
755
+ "metadata.json": JSON.stringify(metadata, null, 2) + "\n",
756
+ "summary.md": summary,
757
+ "decisions.json": JSON.stringify({ decisions: [] }, null, 2) + "\n",
758
+ "files-changed.json": JSON.stringify({ files: [] }, null, 2) + "\n"
759
+ };
760
+ for (const [name, text] of Object.entries(files)) fs.writeFileSync(path.join(dir, name), text);
761
+ const rel = (path.relative(cwd, dir) || dir).split(path.sep).join("/");
762
+ printJson({
763
+ success: true,
764
+ app,
765
+ sessionId,
766
+ dir,
767
+ files: Object.keys(files),
768
+ next: [
769
+ `Edit ${rel}/summary.md (required) and ${rel}/metadata.json (title, topics, finishedAt).`,
770
+ "Optionally fill decisions.json / files-changed.json, or delete them.",
771
+ `mono skills save --dir ${rel} --dry-run`,
772
+ `mono skills save --dir ${rel}`
773
+ ]
774
+ });
775
+ process.stderr.write(`\nStaged session skeleton created at ${dir}\n`);
776
+ }
777
+ });
778
+
779
+ //#endregion
780
+ //#region pkg/cli/skills/commands/sync.ts
781
+ /**
782
+ * `mono skills sync` — fetch the configured repository into the local clone
783
+ * (`.mono/skills/repo/`) right now, regardless of staleness. `read`/`search`
784
+ * refresh on their own when stale; this is for a human who wants to browse the
785
+ * clone, or to verify access end-to-end.
786
+ */
787
+ const syncCommand = defineCommand({
788
+ meta: {
789
+ name: "sync",
790
+ description: "Refresh the local clone of the skills repository (.mono/skills/repo/) now."
791
+ },
792
+ async run({ rawArgs }) {
793
+ guardArgs(rawArgs);
794
+ const cwd = prelude();
795
+ const { target } = requireSkillConfig(cwd);
796
+ const { remote, repo } = connect(cwd, target, "always");
797
+ printJson({
798
+ success: true,
799
+ repository: redactUrl(target.remoteUrl),
800
+ ref: remote.ref,
801
+ dir: remote.dir,
802
+ transport: remote.transport,
803
+ emptyRemote: remote.emptyRemote,
804
+ headSha: repo.headSha,
805
+ path: repo.repoDir,
806
+ refreshed: repo.refreshed,
807
+ stale: repo.stale
808
+ });
809
+ 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`);
810
+ }
811
+ });
812
+
813
+ //#endregion
814
+ //#region pkg/cli/skills/index.ts
815
+ const main = defineCommand({
816
+ meta: {
817
+ name: "skills",
818
+ 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."
819
+ },
820
+ subCommands: {
821
+ check: checkCommand,
822
+ whoami: whoamiCommand,
823
+ init: initCommand,
824
+ read: readCommand,
825
+ search: searchCommand,
826
+ save: saveCommand,
827
+ retry: retryCommand,
828
+ pending: pendingCommand,
829
+ failed: failedCommand,
830
+ session: sessionCommand,
831
+ sync: syncCommand,
832
+ template: templateCommand
833
+ }
834
+ });
835
+ runMain(main);
836
+
837
+ //#endregion