@jaimevalasek/aioson 1.19.0 → 1.20.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaimevalasek/aioson",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "AI operating framework for hyper-personalized software.",
5
5
  "keywords": [
6
6
  "ai",
package/src/cli.js CHANGED
@@ -188,7 +188,7 @@ const { runOpShow } = require('./commands/op-show');
188
188
  const { runOpReinforce } = require('./commands/op-reinforce');
189
189
  const { runOpMigrate } = require('./commands/op-migrate');
190
190
  const { runFeatureClose } = require('./commands/feature-close');
191
- const { runFeatureArchive } = require('./commands/feature-archive');
191
+ const { runFeatureArchive, runFeatureSweep } = require('./commands/feature-archive');
192
192
  const { runDossierInit, runDossierShow, runDossierAddFinding, runDossierAddCodemap, runDossierLinkRule, runDossierCompact } = require('./commands/dossier');
193
193
  const { runDossierAddResearch } = require('./commands/dossier-add-research');
194
194
  const { runDossierAudit } = require('./commands/dossier-audit');
@@ -620,6 +620,8 @@ const JSON_SUPPORTED_COMMANDS = new Set([
620
620
  'feature-close',
621
621
  'feature:archive',
622
622
  'feature-archive',
623
+ 'feature:sweep',
624
+ 'feature-sweep',
623
625
  'dossier:init',
624
626
  'dossier-init',
625
627
  'dossier:show',
@@ -1480,7 +1482,13 @@ async function main() {
1480
1482
  } else if (command === 'feature:close' || command === 'feature-close') {
1481
1483
  result = await runFeatureClose({ args, options, logger: commandLogger });
1482
1484
  } else if (command === 'feature:archive' || command === 'feature-archive') {
1483
- result = await runFeatureArchive({ args, options, logger: commandLogger });
1485
+ if (options.sweep) {
1486
+ result = await runFeatureSweep({ args, options, logger: commandLogger });
1487
+ } else {
1488
+ result = await runFeatureArchive({ args, options, logger: commandLogger });
1489
+ }
1490
+ } else if (command === 'feature:sweep' || command === 'feature-sweep') {
1491
+ result = await runFeatureSweep({ args, options, logger: commandLogger });
1484
1492
  } else if (command === 'dossier:init' || command === 'dossier-init') {
1485
1493
  result = await runDossierInit({ args, options, logger: commandLogger });
1486
1494
  } else if (command === 'dossier:show' || command === 'dossier-show') {
@@ -270,19 +270,42 @@ async function runFeatureArchive({ args = [], options = {}, logger }) {
270
270
  const otherSlugs = await readOtherSlugs(featuresPath, slug);
271
271
  const rootFiles = await findSlugFiles(ctxDir, slug, otherSlugs);
272
272
  const alreadyArchived = (await dirExists(archiveDir)) ? await findArchivedFiles(archiveDir) : [];
273
- const dossierSourceDir = path.join(ctxDir, 'features', slug);
274
- const dossierTargetDir = path.join(archiveDir, 'dossier');
275
- const hasDossierToMove = await dirExists(dossierSourceDir);
276
- const dossierAlreadyArchived = await dirExists(dossierTargetDir);
273
+
274
+ const SLUG_DIRS = [
275
+ { label: 'dossier', sourceBase: path.join(ctxDir, 'features'), archiveLabel: 'dossier' },
276
+ { label: 'plans', sourceBase: path.join(targetDir, '.aioson', 'plans'), archiveLabel: 'plans' },
277
+ { label: 'briefings', sourceBase: path.join(targetDir, '.aioson', 'briefings'), archiveLabel: 'briefings' }
278
+ ];
279
+
280
+ const dirPlans = [];
281
+ for (const dir of SLUG_DIRS) {
282
+ const sourceDir = path.join(dir.sourceBase, slug);
283
+ const targetDirPath = path.join(archiveDir, dir.archiveLabel);
284
+ const hasSource = await dirExists(sourceDir);
285
+ const alreadyDone = await dirExists(targetDirPath);
286
+ if (hasSource || alreadyDone) {
287
+ dirPlans.push({
288
+ label: dir.label,
289
+ sourceDir,
290
+ targetDir: targetDirPath,
291
+ sourceBase: dir.sourceBase,
292
+ action: hasSource
293
+ ? (alreadyDone ? 'skip' : 'move')
294
+ : (alreadyDone ? 'noop' : null),
295
+ reason: alreadyDone ? 'already_archived' : null
296
+ });
297
+ }
298
+ }
299
+
300
+ const hasAnyDir = dirPlans.some((d) => d.action === 'move' || d.action === 'skip' || d.action === 'noop');
277
301
 
278
302
  if (
279
303
  rootFiles.length === 0 &&
280
304
  alreadyArchived.length === 0 &&
281
- !hasDossierToMove &&
282
- !dossierAlreadyArchived
305
+ !hasAnyDir
283
306
  ) {
284
307
  if (jsonOut) return { ok: true, slug, moved: [], skipped: [], alreadyArchived: [], noop: true };
285
- log(`No files matched "*-${slug}.{${ARCHIVED_EXTENSIONS.join(',')}}" in .aioson/context/ root and no features/${slug}/ dossier dir — nothing to archive.`);
308
+ log(`No files matched "*-${slug}.{${ARCHIVED_EXTENSIONS.join(',')}}" in .aioson/context/ root and no slug directories found — nothing to archive.`);
286
309
  return { ok: true, noop: true };
287
310
  }
288
311
 
@@ -305,11 +328,16 @@ async function runFeatureArchive({ args = [], options = {}, logger }) {
305
328
  : null;
306
329
  const summary = summarySource ? await extractSummary(summarySource) : null;
307
330
 
308
- const dossierPlan = hasDossierToMove
309
- ? (dossierAlreadyArchived ? { action: 'skip', reason: 'already_archived' } : { action: 'move' })
310
- : (dossierAlreadyArchived ? { action: 'noop', reason: 'already_archived' } : null);
311
-
312
331
  if (dryRun) {
332
+ const dirs = dirPlans
333
+ .filter((d) => d.action)
334
+ .map((d) => ({
335
+ label: d.label,
336
+ source: path.relative(targetDir, d.sourceDir),
337
+ target: path.relative(targetDir, d.targetDir),
338
+ action: d.action,
339
+ reason: d.reason
340
+ }));
313
341
  const result = {
314
342
  ok: true,
315
343
  dryRun: true,
@@ -317,13 +345,7 @@ async function runFeatureArchive({ args = [], options = {}, logger }) {
317
345
  targetDir: path.relative(targetDir, archiveDir),
318
346
  move: toMove,
319
347
  skip: toSkip,
320
- dossier: dossierPlan
321
- ? {
322
- source: path.relative(targetDir, dossierSourceDir),
323
- target: path.relative(targetDir, dossierTargetDir),
324
- ...dossierPlan
325
- }
326
- : null,
348
+ dirs,
327
349
  manifestEntry: {
328
350
  slug,
329
351
  completed,
@@ -340,10 +362,12 @@ async function runFeatureArchive({ args = [], options = {}, logger }) {
340
362
  log(` would skip: ${toSkip.length} file(s)`);
341
363
  for (const s of toSkip) log(` • ${s.name} (${s.reason})`);
342
364
  }
343
- if (dossierPlan && dossierPlan.action === 'move') {
344
- log(` would move dossier dir: features/${slug}/ → ${path.relative(targetDir, dossierTargetDir)}/`);
345
- } else if (dossierPlan && dossierPlan.action === 'skip') {
346
- log(` would skip dossier dir: already archived at ${path.relative(targetDir, dossierTargetDir)}/`);
365
+ for (const d of dirPlans) {
366
+ if (d.action === 'move') {
367
+ log(` would move ${d.label} dir: ${path.relative(targetDir, d.sourceDir)}/ → ${path.relative(targetDir, d.targetDir)}/`);
368
+ } else if (d.action === 'skip') {
369
+ log(` would skip ${d.label} dir: already archived at ${path.relative(targetDir, d.targetDir)}/`);
370
+ }
347
371
  }
348
372
  log(` manifest entry: | ${slug} | ${completed} | ${toMove.length + alreadyArchived.length} | ${summary || '—'} |`);
349
373
  return result;
@@ -359,27 +383,29 @@ async function runFeatureArchive({ args = [], options = {}, logger }) {
359
383
  moved.push(name);
360
384
  }
361
385
 
362
- let dossierResult = null;
363
- if (dossierPlan && dossierPlan.action === 'move') {
364
- await fs.rename(dossierSourceDir, dossierTargetDir);
365
- dossierResult = {
366
- action: 'moved',
367
- source: path.relative(targetDir, dossierSourceDir),
368
- target: path.relative(targetDir, dossierTargetDir)
369
- };
370
- try {
371
- const parent = path.join(ctxDir, 'features');
372
- const remaining = await fs.readdir(parent);
373
- if (remaining.length === 0) await fs.rmdir(parent);
374
- } catch {
375
- // parent missing or non-empty — leave it
386
+ const dirResults = [];
387
+ for (const d of dirPlans) {
388
+ if (d.action === 'move') {
389
+ await fs.mkdir(path.dirname(d.targetDir), { recursive: true });
390
+ await fs.rename(d.sourceDir, d.targetDir);
391
+ dirResults.push({
392
+ label: d.label,
393
+ action: 'moved',
394
+ source: path.relative(targetDir, d.sourceDir),
395
+ target: path.relative(targetDir, d.targetDir)
396
+ });
397
+ try {
398
+ const remaining = await fs.readdir(d.sourceBase);
399
+ if (remaining.length === 0) await fs.rmdir(d.sourceBase);
400
+ } catch { /* parent missing or non-empty */ }
401
+ } else if (d.action === 'skip') {
402
+ dirResults.push({
403
+ label: d.label,
404
+ action: 'skipped',
405
+ reason: d.reason,
406
+ target: path.relative(targetDir, d.targetDir)
407
+ });
376
408
  }
377
- } else if (dossierPlan && dossierPlan.action === 'skip') {
378
- dossierResult = {
379
- action: 'skipped',
380
- reason: dossierPlan.reason,
381
- target: path.relative(targetDir, dossierTargetDir)
382
- };
383
409
  }
384
410
 
385
411
  const totalArchived = (await findArchivedFiles(archiveDir)).length;
@@ -399,7 +425,8 @@ async function runFeatureArchive({ args = [], options = {}, logger }) {
399
425
  moved,
400
426
  skipped: toSkip,
401
427
  totalArchived,
402
- dossier: dossierResult,
428
+ dirs: dirResults.length > 0 ? dirResults : undefined,
429
+ dossier: dirResults.find((d) => d.label === 'dossier') || null,
403
430
  manifestEntry: entry
404
431
  };
405
432
 
@@ -412,10 +439,12 @@ async function runFeatureArchive({ args = [], options = {}, logger }) {
412
439
  log(` skipped: ${toSkip.length} file(s) already in archive`);
413
440
  for (const s of toSkip) log(` • ${s.name}`);
414
441
  }
415
- if (dossierResult && dossierResult.action === 'moved') {
416
- log(` moved dossier dir: ${dossierResult.source}/ → ${dossierResult.target}/`);
417
- } else if (dossierResult && dossierResult.action === 'skipped') {
418
- log(` skipped dossier dir: already archived at ${dossierResult.target}/`);
442
+ for (const d of dirResults) {
443
+ if (d.action === 'moved') {
444
+ log(` moved ${d.label} dir: ${d.source}/ ${d.target}/`);
445
+ } else if (d.action === 'skipped') {
446
+ log(` skipped ${d.label} dir: already archived at ${d.target}/`);
447
+ }
419
448
  }
420
449
  log(` manifest updated: .aioson/context/done/MANIFEST.md`);
421
450
  return result;
@@ -510,4 +539,92 @@ async function runRestore({ slug, ctxDir, archiveDir, manifestPath, dryRun, json
510
539
  return result;
511
540
  }
512
541
 
513
- module.exports = { runFeatureArchive };
542
+ async function listDoneFeatures(featuresPath) {
543
+ const content = await readFileSafe(featuresPath);
544
+ if (!content) return [];
545
+ const results = [];
546
+ const lines = content.split(/\r?\n/);
547
+ for (const line of lines) {
548
+ const m = line.match(/^\|\s*([a-z][a-z0-9-]*)\s*\|\s*done\s*\|/i);
549
+ if (m) results.push(m[1].toLowerCase());
550
+ }
551
+ return results;
552
+ }
553
+
554
+ async function listArchivedSlugs(manifestPath) {
555
+ const content = await readFileSafe(manifestPath);
556
+ if (!content) return new Set();
557
+ const slugs = new Set();
558
+ const lines = content.split(/\r?\n/);
559
+ for (const line of lines) {
560
+ const m = line.match(/^\|\s*([a-z][a-z0-9-]+)\s*\|/i);
561
+ if (m && m[1] !== 'slug') slugs.add(m[1].toLowerCase());
562
+ }
563
+ return slugs;
564
+ }
565
+
566
+ async function runFeatureSweep({ args = [], options = {}, logger }) {
567
+ const targetDir = path.resolve(process.cwd(), args[0] || '.');
568
+ const dryRun = Boolean(options['dry-run'] || options.dryRun);
569
+ const jsonOut = Boolean(options.json);
570
+ const log = (msg) => { if (logger && !jsonOut) logger.log(msg); };
571
+
572
+ const ctxDir = contextDir(targetDir);
573
+ if (!(await dirExists(ctxDir))) {
574
+ if (jsonOut) return { ok: false, reason: 'no_context_dir' };
575
+ log('.aioson/context/ not found. Run aioson setup first.');
576
+ return { ok: false };
577
+ }
578
+
579
+ const featuresPath = path.join(ctxDir, 'features.md');
580
+ const manifestPath = path.join(ctxDir, 'done', 'MANIFEST.md');
581
+
582
+ const doneSlugs = await listDoneFeatures(featuresPath);
583
+ const archivedSlugs = await listArchivedSlugs(manifestPath);
584
+ const pending = doneSlugs.filter((s) => !archivedSlugs.has(s));
585
+
586
+ if (pending.length === 0) {
587
+ const result = { ok: true, pending: [], archived: [] };
588
+ if (jsonOut) return result;
589
+ log('All done features are already archived.');
590
+ return result;
591
+ }
592
+
593
+ if (dryRun) {
594
+ const result = { ok: true, dryRun: true, pending, archived: [] };
595
+ if (jsonOut) return result;
596
+ log(`[dry-run] ${pending.length} done feature(s) not yet archived:`);
597
+ for (const s of pending) log(` • ${s}`);
598
+ return result;
599
+ }
600
+
601
+ const archived = [];
602
+ const failed = [];
603
+ for (const slug of pending) {
604
+ try {
605
+ const archiveResult = await runFeatureArchive({
606
+ args: [targetDir],
607
+ options: { feature: slug, json: true },
608
+ logger: null
609
+ });
610
+ if (archiveResult && archiveResult.ok) {
611
+ const movedCount = archiveResult.moved ? archiveResult.moved.length : 0;
612
+ archived.push({ slug, moved: movedCount });
613
+ log(` ✓ ${slug} — ${movedCount} file(s) archived`);
614
+ } else {
615
+ failed.push({ slug, reason: archiveResult.reason || 'unknown' });
616
+ log(` ✗ ${slug} — ${archiveResult.reason || 'unknown'}`);
617
+ }
618
+ } catch (err) {
619
+ failed.push({ slug, reason: err.message || String(err) });
620
+ log(` ✗ ${slug} — ${err.message || err}`);
621
+ }
622
+ }
623
+
624
+ const result = { ok: true, pending, archived, failed: failed.length > 0 ? failed : undefined };
625
+ if (jsonOut) return result;
626
+ log(`\nSweep complete: ${archived.length} archived, ${failed.length} failed.`);
627
+ return result;
628
+ }
629
+
630
+ module.exports = { runFeatureArchive, runFeatureSweep };
@@ -228,6 +228,8 @@ Before the first code change, decide which dev docs must be loaded:
228
228
 
229
229
  Do not preload these docs if the current slice does not need them.
230
230
 
231
+ Before touching code, if `aioson` is available, run `aioson feature:sweep . --dry-run --json` to detect done features not yet archived. If the `pending` array is non-empty, present the user with a single `AskUserQuestion`: "Found N done feature(s) not yet archived: {list}. Archive now?" with options "(Recomendado) Sim, arquivar agora" and "Não, seguir sem arquivar". If yes, run `aioson feature:sweep .` and report the result. This step is advisory — never block session start.
232
+
231
233
  ## Execution invariants
232
234
 
233
235
  These rules apply even if no extra dev doc was loaded:
@@ -90,6 +90,7 @@ Run this after the immediate scope gate and before touching code:
90
90
  6. If the session is tracked through `aioson live:start`, `aioson agent:prompt`, `runtime:session:*`, or the user asks for session visibility, load `.aioson/docs/deyvin/runtime-handoffs.md`
91
91
  7. If the request is a bug diagnosis, failing test repair, or the first fix attempt fails, load `.aioson/docs/deyvin/debugging-escalation.md`
92
92
  8. Do not touch code until all required modules have been loaded
93
+ 9. If `aioson` is available, run `aioson feature:sweep . --dry-run --json` to detect done features not yet archived. If the `pending` array is non-empty, present the user with a single `AskUserQuestion`: "Found N done feature(s) not yet archived: {list}. Archive now?" with options "(Recomendado) Sim, arquivar agora" and "Não, seguir sem arquivar". If yes, run `aioson feature:sweep .` and report the result. This step is advisory — never block session start.
93
94
 
94
95
  ## Working kernel
95
96