@litfamily/litclaude 1.0.37 → 1.0.39
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 +71 -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 +117 -26
- package/docs/workflow-compatibility-audit.md +1 -1
- package/package.json +1 -1
- 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 +373 -53
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/commands/lit-adhd.md +107 -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 +107 -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 +205 -101
- package/plugins/litclaude/lib/lit-activation.mjs +24 -10
- package/plugins/litclaude/lib/mod/frame.mjs +235 -49
- 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 +167 -25
- package/plugins/litclaude/lib/mod/timeline.mjs +28 -5
- package/plugins/litclaude/lib/mod/toasts.mjs +5 -2
- package/plugins/litclaude/lib/mod/view.mjs +240 -6
- 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/brief.mjs +370 -0
- package/plugins/litclaude/lib/rewind/collect.mjs +413 -0
- package/plugins/litclaude/lib/rewind/gauge.mjs +87 -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/suggest.mjs +51 -0
- package/plugins/litclaude/lib/rewind/transcripts.mjs +259 -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 +18 -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/production-interview.md +1 -1
- 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 +168 -0
- package/plugins/litclaude/skills/lit-adhd/references/card-examples.md +125 -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 +17 -5
- 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-docx/SKILL.md +6 -1
- package/plugins/litclaude/skills/lit-docx/references/direction-step.md +8 -4
- package/plugins/litclaude/skills/lit-handoff/SKILL.md +2 -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 +35 -15
- 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 +23 -4
- 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 +4 -0
- package/plugins/litclaude/skills/lit-schematic/SKILL.md +123 -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 +54 -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/SKILL.md +10 -0
- package/plugins/litclaude/skills/readme-studio/references/production-interview.md +2 -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,413 @@
|
|
|
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 { renderBrief } from "./brief.mjs";
|
|
15
|
+
import { aggregateProgress, clipToWidth, displayWidth, progressOf } from "./gauge.mjs";
|
|
16
|
+
import { chooseNextStep, writeNextStep } from "./next-step.mjs";
|
|
17
|
+
import { makeRedactor } from "./redact.mjs";
|
|
18
|
+
import { findTranscripts, makeBudget, readTranscriptLines, sessionRecord } from "./transcripts.mjs";
|
|
19
|
+
|
|
20
|
+
const SMALL_FILE_BYTES = 1024 * 1024;
|
|
21
|
+
const HERDR_TIMEOUT_MS = 2000;
|
|
22
|
+
const GIT_TIMEOUT_MS = 5000;
|
|
23
|
+
const DEFAULT_SINCE = "7d";
|
|
24
|
+
const DEFAULT_MAX = 12;
|
|
25
|
+
const NAME_MAX = 90;
|
|
26
|
+
const PLAN_LIMIT = 8;
|
|
27
|
+
|
|
28
|
+
/** `7d`, `12h`, `30m` in milliseconds, or null. */
|
|
29
|
+
export const parseSince = (text) => {
|
|
30
|
+
const match = /^(\d{1,4})([dhm])$/u.exec(String(text ?? ""));
|
|
31
|
+
if (!match) return null;
|
|
32
|
+
return Number(match[1]) * { d: 86_400_000, h: 3_600_000, m: 60_000 }[match[2]];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const readSmallFile = (path, budget) => {
|
|
36
|
+
let fd;
|
|
37
|
+
try {
|
|
38
|
+
if (!lstatSync(path).isFile()) return null;
|
|
39
|
+
fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
40
|
+
const { size } = fstatSync(fd);
|
|
41
|
+
const length = Math.min(size, SMALL_FILE_BYTES, budget.limit - budget.used);
|
|
42
|
+
if (length < size) budget.exhausted = budget.exhausted || length < Math.min(size, SMALL_FILE_BYTES);
|
|
43
|
+
const buffer = Buffer.alloc(Math.max(0, length));
|
|
44
|
+
const read = length > 0 ? readSync(fd, buffer, 0, length, 0) : 0;
|
|
45
|
+
budget.used += read;
|
|
46
|
+
return buffer.subarray(0, read).toString("utf8");
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
} finally {
|
|
50
|
+
if (fd !== undefined) closeSync(fd);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const readJson = (path, budget) => {
|
|
54
|
+
const text = readSmallFile(path, budget);
|
|
55
|
+
if (text === null) return null;
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(text);
|
|
58
|
+
} catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const entries = (directory) => {
|
|
63
|
+
try {
|
|
64
|
+
return readdirSync(directory, { withFileTypes: true });
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const defaultExec = (file, args, options) => execFileSync(file, args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], ...options });
|
|
71
|
+
|
|
72
|
+
const worktreesOf = (cwd, exec) => {
|
|
73
|
+
try {
|
|
74
|
+
const out = exec("git", ["worktree", "list", "--porcelain"], { cwd, timeout: GIT_TIMEOUT_MS });
|
|
75
|
+
const paths = out.split("\n").filter((line) => line.startsWith("worktree ")).map((line) => line.slice(9).trim()).filter(Boolean);
|
|
76
|
+
return paths.length ? paths : null;
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// A plan scaffold nobody filled in: a row that is still a `<placeholder>`, or every row the same.
|
|
83
|
+
const isTemplate = (rows) => rows.some((row) => /<[^<>]{1,40}>/u.test(row.text)) || (rows.length > 1 && new Set(rows.map((row) => row.text.trim())).size === 1);
|
|
84
|
+
const mtimeOf = (path) => {
|
|
85
|
+
try {
|
|
86
|
+
return lstatSync(path).mtimeMs;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const plansIn = (root, budget, redact, local) => {
|
|
93
|
+
const list = entries(join(root, "plans"));
|
|
94
|
+
if (!list) return null;
|
|
95
|
+
return list.filter((entry) => entry.isFile() && entry.name.endsWith(".md")).sort((a, b) => a.name.localeCompare(b.name)).flatMap((entry) => {
|
|
96
|
+
const text = readSmallFile(join(root, "plans", entry.name), budget);
|
|
97
|
+
if (text === null) return [];
|
|
98
|
+
const rows = parsePlanTaskRows(text);
|
|
99
|
+
if (!rows.length || isTemplate(rows)) return [];
|
|
100
|
+
const open = rows.filter((row) => !row.checked);
|
|
101
|
+
if (!open.length) return [];
|
|
102
|
+
const done = rows.length - open.length;
|
|
103
|
+
return [{
|
|
104
|
+
worktree: redact(root),
|
|
105
|
+
plan: `plans/${entry.name}`,
|
|
106
|
+
local,
|
|
107
|
+
changedMs: mtimeOf(join(root, "plans", entry.name)),
|
|
108
|
+
rows: rows.map((row) => ({ checked: row.checked, title: redact(clipToWidth(row.text, NAME_MAX)) })),
|
|
109
|
+
current: redact(clipToWidth(open[0].text, NAME_MAX)),
|
|
110
|
+
progress: progressOf(done, rows.length, open.map((row) => redact(clipToWidth(row.text, NAME_MAX)))),
|
|
111
|
+
}];
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const litgoalOf = (root, budget, redact) => {
|
|
116
|
+
const goals = readJson(join(root, ".litclaude", "litgoal", "goals.json"), budget);
|
|
117
|
+
if (!goals || !Array.isArray(goals.criteria)) return null;
|
|
118
|
+
const passed = goals.criteria.filter((criterion) => criterion?.status === "passed");
|
|
119
|
+
const remaining = goals.criteria.filter((criterion) => criterion?.status !== "passed").map((criterion) => redact(clipToWidth(String(criterion?.description ?? criterion?.id ?? "unknown"), NAME_MAX)));
|
|
120
|
+
return {
|
|
121
|
+
worktree: redact(root),
|
|
122
|
+
status: typeof goals.status === "string" ? goals.status : "unknown",
|
|
123
|
+
objective: redact(clipToWidth(String(goals.objective ?? "unknown").split("\n")[0], 120)),
|
|
124
|
+
progress: progressOf(passed.length, goals.criteria.length, remaining),
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const handoffsOf = (root, budget, redact) => (entries(root) ?? [])
|
|
129
|
+
.filter((entry) => entry.isFile() && /^HANDOFF.*\.md$/u.test(entry.name))
|
|
130
|
+
.map((entry) => {
|
|
131
|
+
const text = readSmallFile(join(root, entry.name), budget) ?? "";
|
|
132
|
+
const headings = text.split("\n").slice(0, 40).filter((line) => /^#{1,3} /u.test(line)).map((line) => redact(clipToWidth(line, 100)));
|
|
133
|
+
return { worktree: redact(root), file: entry.name, headings };
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const commitsOf = (root, sinceMs, now, exec, redact) => {
|
|
137
|
+
try {
|
|
138
|
+
const since = new Date(now - sinceMs).toISOString();
|
|
139
|
+
const branch = exec("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd: root, timeout: GIT_TIMEOUT_MS }).trim();
|
|
140
|
+
const out = exec("git", ["log", `--since=${since}`, "--max-count=20", "--format=%H%x09%cI%x09%s"], { cwd: root, timeout: GIT_TIMEOUT_MS });
|
|
141
|
+
return out.split("\n").filter(Boolean).map((line) => {
|
|
142
|
+
const [hash, at, ...subject] = line.split("\t");
|
|
143
|
+
return { worktree: redact(root), branch: redact(branch), hash: hash.slice(0, 7), at, atMs: Date.parse(at), subject: redact(clipToWidth(subject.join("\t"), 100)) };
|
|
144
|
+
});
|
|
145
|
+
} catch {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const stacksOf = (root, budget, redact) => {
|
|
151
|
+
const directory = join(root, ".litclaude", "workflow-stack");
|
|
152
|
+
const list = entries(directory);
|
|
153
|
+
if (!list) return null;
|
|
154
|
+
return list.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).flatMap((entry) => {
|
|
155
|
+
const stack = readJson(join(directory, entry.name), budget);
|
|
156
|
+
if (!stack || !Array.isArray(stack.frames)) return [];
|
|
157
|
+
return stack.frames.slice(0, 3).map((frame) => ({
|
|
158
|
+
worktree: redact(root),
|
|
159
|
+
sessionId: typeof stack.sessionId === "string" ? stack.sessionId : null,
|
|
160
|
+
id8: typeof stack.sessionId === "string" ? stack.sessionId.slice(0, 8) : "unknown",
|
|
161
|
+
skill: typeof frame.skill === "string" ? frame.skill : "unknown",
|
|
162
|
+
stage: typeof frame.stage === "string" ? frame.stage : "unknown",
|
|
163
|
+
role: frame.role === "spine" ? "spine" : "side",
|
|
164
|
+
status: frame.status === "paused" ? "paused" : "active",
|
|
165
|
+
at: typeof frame.at === "string" ? frame.at : "unknown",
|
|
166
|
+
progress: progressOf(frame.n, frame.total, Array.isArray(frame.remaining) ? frame.remaining.map((name) => redact(clipToWidth(String(name), NAME_MAX))) : undefined),
|
|
167
|
+
}));
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const startWorkOf = (root, budget, redact) => {
|
|
172
|
+
const state = readJson(join(root, ".litclaude", "boulder.json"), budget);
|
|
173
|
+
if (!state || typeof state.works !== "object" || state.works === null) return null;
|
|
174
|
+
const work = state.active_work_id ? state.works[state.active_work_id] : null;
|
|
175
|
+
if (!work) return [];
|
|
176
|
+
// The plan's own checkboxes are current; the stored snapshot only moves at a Stop.
|
|
177
|
+
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;
|
|
178
|
+
const rows = planText === null ? [] : parsePlanTaskRows(planText);
|
|
179
|
+
const open = rows.filter((row) => !row.checked);
|
|
180
|
+
const progress = rows.length
|
|
181
|
+
? progressOf(rows.length - open.length, rows.length, open.map((row) => redact(clipToWidth(row.text, NAME_MAX))))
|
|
182
|
+
: progressOf(work.progress?.checked, work.progress?.total, work.progress?.next_task ? [redact(clipToWidth(work.progress.next_task, NAME_MAX))] : undefined);
|
|
183
|
+
return [{
|
|
184
|
+
worktree: redact(root),
|
|
185
|
+
workId: work.work_id,
|
|
186
|
+
plan: typeof work.plan_name === "string" ? `plans/${work.plan_name}` : "unknown",
|
|
187
|
+
status: work.status,
|
|
188
|
+
sessionId: work.root_session_id ?? null,
|
|
189
|
+
id8: typeof work.root_session_id === "string" ? work.root_session_id.slice(0, 8) : "unknown",
|
|
190
|
+
...(work.pending_boundary ? { pendingBoundary: { action: work.pending_boundary.action, root: redact(work.pending_boundary.root) } } : {}),
|
|
191
|
+
progress,
|
|
192
|
+
}];
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const herdrOf = (env, exec, redact) => {
|
|
196
|
+
if (env.HERDR_ENV !== "1") return { status: "unknown", agents: [] };
|
|
197
|
+
try {
|
|
198
|
+
const out = exec("herdr", ["agent", "list"], { timeout: HERDR_TIMEOUT_MS });
|
|
199
|
+
return { status: "ok", agents: out.split("\n").filter((line) => line.trim()).slice(0, 20).map((line) => redact(clipToWidth(line.trim(), 120))) };
|
|
200
|
+
} catch {
|
|
201
|
+
return { status: "unknown", agents: [] };
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const known = (list) => (list === null ? "unknown" : "ok");
|
|
206
|
+
const statusRank = { "waiting-on-user": 0, active: 1, ended: 2, unknown: 3 };
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Collects the brief. Options: `cwd`, `here` (cwd only), `since` (`7d`), `max` (12), `sessionId`
|
|
210
|
+
* (this session, for the next step and waiting state), `env`, `now`, `exec` (git/herdr runner).
|
|
211
|
+
*/
|
|
212
|
+
export const collectRewind = ({
|
|
213
|
+
cwd = process.cwd(),
|
|
214
|
+
here = false,
|
|
215
|
+
since = DEFAULT_SINCE,
|
|
216
|
+
max = DEFAULT_MAX,
|
|
217
|
+
sessionId = null,
|
|
218
|
+
env = process.env,
|
|
219
|
+
now = Date.now(),
|
|
220
|
+
exec = defaultExec,
|
|
221
|
+
record = true,
|
|
222
|
+
} = {}) => {
|
|
223
|
+
const home = env.HOME || homedir();
|
|
224
|
+
const redact = makeRedactor({ env, home });
|
|
225
|
+
const budget = makeBudget();
|
|
226
|
+
const sinceMs = parseSince(since) ?? parseSince(DEFAULT_SINCE);
|
|
227
|
+
const limit = Number.isInteger(max) && max > 0 ? Math.min(max, 50) : DEFAULT_MAX;
|
|
228
|
+
const start = resolve(cwd);
|
|
229
|
+
const stateRoot = resolveProjectStateRoot(start);
|
|
230
|
+
const listed = here ? null : worktreesOf(start, exec);
|
|
231
|
+
const roots = [...new Set([start, ...(here ? [] : listed ?? [stateRoot])])];
|
|
232
|
+
|
|
233
|
+
const transcripts = findTranscripts(env.CLAUDE_CONFIG_DIR || join(home, ".claude"), roots);
|
|
234
|
+
const sessions = [];
|
|
235
|
+
for (const file of transcripts.files) {
|
|
236
|
+
if (sessions.length >= limit || budget.exhausted) break;
|
|
237
|
+
const lines = readTranscriptLines(file, budget);
|
|
238
|
+
const session = lines ? sessionRecord(lines, { redact, now }) : null;
|
|
239
|
+
if (!session || (session.lastMs !== null && now - session.lastMs > sinceMs)) continue;
|
|
240
|
+
if (here && session.cwd && resolve(session.cwd).normalize("NFC") !== start.normalize("NFC")) continue;
|
|
241
|
+
sessions.push(session);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const collectEach = (read) => {
|
|
245
|
+
const results = roots.map(read);
|
|
246
|
+
return results.every((value) => value === null) ? null : results.flatMap((value) => value ?? []);
|
|
247
|
+
};
|
|
248
|
+
const plans = collectEach((root) => plansIn(root, budget, redact, resolve(root) === stateRoot || resolve(root) === start));
|
|
249
|
+
const litgoal = collectEach((root) => {
|
|
250
|
+
const goal = litgoalOf(root, budget, redact);
|
|
251
|
+
return goal ? [{ ...goal, local: resolve(root) === stateRoot || resolve(root) === start }] : null;
|
|
252
|
+
});
|
|
253
|
+
const handoffs = roots.flatMap((root) => handoffsOf(root, budget, redact));
|
|
254
|
+
const commits = collectEach((root) => commitsOf(root, sinceMs, now, exec, redact));
|
|
255
|
+
const workflows = collectEach((root) => stacksOf(root, budget, redact));
|
|
256
|
+
const startWork = collectEach((root) => startWorkOf(root, budget, redact));
|
|
257
|
+
const herdr = herdrOf(env, exec, redact);
|
|
258
|
+
|
|
259
|
+
// A session waits on the user when it asked something, or holds a paused frame or boundary.
|
|
260
|
+
for (const session of sessions) {
|
|
261
|
+
const frames = (workflows ?? []).filter((frame) => frame.sessionId === session.sessionId);
|
|
262
|
+
const top = frames.at(-1);
|
|
263
|
+
const work = (startWork ?? []).find((item) => item.sessionId === session.sessionId);
|
|
264
|
+
if (frames.some((frame) => frame.status === "paused") && session.status !== "waiting-on-user") {
|
|
265
|
+
session.status = "waiting-on-user";
|
|
266
|
+
session.waitingReason = "paused workflow";
|
|
267
|
+
}
|
|
268
|
+
if (work?.status === "paused") {
|
|
269
|
+
session.status = "waiting-on-user";
|
|
270
|
+
session.waitingReason = "start-work boundary";
|
|
271
|
+
}
|
|
272
|
+
session.progress = top?.progress ?? work?.progress ?? progressOf(null, null);
|
|
273
|
+
session.done.commits = (commits ?? [])
|
|
274
|
+
.filter((commit) => session.lastMs !== null && Date.parse(session.started) <= commit.atMs && commit.atMs <= session.lastMs + 5 * 60_000
|
|
275
|
+
&& (session.branch === "unknown" || commit.branch === session.branch))
|
|
276
|
+
.slice(0, 5)
|
|
277
|
+
.map(({ hash, subject }) => ({ hash, subject }));
|
|
278
|
+
}
|
|
279
|
+
sessions.sort((a, b) => statusRank[a.status] - statusRank[b.status] || (b.lastMs ?? 0) - (a.lastMs ?? 0));
|
|
280
|
+
|
|
281
|
+
// This worktree's open plans and the ones another worktree touched inside the window are listed,
|
|
282
|
+
// this one's first, then the most recently changed, up to a short cap; a stale plan elsewhere is
|
|
283
|
+
// left out entirely. The roadmap gauge counts this worktree only, since a sum over unrelated
|
|
284
|
+
// branches measures nothing.
|
|
285
|
+
const recent = (plan) => plan.local || (plan.changedMs !== null && now - plan.changedMs <= sinceMs);
|
|
286
|
+
const orderedPlans = (plans ?? []).filter(recent).sort((a, b) => Number(b.local) - Number(a.local) || (b.changedMs ?? 0) - (a.changedMs ?? 0));
|
|
287
|
+
const shownPlans = orderedPlans.slice(0, PLAN_LIMIT);
|
|
288
|
+
const localGoals = (litgoal ?? []).filter((goal) => goal.local);
|
|
289
|
+
const roadmapItems = [...orderedPlans.filter((plan) => plan.local).map((plan) => plan.progress), ...localGoals.map((goal) => goal.progress)];
|
|
290
|
+
const data = {
|
|
291
|
+
version: 1,
|
|
292
|
+
generatedAt: new Date(now).toISOString(),
|
|
293
|
+
scope: { here, since: sinceMs === parseSince(since) ? since : DEFAULT_SINCE, max: limit, worktrees: roots.map(redact) },
|
|
294
|
+
sources: {
|
|
295
|
+
transcripts: transcripts.status,
|
|
296
|
+
litgoal: known(litgoal),
|
|
297
|
+
plans: known(plans),
|
|
298
|
+
handoffs: handoffs.length ? "ok" : "unknown",
|
|
299
|
+
git: known(commits),
|
|
300
|
+
workflowStack: known(workflows),
|
|
301
|
+
startWork: known(startWork),
|
|
302
|
+
herdr: herdr.status,
|
|
303
|
+
},
|
|
304
|
+
budget: { bytesRead: budget.used, limit: budget.limit, exhausted: budget.exhausted },
|
|
305
|
+
summary: {
|
|
306
|
+
sessions: sessions.length,
|
|
307
|
+
waitingOnUser: sessions.filter((session) => session.status === "waiting-on-user").length,
|
|
308
|
+
active: sessions.filter((session) => session.status === "active").length,
|
|
309
|
+
},
|
|
310
|
+
sessions: sessions.map(({ cwd: _cwd, lastMs: _lastMs, sessionId: id, ...rest }) => ({ ...rest, self: Boolean(sessionId) && id === sessionId })),
|
|
311
|
+
roadmap: {
|
|
312
|
+
plans: shownPlans,
|
|
313
|
+
plansOmitted: orderedPlans.length - shownPlans.length,
|
|
314
|
+
// Another worktree's finished objective is history, not roadmap.
|
|
315
|
+
litgoal: (litgoal ?? []).filter((goal) => goal.local || goal.status !== "complete"),
|
|
316
|
+
progress: roadmapItems.length ? aggregateProgress(roadmapItems) : progressOf(null, null),
|
|
317
|
+
},
|
|
318
|
+
workflows: (workflows ?? []).map((frame) => ({ ...frame, self: Boolean(sessionId) && frame.sessionId === sessionId })),
|
|
319
|
+
startWork: startWork ?? [],
|
|
320
|
+
handoffs,
|
|
321
|
+
commits: (commits ?? []).slice(0, 20).map(({ atMs: _atMs, ...commit }) => commit),
|
|
322
|
+
herdr,
|
|
323
|
+
};
|
|
324
|
+
const next = chooseNextStep(data, sessionId);
|
|
325
|
+
data.next = next;
|
|
326
|
+
data.nextRecorded = false;
|
|
327
|
+
if (record && sessionId) {
|
|
328
|
+
try {
|
|
329
|
+
writeNextStep(stateRoot, sessionId, next, new Date(now));
|
|
330
|
+
data.nextRecorded = true;
|
|
331
|
+
} catch {
|
|
332
|
+
data.nextRecorded = false;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (const frame of data.workflows) delete frame.sessionId;
|
|
336
|
+
for (const work of data.startWork) delete work.sessionId;
|
|
337
|
+
return data;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const line = (text, width) => clipToWidth(text, width);
|
|
341
|
+
const remainingLine = (names, width) => {
|
|
342
|
+
if (!names.length || (names.length === 1 && names[0] === "unknown")) return null;
|
|
343
|
+
let out = " left:";
|
|
344
|
+
for (const [index, name] of names.entries()) {
|
|
345
|
+
const piece = ` ${name}${index < names.length - 1 ? "," : ""}`;
|
|
346
|
+
if (displayWidth(out + piece) > width - 4) return `${out} …(+${names.length - index})`;
|
|
347
|
+
out += piece;
|
|
348
|
+
}
|
|
349
|
+
return out;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// A gauge with its leading space, or nothing: an unknown total has no gauge to print.
|
|
353
|
+
const shown = (progress) => (progress?.gauge ? ` ${progress.gauge}` : "");
|
|
354
|
+
|
|
355
|
+
/** Plain-text rendering: every gauge with its remaining names under it, clipped to `width`. */
|
|
356
|
+
export const renderRewind = (data, width = 100) => {
|
|
357
|
+
const out = [];
|
|
358
|
+
const push = (text) => out.push(line(text, width));
|
|
359
|
+
push(`lit-adhd: ${data.summary.sessions} session(s), ${data.summary.waitingOnUser} waiting on you, ${data.summary.active} active`);
|
|
360
|
+
push(`roadmap here${shown(data.roadmap.progress)}`);
|
|
361
|
+
for (const plan of data.roadmap.plans) {
|
|
362
|
+
push(` ${plan.local ? "" : `${basename(plan.worktree)}: `}${plan.plan}${shown(plan.progress)} now: ${plan.current}`);
|
|
363
|
+
const left = remainingLine(plan.progress.remaining, width);
|
|
364
|
+
if (left) push(` ${left}`);
|
|
365
|
+
}
|
|
366
|
+
if (data.roadmap.plansOmitted) push(` …(+${data.roadmap.plansOmitted} more open plans)`);
|
|
367
|
+
for (const goal of data.roadmap.litgoal) push(` litgoal${shown(goal.progress)} ${goal.objective}`);
|
|
368
|
+
for (const session of data.sessions) {
|
|
369
|
+
push(`${session.id8} ${session.status}${shown(session.progress)} ${session.title}`);
|
|
370
|
+
const left = remainingLine(session.progress.remaining, width);
|
|
371
|
+
if (left) push(left);
|
|
372
|
+
}
|
|
373
|
+
for (const frame of data.workflows) push(` ${frame.id8} ${frame.skill} ${frame.stage} ${frame.status}${shown(frame.progress)}`);
|
|
374
|
+
push(`next: ${data.next.kind}${data.next.say ? ` (say "${data.next.say}")` : ""}`);
|
|
375
|
+
const unknown = Object.entries(data.sources).filter(([, status]) => status !== "ok").map(([name]) => name);
|
|
376
|
+
if (unknown.length) push(`unknown: ${unknown.join(", ")}`);
|
|
377
|
+
return `${out.join("\n")}\n`;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* `litclaude-ai rewind [--brief [--lang ko|en] | --json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]`.
|
|
382
|
+
* `--brief` prints the Markdown brief the lit-adhd skill copies; `--json` the data under it.
|
|
383
|
+
*/
|
|
384
|
+
export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, stdout = process.stdout, stderr = process.stderr } = {}) => {
|
|
385
|
+
const options = { cwd, env, here: false, since: DEFAULT_SINCE, max: DEFAULT_MAX, sessionId: env.CLAUDE_CODE_SESSION_ID || null };
|
|
386
|
+
let json = false;
|
|
387
|
+
let brief = false;
|
|
388
|
+
let lang = "en";
|
|
389
|
+
let width = Number(stdout.columns) || 100;
|
|
390
|
+
const usage = "Usage: litclaude-ai rewind [--brief [--lang ko|en] | --json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]";
|
|
391
|
+
if (args.some((arg) => arg === "--help" || arg === "-h")) {
|
|
392
|
+
stdout.write(`${usage}\n`);
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
396
|
+
const arg = args[index];
|
|
397
|
+
if (arg === "--json") json = true;
|
|
398
|
+
else if (arg === "--brief") brief = true;
|
|
399
|
+
else if (arg === "--lang" && ["ko", "en"].includes(args[index + 1])) lang = args[++index];
|
|
400
|
+
else if (arg === "--here") options.here = true;
|
|
401
|
+
else if (arg === "--since" && parseSince(args[index + 1])) options.since = args[++index];
|
|
402
|
+
else if (arg === "--max" && /^\d{1,2}$/u.test(args[index + 1] ?? "")) options.max = Number(args[++index]);
|
|
403
|
+
else if (arg === "--session" && /^[A-Za-z0-9._:-]{1,160}$/u.test(args[index + 1] ?? "")) options.sessionId = args[++index];
|
|
404
|
+
else if (arg === "--width" && /^\d{2,3}$/u.test(args[index + 1] ?? "")) width = Number(args[++index]);
|
|
405
|
+
else {
|
|
406
|
+
stderr.write(`litclaude-ai rewind: unknown argument ${JSON.stringify(basename(String(arg)))}. ${usage}\n`);
|
|
407
|
+
return 64;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const data = collectRewind(options);
|
|
411
|
+
stdout.write(json ? `${JSON.stringify(data, null, 2)}\n` : brief ? renderBrief(data, { lang }) : renderRewind(data, width));
|
|
412
|
+
return 0;
|
|
413
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Progress gauges for the lit-adhd brief and the LIT card (plans/lit-adhd.md D9). Code draws them so
|
|
2
|
+
// the model copies them and never invents its own: `[▉▉▉░░] 3/5`, one cell per item up to ten, scaled
|
|
3
|
+
// to ten cells above that. A gauge needs two real numbers; with either missing there is no gauge, and
|
|
4
|
+
// the reader gets what is known in words instead (knownFacts).
|
|
5
|
+
|
|
6
|
+
const MAX_CELLS = 10;
|
|
7
|
+
const known = (value) => Number.isInteger(value) && value >= 0;
|
|
8
|
+
|
|
9
|
+
/** `[▉▉▉░░] 3/5`, or null unless both the count and a total above zero are known. */
|
|
10
|
+
export const gauge = (done, total) => {
|
|
11
|
+
if (!known(total) || total === 0 || !known(done)) return null;
|
|
12
|
+
const k = Math.min(done, total);
|
|
13
|
+
const cells = Math.min(total, MAX_CELLS);
|
|
14
|
+
let filled = k;
|
|
15
|
+
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)));
|
|
16
|
+
return `[${"▉".repeat(filled)}${"░".repeat(cells - filled)}] ${k}/${total}`;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const duration = (ms) => {
|
|
20
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
21
|
+
if (seconds < 60) return `${seconds}s`;
|
|
22
|
+
const minutes = Math.floor(seconds / 60);
|
|
23
|
+
if (minutes < 60) return `${minutes}m`;
|
|
24
|
+
const hours = Math.floor(minutes / 60);
|
|
25
|
+
return minutes % 60 ? `${hours}h ${minutes % 60}m` : `${hours}h`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* What is known of a thread whose total is not: `12 steps · 4m · last: Edit README.md`, or with no
|
|
30
|
+
* steps `running 4m` (`paused 4m`, …, by `state`), or the state word alone.
|
|
31
|
+
*/
|
|
32
|
+
export const knownFacts = ({ steps = null, elapsedMs = null, last = null, state = "running" } = {}) => {
|
|
33
|
+
const time = Number.isFinite(elapsedMs) && elapsedMs >= 0 ? duration(elapsedMs) : null;
|
|
34
|
+
if (!(known(steps) && steps > 0)) return time ? `${state} ${time}` : state;
|
|
35
|
+
return [`${steps} ${steps === 1 ? "step" : "steps"}`, time, last ? `last: ${last}` : null].filter(Boolean).join(" · ");
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** `{done, total, gauge, remaining}`; `gauge` is null without two real numbers, `remaining` as recorded or `["unknown"]`. */
|
|
39
|
+
export const progressOf = (done, total, remaining) => ({
|
|
40
|
+
done: known(done) ? done : null,
|
|
41
|
+
total: known(total) ? total : null,
|
|
42
|
+
gauge: gauge(done, total),
|
|
43
|
+
remaining: Array.isArray(remaining) && remaining.length ? remaining : known(total) && known(done) && done >= total ? [] : ["unknown"],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/** One gauge over several: the sum of known totals, or no gauge when any total is unknown. */
|
|
47
|
+
export const aggregateProgress = (items) => {
|
|
48
|
+
const done = items.reduce((sum, item) => sum + (known(item.done) ? item.done : 0), 0);
|
|
49
|
+
const total = items.every((item) => known(item.total)) ? items.reduce((sum, item) => sum + item.total, 0) : null;
|
|
50
|
+
return { done, total, gauge: gauge(done, total) };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Terminal columns a character takes: combining marks and Hangul medial/final jamo take none, East
|
|
54
|
+
// Asian wide and fullwidth characters and most emoji take two.
|
|
55
|
+
const charWidth = (codePoint) => {
|
|
56
|
+
if (codePoint === 0 || codePoint < 32 || (codePoint >= 0x7f && codePoint < 0xa0)) return 0;
|
|
57
|
+
if (/\p{Mn}|\p{Me}|\p{Cf}/u.test(String.fromCodePoint(codePoint)) || (codePoint >= 0x1160 && codePoint <= 0x11ff)) return 0;
|
|
58
|
+
if (
|
|
59
|
+
(codePoint >= 0x1100 && codePoint <= 0x115f)
|
|
60
|
+
|| (codePoint >= 0x2e80 && codePoint <= 0xa4cf)
|
|
61
|
+
|| (codePoint >= 0xac00 && codePoint <= 0xd7a3)
|
|
62
|
+
|| (codePoint >= 0xf900 && codePoint <= 0xfaff)
|
|
63
|
+
|| (codePoint >= 0xfe30 && codePoint <= 0xfe4f)
|
|
64
|
+
|| (codePoint >= 0xff00 && codePoint <= 0xff60)
|
|
65
|
+
|| (codePoint >= 0xffe0 && codePoint <= 0xffe6)
|
|
66
|
+
|| (codePoint >= 0x1f300 && codePoint <= 0x1faff)
|
|
67
|
+
|| (codePoint >= 0x20000 && codePoint <= 0x3fffd)
|
|
68
|
+
) return 2;
|
|
69
|
+
return 1;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const displayWidth = (text) => [...String(text)].reduce((sum, ch) => sum + charWidth(ch.codePointAt(0)), 0);
|
|
73
|
+
|
|
74
|
+
/** Clips to `width` display columns, ending in `…` when anything was cut. */
|
|
75
|
+
export const clipToWidth = (text, width) => {
|
|
76
|
+
const value = String(text);
|
|
77
|
+
if (displayWidth(value) <= width) return value;
|
|
78
|
+
let out = "";
|
|
79
|
+
let used = 0;
|
|
80
|
+
for (const ch of value) {
|
|
81
|
+
const w = charWidth(ch.codePointAt(0));
|
|
82
|
+
if (used + w > width - 1) break;
|
|
83
|
+
out += ch;
|
|
84
|
+
used += w;
|
|
85
|
+
}
|
|
86
|
+
return `${out}…`;
|
|
87
|
+
};
|
|
@@ -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
|
+
};
|