@litfamily/litclaude 1.0.36 → 1.0.38
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/CHANGELOG.md +49 -0
- package/README.md +11 -8
- package/README_ko-KR.md +11 -8
- package/bin/litclaude-ai.js +3 -3
- package/docs/assets/readme/badge-version.svg +1 -1
- package/docs/assets/skills/lit-adhd.webp +0 -0
- package/docs/assets/skills/lit-hijack.webp +0 -0
- package/docs/assets/skills/lit-schematic.webp +0 -0
- package/docs/hooks.md +112 -26
- package/docs/workflow-compatibility-audit.md +1 -1
- package/package.json +1 -1
- package/plugins/litclaude/.claude-plugin/icon.png +0 -0
- package/plugins/litclaude/.claude-plugin/plugin.json +1 -1
- package/plugins/litclaude/agents/lit-executor.md +4 -2
- package/plugins/litclaude/bin/litclaude-ai +1 -0
- package/plugins/litclaude/bin/litclaude-hook.js +349 -47
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/commands/lit-adhd.md +103 -0
- package/plugins/litclaude/commands/lit-hijack.md +102 -0
- package/plugins/litclaude/commands/lit-loop.md +4 -2
- package/plugins/litclaude/commands/lit-plan.md +5 -4
- package/plugins/litclaude/commands/lit-rewind.md +103 -0
- package/plugins/litclaude/commands/litgoal.md +5 -4
- package/plugins/litclaude/commands/start-work.md +25 -10
- package/plugins/litclaude/hooks/lit-mod.mjs +51 -5
- package/plugins/litclaude/lib/canonical-skill-catalog.mjs +3 -0
- package/plugins/litclaude/lib/canonical-skill-resources.mjs +199 -96
- package/plugins/litclaude/lib/lit-activation.mjs +24 -10
- package/plugins/litclaude/lib/mod/frame.mjs +158 -39
- package/plugins/litclaude/lib/mod/motion.mjs +21 -0
- package/plugins/litclaude/lib/mod/settings.mjs +4 -0
- package/plugins/litclaude/lib/mod/skills.mjs +3 -0
- package/plugins/litclaude/lib/mod/state.mjs +100 -7
- package/plugins/litclaude/lib/mod/svg-card.mjs +115 -15
- package/plugins/litclaude/lib/mod/timeline.mjs +24 -2
- package/plugins/litclaude/lib/mod/toasts.mjs +5 -2
- package/plugins/litclaude/lib/mod/view.mjs +199 -5
- package/plugins/litclaude/lib/mod/workflow.mjs +36 -7
- package/plugins/litclaude/lib/motion-render-gate.mjs +25 -7
- package/plugins/litclaude/lib/render_pages.py +29 -1
- package/plugins/litclaude/lib/rewind/collect.mjs +387 -0
- package/plugins/litclaude/lib/rewind/gauge.mjs +67 -0
- package/plugins/litclaude/lib/rewind/next-step.mjs +89 -0
- package/plugins/litclaude/lib/rewind/redact.mjs +36 -0
- package/plugins/litclaude/lib/rewind/transcripts.mjs +244 -0
- package/plugins/litclaude/lib/start-work-lifecycle.mjs +403 -18
- package/plugins/litclaude/lib/workflow-stack.mjs +243 -0
- package/plugins/litclaude/lib/workflow-stage.mjs +127 -103
- package/plugins/litclaude/scripts/scaffold-plan.mjs +1 -1
- package/plugins/litclaude/skills/frontend-ui-ux/SKILL.md +11 -3
- package/plugins/litclaude/skills/frontend-ui-ux/kit/components.css +414 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/fonts.json +22 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
- package/plugins/litclaude/skills/frontend-ui-ux/kit/ui.js +226 -0
- package/plugins/litclaude/skills/frontend-ui-ux/references/brand-and-imagery.md +1 -1
- package/plugins/litclaude/skills/frontend-ui-ux/references/complete-contract.md +1 -0
- package/plugins/litclaude/skills/frontend-ui-ux/references/craft-floor.md +9 -4
- package/plugins/litclaude/skills/frontend-ui-ux/references/default-editorial-pixel.json +6 -5
- package/plugins/litclaude/skills/frontend-ui-ux/references/house-styles.md +234 -0
- package/plugins/litclaude/skills/frontend-ui-ux/references/motion-guide.md +3 -3
- package/plugins/litclaude/skills/frontend-ui-ux/references/slop-register.md +7 -7
- package/plugins/litclaude/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
- package/plugins/litclaude/skills/frontend-ui-ux/scripts/interface-probe-lock.mjs +196 -0
- package/plugins/litclaude/skills/frontend-ui-ux/scripts/interface-probe-page.mjs +30 -9
- package/plugins/litclaude/skills/frontend-ui-ux/scripts/interface-probe-rules.mjs +19 -7
- package/plugins/litclaude/skills/frontend-ui-ux/scripts/interface-probe-static.mjs +12 -2
- package/plugins/litclaude/skills/frontend-ui-ux/scripts/interface-probe.mjs +53 -6
- package/plugins/litclaude/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
- package/plugins/litclaude/skills/lit-adhd/SKILL.md +151 -0
- package/plugins/litclaude/skills/lit-adhd/references/card-examples.md +69 -0
- package/plugins/litclaude/skills/lit-adhd/references/status-taxonomy.md +43 -0
- package/plugins/litclaude/skills/lit-adhd/scripts/rewind.mjs +11 -0
- package/plugins/litclaude/skills/lit-diagram-drawer/SKILL.md +5 -4
- package/plugins/litclaude/skills/lit-diagram-drawer/references/style-guide.md +20 -11
- package/plugins/litclaude/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
- package/plugins/litclaude/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
- package/plugins/litclaude/skills/lit-diagram-drawer/references/type-tree.md +3 -3
- package/plugins/litclaude/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
- package/plugins/litclaude/skills/lit-diagram-drawer/references/verifier-guide.md +1 -1
- package/plugins/litclaude/skills/lit-diagram-drawer/scripts/visual-quality.mjs +3 -3
- package/plugins/litclaude/skills/lit-handoff/SKILL.md +1 -1
- package/plugins/litclaude/skills/lit-hijack/SKILL.md +551 -0
- package/plugins/litclaude/skills/lit-hijack/references/capture-and-provenance.md +124 -0
- package/plugins/litclaude/skills/lit-hijack/references/clean-room-build.md +133 -0
- package/plugins/litclaude/skills/lit-hijack/references/distil-and-licence.md +128 -0
- package/plugins/litclaude/skills/lit-hijack/references/gap-and-port-design.md +152 -0
- package/plugins/litclaude/skills/lit-hijack/references/parity-and-report.md +131 -0
- package/plugins/litclaude/skills/lit-hijack/scripts/hijack.mjs +854 -0
- package/plugins/litclaude/skills/lit-loop/SKILL.md +4 -3
- package/plugins/litclaude/skills/lit-plan/SKILL.md +16 -10
- package/plugins/litclaude/skills/lit-pptx/SKILL.md +29 -14
- package/plugins/litclaude/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
- package/plugins/litclaude/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
- package/plugins/litclaude/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
- package/plugins/litclaude/skills/lit-pptx/fonts/provenance.json +32 -1
- package/plugins/litclaude/skills/lit-pptx/references/agents/architect.md +1 -1
- package/plugins/litclaude/skills/lit-pptx/references/anti-slop-checklist.md +32 -11
- package/plugins/litclaude/skills/lit-pptx/references/authoring-guide.md +2 -2
- package/plugins/litclaude/skills/lit-pptx/references/data-display-cookbook.md +1 -1
- package/plugins/litclaude/skills/lit-pptx/references/density-and-fill.md +3 -4
- package/plugins/litclaude/skills/lit-pptx/references/direction-step.md +19 -2
- package/plugins/litclaude/skills/lit-pptx/references/examples/13-engineering-review-computational-brutalism-ko.md +173 -0
- package/plugins/litclaude/skills/lit-pptx/references/examples/14-launch-pitch-neo-brutalism-ko.md +154 -0
- package/plugins/litclaude/skills/lit-pptx/references/examples/15-design-lecture-bauhaus-ko.md +139 -0
- package/plugins/litclaude/skills/lit-pptx/references/examples/16-community-programme-riso-ko.md +158 -0
- package/plugins/litclaude/skills/lit-pptx/references/examples/17-public-data-briefing-newsroom-ko.md +179 -0
- package/plugins/litclaude/skills/lit-pptx/references/layout-families.md +22 -26
- package/plugins/litclaude/skills/lit-pptx/references/title-treatments.md +30 -26
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/atlas.md +4 -4
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/bauhaus.md +140 -0
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/chalk.md +3 -3
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/computational-brutalism.md +150 -0
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/gazette.md +1 -1
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/ledger.md +1 -1
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/neo-brutalism.md +161 -0
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/newsroom.md +144 -0
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/night.md +1 -1
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/paper.md +3 -3
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/riso.md +137 -0
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/signal.md +2 -2
- package/plugins/litclaude/skills/lit-pptx/references/tonalities/studio.md +6 -7
- package/plugins/litclaude/skills/lit-pptx/scripts/compile-deck.js +1 -1
- package/plugins/litclaude/skills/lit-pptx/scripts/craft_extras.py +135 -91
- package/plugins/litclaude/skills/lit-pptx/scripts/embed_fonts.py +13 -1
- package/plugins/litclaude/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
- package/plugins/litclaude/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
- package/plugins/litclaude/skills/lit-pptx/scripts/lib/render-pack.js +370 -563
- package/plugins/litclaude/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
- package/plugins/litclaude/skills/lit-pptx/scripts/lib/template-registry.js +57 -6
- package/plugins/litclaude/skills/lit-pptx/scripts/qa_deck.py +5 -5
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +1 -1
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +1 -1
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +99 -0
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +1 -1
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +1 -1
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/night/pack.yaml +1 -1
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/paper/pack.yaml +1 -1
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/signal/pack.yaml +2 -2
- package/plugins/litclaude/skills/lit-pptx/templates/tonalities/studio/pack.yaml +1 -1
- package/plugins/litclaude/skills/lit-recap/SKILL.md +3 -0
- package/plugins/litclaude/skills/lit-schematic/SKILL.md +112 -0
- package/plugins/litclaude/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
- package/plugins/litclaude/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
- package/plugins/litclaude/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
- package/plugins/litclaude/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
- package/plugins/litclaude/skills/lit-schematic/references/cutaway-outputs.md +70 -0
- package/plugins/litclaude/skills/lit-schematic/references/isometric-craft.md +101 -0
- package/plugins/litclaude/skills/lit-schematic/references/journal-figures.md +72 -0
- package/plugins/litclaude/skills/lit-schematic/references/kit-api.md +134 -0
- package/plugins/litclaude/skills/lit-schematic/references/pfd-and-layout.md +53 -0
- package/plugins/litclaude/skills/lit-schematic/references/pid-drafting.md +103 -0
- package/plugins/litclaude/skills/lit-schematic/references/pid-symbols.md +163 -0
- package/plugins/litclaude/skills/lit-schematic/references/verification.md +100 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/doctor.mjs +57 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/fonts.mjs +27 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/png.mjs +132 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/route.mjs +218 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/motion.mjs +129 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/qa.mjs +92 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/render.mjs +233 -0
- package/plugins/litclaude/skills/lit-schematic/scripts/scaffold.mjs +60 -0
- package/plugins/litclaude/skills/lit-scientific-visualization/SKILL.md +14 -4
- package/plugins/litclaude/skills/lit-typographic-motion/SKILL.md +50 -45
- package/plugins/litclaude/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +11 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/blender/runner.py +218 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/core/presets.mjs +1 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/analysis.mjs +65 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/assets.mjs +208 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/blender.mjs +143 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/board.mjs +136 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/brief.mjs +7 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/chrome.mjs +6 -4
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-assets.mjs +5 -3
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-capture.mjs +4 -4
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-treatment.mjs +37 -4
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover.mjs +17 -5
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/done.mjs +42 -3
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/frame-worker.mjs +7 -5
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/gallery.mjs +121 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/house.mjs +44 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/look.mjs +33 -19
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/pipeline.mjs +18 -7
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/scaffold.mjs +210 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/score.mjs +639 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/sound-cli.mjs +21 -4
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/sound.mjs +126 -27
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-capture.mjs +7 -6
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-gate.mjs +59 -5
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-qa.mjs +141 -9
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-serve.mjs +28 -5
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage.mjs +82 -14
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/styles.mjs +213 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/treatment.mjs +311 -10
- package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/cover-init.js +14 -2
- package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/init.js +11 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/qa.js +6 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/stage-kit.js +83 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/vendor/three/LICENSE +21 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/vendor/three/addons/environments/RoomEnvironment.js +144 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/vendor/three/three.module.js +54571 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/hero-3d/expected.json +69 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/hero-3d/index.html +139 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +2 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/painted-light/expected.json +2 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/weight-tide/expected.json +2 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/cover.md +67 -15
- package/plugins/litclaude/skills/lit-typographic-motion/references/craft-loop.md +3 -2
- package/plugins/litclaude/skills/lit-typographic-motion/references/depth.md +122 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/look.md +28 -13
- package/plugins/litclaude/skills/lit-typographic-motion/references/runtime.md +4 -3
- package/plugins/litclaude/skills/lit-typographic-motion/references/sound.md +92 -23
- package/plugins/litclaude/skills/lit-typographic-motion/references/stage.md +43 -22
- package/plugins/litclaude/skills/lit-typographic-motion/references/studio.md +245 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/style-bibles.md +30 -6
- package/plugins/litclaude/skills/lit-typographic-motion/references/treatment.md +108 -14
- package/plugins/litclaude/skills/lit-typographic-motion/scripts/motion-doctor.mjs +16 -3
- package/plugins/litclaude/skills/lit-typographic-motion/scripts/motion.mjs +47 -7
- package/plugins/litclaude/skills/lit-typographic-motion/styles/paper.json +41 -0
- package/plugins/litclaude/skills/lit-typographic-motion/styles/swiss-signal.json +41 -0
- package/plugins/litclaude/skills/lit-typographic-motion/styles/terminalcore.json +42 -0
- package/plugins/litclaude/skills/lit-typographic-motion/styles/tidal.json +41 -0
- package/plugins/litclaude/skills/litgoal/SKILL.md +3 -2
- package/plugins/litclaude/skills/litresearch/SKILL.md +5 -0
- package/plugins/litclaude/skills/readme-studio/templates/hyperframes-cover/package-lock.json +3 -3
- package/plugins/litclaude/skills/readme-studio/templates/remotion-cover/package-lock.json +3 -3
- package/plugins/litclaude/skills/start-work/SKILL.md +24 -11
- package/scripts/qa-cover-recipes.mjs +3 -3
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
// The lit-adhd record collector behind `litclaude-ai rewind` (plans/lit-adhd.md todo 10). It reads
|
|
2
|
+
// what is on disk for every worktree of this repo (Claude transcripts, the litgoal ledger, plan
|
|
3
|
+
// rows, handoff headings, git log, workflow stacks, start-work state, and herdr when HERDR_ENV=1)
|
|
4
|
+
// and returns one redacted, capped JSON brief. A source that is not there reads `unknown`; nothing
|
|
5
|
+
// is inferred. It writes one file only: this session's next-step record for `go`.
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readdirSync } from "node:fs";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { basename, join, resolve } from "node:path";
|
|
11
|
+
|
|
12
|
+
import { parsePlanTaskRows } from "../plan-task-rows.mjs";
|
|
13
|
+
import { resolveProjectStateRoot } from "../project-state-root.mjs";
|
|
14
|
+
import { aggregateProgress, clipToWidth, displayWidth, progressOf } from "./gauge.mjs";
|
|
15
|
+
import { chooseNextStep, writeNextStep } from "./next-step.mjs";
|
|
16
|
+
import { makeRedactor } from "./redact.mjs";
|
|
17
|
+
import { findTranscripts, makeBudget, readTranscriptLines, sessionRecord } from "./transcripts.mjs";
|
|
18
|
+
|
|
19
|
+
const SMALL_FILE_BYTES = 1024 * 1024;
|
|
20
|
+
const HERDR_TIMEOUT_MS = 2000;
|
|
21
|
+
const GIT_TIMEOUT_MS = 5000;
|
|
22
|
+
const DEFAULT_SINCE = "7d";
|
|
23
|
+
const DEFAULT_MAX = 12;
|
|
24
|
+
const NAME_MAX = 90;
|
|
25
|
+
const PLAN_LIMIT = 8;
|
|
26
|
+
|
|
27
|
+
/** `7d`, `12h`, `30m` in milliseconds, or null. */
|
|
28
|
+
export const parseSince = (text) => {
|
|
29
|
+
const match = /^(\d{1,4})([dhm])$/u.exec(String(text ?? ""));
|
|
30
|
+
if (!match) return null;
|
|
31
|
+
return Number(match[1]) * { d: 86_400_000, h: 3_600_000, m: 60_000 }[match[2]];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const readSmallFile = (path, budget) => {
|
|
35
|
+
let fd;
|
|
36
|
+
try {
|
|
37
|
+
if (!lstatSync(path).isFile()) return null;
|
|
38
|
+
fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
39
|
+
const { size } = fstatSync(fd);
|
|
40
|
+
const length = Math.min(size, SMALL_FILE_BYTES, budget.limit - budget.used);
|
|
41
|
+
if (length < size) budget.exhausted = budget.exhausted || length < Math.min(size, SMALL_FILE_BYTES);
|
|
42
|
+
const buffer = Buffer.alloc(Math.max(0, length));
|
|
43
|
+
const read = length > 0 ? readSync(fd, buffer, 0, length, 0) : 0;
|
|
44
|
+
budget.used += read;
|
|
45
|
+
return buffer.subarray(0, read).toString("utf8");
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
} finally {
|
|
49
|
+
if (fd !== undefined) closeSync(fd);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const readJson = (path, budget) => {
|
|
53
|
+
const text = readSmallFile(path, budget);
|
|
54
|
+
if (text === null) return null;
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(text);
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const entries = (directory) => {
|
|
62
|
+
try {
|
|
63
|
+
return readdirSync(directory, { withFileTypes: true });
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const defaultExec = (file, args, options) => execFileSync(file, args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], ...options });
|
|
70
|
+
|
|
71
|
+
const worktreesOf = (cwd, exec) => {
|
|
72
|
+
try {
|
|
73
|
+
const out = exec("git", ["worktree", "list", "--porcelain"], { cwd, timeout: GIT_TIMEOUT_MS });
|
|
74
|
+
const paths = out.split("\n").filter((line) => line.startsWith("worktree ")).map((line) => line.slice(9).trim()).filter(Boolean);
|
|
75
|
+
return paths.length ? paths : null;
|
|
76
|
+
} catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const plansIn = (root, budget, redact, local) => {
|
|
82
|
+
const list = entries(join(root, "plans"));
|
|
83
|
+
if (!list) return null;
|
|
84
|
+
return list.filter((entry) => entry.isFile() && entry.name.endsWith(".md")).sort((a, b) => a.name.localeCompare(b.name)).flatMap((entry) => {
|
|
85
|
+
const text = readSmallFile(join(root, "plans", entry.name), budget);
|
|
86
|
+
if (text === null) return [];
|
|
87
|
+
const rows = parsePlanTaskRows(text);
|
|
88
|
+
if (!rows.length) return [];
|
|
89
|
+
const open = rows.filter((row) => !row.checked);
|
|
90
|
+
if (!open.length) return [];
|
|
91
|
+
const done = rows.length - open.length;
|
|
92
|
+
return [{
|
|
93
|
+
worktree: redact(root),
|
|
94
|
+
plan: `plans/${entry.name}`,
|
|
95
|
+
local,
|
|
96
|
+
rows: rows.map((row) => ({ checked: row.checked, title: redact(clipToWidth(row.text, NAME_MAX)) })),
|
|
97
|
+
current: redact(clipToWidth(open[0].text, NAME_MAX)),
|
|
98
|
+
progress: progressOf(done, rows.length, open.map((row) => redact(clipToWidth(row.text, NAME_MAX)))),
|
|
99
|
+
}];
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const litgoalOf = (root, budget, redact) => {
|
|
104
|
+
const goals = readJson(join(root, ".litclaude", "litgoal", "goals.json"), budget);
|
|
105
|
+
if (!goals || !Array.isArray(goals.criteria)) return null;
|
|
106
|
+
const passed = goals.criteria.filter((criterion) => criterion?.status === "passed");
|
|
107
|
+
const remaining = goals.criteria.filter((criterion) => criterion?.status !== "passed").map((criterion) => redact(clipToWidth(String(criterion?.description ?? criterion?.id ?? "unknown"), NAME_MAX)));
|
|
108
|
+
return {
|
|
109
|
+
worktree: redact(root),
|
|
110
|
+
status: typeof goals.status === "string" ? goals.status : "unknown",
|
|
111
|
+
objective: redact(clipToWidth(String(goals.objective ?? "unknown").split("\n")[0], 120)),
|
|
112
|
+
progress: progressOf(passed.length, goals.criteria.length, remaining),
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const handoffsOf = (root, budget, redact) => (entries(root) ?? [])
|
|
117
|
+
.filter((entry) => entry.isFile() && /^HANDOFF.*\.md$/u.test(entry.name))
|
|
118
|
+
.map((entry) => {
|
|
119
|
+
const text = readSmallFile(join(root, entry.name), budget) ?? "";
|
|
120
|
+
const headings = text.split("\n").slice(0, 40).filter((line) => /^#{1,3} /u.test(line)).map((line) => redact(clipToWidth(line, 100)));
|
|
121
|
+
return { worktree: redact(root), file: entry.name, headings };
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const commitsOf = (root, sinceMs, now, exec, redact) => {
|
|
125
|
+
try {
|
|
126
|
+
const since = new Date(now - sinceMs).toISOString();
|
|
127
|
+
const branch = exec("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd: root, timeout: GIT_TIMEOUT_MS }).trim();
|
|
128
|
+
const out = exec("git", ["log", `--since=${since}`, "--max-count=20", "--format=%H%x09%cI%x09%s"], { cwd: root, timeout: GIT_TIMEOUT_MS });
|
|
129
|
+
return out.split("\n").filter(Boolean).map((line) => {
|
|
130
|
+
const [hash, at, ...subject] = line.split("\t");
|
|
131
|
+
return { worktree: redact(root), branch: redact(branch), hash: hash.slice(0, 7), at, atMs: Date.parse(at), subject: redact(clipToWidth(subject.join("\t"), 100)) };
|
|
132
|
+
});
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const stacksOf = (root, budget, redact) => {
|
|
139
|
+
const directory = join(root, ".litclaude", "workflow-stack");
|
|
140
|
+
const list = entries(directory);
|
|
141
|
+
if (!list) return null;
|
|
142
|
+
return list.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).flatMap((entry) => {
|
|
143
|
+
const stack = readJson(join(directory, entry.name), budget);
|
|
144
|
+
if (!stack || !Array.isArray(stack.frames)) return [];
|
|
145
|
+
return stack.frames.slice(0, 3).map((frame) => ({
|
|
146
|
+
worktree: redact(root),
|
|
147
|
+
sessionId: typeof stack.sessionId === "string" ? stack.sessionId : null,
|
|
148
|
+
id8: typeof stack.sessionId === "string" ? stack.sessionId.slice(0, 8) : "unknown",
|
|
149
|
+
skill: typeof frame.skill === "string" ? frame.skill : "unknown",
|
|
150
|
+
stage: typeof frame.stage === "string" ? frame.stage : "unknown",
|
|
151
|
+
role: frame.role === "spine" ? "spine" : "side",
|
|
152
|
+
status: frame.status === "paused" ? "paused" : "active",
|
|
153
|
+
at: typeof frame.at === "string" ? frame.at : "unknown",
|
|
154
|
+
progress: progressOf(frame.n, frame.total, Array.isArray(frame.remaining) ? frame.remaining.map((name) => redact(clipToWidth(String(name), NAME_MAX))) : undefined),
|
|
155
|
+
}));
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const startWorkOf = (root, budget, redact) => {
|
|
160
|
+
const state = readJson(join(root, ".litclaude", "boulder.json"), budget);
|
|
161
|
+
if (!state || typeof state.works !== "object" || state.works === null) return null;
|
|
162
|
+
const work = state.active_work_id ? state.works[state.active_work_id] : null;
|
|
163
|
+
if (!work) return [];
|
|
164
|
+
// The plan's own checkboxes are current; the stored snapshot only moves at a Stop.
|
|
165
|
+
const planText = typeof work.plan_name === "string" && /^[A-Za-z0-9._-]+\.md$/u.test(work.plan_name) ? readSmallFile(join(root, "plans", work.plan_name), budget) : null;
|
|
166
|
+
const rows = planText === null ? [] : parsePlanTaskRows(planText);
|
|
167
|
+
const open = rows.filter((row) => !row.checked);
|
|
168
|
+
const progress = rows.length
|
|
169
|
+
? progressOf(rows.length - open.length, rows.length, open.map((row) => redact(clipToWidth(row.text, NAME_MAX))))
|
|
170
|
+
: progressOf(work.progress?.checked, work.progress?.total, work.progress?.next_task ? [redact(clipToWidth(work.progress.next_task, NAME_MAX))] : undefined);
|
|
171
|
+
return [{
|
|
172
|
+
worktree: redact(root),
|
|
173
|
+
workId: work.work_id,
|
|
174
|
+
plan: typeof work.plan_name === "string" ? `plans/${work.plan_name}` : "unknown",
|
|
175
|
+
status: work.status,
|
|
176
|
+
sessionId: work.root_session_id ?? null,
|
|
177
|
+
id8: typeof work.root_session_id === "string" ? work.root_session_id.slice(0, 8) : "unknown",
|
|
178
|
+
...(work.pending_boundary ? { pendingBoundary: { action: work.pending_boundary.action, root: redact(work.pending_boundary.root) } } : {}),
|
|
179
|
+
progress,
|
|
180
|
+
}];
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const herdrOf = (env, exec, redact) => {
|
|
184
|
+
if (env.HERDR_ENV !== "1") return { status: "unknown", agents: [] };
|
|
185
|
+
try {
|
|
186
|
+
const out = exec("herdr", ["agent", "list"], { timeout: HERDR_TIMEOUT_MS });
|
|
187
|
+
return { status: "ok", agents: out.split("\n").filter((line) => line.trim()).slice(0, 20).map((line) => redact(clipToWidth(line.trim(), 120))) };
|
|
188
|
+
} catch {
|
|
189
|
+
return { status: "unknown", agents: [] };
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const known = (list) => (list === null ? "unknown" : "ok");
|
|
194
|
+
const statusRank = { "waiting-on-user": 0, active: 1, ended: 2, unknown: 3 };
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Collects the brief. Options: `cwd`, `here` (cwd only), `since` (`7d`), `max` (12), `sessionId`
|
|
198
|
+
* (this session, for the next step and waiting state), `env`, `now`, `exec` (git/herdr runner).
|
|
199
|
+
*/
|
|
200
|
+
export const collectRewind = ({
|
|
201
|
+
cwd = process.cwd(),
|
|
202
|
+
here = false,
|
|
203
|
+
since = DEFAULT_SINCE,
|
|
204
|
+
max = DEFAULT_MAX,
|
|
205
|
+
sessionId = null,
|
|
206
|
+
env = process.env,
|
|
207
|
+
now = Date.now(),
|
|
208
|
+
exec = defaultExec,
|
|
209
|
+
record = true,
|
|
210
|
+
} = {}) => {
|
|
211
|
+
const home = env.HOME || homedir();
|
|
212
|
+
const redact = makeRedactor({ env, home });
|
|
213
|
+
const budget = makeBudget();
|
|
214
|
+
const sinceMs = parseSince(since) ?? parseSince(DEFAULT_SINCE);
|
|
215
|
+
const limit = Number.isInteger(max) && max > 0 ? Math.min(max, 50) : DEFAULT_MAX;
|
|
216
|
+
const start = resolve(cwd);
|
|
217
|
+
const stateRoot = resolveProjectStateRoot(start);
|
|
218
|
+
const listed = here ? null : worktreesOf(start, exec);
|
|
219
|
+
const roots = [...new Set([start, ...(here ? [] : listed ?? [stateRoot])])];
|
|
220
|
+
|
|
221
|
+
const transcripts = findTranscripts(env.CLAUDE_CONFIG_DIR || join(home, ".claude"), roots);
|
|
222
|
+
const sessions = [];
|
|
223
|
+
for (const file of transcripts.files) {
|
|
224
|
+
if (sessions.length >= limit || budget.exhausted) break;
|
|
225
|
+
const lines = readTranscriptLines(file, budget);
|
|
226
|
+
const session = lines ? sessionRecord(lines, { redact, now }) : null;
|
|
227
|
+
if (!session || (session.lastMs !== null && now - session.lastMs > sinceMs)) continue;
|
|
228
|
+
if (here && session.cwd && resolve(session.cwd).normalize("NFC") !== start.normalize("NFC")) continue;
|
|
229
|
+
sessions.push(session);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const collectEach = (read) => {
|
|
233
|
+
const results = roots.map(read);
|
|
234
|
+
return results.every((value) => value === null) ? null : results.flatMap((value) => value ?? []);
|
|
235
|
+
};
|
|
236
|
+
const plans = collectEach((root) => plansIn(root, budget, redact, resolve(root) === stateRoot || resolve(root) === start));
|
|
237
|
+
const litgoal = collectEach((root) => {
|
|
238
|
+
const goal = litgoalOf(root, budget, redact);
|
|
239
|
+
return goal ? [{ ...goal, local: resolve(root) === stateRoot || resolve(root) === start }] : null;
|
|
240
|
+
});
|
|
241
|
+
const handoffs = roots.flatMap((root) => handoffsOf(root, budget, redact));
|
|
242
|
+
const commits = collectEach((root) => commitsOf(root, sinceMs, now, exec, redact));
|
|
243
|
+
const workflows = collectEach((root) => stacksOf(root, budget, redact));
|
|
244
|
+
const startWork = collectEach((root) => startWorkOf(root, budget, redact));
|
|
245
|
+
const herdr = herdrOf(env, exec, redact);
|
|
246
|
+
|
|
247
|
+
// A session waits on the user when it asked something, or holds a paused frame or boundary.
|
|
248
|
+
for (const session of sessions) {
|
|
249
|
+
const frames = (workflows ?? []).filter((frame) => frame.sessionId === session.sessionId);
|
|
250
|
+
const top = frames.at(-1);
|
|
251
|
+
const work = (startWork ?? []).find((item) => item.sessionId === session.sessionId);
|
|
252
|
+
if (frames.some((frame) => frame.status === "paused") && session.status !== "waiting-on-user") {
|
|
253
|
+
session.status = "waiting-on-user";
|
|
254
|
+
session.waitingReason = "paused workflow";
|
|
255
|
+
}
|
|
256
|
+
if (work?.status === "paused") {
|
|
257
|
+
session.status = "waiting-on-user";
|
|
258
|
+
session.waitingReason = "start-work boundary";
|
|
259
|
+
}
|
|
260
|
+
session.progress = top?.progress ?? work?.progress ?? progressOf(null, null);
|
|
261
|
+
session.done.commits = (commits ?? [])
|
|
262
|
+
.filter((commit) => session.lastMs !== null && Date.parse(session.started) <= commit.atMs && commit.atMs <= session.lastMs + 5 * 60_000
|
|
263
|
+
&& (session.branch === "unknown" || commit.branch === session.branch))
|
|
264
|
+
.slice(0, 5)
|
|
265
|
+
.map(({ hash, subject }) => ({ hash, subject }));
|
|
266
|
+
}
|
|
267
|
+
sessions.sort((a, b) => statusRank[a.status] - statusRank[b.status] || (b.lastMs ?? 0) - (a.lastMs ?? 0));
|
|
268
|
+
|
|
269
|
+
// Every worktree's open plans are listed, this one's first, up to a short cap; the roadmap gauge
|
|
270
|
+
// counts this worktree only, since a sum over unrelated branches measures nothing.
|
|
271
|
+
const orderedPlans = [...(plans ?? [])].sort((a, b) => Number(b.local) - Number(a.local));
|
|
272
|
+
const shownPlans = orderedPlans.slice(0, PLAN_LIMIT);
|
|
273
|
+
const localGoals = (litgoal ?? []).filter((goal) => goal.local);
|
|
274
|
+
const roadmapItems = [...orderedPlans.filter((plan) => plan.local).map((plan) => plan.progress), ...localGoals.map((goal) => goal.progress)];
|
|
275
|
+
const data = {
|
|
276
|
+
version: 1,
|
|
277
|
+
generatedAt: new Date(now).toISOString(),
|
|
278
|
+
scope: { here, since: sinceMs === parseSince(since) ? since : DEFAULT_SINCE, max: limit, worktrees: roots.map(redact) },
|
|
279
|
+
sources: {
|
|
280
|
+
transcripts: transcripts.status,
|
|
281
|
+
litgoal: known(litgoal),
|
|
282
|
+
plans: known(plans),
|
|
283
|
+
handoffs: handoffs.length ? "ok" : "unknown",
|
|
284
|
+
git: known(commits),
|
|
285
|
+
workflowStack: known(workflows),
|
|
286
|
+
startWork: known(startWork),
|
|
287
|
+
herdr: herdr.status,
|
|
288
|
+
},
|
|
289
|
+
budget: { bytesRead: budget.used, limit: budget.limit, exhausted: budget.exhausted },
|
|
290
|
+
summary: {
|
|
291
|
+
sessions: sessions.length,
|
|
292
|
+
waitingOnUser: sessions.filter((session) => session.status === "waiting-on-user").length,
|
|
293
|
+
active: sessions.filter((session) => session.status === "active").length,
|
|
294
|
+
},
|
|
295
|
+
sessions: sessions.map(({ cwd: _cwd, lastMs: _lastMs, sessionId: id, ...rest }) => ({ ...rest, self: Boolean(sessionId) && id === sessionId })),
|
|
296
|
+
roadmap: {
|
|
297
|
+
plans: shownPlans,
|
|
298
|
+
plansOmitted: orderedPlans.length - shownPlans.length,
|
|
299
|
+
litgoal: litgoal ?? [],
|
|
300
|
+
progress: roadmapItems.length ? aggregateProgress(roadmapItems) : progressOf(null, null),
|
|
301
|
+
},
|
|
302
|
+
workflows: (workflows ?? []).map((frame) => ({ ...frame, self: Boolean(sessionId) && frame.sessionId === sessionId })),
|
|
303
|
+
startWork: startWork ?? [],
|
|
304
|
+
handoffs,
|
|
305
|
+
commits: (commits ?? []).slice(0, 20).map(({ atMs: _atMs, ...commit }) => commit),
|
|
306
|
+
herdr,
|
|
307
|
+
};
|
|
308
|
+
const next = chooseNextStep(data, sessionId);
|
|
309
|
+
data.next = next;
|
|
310
|
+
data.nextRecorded = false;
|
|
311
|
+
if (record && sessionId) {
|
|
312
|
+
try {
|
|
313
|
+
writeNextStep(stateRoot, sessionId, next, new Date(now));
|
|
314
|
+
data.nextRecorded = true;
|
|
315
|
+
} catch {
|
|
316
|
+
data.nextRecorded = false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
for (const frame of data.workflows) delete frame.sessionId;
|
|
320
|
+
for (const work of data.startWork) delete work.sessionId;
|
|
321
|
+
return data;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const line = (text, width) => clipToWidth(text, width);
|
|
325
|
+
const remainingLine = (names, width) => {
|
|
326
|
+
if (!names.length || (names.length === 1 && names[0] === "unknown")) return null;
|
|
327
|
+
let out = " left:";
|
|
328
|
+
for (const [index, name] of names.entries()) {
|
|
329
|
+
const piece = ` ${name}${index < names.length - 1 ? "," : ""}`;
|
|
330
|
+
if (displayWidth(out + piece) > width - 4) return `${out} …(+${names.length - index})`;
|
|
331
|
+
out += piece;
|
|
332
|
+
}
|
|
333
|
+
return out;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/** Plain-text rendering: every gauge with its remaining names under it, clipped to `width`. */
|
|
337
|
+
export const renderRewind = (data, width = 100) => {
|
|
338
|
+
const out = [];
|
|
339
|
+
const push = (text) => out.push(line(text, width));
|
|
340
|
+
push(`lit-adhd: ${data.summary.sessions} session(s), ${data.summary.waitingOnUser} waiting on you, ${data.summary.active} active`);
|
|
341
|
+
push(`roadmap here ${data.roadmap.progress.gauge}`);
|
|
342
|
+
for (const plan of data.roadmap.plans) {
|
|
343
|
+
push(` ${plan.local ? "" : `${basename(plan.worktree)}: `}${plan.plan} ${plan.progress.gauge} now: ${plan.current}`);
|
|
344
|
+
const left = remainingLine(plan.progress.remaining, width);
|
|
345
|
+
if (left) push(` ${left}`);
|
|
346
|
+
}
|
|
347
|
+
if (data.roadmap.plansOmitted) push(` …(+${data.roadmap.plansOmitted} more open plans)`);
|
|
348
|
+
for (const goal of data.roadmap.litgoal) push(` litgoal ${goal.progress.gauge} ${goal.objective}`);
|
|
349
|
+
for (const session of data.sessions) {
|
|
350
|
+
push(`${session.id8} ${session.status} ${session.progress.gauge} ${session.title}`);
|
|
351
|
+
const left = remainingLine(session.progress.remaining, width);
|
|
352
|
+
if (left) push(left);
|
|
353
|
+
}
|
|
354
|
+
for (const frame of data.workflows) push(` ${frame.id8} ${frame.skill} ${frame.stage} ${frame.status} ${frame.progress.gauge}`);
|
|
355
|
+
push(`next: ${data.next.kind}${data.next.say ? ` (say "${data.next.say}")` : ""}`);
|
|
356
|
+
const unknown = Object.entries(data.sources).filter(([, status]) => status !== "ok").map(([name]) => name);
|
|
357
|
+
if (unknown.length) push(`unknown: ${unknown.join(", ")}`);
|
|
358
|
+
return `${out.join("\n")}\n`;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/** `litclaude-ai rewind [--json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]`. */
|
|
362
|
+
export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, stdout = process.stdout, stderr = process.stderr } = {}) => {
|
|
363
|
+
const options = { cwd, env, here: false, since: DEFAULT_SINCE, max: DEFAULT_MAX, sessionId: env.CLAUDE_CODE_SESSION_ID || null };
|
|
364
|
+
let json = false;
|
|
365
|
+
let width = Number(stdout.columns) || 100;
|
|
366
|
+
const usage = "Usage: litclaude-ai rewind [--json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]";
|
|
367
|
+
if (args.some((arg) => arg === "--help" || arg === "-h")) {
|
|
368
|
+
stdout.write(`${usage}\n`);
|
|
369
|
+
return 0;
|
|
370
|
+
}
|
|
371
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
372
|
+
const arg = args[index];
|
|
373
|
+
if (arg === "--json") json = true;
|
|
374
|
+
else if (arg === "--here") options.here = true;
|
|
375
|
+
else if (arg === "--since" && parseSince(args[index + 1])) options.since = args[++index];
|
|
376
|
+
else if (arg === "--max" && /^\d{1,2}$/u.test(args[index + 1] ?? "")) options.max = Number(args[++index]);
|
|
377
|
+
else if (arg === "--session" && /^[A-Za-z0-9._:-]{1,160}$/u.test(args[index + 1] ?? "")) options.sessionId = args[++index];
|
|
378
|
+
else if (arg === "--width" && /^\d{2,3}$/u.test(args[index + 1] ?? "")) width = Number(args[++index]);
|
|
379
|
+
else {
|
|
380
|
+
stderr.write(`litclaude-ai rewind: unknown argument ${JSON.stringify(basename(String(arg)))}. ${usage}\n`);
|
|
381
|
+
return 64;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const data = collectRewind(options);
|
|
385
|
+
stdout.write(json ? `${JSON.stringify(data, null, 2)}\n` : renderRewind(data, width));
|
|
386
|
+
return 0;
|
|
387
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Progress gauges for the lit-adhd brief (plans/lit-adhd.md D9). Code draws them so the model
|
|
2
|
+
// copies them and never invents its own: `[▉▉▉░░] 3/5`, one cell per item up to ten, scaled to ten
|
|
3
|
+
// cells above that, and `[???] k/?` when the total is not recorded.
|
|
4
|
+
|
|
5
|
+
const MAX_CELLS = 10;
|
|
6
|
+
const known = (value) => Number.isInteger(value) && value >= 0;
|
|
7
|
+
|
|
8
|
+
/** `[▉▉▉░░] 3/5`; an unknown total reads `[???] k/?`, an unknown count `[???] ?/?`. */
|
|
9
|
+
export const gauge = (done, total) => {
|
|
10
|
+
if (!known(total)) return `[???] ${known(done) ? done : "?"}/?`;
|
|
11
|
+
const k = known(done) ? Math.min(done, total) : 0;
|
|
12
|
+
const cells = Math.min(total, MAX_CELLS);
|
|
13
|
+
let filled = k;
|
|
14
|
+
if (total > MAX_CELLS) filled = k === total ? MAX_CELLS : k === 0 ? 0 : Math.min(MAX_CELLS - 1, Math.max(1, Math.floor((k * MAX_CELLS) / total)));
|
|
15
|
+
return `[${"▉".repeat(filled)}${"░".repeat(cells - filled)}] ${k}/${total}`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** `{done, total, gauge, remaining}` with `remaining` as recorded, or `["unknown"]`. */
|
|
19
|
+
export const progressOf = (done, total, remaining) => ({
|
|
20
|
+
done: known(done) ? done : null,
|
|
21
|
+
total: known(total) ? total : null,
|
|
22
|
+
gauge: gauge(done, total),
|
|
23
|
+
remaining: Array.isArray(remaining) && remaining.length ? remaining : known(total) && known(done) && done >= total ? [] : ["unknown"],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** One gauge over several: the sum of known totals, or `[???] k/?` when any total is unknown. */
|
|
27
|
+
export const aggregateProgress = (items) => {
|
|
28
|
+
const done = items.reduce((sum, item) => sum + (known(item.done) ? item.done : 0), 0);
|
|
29
|
+
const total = items.every((item) => known(item.total)) ? items.reduce((sum, item) => sum + item.total, 0) : null;
|
|
30
|
+
return { done, total, gauge: gauge(done, total) };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Terminal columns a character takes: combining marks and Hangul medial/final jamo take none, East
|
|
34
|
+
// Asian wide and fullwidth characters and most emoji take two.
|
|
35
|
+
const charWidth = (codePoint) => {
|
|
36
|
+
if (codePoint === 0 || codePoint < 32 || (codePoint >= 0x7f && codePoint < 0xa0)) return 0;
|
|
37
|
+
if (/\p{Mn}|\p{Me}|\p{Cf}/u.test(String.fromCodePoint(codePoint)) || (codePoint >= 0x1160 && codePoint <= 0x11ff)) return 0;
|
|
38
|
+
if (
|
|
39
|
+
(codePoint >= 0x1100 && codePoint <= 0x115f)
|
|
40
|
+
|| (codePoint >= 0x2e80 && codePoint <= 0xa4cf)
|
|
41
|
+
|| (codePoint >= 0xac00 && codePoint <= 0xd7a3)
|
|
42
|
+
|| (codePoint >= 0xf900 && codePoint <= 0xfaff)
|
|
43
|
+
|| (codePoint >= 0xfe30 && codePoint <= 0xfe4f)
|
|
44
|
+
|| (codePoint >= 0xff00 && codePoint <= 0xff60)
|
|
45
|
+
|| (codePoint >= 0xffe0 && codePoint <= 0xffe6)
|
|
46
|
+
|| (codePoint >= 0x1f300 && codePoint <= 0x1faff)
|
|
47
|
+
|| (codePoint >= 0x20000 && codePoint <= 0x3fffd)
|
|
48
|
+
) return 2;
|
|
49
|
+
return 1;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const displayWidth = (text) => [...String(text)].reduce((sum, ch) => sum + charWidth(ch.codePointAt(0)), 0);
|
|
53
|
+
|
|
54
|
+
/** Clips to `width` display columns, ending in `…` when anything was cut. */
|
|
55
|
+
export const clipToWidth = (text, width) => {
|
|
56
|
+
const value = String(text);
|
|
57
|
+
if (displayWidth(value) <= width) return value;
|
|
58
|
+
let out = "";
|
|
59
|
+
let used = 0;
|
|
60
|
+
for (const ch of value) {
|
|
61
|
+
const w = charWidth(ch.codePointAt(0));
|
|
62
|
+
if (used + w > width - 1) break;
|
|
63
|
+
out += ch;
|
|
64
|
+
used += w;
|
|
65
|
+
}
|
|
66
|
+
return `${out}…`;
|
|
67
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The one next step a lit-adhd brief offers, chosen by a fixed priority over the collected records
|
|
2
|
+
// (plans/lit-adhd.md todo 10), and the small record `go` later reads back (todo 12):
|
|
3
|
+
// 1. this session's paused spine frame -> resume-frame (`lit continue`)
|
|
4
|
+
// 2. a paused start-work boundary -> approve-boundary (shown only, never automatic)
|
|
5
|
+
// 3. an active start-work of this session -> continue-work
|
|
6
|
+
// 4. a single open plan with no work running -> start-plan (`/litclaude:start-work <plan>`)
|
|
7
|
+
// 5. otherwise -> none
|
|
8
|
+
|
|
9
|
+
import { closeSync, constants, fstatSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
|
|
12
|
+
import { ignitionFileName } from "../mod/state.mjs";
|
|
13
|
+
import { ensureStateDirIgnored } from "../project-state-root.mjs";
|
|
14
|
+
|
|
15
|
+
export const chooseNextStep = (data, sessionId) => {
|
|
16
|
+
const ownStack = data.workflows.find((frame) => frame.sessionId === sessionId && frame.role === "spine" && frame.status === "paused");
|
|
17
|
+
if (sessionId && ownStack) {
|
|
18
|
+
return { kind: "resume-frame", target: { skill: ownStack.skill, stage: ownStack.stage, progress: ownStack.progress.gauge }, say: "lit continue" };
|
|
19
|
+
}
|
|
20
|
+
const paused = data.startWork.find((work) => work.status === "paused" && work.pendingBoundary);
|
|
21
|
+
if (paused) {
|
|
22
|
+
return { kind: "approve-boundary", target: { workId: paused.workId, plan: paused.plan, ...paused.pendingBoundary }, say: "lit approve", automatic: false };
|
|
23
|
+
}
|
|
24
|
+
const own = data.startWork.find((work) => work.status === "active" && sessionId && work.sessionId === sessionId);
|
|
25
|
+
if (own) return { kind: "continue-work", target: { workId: own.workId, plan: own.plan }, say: "go" };
|
|
26
|
+
const running = data.startWork.some((work) => ["active", "paused"].includes(work.status));
|
|
27
|
+
const open = data.roadmap.plans.filter((plan) => plan.local && plan.progress.total !== null && plan.progress.done < plan.progress.total);
|
|
28
|
+
if (!running && open.length === 1) {
|
|
29
|
+
return { kind: "start-plan", target: { plan: open[0].plan }, say: "go", command: `/litclaude:start-work ${open[0].plan}` };
|
|
30
|
+
}
|
|
31
|
+
return { kind: "none", target: null };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const nextStepPath = (stateRoot, sessionId) => join(stateRoot, ".litclaude", "adhd", `next-${ignitionFileName(sessionId)}`);
|
|
35
|
+
|
|
36
|
+
/** Writes `{kind, target, at}` for this session, whole, through a temporary file. */
|
|
37
|
+
export const writeNextStep = (stateRoot, sessionId, step, now = new Date()) => {
|
|
38
|
+
const path = nextStepPath(stateRoot, sessionId);
|
|
39
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
40
|
+
ensureStateDirIgnored(path);
|
|
41
|
+
const staging = `${path}.${process.pid}.tmp`;
|
|
42
|
+
writeFileSync(staging, `${JSON.stringify({ kind: step.kind, target: step.target, at: now.toISOString() })}\n`);
|
|
43
|
+
renameSync(staging, path);
|
|
44
|
+
return path;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// The whole prompt, nothing more: `go`, `lit go`, `ㄱㄱ`, `고` or `진행`, with trailing punctuation.
|
|
48
|
+
const GO_PROMPT = /^\s*(?:(?:lit\s+)?go|ㄱㄱ|고|진행)[\s.!?]*$/iu;
|
|
49
|
+
export const isGoPrompt = (prompt) => typeof prompt === "string" && prompt.length <= 64 && GO_PROMPT.test(prompt);
|
|
50
|
+
|
|
51
|
+
export const NEXT_STEP_MAX_AGE_MS = 30 * 60_000;
|
|
52
|
+
const KINDS = new Set(["resume-frame", "approve-boundary", "continue-work", "start-plan", "none"]);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Reads and deletes this session's next-step record. The session binding is the file name, so
|
|
56
|
+
* another session's record is never opened. Returns `{kind, target}` when the record is whole and
|
|
57
|
+
* at most 30 minutes old, otherwise null; a stale or unreadable record is deleted all the same.
|
|
58
|
+
*/
|
|
59
|
+
export const takeNextStep = (stateRoot, sessionId, now = Date.now()) => {
|
|
60
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) return null;
|
|
61
|
+
const path = nextStepPath(stateRoot, sessionId);
|
|
62
|
+
let text;
|
|
63
|
+
try {
|
|
64
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
65
|
+
try {
|
|
66
|
+
const stat = fstatSync(fd);
|
|
67
|
+
if (!stat.isFile() || stat.size > 16_384) return null;
|
|
68
|
+
text = readFileSync(fd, "utf8");
|
|
69
|
+
} finally {
|
|
70
|
+
closeSync(fd);
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
} finally {
|
|
75
|
+
try {
|
|
76
|
+
unlinkSync(path);
|
|
77
|
+
} catch {
|
|
78
|
+
// Nothing to consume.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const record = JSON.parse(text);
|
|
83
|
+
const age = now - Date.parse(record.at);
|
|
84
|
+
if (!KINDS.has(record.kind) || !(age >= -60_000 && age <= NEXT_STEP_MAX_AGE_MS)) return null;
|
|
85
|
+
return { kind: record.kind, target: record.target && typeof record.target === "object" ? record.target : null };
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Redaction for every string the lit-adhd collector emits. Credential shapes and URI userinfo come
|
|
2
|
+
// from the shared secret-shape set; `NAME=value` pairs with a secret-like name lose their value; any
|
|
3
|
+
// substring equal to a current environment value of 8+ characters is replaced (compared here,
|
|
4
|
+
// never printed); the home directory becomes `~`. Path-shaped and locale/terminal values are not
|
|
5
|
+
// credentials and stay, or every path in the brief would be blanked.
|
|
6
|
+
|
|
7
|
+
import { SECRET_SHAPE_PATTERNS, URI_USERINFO_PATTERN } from "../secret-shapes.mjs";
|
|
8
|
+
|
|
9
|
+
const MASK = "[redacted]";
|
|
10
|
+
const SECRET_NAME = /KEY|TOKEN|SECRET|PASS|AUTH|COOKIE/iu;
|
|
11
|
+
const ASSIGNMENT = /\b([A-Za-z_][A-Za-z0-9_]*)=("[^"]*"|'[^']*'|[^\s"'`]+)/gu;
|
|
12
|
+
const PLAIN_ENV_NAMES = /^(?:PATH|HOME|PWD|OLDPWD|SHELL|USER|LOGNAME|LANG|LANGUAGE|TERM|TERM_PROGRAM|TERM_PROGRAM_VERSION|COLORTERM|EDITOR|VISUAL|PAGER|TMPDIR|SHLVL|LC_[A-Z]+|XPC_[A-Z_]+|__CF[A-Z_]*|COMMAND_MODE|_)$/u;
|
|
13
|
+
const globalOf = (pattern) => new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
14
|
+
const SHAPES = [...SECRET_SHAPE_PATTERNS.map(globalOf)];
|
|
15
|
+
const USERINFO = globalOf(URI_USERINFO_PATTERN);
|
|
16
|
+
|
|
17
|
+
const envSecrets = (env) => Object.entries(env ?? {})
|
|
18
|
+
.filter(([name, value]) => typeof value === "string" && value.length >= 8 && !PLAIN_ENV_NAMES.test(name)
|
|
19
|
+
&& !/^[~/]/u.test(value) && !value.includes(":/") && !/^(?:true|false|\d+)$/iu.test(value))
|
|
20
|
+
.map(([, value]) => value)
|
|
21
|
+
.sort((a, b) => b.length - a.length);
|
|
22
|
+
|
|
23
|
+
/** A redactor bound to one environment and home, so the env scan happens once per run. */
|
|
24
|
+
export const makeRedactor = ({ env = process.env, home = env?.HOME } = {}) => {
|
|
25
|
+
const values = envSecrets(env);
|
|
26
|
+
return (input) => {
|
|
27
|
+
if (typeof input !== "string" || input === "") return input;
|
|
28
|
+
let text = input;
|
|
29
|
+
for (const value of values) if (text.includes(value)) text = text.split(value).join(MASK);
|
|
30
|
+
text = text.replace(USERINFO, (match) => match.replace(/\/\/[^/?#\s]+@/u, `//${MASK}@`));
|
|
31
|
+
text = text.replace(ASSIGNMENT, (match, name) => (SECRET_NAME.test(name) ? `${name}=${MASK}` : match));
|
|
32
|
+
for (const pattern of SHAPES) text = text.replace(pattern, MASK);
|
|
33
|
+
if (typeof home === "string" && home.length > 1) text = text.split(home).join("~");
|
|
34
|
+
return text;
|
|
35
|
+
};
|
|
36
|
+
};
|