@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
2
3
|
import {
|
|
3
4
|
appendFileSync,
|
|
4
5
|
closeSync,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
lstatSync,
|
|
10
11
|
mkdirSync,
|
|
11
12
|
openSync,
|
|
13
|
+
readdirSync,
|
|
12
14
|
readFileSync,
|
|
13
15
|
realpathSync,
|
|
14
16
|
renameSync,
|
|
@@ -178,7 +180,7 @@ const canonicalDirectory = (path, label) => {
|
|
|
178
180
|
}
|
|
179
181
|
if (stats.isSymbolicLink()) throw new StartWorkLifecycleError(`${label} must not be a symbolic link`);
|
|
180
182
|
if (!stats.isDirectory()) throw new StartWorkLifecycleError(`${label} must be a directory`);
|
|
181
|
-
return realpathSync(requested);
|
|
183
|
+
return realpathSync(requested).normalize("NFC");
|
|
182
184
|
};
|
|
183
185
|
|
|
184
186
|
const canonicalTarget = (path, label) => {
|
|
@@ -189,10 +191,10 @@ const canonicalTarget = (path, label) => {
|
|
|
189
191
|
if (parent === existing) throw new StartWorkLifecycleError(`${label} has no existing canonical ancestor`);
|
|
190
192
|
existing = parent;
|
|
191
193
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
// A linked ancestor (macOS `/tmp`, `/var`) resolves to where it points; the grant check then
|
|
195
|
+
// judges that real place, so a link cannot carry a path out of the grants.
|
|
194
196
|
const canonicalExisting = realpathSync(existing);
|
|
195
|
-
return resolve(canonicalExisting, relative(existing, requested));
|
|
197
|
+
return resolve(canonicalExisting, relative(existing, requested)).normalize("NFC");
|
|
196
198
|
};
|
|
197
199
|
|
|
198
200
|
const canonicalPlan = (root, plan) => {
|
|
@@ -208,8 +210,10 @@ const canonicalPlan = (root, plan) => {
|
|
|
208
210
|
return realpathSync(requested);
|
|
209
211
|
};
|
|
210
212
|
|
|
213
|
+
// APFS looks names up regardless of Unicode normalization, so `챌린지` typed (NFC) and stored (NFD)
|
|
214
|
+
// are one folder; both sides compare in NFC.
|
|
211
215
|
const rootCovers = (grantRoot, requestedRoot) => {
|
|
212
|
-
const path = relative(grantRoot, requestedRoot);
|
|
216
|
+
const path = relative(grantRoot.normalize("NFC"), requestedRoot.normalize("NFC"));
|
|
213
217
|
return path === "" || (!path.startsWith("..") && !isAbsolute(path));
|
|
214
218
|
};
|
|
215
219
|
|
|
@@ -473,6 +477,19 @@ export const readPlanProgress = (planPath) => {
|
|
|
473
477
|
};
|
|
474
478
|
|
|
475
479
|
const parseGrant = (root, raw, index) => {
|
|
480
|
+
if (raw && typeof raw === "object") {
|
|
481
|
+
const action = normalizeAction(raw.action);
|
|
482
|
+
const grantRoot = canonicalDirectory(raw.root, "grant root");
|
|
483
|
+
return {
|
|
484
|
+
grant_id: `grant-${shortHash(`${index}:${action}:${grantRoot}`)}`,
|
|
485
|
+
boundary_id: `boundary-${shortHash(`${action}:${grantRoot}`)}`,
|
|
486
|
+
action,
|
|
487
|
+
root: grantRoot,
|
|
488
|
+
issued_by: typeof raw.issuedBy === "string" ? raw.issuedBy : "approved-init",
|
|
489
|
+
issued_at: nowIso(),
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
if (typeof raw !== "string") throw new StartWorkLifecycleError("grant must be action:path", 64);
|
|
476
493
|
const separator = raw.indexOf(":");
|
|
477
494
|
if (separator <= 0 || separator === raw.length - 1) throw new StartWorkLifecycleError("grant must be action:path", 64);
|
|
478
495
|
const action = normalizeAction(raw.slice(0, separator));
|
|
@@ -558,6 +575,8 @@ export const initializeStartWork = (root, request) => withLock(root, () => {
|
|
|
558
575
|
authority: {
|
|
559
576
|
envelope_id: `authority-${shortHash(`${request.workId}:${authorityRoot}:${JSON.stringify(grants)}`)}`,
|
|
560
577
|
authority_root: authorityRoot,
|
|
578
|
+
issued_by: request.issuedBy === "user-invocation" ? "user-invocation" : "agent-init",
|
|
579
|
+
origin_prompt_id: typeof request.originPromptId === "string" ? request.originPromptId : null,
|
|
561
580
|
authority_roots: [...new Set([authorityRoot, ...grants.map(({ root: grantRoot }) => grantRoot)])],
|
|
562
581
|
cwd_root: canonicalCwd,
|
|
563
582
|
plan_root: planRoot,
|
|
@@ -565,6 +584,7 @@ export const initializeStartWork = (root, request) => withLock(root, () => {
|
|
|
565
584
|
effective_worktree_root: effectiveWorktree,
|
|
566
585
|
grants,
|
|
567
586
|
consumed_grants: [],
|
|
587
|
+
denied_boundaries: [],
|
|
568
588
|
resume_token_receipts: [],
|
|
569
589
|
forbidden_actions: [...forbiddenActions].sort(),
|
|
570
590
|
},
|
|
@@ -1041,6 +1061,11 @@ const classifyBashWords = (words, cwd) => {
|
|
|
1041
1061
|
if (rest[0] === "workflow-stage" && rest.every((word) => !word.includes("/"))) {
|
|
1042
1062
|
return movesLifecycle([cwd, ...cli], "write");
|
|
1043
1063
|
}
|
|
1064
|
+
// lit-adhd's collector only reads records; its one write is this session's own next-step note
|
|
1065
|
+
// under .litclaude/adhd, so it is a read for the owner and for every other session.
|
|
1066
|
+
if (trusted && rest[0] === "rewind" && rest.slice(1).every((word) => PLAIN_ARG.test(word))) {
|
|
1067
|
+
return canonicalBashTargets(cwd, [], "read");
|
|
1068
|
+
}
|
|
1044
1069
|
// The lifecycle's own moves for the active work write its state under the project's .litclaude
|
|
1045
1070
|
// directory. `init` declares grants and `--root` points at another lifecycle, so neither passes.
|
|
1046
1071
|
if (rest[0] === "start-work" && START_WORK_SELF_MOVES.has(rest[1]) && !rest.includes("--root") && rest.every((word) => !word.includes("/"))) {
|
|
@@ -1055,6 +1080,9 @@ const classifyBashWords = (words, cwd) => {
|
|
|
1055
1080
|
return movesLifecycle([cwd, ...cli], "write");
|
|
1056
1081
|
}
|
|
1057
1082
|
}
|
|
1083
|
+
if (head.text === "node" && args[0] && isOwnRewindScript(args[0].text, cwd) && args.slice(1).every(({ text }) => PLAIN_ARG.test(text))) {
|
|
1084
|
+
return canonicalBashTargets(cwd, [], "read");
|
|
1085
|
+
}
|
|
1058
1086
|
if (head.text === "node") return classifyNodeScriptWords(args, cwd);
|
|
1059
1087
|
return null;
|
|
1060
1088
|
};
|
|
@@ -1114,7 +1142,42 @@ const classifyBash = (command, cwd) => {
|
|
|
1114
1142
|
return { chain };
|
|
1115
1143
|
};
|
|
1116
1144
|
|
|
1117
|
-
|
|
1145
|
+
// `env -u NAME…` only removes variables, `2>&1` only joins the streams, and a trailing filter
|
|
1146
|
+
// (`| tail -8`, `| grep -c ok`, `| wc -l`) only reads the output: each is peeled off before the
|
|
1147
|
+
// command under it is classified. An assignment, a file operand or any other pipe stays put.
|
|
1148
|
+
const ENV_UNSET = /^env(?:[ \t]+-u[ \t]+[A-Za-z_][A-Za-z0-9_]*)+[ \t]+(?=\S)/u;
|
|
1149
|
+
// Each filter takes only flags that read stdin and print: no `-f` pattern file, no `-o` output file.
|
|
1150
|
+
const FILTER_PIPE = /[ \t]*\|[ \t]*(?:(?:tail|head)(?:[ \t]+-[nc][ \t]+\d+|[ \t]+-\d+|[ \t]+-q)*|wc(?:[ \t]+-[lwcm]+)*|sort(?:[ \t]+-[unrb]+)*|grep(?:[ \t]+-[cvinlEFwxq]+)*[ \t]+[A-Za-z0-9_.:-]+)[ \t]*$/u;
|
|
1151
|
+
const STDERR_JOIN = /[ \t]+2>&1(?=[ \t]*$)/u;
|
|
1152
|
+
const peelShellNoise = (segment) => {
|
|
1153
|
+
let text = segment.replace(ENV_UNSET, "");
|
|
1154
|
+
for (let guard = 0; guard < 4 && FILTER_PIPE.test(text); guard += 1) text = text.replace(FILTER_PIPE, "");
|
|
1155
|
+
return text.replace(STDERR_JOIN, "").trim();
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
// `npx <bin>` runs a tool the project declared: a dependency name in its package.json or a binary
|
|
1159
|
+
// its install linked under node_modules/.bin. Its words stay plain (no path, no expansion).
|
|
1160
|
+
const declaredNpxBin = (cwd, name) => {
|
|
1161
|
+
try {
|
|
1162
|
+
const manifest = JSON.parse(readFileSync(join(cwd, "package.json"), "utf8"));
|
|
1163
|
+
const declared = { ...manifest?.dependencies, ...manifest?.devDependencies };
|
|
1164
|
+
return Object.hasOwn(declared, name) || existsSync(join(cwd, "node_modules", ".bin", name));
|
|
1165
|
+
} catch {
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
const PLAIN_ARG = /^-{0,2}[A-Za-z0-9][\w.:=-]*$/u;
|
|
1170
|
+
|
|
1171
|
+
// A quoted word with no space, glob, expansion or operator in it means the same word unquoted, so
|
|
1172
|
+
// `ls "<dir>"` is classified as `ls <dir>`. Anything else inside quotes keeps the old deny.
|
|
1173
|
+
const DEQUOTED_WORD = /^[^\s;&|<>()`$\\*?[\]{}~#'"!]+$/u;
|
|
1174
|
+
const classifyBashSegment = (raw, cwd) => {
|
|
1175
|
+
const trimmed = peelShellNoise(raw);
|
|
1176
|
+
if (!trimmed) return pathArgumentDenied;
|
|
1177
|
+
if (/["']/u.test(trimmed)) {
|
|
1178
|
+
const plain = shellWords(trimmed)?.map(({ text }) => text);
|
|
1179
|
+
if (plain?.every((word) => DEQUOTED_WORD.test(word))) return classifyBashSegment(plain.join(" "), cwd);
|
|
1180
|
+
}
|
|
1118
1181
|
const relocated = classifyRelocatedGit(trimmed, cwd);
|
|
1119
1182
|
if (relocated) return relocated;
|
|
1120
1183
|
if (relocationPatternFor(trimmed).test(trimmed)) return { denied: "Bash relocation flags are not authorized" };
|
|
@@ -1152,6 +1215,32 @@ const classifyBashSegment = (trimmed, cwd) => {
|
|
|
1152
1215
|
return canonicalBashTargets(cwd, [find[1]], "read");
|
|
1153
1216
|
}
|
|
1154
1217
|
if (trimmed === "pwd") return canonicalBashTargets(cwd, [], "read");
|
|
1218
|
+
const mkdir = /^mkdir[ \t]+-p[ \t]+(.+)$/u.exec(trimmed);
|
|
1219
|
+
if (mkdir) {
|
|
1220
|
+
const targets = mkdir[1].split(/\s+/u);
|
|
1221
|
+
if (targets.some((target) => target.startsWith("-"))) return pathArgumentDenied;
|
|
1222
|
+
return canonicalBashTargets(cwd, targets, "write");
|
|
1223
|
+
}
|
|
1224
|
+
// `rm [-f] <file>…` removes regular files inside the write grant, such as a check script the work
|
|
1225
|
+
// wrote and no longer needs. A directory, a link, a missing target or any other flag stays refused.
|
|
1226
|
+
const rm = /^rm(?:[ \t]+-f)?[ \t]+(.+)$/u.exec(trimmed);
|
|
1227
|
+
if (rm) {
|
|
1228
|
+
const targets = rm[1].split(/\s+/u);
|
|
1229
|
+
if (targets.some((target) => target.startsWith("-"))) return pathArgumentDenied;
|
|
1230
|
+
try {
|
|
1231
|
+
if (!targets.every((target) => lstatSync(resolve(cwd, target)).isFile())) return pathArgumentDenied;
|
|
1232
|
+
} catch {
|
|
1233
|
+
return pathArgumentDenied;
|
|
1234
|
+
}
|
|
1235
|
+
return canonicalBashTargets(cwd, targets, "write");
|
|
1236
|
+
}
|
|
1237
|
+
const npx = /^npx[ \t]+((?:@[a-z0-9][\w-]*\/)?[a-z0-9][\w-]*)((?:[ \t]+\S+)*)$/u.exec(trimmed);
|
|
1238
|
+
if (npx) {
|
|
1239
|
+
const args = npx[2].trim() ? npx[2].trim().split(/\s+/u) : [];
|
|
1240
|
+
if (!declaredNpxBin(cwd, npx[1]) || !args.every((word) => PLAIN_ARG.test(word))) return { denied: "unclassified mutating Bash command" };
|
|
1241
|
+
return canonicalBashTargets(cwd, [], "test");
|
|
1242
|
+
}
|
|
1243
|
+
if (/^python3?[ \t]+-m[ \t]+pytest(?:[ \t]+-{1,2}[A-Za-z][\w-]*)*$/u.test(trimmed)) return canonicalBashTargets(cwd, [], "test");
|
|
1155
1244
|
const list = /^ls(?:\s+(.+))?$/u.exec(trimmed);
|
|
1156
1245
|
if (list) {
|
|
1157
1246
|
const targets = (list[1]?.split(/\s+/u) ?? []).filter((target) => !target.startsWith("-"));
|
|
@@ -1164,7 +1253,7 @@ const classifyBashSegment = (trimmed, cwd) => {
|
|
|
1164
1253
|
if (targets.some((target) => target.startsWith("-"))) return { denied: "unverified path-bearing Bash argument" };
|
|
1165
1254
|
return canonicalBashTargets(cwd, targets, "test");
|
|
1166
1255
|
}
|
|
1167
|
-
if (/^(?:
|
|
1256
|
+
if (/^(?:npm|pnpm|yarn)\s+(?:run\s+)?test$/iu.test(trimmed)) {
|
|
1168
1257
|
return canonicalBashTargets(cwd, [], "test");
|
|
1169
1258
|
}
|
|
1170
1259
|
if (/^(?:npm|pnpm|yarn)\s+(?:run\s+)?(?:build|check|lint|typecheck|validate|doctor|scan|qa)(?:[:\w-]*)?$/iu.test(trimmed)) {
|
|
@@ -1203,6 +1292,9 @@ const classifyToolAuthority = (root, input) => {
|
|
|
1203
1292
|
case "Bash": {
|
|
1204
1293
|
return classifyBash(toolInput.command, root);
|
|
1205
1294
|
}
|
|
1295
|
+
case "Skill":
|
|
1296
|
+
// Loading a skill only reads its text into the turn; what the skill does next is checked call by call.
|
|
1297
|
+
return lifecycleControl;
|
|
1206
1298
|
case "Agent": {
|
|
1207
1299
|
const explore = /^(?:Explore|Plan|litclaude:(?:lit-verifier|quality-reviewer|librarian-researcher))$/u.test(toolInput.subagent_type ?? "");
|
|
1208
1300
|
return { action: explore ? "read" : "execute", targetRoot: root };
|
|
@@ -1214,12 +1306,149 @@ const classifyToolAuthority = (root, input) => {
|
|
|
1214
1306
|
|
|
1215
1307
|
const denial = (reason) => ({ decision: "deny", reason });
|
|
1216
1308
|
|
|
1217
|
-
|
|
1309
|
+
// The bundled fallback of `litclaude-ai rewind`, inside this plugin only.
|
|
1310
|
+
const isOwnRewindScript = (path, cwd) => {
|
|
1311
|
+
if (!PLUGIN_ROOT) return false;
|
|
1312
|
+
try {
|
|
1313
|
+
return realpathSync(resolve(cwd, path)).normalize("NFC") === join(PLUGIN_ROOT, "skills", "lit-adhd", "scripts", "rewind.mjs");
|
|
1314
|
+
} catch {
|
|
1315
|
+
return false;
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
// A Bash shape the guard cannot verify is refused, not paused, so the refusal says what does run;
|
|
1320
|
+
// without it a session tried a script in the write-only temp folder and stopped. Forbidden actions
|
|
1321
|
+
// (push, publish, tag, reset) never get this note.
|
|
1322
|
+
const BASH_WAY_OUT = "This start-work guard verifies one plain command per Bash call: no `;`, `||`, `$`, backticks or quoted code, redirects only as `2>&1`, at most four plain commands joined by ` && `, and an optional trailing `| tail`, `head`, `grep`, `wc` or `sort` with flags only. Split the command into separate calls. To run code, write a script inside the project (the private temp folder is write-only) and run `node <script>`, then remove it. This is not an approval prompt; `lit approve` does not apply.";
|
|
1323
|
+
const bashDenial = (reason) => denial(`${reason}. ${BASH_WAY_OUT}`);
|
|
1324
|
+
|
|
1325
|
+
// The plugin this module ships in: reading its own skills, commands and references is never a
|
|
1326
|
+
// boundary. Writing there still is.
|
|
1327
|
+
const PLUGIN_ROOT = (() => {
|
|
1328
|
+
try {
|
|
1329
|
+
return realpathSync(fileURLToPath(new URL("..", import.meta.url))).normalize("NFC");
|
|
1330
|
+
} catch {
|
|
1331
|
+
return null;
|
|
1332
|
+
}
|
|
1333
|
+
})();
|
|
1334
|
+
const pluginSelfRead = (classified) => classified.action === "read" && PLUGIN_ROOT !== null
|
|
1335
|
+
&& (classified.targetRoots ?? [classified.targetRoot]).every((target) => rootCovers(PLUGIN_ROOT, target));
|
|
1336
|
+
|
|
1337
|
+
// What an approved boundary covers: a read reaches the target's folder, or the toplevel of another
|
|
1338
|
+
// git checkout the target sits in; a write reaches the target's folder only. The next file beside
|
|
1339
|
+
// the first then needs no second approval.
|
|
1340
|
+
const gitToplevel = (directory) => {
|
|
1341
|
+
for (let at = directory; ; at = dirname(at)) {
|
|
1342
|
+
if (existsSync(join(at, ".git"))) return at;
|
|
1343
|
+
if (dirname(at) === at) return null;
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
const boundaryRoot = (action, target, projectRoot) => {
|
|
1347
|
+
let directory = target;
|
|
1348
|
+
try {
|
|
1349
|
+
if (!lstatSync(target).isDirectory()) directory = dirname(target);
|
|
1350
|
+
} catch {
|
|
1351
|
+
directory = dirname(target);
|
|
1352
|
+
}
|
|
1353
|
+
if (action !== "read") return directory;
|
|
1354
|
+
const toplevel = gitToplevel(directory);
|
|
1355
|
+
return toplevel && !rootCovers(toplevel, projectRoot) && !rootCovers(projectRoot, toplevel) ? toplevel : directory;
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1358
|
+
// What the model reads when a tool call meets the pending boundary: the access asked for and the two
|
|
1359
|
+
// replies that settle it. The exact 5-ID resume route stays accepted but is no longer printed.
|
|
1360
|
+
const pausedMessage = (work) => {
|
|
1218
1361
|
const boundary = work.pending_boundary;
|
|
1219
|
-
return
|
|
1362
|
+
return boundary
|
|
1363
|
+
? `LitClaude start-work paused: ${boundary.action} access to ${boundary.root} is outside this plan's scope. Reply "lit approve" to allow it for this work, or "lit deny".`
|
|
1364
|
+
: "LitClaude start-work is paused. Reply \"lit approve\" or \"lit deny\".";
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
// A run is stale, and another session may take it over, once its owning session has ended or the
|
|
1368
|
+
// lifecycle has not been written for two hours (plans/lit-adhd.md D8).
|
|
1369
|
+
export const START_WORK_STALE_MS = 2 * 60 * 60 * 1000;
|
|
1370
|
+
const idleMs = (work, now) => Math.max(0, now - (Date.parse(work.updated_at) || now));
|
|
1371
|
+
const isStale = (work, now) => Boolean(work.root_session_ended_at) || idleMs(work, now) >= START_WORK_STALE_MS;
|
|
1372
|
+
const formatAge = (ms) => {
|
|
1373
|
+
const minutes = Math.floor(ms / 60_000);
|
|
1374
|
+
if (minutes < 1) return "under a minute";
|
|
1375
|
+
if (minutes < 60) return `${minutes} min`;
|
|
1376
|
+
const hours = Math.floor(minutes / 60);
|
|
1377
|
+
return minutes % 60 ? `${hours} h ${minutes % 60} min` : `${hours} h`;
|
|
1378
|
+
};
|
|
1379
|
+
const planRoute = (root, work) => {
|
|
1380
|
+
const path = relative(root, work.active_plan);
|
|
1381
|
+
return path.startsWith("..") || isAbsolute(path) ? work.active_plan : path;
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1384
|
+
// Another session in the project of a running work: reading, searching, read-only shell, loading a
|
|
1385
|
+
// skill, a read-type agent and the status call pass with a note; anything that changes files is
|
|
1386
|
+
// refused with the work, its age and the ways out. The owner's work never pauses for it.
|
|
1387
|
+
const STATUS_CALL = /^(?:litclaude-ai|litclaude)[ \t]+start-work[ \t]+status(?:[ \t]+--json)?$/u;
|
|
1388
|
+
const READ_ACTIONS = new Set(["read", "vcs-read"]);
|
|
1389
|
+
const otherSessionDecision = (root, work, input, now) => {
|
|
1390
|
+
const age = formatAge(idleMs(work, now));
|
|
1391
|
+
const toolName = input?.tool_name;
|
|
1392
|
+
let reads = toolName === "Skill" || (toolName === "Bash" && STATUS_CALL.test(String(input?.tool_input?.command ?? "").trim()));
|
|
1393
|
+
if (!reads) {
|
|
1394
|
+
try {
|
|
1395
|
+
const executionRoot = canonicalDirectory(typeof input.cwd === "string" ? input.cwd : root, "tool cwd");
|
|
1396
|
+
const classified = classifyToolAuthority(executionRoot, input);
|
|
1397
|
+
reads = !classified.denied && !classified.control
|
|
1398
|
+
&& (classified.chain ? classified.chain.every((link) => !link.control && READ_ACTIONS.has(link.action)) : READ_ACTIONS.has(classified.action));
|
|
1399
|
+
} catch {
|
|
1400
|
+
reads = false;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
if (reads) {
|
|
1404
|
+
return { decision: "allow-normal", action: "read", root, roots: [root], context: `Another session is running start-work ${work.work_id} here (last activity ${age} ago); you may read, not change files.` };
|
|
1405
|
+
}
|
|
1406
|
+
const route = `/litclaude:start-work ${planRoute(root, work)}`;
|
|
1407
|
+
const takeover = isStale(work, now)
|
|
1408
|
+
? `That session has ended or gone idle, so you can take the work over by typing ${route} here.`
|
|
1409
|
+
: `Once that session ends or sits idle for 2 hours, you can take it over by typing ${route} here.`;
|
|
1410
|
+
return denial(`LitClaude start-work ${work.work_id} (${work.plan_name}) belongs to another session in this project (last activity ${age} ago), so this session may read but not change files. It frees up when that session finishes the work. ${takeover}`);
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* A typed `/litclaude:start-work <plan>` from a session that does not own the running work: the
|
|
1415
|
+
* session takes the work over when it is stale and runs the same plan, keeping its grants.
|
|
1416
|
+
* Returns `{ adopted }`, `{ refused }` with a sentence to show, or null when there is nothing to
|
|
1417
|
+
* take over (no running work, or this session already owns it).
|
|
1418
|
+
*/
|
|
1419
|
+
export const adoptStartWork = (root, { sessionId, plan, promptId = null, now = Date.now() }) => {
|
|
1420
|
+
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
1421
|
+
if (!existsSync(startWorkStatePath(canonicalRoot))) return null;
|
|
1422
|
+
if (typeof sessionId !== "string" || !/^[A-Za-z0-9._:-]{1,160}$/u.test(sessionId)) return null;
|
|
1423
|
+
return withLock(canonicalRoot, () => {
|
|
1424
|
+
const state = readState(canonicalRoot);
|
|
1425
|
+
const work = state.active_work_id ? state.works[state.active_work_id] : null;
|
|
1426
|
+
if (!work || !["active", "paused"].includes(work.status) || work.root_session_id === sessionId) return null;
|
|
1427
|
+
let wanted;
|
|
1428
|
+
try {
|
|
1429
|
+
wanted = canonicalPlan(canonicalRoot, plan).normalize("NFC");
|
|
1430
|
+
} catch {
|
|
1431
|
+
return { refused: `start-work ${work.work_id} (${work.plan_name}) is running in another session; ${plan} was not found, so nothing was taken over.` };
|
|
1432
|
+
}
|
|
1433
|
+
if (wanted !== work.active_plan.normalize("NFC")) {
|
|
1434
|
+
return { refused: `start-work ${work.work_id} runs a different plan (${work.plan_name}) in another session; finish or cancel it before starting ${plan}.` };
|
|
1435
|
+
}
|
|
1436
|
+
if (!isStale(work, now)) {
|
|
1437
|
+
return { refused: `start-work ${work.work_id} (${work.plan_name}) is still running in another session (last activity ${formatAge(idleMs(work, now))} ago); it can be taken over once that session ends or sits idle for 2 hours.` };
|
|
1438
|
+
}
|
|
1439
|
+
const from = work.root_session_id;
|
|
1440
|
+
const fromAge = formatAge(idleMs(work, now));
|
|
1441
|
+
work.session_ids = [...new Set([...(work.session_ids ?? []), sessionId])];
|
|
1442
|
+
work.root_session_id = sessionId;
|
|
1443
|
+
work.active_session_id = sessionId;
|
|
1444
|
+
delete work.root_session_ended_at;
|
|
1445
|
+
appendEvent(state, work, "work.adopted", { from_session_id: from, from_age: fromAge, ...(promptId ? { origin_prompt_id: promptId } : {}) });
|
|
1446
|
+
saveState(canonicalRoot, state);
|
|
1447
|
+
return { adopted: { workId: work.work_id, plan: work.plan_name, fromAge } };
|
|
1448
|
+
});
|
|
1220
1449
|
};
|
|
1221
1450
|
|
|
1222
|
-
export const handleStartWorkPreToolUse = (root, input) => {
|
|
1451
|
+
export const handleStartWorkPreToolUse = (root, input, { now = Date.now() } = {}) => {
|
|
1223
1452
|
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
1224
1453
|
if (!existsSync(startWorkStatePath(canonicalRoot))) return { decision: "allow-normal" };
|
|
1225
1454
|
return withLock(canonicalRoot, () => {
|
|
@@ -1228,19 +1457,22 @@ export const handleStartWorkPreToolUse = (root, input) => {
|
|
|
1228
1457
|
const work = state.works[state.active_work_id];
|
|
1229
1458
|
if (!work || !["active", "paused"].includes(work.status)) return { decision: "allow-normal" };
|
|
1230
1459
|
if (typeof input?.session_id !== "string" || input.session_id !== work.root_session_id) {
|
|
1231
|
-
return
|
|
1460
|
+
return otherSessionDecision(canonicalRoot, work, input, now);
|
|
1232
1461
|
}
|
|
1233
1462
|
if (work.status === "paused") {
|
|
1234
|
-
return denial(
|
|
1463
|
+
return denial(pausedMessage(work));
|
|
1235
1464
|
}
|
|
1236
1465
|
const executionRoot = canonicalDirectory(typeof input.cwd === "string" ? input.cwd : canonicalRoot, "tool cwd");
|
|
1237
1466
|
const classified = classifyToolAuthority(executionRoot, input);
|
|
1238
|
-
if (classified.denied)
|
|
1467
|
+
if (classified.denied) {
|
|
1468
|
+
return input.tool_name === "Bash" && !classified.denied.startsWith("forbidden") ? bashDenial(classified.denied) : denial(classified.denied);
|
|
1469
|
+
}
|
|
1239
1470
|
if (classified.control) return { decision: "allow-normal", action: "control", root: executionRoot, roots: [executionRoot] };
|
|
1471
|
+
if (pluginSelfRead(classified)) return { decision: "allow-normal", action: "read", root: PLUGIN_ROOT, roots: [PLUGIN_ROOT] };
|
|
1240
1472
|
if (classified.chain) {
|
|
1241
1473
|
const covered = classified.chain.every((link) => link.control
|
|
1242
1474
|
|| link.targetRoots.every((targetRoot) => work.authority.grants.some((grant) => grantCovers(grant, link.action, targetRoot))));
|
|
1243
|
-
return covered ? { decision: "allow-normal", action: "chain", root: executionRoot, roots: [executionRoot] } :
|
|
1475
|
+
return covered ? { decision: "allow-normal", action: "chain", root: executionRoot, roots: [executionRoot] } : bashDenial("Bash target is outside the effective authority grant");
|
|
1244
1476
|
}
|
|
1245
1477
|
const targetRoots = classified.targetRoots ?? [classified.targetRoot];
|
|
1246
1478
|
const authorized = targetRoots.every((targetRoot) => work.authority.grants.some((grant) => grantCovers(grant, classified.action, targetRoot)));
|
|
@@ -1248,12 +1480,17 @@ export const handleStartWorkPreToolUse = (root, input) => {
|
|
|
1248
1480
|
return { decision: "allow-normal", action: classified.action, root: targetRoots[0], roots: targetRoots };
|
|
1249
1481
|
}
|
|
1250
1482
|
if (classified.boundaryExpansion === false) {
|
|
1251
|
-
return
|
|
1483
|
+
return bashDenial("Bash target is outside the effective authority grant");
|
|
1484
|
+
}
|
|
1485
|
+
const refused = (work.authority.denied_boundaries ?? []).find((denied) => denied.action === classified.action
|
|
1486
|
+
&& targetRoots.every((targetRoot) => rootCovers(denied.root, targetRoot)));
|
|
1487
|
+
if (refused) {
|
|
1488
|
+
return denial(`LitClaude start-work: the user denied ${refused.action} access to ${refused.root} for this work. Carry on without it, or ask the user if the task cannot be done otherwise.`);
|
|
1252
1489
|
}
|
|
1253
1490
|
if (typeof input.prompt_id !== "string" || !/^[A-Za-z0-9._:-]{1,160}$/u.test(input.prompt_id)) {
|
|
1254
1491
|
return denial("missing valid prompt identity for a new authority boundary");
|
|
1255
1492
|
}
|
|
1256
|
-
const targetRoot = targetRoots[0];
|
|
1493
|
+
const targetRoot = boundaryRoot(classified.action, targetRoots[0], canonicalRoot);
|
|
1257
1494
|
const boundaryId = `boundary-${shortHash(`${work.work_id}:${classified.action}:${targetRoot}`)}`;
|
|
1258
1495
|
const grantId = `grant-${shortHash(`${work.work_id}:${classified.action}:${targetRoot}:${input.prompt_id}:${input.tool_use_id ?? "unknown"}`)}`;
|
|
1259
1496
|
work.status = "paused";
|
|
@@ -1274,7 +1511,7 @@ export const handleStartWorkPreToolUse = (root, input) => {
|
|
|
1274
1511
|
origin_prompt_id: input.prompt_id,
|
|
1275
1512
|
});
|
|
1276
1513
|
saveState(canonicalRoot, state);
|
|
1277
|
-
return denial(
|
|
1514
|
+
return denial(pausedMessage(work));
|
|
1278
1515
|
});
|
|
1279
1516
|
};
|
|
1280
1517
|
|
|
@@ -1386,7 +1623,7 @@ export const handleStartWorkStop = (root, input) => {
|
|
|
1386
1623
|
});
|
|
1387
1624
|
const next = progress.next_task
|
|
1388
1625
|
? `Continue work ${work.work_id} with next top-level task: ${progress.next_task}.`
|
|
1389
|
-
: `Work ${work.work_id} has all top-level tasks checked; run final verification
|
|
1626
|
+
: `Work ${work.work_id} has all top-level tasks checked; run final verification and cleanup, then complete it with \`litclaude-ai start-work complete --work-id ${work.work_id} --session-id ${input.session_id} --expected-revision ${work.revision} --idempotency-key complete-${work.work_id}-${work.revision}\`.`;
|
|
1390
1627
|
const output = {
|
|
1391
1628
|
decision: "block",
|
|
1392
1629
|
reason: `LitClaude start-work continuation: ${next}`,
|
|
@@ -1409,3 +1646,151 @@ export const handleStartWorkStop = (root, input) => {
|
|
|
1409
1646
|
return { handled: true, output };
|
|
1410
1647
|
});
|
|
1411
1648
|
};
|
|
1649
|
+
|
|
1650
|
+
// Typing start-work is the approval (plans/lit-adhd.md todo 8). Only a whole prompt counts: a
|
|
1651
|
+
// quoted, fenced or longer prompt that merely mentions the command or a token is inert.
|
|
1652
|
+
const INVOCATION = /^\/(?:litclaude:)?start-work(?:[ \t]+(\S+))?$/u;
|
|
1653
|
+
const APPROVE_TOKEN = /^lit[ \t]+(?:approve|승인)$/u;
|
|
1654
|
+
const DENY_TOKEN = /^lit[ \t]+(?:deny|거절)$/u;
|
|
1655
|
+
const NATURAL_START = /^lit(?:work)?[ \t]+start[ \t]+work$/u;
|
|
1656
|
+
|
|
1657
|
+
/** `{kind: "start", plan, natural?}`, `{kind: "approve"}`, `{kind: "deny"}`, or null. */
|
|
1658
|
+
export const parseStartWorkInvocation = (prompt) => {
|
|
1659
|
+
if (typeof prompt !== "string" || prompt.length > 512) return null;
|
|
1660
|
+
const text = prompt.trim();
|
|
1661
|
+
if (APPROVE_TOKEN.test(text)) return { kind: "approve" };
|
|
1662
|
+
if (DENY_TOKEN.test(text)) return { kind: "deny" };
|
|
1663
|
+
if (NATURAL_START.test(text)) return { kind: "start", plan: null, natural: true };
|
|
1664
|
+
const match = INVOCATION.exec(text);
|
|
1665
|
+
if (!match) return null;
|
|
1666
|
+
if (match[1] === "approve" || match[1] === "deny") return { kind: match[1] };
|
|
1667
|
+
if (match[1] === "resume") return null;
|
|
1668
|
+
return { kind: "start", plan: match[1] ?? null };
|
|
1669
|
+
};
|
|
1670
|
+
|
|
1671
|
+
/** Project-relative `plans/*.md` files that still have an unchecked top-level task. */
|
|
1672
|
+
export const openPlans = (root) => {
|
|
1673
|
+
const directory = join(root, "plans");
|
|
1674
|
+
let names;
|
|
1675
|
+
try {
|
|
1676
|
+
names = readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".md")).map((entry) => entry.name).sort();
|
|
1677
|
+
} catch {
|
|
1678
|
+
return [];
|
|
1679
|
+
}
|
|
1680
|
+
return names.filter((name) => {
|
|
1681
|
+
try {
|
|
1682
|
+
return readPlanProgress(join(directory, name)).unchecked > 0;
|
|
1683
|
+
} catch {
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
}).map((name) => `plans/${name}`);
|
|
1687
|
+
};
|
|
1688
|
+
|
|
1689
|
+
// `Scope roots: <path> (<action>, <action>)` lines in the plan widen the grants it starts with.
|
|
1690
|
+
const SCOPE_LINE = /^Scope roots?:[ \t]*(\S+)[ \t]*\(([a-z, -]+)\)[ \t]*$/gmu;
|
|
1691
|
+
|
|
1692
|
+
const derivedGrants = (root, plan, workId) => {
|
|
1693
|
+
const grants = ["read", "write", "execute", "test", "package", "vcs-read"].map((action) => ({ action, root, issuedBy: "user-invocation" }));
|
|
1694
|
+
if (!rootCovers(root, dirname(plan))) grants.push({ action: "read", root: dirname(plan), issuedBy: "user-invocation" });
|
|
1695
|
+
for (const [, path, actions] of readCanonicalPlanText(plan).matchAll(SCOPE_LINE)) {
|
|
1696
|
+
const scoped = isAbsolute(path) ? path : resolve(root, path);
|
|
1697
|
+
try {
|
|
1698
|
+
if (!lstatSync(scoped).isDirectory()) continue;
|
|
1699
|
+
} catch {
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
for (const action of actions.split(",").map((word) => word.trim())) {
|
|
1703
|
+
if (allowedActions.has(action)) grants.push({ action, root: scoped, issuedBy: "plan-scope" });
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
if (PLUGIN_ROOT) grants.push({ action: "read", root: PLUGIN_ROOT, issuedBy: "plugin-self" });
|
|
1707
|
+
const scratch = join(realpathSync(tmpdir()), `litclaude-${workId}`);
|
|
1708
|
+
mkdirSync(scratch, { recursive: true, mode: 0o700 });
|
|
1709
|
+
grants.push({ action: "write", root: scratch, issuedBy: "user-invocation" });
|
|
1710
|
+
return grants.slice(0, MAX_GRANTS);
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* Starts the work a typed `/litclaude:start-work [plan]` asked for, with the hook's session and
|
|
1715
|
+
* prompt identity. Returns `{started}`, `{running}` (this session already runs that plan),
|
|
1716
|
+
* `{choose: [plans]}` (no plan named and not exactly one open), or `{refused}`.
|
|
1717
|
+
*/
|
|
1718
|
+
export const startWorkFromInvocation = (root, { sessionId, promptId, plan = null }) => {
|
|
1719
|
+
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
1720
|
+
const candidates = plan ? [plan] : openPlans(canonicalRoot);
|
|
1721
|
+
if (candidates.length !== 1) return { choose: candidates };
|
|
1722
|
+
let planPath;
|
|
1723
|
+
try {
|
|
1724
|
+
planPath = canonicalPlan(canonicalRoot, candidates[0]);
|
|
1725
|
+
} catch (error) {
|
|
1726
|
+
return { refused: `${candidates[0]}: ${error.message}` };
|
|
1727
|
+
}
|
|
1728
|
+
const state = readState(canonicalRoot, { optional: true });
|
|
1729
|
+
const running = state?.active_work_id ? state.works[state.active_work_id] : null;
|
|
1730
|
+
if (running && ["active", "paused"].includes(running.status)) {
|
|
1731
|
+
if (running.root_session_id === sessionId && running.active_plan.normalize("NFC") === planPath.normalize("NFC")) {
|
|
1732
|
+
return { running: { workId: running.work_id, plan: running.plan_name, status: running.status } };
|
|
1733
|
+
}
|
|
1734
|
+
return { refused: `start-work ${running.work_id} (${running.plan_name}) is already running here; finish or cancel it first.` };
|
|
1735
|
+
}
|
|
1736
|
+
const slug = basename(planPath, ".md").toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-|-$/gu, "").slice(0, 40) || "plan";
|
|
1737
|
+
const workId = `work-${slug}-${hash(`${sessionId}:${planPath}:${promptId}`).slice(0, 8)}`;
|
|
1738
|
+
const response = initializeStartWork(canonicalRoot, {
|
|
1739
|
+
plan: planPath,
|
|
1740
|
+
workId,
|
|
1741
|
+
sessionId,
|
|
1742
|
+
grants: derivedGrants(canonicalRoot, planPath, workId),
|
|
1743
|
+
idempotencyKey: `typed-start:${promptId}`,
|
|
1744
|
+
issuedBy: "user-invocation",
|
|
1745
|
+
originPromptId: promptId,
|
|
1746
|
+
});
|
|
1747
|
+
const work = response.state.works[workId];
|
|
1748
|
+
return { started: { workId, plan: work.plan_name, next: work.progress.next_task } };
|
|
1749
|
+
};
|
|
1750
|
+
|
|
1751
|
+
const pendingFor = (state, sessionId) => {
|
|
1752
|
+
const work = state?.active_work_id ? state.works[state.active_work_id] : null;
|
|
1753
|
+
return work?.status === "paused" && work.pending_boundary && work.root_session_id === sessionId && work.pending_boundary.origin_session_id === sessionId ? work : null;
|
|
1754
|
+
};
|
|
1755
|
+
|
|
1756
|
+
/** `lit approve`: grants the one pending boundary of this session's work, or returns null. */
|
|
1757
|
+
export const approveStartWorkBoundary = (root, { sessionId, promptId }) => {
|
|
1758
|
+
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
1759
|
+
const work = pendingFor(readState(canonicalRoot, { optional: true }), sessionId);
|
|
1760
|
+
if (!work) return null;
|
|
1761
|
+
const boundary = work.pending_boundary;
|
|
1762
|
+
const response = resumeStartWorkFromUserPrompt(canonicalRoot, {
|
|
1763
|
+
workId: work.work_id,
|
|
1764
|
+
expectedRevision: work.revision,
|
|
1765
|
+
boundaryId: boundary.boundary_id,
|
|
1766
|
+
originPromptId: boundary.origin_prompt_id,
|
|
1767
|
+
grantId: boundary.grant_id,
|
|
1768
|
+
sessionId,
|
|
1769
|
+
consumedByPromptId: promptId,
|
|
1770
|
+
});
|
|
1771
|
+
return { approved: { workId: work.work_id, action: boundary.action, root: boundary.root }, response };
|
|
1772
|
+
};
|
|
1773
|
+
|
|
1774
|
+
/** `lit deny`: clears the pending boundary without granting it; that path then stays refused. */
|
|
1775
|
+
export const denyStartWorkBoundary = (root, { sessionId, promptId }) => {
|
|
1776
|
+
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
1777
|
+
if (!pendingFor(readState(canonicalRoot, { optional: true }), sessionId)) return null;
|
|
1778
|
+
return withLock(canonicalRoot, () => {
|
|
1779
|
+
const state = readState(canonicalRoot);
|
|
1780
|
+
const work = pendingFor(state, sessionId);
|
|
1781
|
+
if (!work) return null;
|
|
1782
|
+
const boundary = work.pending_boundary;
|
|
1783
|
+
work.authority.denied_boundaries = [...(work.authority.denied_boundaries ?? []), {
|
|
1784
|
+
boundary_id: boundary.boundary_id,
|
|
1785
|
+
action: boundary.action,
|
|
1786
|
+
root: boundary.root,
|
|
1787
|
+
denied_by_prompt_id: typeof promptId === "string" ? promptId : null,
|
|
1788
|
+
denied_at: nowIso(),
|
|
1789
|
+
}].slice(-MAX_GRANTS);
|
|
1790
|
+
work.status = "active";
|
|
1791
|
+
work.pending_boundary = null;
|
|
1792
|
+
appendEvent(state, work, "work.boundary_denied", { boundary_id: boundary.boundary_id, action: boundary.action, root: boundary.root });
|
|
1793
|
+
saveState(canonicalRoot, state);
|
|
1794
|
+
return { denied: { workId: work.work_id, action: boundary.action, root: boundary.root } };
|
|
1795
|
+
});
|
|
1796
|
+
};
|