@litfamily/litgravity 0.1.1 → 0.1.3
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 +46 -0
- package/README.md +19 -3
- package/README_ko-KR.md +19 -3
- package/TRADEMARK.md +12 -0
- package/package.json +3 -2
- package/plugin/hooks/lib/lanes.mjs +65 -0
- package/plugin/hooks/lib/liveness.mjs +81 -0
- package/plugin/hooks/lib/motion.mjs +34 -5
- package/plugin/hooks/lib/reentry.mjs +7 -0
- package/plugin/hooks/lib/rewind/brief.mjs +364 -0
- package/plugin/hooks/lib/rewind/collect.mjs +359 -0
- package/plugin/hooks/lib/rewind/gauge.mjs +55 -0
- package/plugin/hooks/lib/rewind/next-step.mjs +77 -0
- package/plugin/hooks/lib/rewind/redact.mjs +60 -0
- package/plugin/hooks/lib/rewind/transcripts.mjs +214 -0
- package/plugin/hooks/lib/routes.mjs +79 -5
- package/plugin/hooks/lib/workflow-stack.mjs +213 -0
- package/plugin/hooks/post-tool-use.mjs +39 -1
- package/plugin/hooks/pre-invocation.mjs +93 -2
- package/plugin/hooks/session-start.mjs +26 -3
- package/plugin/hooks/stop.mjs +55 -6
- package/plugin/hud/looks.mjs +29 -0
- package/plugin/hud/render.mjs +277 -12
- package/plugin/plugin.json +1 -1
- package/plugin/skills/frontend-ui-ux/SKILL.md +12 -1
- package/plugin/skills/frontend-ui-ux/kit/components.css +417 -0
- package/plugin/skills/frontend-ui-ux/kit/fonts.json +22 -0
- package/plugin/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
- package/plugin/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
- package/plugin/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
- package/plugin/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
- package/plugin/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
- package/plugin/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
- package/plugin/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
- package/plugin/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
- package/plugin/skills/frontend-ui-ux/kit/ui.js +226 -0
- package/plugin/skills/frontend-ui-ux/references/house-styles.md +234 -0
- package/plugin/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
- package/plugin/skills/frontend-ui-ux/scripts/interface-probe-lock.mjs +196 -0
- package/plugin/skills/frontend-ui-ux/scripts/interface-probe-page.mjs +30 -9
- package/plugin/skills/frontend-ui-ux/scripts/interface-probe-rules.mjs +20 -8
- package/plugin/skills/frontend-ui-ux/scripts/interface-probe.mjs +42 -9
- package/plugin/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
- package/plugin/skills/lit-adhd/SKILL.md +160 -0
- package/plugin/skills/lit-adhd/references/card-examples.md +107 -0
- package/plugin/skills/lit-adhd/references/status-taxonomy.md +34 -0
- package/plugin/skills/lit-adhd/scripts/rewind.mjs +5 -0
- package/plugin/skills/lit-diagram-drawer/SKILL.md +5 -3
- package/plugin/skills/lit-diagram-drawer/references/drawing-rules.md +1 -1
- package/plugin/skills/lit-diagram-drawer/references/style-guide.md +21 -12
- package/plugin/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
- package/plugin/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
- package/plugin/skills/lit-diagram-drawer/references/type-tree.md +3 -3
- package/plugin/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
- package/plugin/skills/lit-diagram-drawer/scripts/diagram-craft-rules.mjs +1 -2
- package/plugin/skills/lit-diagram-drawer/scripts/visual-quality.mjs +1 -2
- package/plugin/skills/lit-docx/SKILL.md +3 -3
- package/plugin/skills/lit-handoff/SKILL.md +1 -0
- package/plugin/skills/lit-hijack/SKILL.md +263 -0
- package/plugin/skills/lit-hijack/references/capture-and-provenance.md +100 -0
- package/plugin/skills/lit-hijack/references/clean-room-build.md +75 -0
- package/plugin/skills/lit-hijack/references/distil-and-licence.md +67 -0
- package/plugin/skills/lit-hijack/references/gap-and-port-design.md +100 -0
- package/plugin/skills/lit-hijack/references/parity-and-report.md +85 -0
- package/plugin/skills/lit-hijack/scripts/hijack.mjs +953 -0
- package/plugin/skills/lit-plan/SKILL.md +3 -2
- package/plugin/skills/lit-plan/references/plan-contract.md +12 -1
- package/plugin/skills/lit-plan/scripts/check-plan.mjs +39 -3
- package/plugin/skills/lit-plan/templates/plan.md +3 -0
- package/plugin/skills/lit-pptx/SKILL.md +8 -8
- package/plugin/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
- package/plugin/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
- package/plugin/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
- package/plugin/skills/lit-pptx/fonts/provenance.json +32 -1
- package/plugin/skills/lit-pptx/references/agents/analyst.md +34 -56
- package/plugin/skills/lit-pptx/references/agents/antithesis.md +49 -67
- package/plugin/skills/lit-pptx/references/agents/architect.md +38 -51
- package/plugin/skills/lit-pptx/references/agents/critic.md +25 -41
- package/plugin/skills/lit-pptx/references/agents/synthesizer.md +37 -46
- package/plugin/skills/lit-pptx/references/agents/thesis.md +29 -49
- package/plugin/skills/lit-pptx/references/anti-slop-checklist.md +119 -145
- package/plugin/skills/lit-pptx/references/authoring-guide.md +187 -278
- package/plugin/skills/lit-pptx/references/consensus-protocol.md +99 -97
- package/plugin/skills/lit-pptx/references/data-display-cookbook.md +36 -137
- package/plugin/skills/lit-pptx/references/density-and-fill.md +147 -216
- package/plugin/skills/lit-pptx/references/design-system-azure.md +56 -85
- package/plugin/skills/lit-pptx/references/direction-step.md +134 -176
- package/plugin/skills/lit-pptx/references/examples/01-pitch-signal-ko.md +114 -115
- package/plugin/skills/lit-pptx/references/examples/02-pitch-studio-ko.md +66 -66
- package/plugin/skills/lit-pptx/references/examples/03-business-review-ledger-ko.md +63 -63
- package/plugin/skills/lit-pptx/references/examples/04-business-review-night-en.md +96 -96
- package/plugin/skills/lit-pptx/references/examples/05-research-talk-paper-en.md +81 -81
- package/plugin/skills/lit-pptx/references/examples/06-lecture-chalk-ko.md +103 -103
- package/plugin/skills/lit-pptx/references/examples/07-data-review-night-en.md +100 -98
- package/plugin/skills/lit-pptx/references/examples/08-image-led-atlas-ko.md +76 -76
- package/plugin/skills/lit-pptx/references/examples/09-briefing-gazette-ko.md +96 -96
- package/plugin/skills/lit-pptx/references/examples/10-status-update-ledger-ko.md +80 -80
- package/plugin/skills/lit-pptx/references/examples/11-portfolio-studio-en.md +72 -72
- package/plugin/skills/lit-pptx/references/examples/12-research-tutorial-chalk-en.md +95 -95
- package/plugin/skills/lit-pptx/references/examples/13-engineering-review-computational-brutalism-ko.md +173 -0
- package/plugin/skills/lit-pptx/references/examples/14-launch-pitch-neo-brutalism-ko.md +154 -0
- package/plugin/skills/lit-pptx/references/examples/15-design-lecture-bauhaus-ko.md +139 -0
- package/plugin/skills/lit-pptx/references/examples/16-community-programme-riso-ko.md +158 -0
- package/plugin/skills/lit-pptx/references/examples/17-public-data-briefing-newsroom-ko.md +179 -0
- package/plugin/skills/lit-pptx/references/interview-protocol.md +83 -102
- package/plugin/skills/lit-pptx/references/layout-families.md +161 -265
- package/plugin/skills/lit-pptx/references/stages/autopilot.md +30 -70
- package/plugin/skills/lit-pptx/references/stages/interview.md +36 -68
- package/plugin/skills/lit-pptx/references/stages/plan.md +26 -67
- package/plugin/skills/lit-pptx/references/title-treatments.md +93 -145
- package/plugin/skills/lit-pptx/references/tonalities/atlas.md +95 -108
- package/plugin/skills/lit-pptx/references/tonalities/bauhaus.md +140 -0
- package/plugin/skills/lit-pptx/references/tonalities/chalk.md +107 -122
- package/plugin/skills/lit-pptx/references/tonalities/computational-brutalism.md +150 -0
- package/plugin/skills/lit-pptx/references/tonalities/gazette.md +87 -111
- package/plugin/skills/lit-pptx/references/tonalities/ledger.md +96 -125
- package/plugin/skills/lit-pptx/references/tonalities/neo-brutalism.md +161 -0
- package/plugin/skills/lit-pptx/references/tonalities/newsroom.md +144 -0
- package/plugin/skills/lit-pptx/references/tonalities/night.md +104 -131
- package/plugin/skills/lit-pptx/references/tonalities/paper.md +114 -130
- package/plugin/skills/lit-pptx/references/tonalities/riso.md +137 -0
- package/plugin/skills/lit-pptx/references/tonalities/signal.md +96 -103
- package/plugin/skills/lit-pptx/references/tonalities/studio.md +81 -112
- package/plugin/skills/lit-pptx/scripts/compile-deck.js +4 -6
- package/plugin/skills/lit-pptx/scripts/craft_extras.py +135 -91
- package/plugin/skills/lit-pptx/scripts/deck_craft.py +1 -1
- package/plugin/skills/lit-pptx/scripts/embed_fonts.py +13 -1
- package/plugin/skills/lit-pptx/scripts/layout_inventory.py +1 -1
- package/plugin/skills/lit-pptx/scripts/learn_template.py +1 -1
- package/plugin/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
- package/plugin/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
- package/plugin/skills/lit-pptx/scripts/lib/render-pack.js +370 -563
- package/plugin/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
- package/plugin/skills/lit-pptx/scripts/lib/template-registry.js +57 -6
- package/plugin/skills/lit-pptx/scripts/qa_deck.py +6 -6
- package/plugin/skills/lit-pptx/scripts/render_pages.py +31 -0
- package/plugin/skills/lit-pptx/scripts/validate_pptx.py +1 -1
- package/plugin/skills/lit-pptx/specs/markdown-slide-spec-v1.md +167 -191
- package/plugin/skills/lit-pptx/specs/markdown-slide-spec-v2.md +117 -166
- package/plugin/skills/lit-pptx/specs/template-enrollment-contract.md +307 -330
- package/plugin/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +1 -1
- package/plugin/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
- package/plugin/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +1 -1
- package/plugin/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +99 -0
- package/plugin/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +1 -1
- package/plugin/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +1 -1
- package/plugin/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
- package/plugin/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
- package/plugin/skills/lit-pptx/templates/tonalities/night/pack.yaml +1 -1
- package/plugin/skills/lit-pptx/templates/tonalities/paper/pack.yaml +1 -1
- package/plugin/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
- package/plugin/skills/lit-pptx/templates/tonalities/signal/pack.yaml +2 -2
- package/plugin/skills/lit-pptx/templates/tonalities/studio/pack.yaml +1 -1
- package/plugin/skills/lit-schematic/SKILL.md +114 -0
- package/plugin/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
- package/plugin/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
- package/plugin/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
- package/plugin/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
- package/plugin/skills/lit-schematic/references/cutaway-outputs.md +70 -0
- package/plugin/skills/lit-schematic/references/isometric-craft.md +101 -0
- package/plugin/skills/lit-schematic/references/journal-figures.md +72 -0
- package/plugin/skills/lit-schematic/references/kit-api.md +134 -0
- package/plugin/skills/lit-schematic/references/pfd-and-layout.md +53 -0
- package/plugin/skills/lit-schematic/references/pid-drafting.md +103 -0
- package/plugin/skills/lit-schematic/references/pid-symbols.md +163 -0
- package/plugin/skills/lit-schematic/references/verification.md +100 -0
- package/plugin/skills/lit-schematic/scripts/doctor.mjs +57 -0
- package/plugin/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
- package/plugin/skills/lit-schematic/scripts/lib/fonts.mjs +27 -0
- package/plugin/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
- package/plugin/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
- package/plugin/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
- package/plugin/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
- package/plugin/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
- package/plugin/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
- package/plugin/skills/lit-schematic/scripts/lib/png.mjs +132 -0
- package/plugin/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
- package/plugin/skills/lit-schematic/scripts/lib/route.mjs +218 -0
- package/plugin/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
- package/plugin/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
- package/plugin/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
- package/plugin/skills/lit-schematic/scripts/motion.mjs +129 -0
- package/plugin/skills/lit-schematic/scripts/qa.mjs +92 -0
- package/plugin/skills/lit-schematic/scripts/render.mjs +233 -0
- package/plugin/skills/lit-schematic/scripts/scaffold.mjs +60 -0
- package/plugin/skills/lit-scientific-visualization/SKILL.md +17 -6
- package/plugin/skills/lit-typographic-motion/SKILL.md +58 -48
- package/plugin/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +13 -2
- package/plugin/skills/lit-typographic-motion/engine/blender/runner.py +218 -0
- package/plugin/skills/lit-typographic-motion/engine/core/presets.mjs +1 -1
- package/plugin/skills/lit-typographic-motion/engine/node/analysis.mjs +65 -1
- package/plugin/skills/lit-typographic-motion/engine/node/assets.mjs +298 -0
- package/plugin/skills/lit-typographic-motion/engine/node/blender.mjs +143 -0
- package/plugin/skills/lit-typographic-motion/engine/node/board.mjs +136 -0
- package/plugin/skills/lit-typographic-motion/engine/node/brief.mjs +7 -1
- package/plugin/skills/lit-typographic-motion/engine/node/chrome.mjs +9 -12
- package/plugin/skills/lit-typographic-motion/engine/node/cover-assets.mjs +5 -3
- package/plugin/skills/lit-typographic-motion/engine/node/cover-capture.mjs +7 -6
- package/plugin/skills/lit-typographic-motion/engine/node/cover-treatment.mjs +37 -4
- package/plugin/skills/lit-typographic-motion/engine/node/cover.mjs +19 -8
- package/plugin/skills/lit-typographic-motion/engine/node/done.mjs +45 -6
- package/plugin/skills/lit-typographic-motion/engine/node/frame-worker.mjs +7 -5
- package/plugin/skills/lit-typographic-motion/engine/node/gallery.mjs +121 -0
- package/plugin/skills/lit-typographic-motion/engine/node/host.mjs +34 -0
- package/plugin/skills/lit-typographic-motion/engine/node/house.mjs +44 -0
- package/plugin/skills/lit-typographic-motion/engine/node/look.mjs +34 -20
- package/plugin/skills/lit-typographic-motion/engine/node/pipeline.mjs +19 -9
- package/plugin/skills/lit-typographic-motion/engine/node/scaffold.mjs +210 -0
- package/plugin/skills/lit-typographic-motion/engine/node/score.mjs +639 -0
- package/plugin/skills/lit-typographic-motion/engine/node/sound-cli.mjs +21 -4
- package/plugin/skills/lit-typographic-motion/engine/node/sound.mjs +127 -29
- package/plugin/skills/lit-typographic-motion/engine/node/stage-capture.mjs +7 -6
- package/plugin/skills/lit-typographic-motion/engine/node/stage-gate.mjs +59 -5
- package/plugin/skills/lit-typographic-motion/engine/node/stage-qa.mjs +141 -9
- package/plugin/skills/lit-typographic-motion/engine/node/stage-serve.mjs +28 -5
- package/plugin/skills/lit-typographic-motion/engine/node/stage.mjs +82 -14
- package/plugin/skills/lit-typographic-motion/engine/node/styles.mjs +213 -0
- package/plugin/skills/lit-typographic-motion/engine/node/treatment.mjs +311 -10
- package/plugin/skills/lit-typographic-motion/engine/stage/cover-init.js +14 -2
- package/plugin/skills/lit-typographic-motion/engine/stage/init.js +11 -1
- package/plugin/skills/lit-typographic-motion/engine/stage/qa.js +6 -1
- package/plugin/skills/lit-typographic-motion/engine/stage/stage-kit.js +83 -0
- package/plugin/skills/lit-typographic-motion/engine/vendor/three/LICENSE +21 -0
- package/plugin/skills/lit-typographic-motion/engine/vendor/three/addons/environments/RoomEnvironment.js +144 -0
- package/plugin/skills/lit-typographic-motion/engine/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
- package/plugin/skills/lit-typographic-motion/engine/vendor/three/three.module.js +54571 -0
- package/plugin/skills/lit-typographic-motion/recipes/hero-3d/expected.json +69 -0
- package/plugin/skills/lit-typographic-motion/recipes/hero-3d/index.html +139 -0
- package/plugin/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +6 -4
- package/plugin/skills/lit-typographic-motion/recipes/painted-light/expected.json +4 -2
- package/plugin/skills/lit-typographic-motion/recipes/weight-tide/expected.json +7 -5
- package/plugin/skills/lit-typographic-motion/references/cover.md +394 -443
- package/plugin/skills/lit-typographic-motion/references/craft-loop.md +57 -87
- package/plugin/skills/lit-typographic-motion/references/depth.md +122 -0
- package/plugin/skills/lit-typographic-motion/references/look.md +94 -129
- package/plugin/skills/lit-typographic-motion/references/runtime.md +58 -91
- package/plugin/skills/lit-typographic-motion/references/sound.md +130 -99
- package/plugin/skills/lit-typographic-motion/references/stage.md +190 -215
- package/plugin/skills/lit-typographic-motion/references/studio.md +245 -0
- package/plugin/skills/lit-typographic-motion/references/style-bibles.md +108 -97
- package/plugin/skills/lit-typographic-motion/references/treatment.md +191 -143
- package/plugin/skills/lit-typographic-motion/scripts/motion-doctor.mjs +17 -5
- package/plugin/skills/lit-typographic-motion/scripts/motion.mjs +47 -7
- package/plugin/skills/lit-typographic-motion/styles/paper.json +41 -0
- package/plugin/skills/lit-typographic-motion/styles/swiss-signal.json +41 -0
- package/plugin/skills/lit-typographic-motion/styles/terminalcore.json +42 -0
- package/plugin/skills/lit-typographic-motion/styles/tidal.json +41 -0
- package/plugin/skills/litresearch/SKILL.md +1 -0
- package/plugin/skills/readme-studio/SKILL.md +2 -0
- package/plugin/skills/review-work/SKILL.md +1 -1
- package/plugin/skills/start-work/SKILL.md +2 -2
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
// The lit-adhd record collector. Reads what is on disk for the workspace (agy transcripts, plans,
|
|
2
|
+
// litgoal, handoff headings, git log, workflow stacks) and returns one redacted, capped JSON brief.
|
|
3
|
+
// A source that is not there reads `unknown`; nothing is inferred.
|
|
4
|
+
|
|
5
|
+
import { execFileSync } from 'node:child_process';
|
|
6
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readdirSync, statSync } from 'node:fs';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { planRows } from '../continuation.mjs';
|
|
11
|
+
import { sessionPath, stateRoot } from '../common.mjs';
|
|
12
|
+
import { aggregateProgress, clipToWidth, progressOf } from './gauge.mjs';
|
|
13
|
+
import { renderBrief } from './brief.mjs';
|
|
14
|
+
import { chooseNextStep, writeNextStep } from './next-step.mjs';
|
|
15
|
+
import { makeRedactor } from './redact.mjs';
|
|
16
|
+
import { findTranscripts, makeBudget, readTranscriptLines, sessionRecord } from './transcripts.mjs';
|
|
17
|
+
import { listLive } from '../liveness.mjs';
|
|
18
|
+
|
|
19
|
+
const SMALL_FILE_BYTES = 1024 * 1024;
|
|
20
|
+
const GIT_TIMEOUT_MS = 5000;
|
|
21
|
+
const DEFAULT_SINCE = '7d';
|
|
22
|
+
const DEFAULT_MAX = 12;
|
|
23
|
+
const NAME_MAX = 90;
|
|
24
|
+
const PLAN_LIMIT = 8;
|
|
25
|
+
|
|
26
|
+
export const parseSince = (text) => {
|
|
27
|
+
const match = /^(\d{1,4})([dhm])$/u.exec(String(text ?? ''));
|
|
28
|
+
if (!match) return null;
|
|
29
|
+
return Number(match[1]) * { d: 86_400_000, h: 3_600_000, m: 60_000 }[match[2]];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const readSmallFile = (path, budget) => {
|
|
33
|
+
let fd;
|
|
34
|
+
try {
|
|
35
|
+
if (!lstatSync(path).isFile()) return null;
|
|
36
|
+
fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
37
|
+
const { size } = fstatSync(fd);
|
|
38
|
+
const length = Math.min(size, SMALL_FILE_BYTES, budget.limit - budget.used);
|
|
39
|
+
if (length < size) budget.exhausted = budget.exhausted || length < Math.min(size, SMALL_FILE_BYTES);
|
|
40
|
+
const buffer = Buffer.alloc(Math.max(0, length));
|
|
41
|
+
const read = length > 0 ? readSync(fd, buffer, 0, length, 0) : 0;
|
|
42
|
+
budget.used += read;
|
|
43
|
+
return buffer.subarray(0, read).toString('utf8');
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
} finally {
|
|
47
|
+
if (fd !== undefined) closeSync(fd);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const readJson = (path, budget) => {
|
|
52
|
+
const text = readSmallFile(path, budget);
|
|
53
|
+
if (text === null) return null;
|
|
54
|
+
try { return JSON.parse(text); } catch { return null; }
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const entries = (directory) => {
|
|
58
|
+
try { return readdirSync(directory, { withFileTypes: true }); } catch { return null; }
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const defaultExec = (file, args, options) => execFileSync(file, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], ...options });
|
|
62
|
+
|
|
63
|
+
const worktreesOf = (cwd, exec) => {
|
|
64
|
+
try {
|
|
65
|
+
const out = exec('git', ['worktree', 'list', '--porcelain'], { cwd, timeout: GIT_TIMEOUT_MS });
|
|
66
|
+
const paths = out.split('\n').filter((l) => l.startsWith('worktree ')).map((l) => l.slice(9).trim()).filter(Boolean);
|
|
67
|
+
return paths.length ? paths : null;
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// A plan scaffold nobody filled in: a row still holding a `<placeholder>`, or every row the same.
|
|
74
|
+
const isTemplate = (rows) => rows.some((r) => /<[^<>]{1,40}>/u.test(r.title)) || (rows.length > 1 && new Set(rows.map((r) => r.title.trim())).size === 1);
|
|
75
|
+
|
|
76
|
+
// `skipped.count` grows by one per Markdown file under plans/ that is no plan: unreadable, without task rows, an
|
|
77
|
+
// unfilled scaffold, or a name with a control character.
|
|
78
|
+
const plansIn = (root, budget, redact, local, skipped) => {
|
|
79
|
+
const list = entries(join(root, 'plans'));
|
|
80
|
+
if (!list) return null;
|
|
81
|
+
const markdown = list.filter((e) => e.isFile() && e.name.endsWith('.md'));
|
|
82
|
+
// A name with a control character could carry its own lines into the brief or the `go` note; skip it.
|
|
83
|
+
const named = markdown.filter((e) => !/[\p{Cc}\p{Cf}]/u.test(e.name));
|
|
84
|
+
skipped.count += markdown.length - named.length;
|
|
85
|
+
return named.sort((a, b) => a.name.localeCompare(b.name)).flatMap((e) => {
|
|
86
|
+
const text = readSmallFile(join(root, 'plans', e.name), budget);
|
|
87
|
+
const rows = text === null ? [] : planRows(text);
|
|
88
|
+
if (!rows.length || isTemplate(rows)) {
|
|
89
|
+
skipped.count += 1;
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const open = rows.filter((r) => !r.done);
|
|
93
|
+
const done = rows.length - open.length;
|
|
94
|
+
let mtime = null;
|
|
95
|
+
try { mtime = statSync(join(root, 'plans', e.name)).mtimeMs; } catch { /* skip */ }
|
|
96
|
+
return [{
|
|
97
|
+
worktree: redact(root), plan: `plans/${e.name}`, local,
|
|
98
|
+
rows: rows.map((r) => ({ checked: r.done, title: clipToWidth(redact(r.title), NAME_MAX) })),
|
|
99
|
+
current: open.length ? clipToWidth(redact(open[0].title), NAME_MAX) : null,
|
|
100
|
+
finished: open.length === 0,
|
|
101
|
+
mtime,
|
|
102
|
+
progress: progressOf(done, rows.length, open.map((r) => clipToWidth(redact(r.title), NAME_MAX))),
|
|
103
|
+
}];
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const litgoalOf = (root, budget, redact) => {
|
|
108
|
+
const goals = readJson(join(root, '.litgravity', 'goals', 'active.json'), budget);
|
|
109
|
+
if (!goals || !Array.isArray(goals.criteria)) return null;
|
|
110
|
+
const passed = goals.criteria.filter((c) => c?.status === 'pass');
|
|
111
|
+
const remaining = goals.criteria.filter((c) => c?.status !== 'pass').map((c) => clipToWidth(redact(String(c?.text ?? c?.id ?? 'unknown')), NAME_MAX));
|
|
112
|
+
return {
|
|
113
|
+
worktree: redact(root), status: typeof goals.status === 'string' ? goals.status : 'unknown',
|
|
114
|
+
objective: clipToWidth(redact(String(goals.objective ?? 'unknown').split('\n')[0]), 120),
|
|
115
|
+
progress: progressOf(passed.length, goals.criteria.length, remaining),
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// The first item under a handoff's `## Next` heading, without its list marker, or null.
|
|
120
|
+
const nextOfHandoff = (text) => {
|
|
121
|
+
const lines = text.split('\n');
|
|
122
|
+
const at = lines.findIndex((l) => /^#{2,3}\s+Next\b/iu.test(l));
|
|
123
|
+
if (at === -1) return null;
|
|
124
|
+
for (const line of lines.slice(at + 1)) {
|
|
125
|
+
if (/^#{1,6} /u.test(line)) return null;
|
|
126
|
+
const item = line.replace(/^\s*(?:[-*+]|\d+[.)])\s+/u, '').replace(/^\s*-\s*\[[ xX]\]\s*/u, '').trim();
|
|
127
|
+
if (item) return item;
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handoffsOf = (root, budget, redact, local) => (entries(root) ?? [])
|
|
133
|
+
.filter((e) => e.isFile() && /^HANDOFF.*\.md$/u.test(e.name))
|
|
134
|
+
.map((e) => {
|
|
135
|
+
const text = readSmallFile(join(root, e.name), budget) ?? '';
|
|
136
|
+
const headings = text.split('\n').slice(0, 40).filter((l) => /^#{1,3} /u.test(l)).map((l) => clipToWidth(redact(l), 100));
|
|
137
|
+
const next = nextOfHandoff(text);
|
|
138
|
+
return { worktree: redact(root), file: e.name, headings, local, next: next ? clipToWidth(redact(next), 100) : null };
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const branchOf = (root, exec) => {
|
|
142
|
+
try {
|
|
143
|
+
return exec('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: root, timeout: GIT_TIMEOUT_MS }).trim() || null;
|
|
144
|
+
} catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const commitsOf = (root, sinceMs, now, exec, redact) => {
|
|
150
|
+
try {
|
|
151
|
+
const since = new Date(now - sinceMs).toISOString();
|
|
152
|
+
const branch = exec('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: root, timeout: GIT_TIMEOUT_MS }).trim();
|
|
153
|
+
const out = exec('git', ['log', `--since=${since}`, '--max-count=20', '--format=%H%x09%cI%x09%s'], { cwd: root, timeout: GIT_TIMEOUT_MS });
|
|
154
|
+
return out.split('\n').filter(Boolean).map((line) => {
|
|
155
|
+
const [hash, at, ...subject] = line.split('\t');
|
|
156
|
+
return { worktree: redact(root), branch: redact(branch), hash: hash.slice(0, 7), at, atMs: Date.parse(at), subject: clipToWidth(redact(subject.join('\t')), 100) };
|
|
157
|
+
});
|
|
158
|
+
} catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const stacksOf = (stateDir, budget, redact) => {
|
|
164
|
+
if (!stateDir) return null;
|
|
165
|
+
const list = entries(stateDir);
|
|
166
|
+
if (!list) return null;
|
|
167
|
+
return list.filter((e) => e.isFile() && e.name.endsWith('.stack.json')).flatMap((e) => {
|
|
168
|
+
const stack = readJson(join(stateDir, e.name), budget);
|
|
169
|
+
if (!stack || !Array.isArray(stack.frames)) return [];
|
|
170
|
+
return stack.frames.slice(0, 3).map((frame) => ({
|
|
171
|
+
sessionId: typeof stack.sessionId === 'string' ? stack.sessionId : null,
|
|
172
|
+
id8: typeof stack.sessionId === 'string' ? stack.sessionId.slice(0, 8) : 'unknown',
|
|
173
|
+
skill: typeof frame.skill === 'string' ? redact(frame.skill) : 'unknown',
|
|
174
|
+
stage: typeof frame.stage === 'string' ? redact(frame.stage) : 'unknown',
|
|
175
|
+
role: frame.role === 'spine' ? 'spine' : 'side',
|
|
176
|
+
status: frame.status === 'paused' ? 'paused' : 'active',
|
|
177
|
+
at: typeof frame.at === 'string' ? frame.at : 'unknown',
|
|
178
|
+
progress: progressOf(frame.n, frame.total, undefined),
|
|
179
|
+
...(frame.ref?.plan ? { ref: { plan: redact(frame.ref.plan) } } : {}),
|
|
180
|
+
}));
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const known = (list) => (list === null ? 'unknown' : 'ok');
|
|
185
|
+
const statusRank = { 'waiting-on-user': 0, active: 1, idle: 2, done: 3, ended: 4, unknown: 5 };
|
|
186
|
+
|
|
187
|
+
export const collectRewind = ({
|
|
188
|
+
cwd = process.cwd(),
|
|
189
|
+
here = false,
|
|
190
|
+
since = DEFAULT_SINCE,
|
|
191
|
+
max = DEFAULT_MAX,
|
|
192
|
+
sessionId = null,
|
|
193
|
+
env = process.env,
|
|
194
|
+
now = Date.now(),
|
|
195
|
+
exec = defaultExec,
|
|
196
|
+
record = true,
|
|
197
|
+
} = {}) => {
|
|
198
|
+
const home = env.HOME || homedir();
|
|
199
|
+
const redact = makeRedactor({ env, home });
|
|
200
|
+
const budget = makeBudget();
|
|
201
|
+
const sinceMs = parseSince(since) ?? parseSince(DEFAULT_SINCE);
|
|
202
|
+
const limit = Number.isInteger(max) && max > 0 ? Math.min(max, 50) : DEFAULT_MAX;
|
|
203
|
+
const start = resolve(cwd);
|
|
204
|
+
const listed = here ? null : worktreesOf(start, exec);
|
|
205
|
+
const roots = [...new Set([start, ...(here ? [] : listed ?? [])])];
|
|
206
|
+
|
|
207
|
+
// Which conversations belong to this workspace: the route-state folder of each root (worktree) lists them by id.
|
|
208
|
+
const stateDirs = roots.map((r) => ({ root: r, dir: dirname(sessionPath(r, 'x', env)) }));
|
|
209
|
+
const owner = new Map();
|
|
210
|
+
for (const { root: r, dir } of stateDirs) {
|
|
211
|
+
for (const e of entries(dir) ?? []) {
|
|
212
|
+
const m = /^([A-Za-z0-9._:-]{1,160})\.json$/.exec(e.name);
|
|
213
|
+
if (e.isFile() && m && !/\.(?:snapshot|stack|motion|live)$/.test(m[1]) && !owner.has(m[1])) owner.set(m[1], r);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Plans, goals, handoffs and stacks are small and come first, so long transcripts cannot use up the read budget
|
|
217
|
+
// before them.
|
|
218
|
+
const collectEach = (read) => {
|
|
219
|
+
const results = roots.map(read);
|
|
220
|
+
return results.every((v) => v === null) ? null : results.flatMap((v) => v ?? []);
|
|
221
|
+
};
|
|
222
|
+
const skipped = { count: 0 };
|
|
223
|
+
const plans = collectEach((r) => plansIn(r, budget, redact, resolve(r) === start, skipped));
|
|
224
|
+
const litgoal = collectEach((r) => {
|
|
225
|
+
const goal = litgoalOf(r, budget, redact);
|
|
226
|
+
return goal ? [{ ...goal, local: resolve(r) === start }] : null;
|
|
227
|
+
});
|
|
228
|
+
const handoffs = roots.flatMap((r) => handoffsOf(r, budget, redact, resolve(r) === start));
|
|
229
|
+
const stackLists = stateDirs.map(({ dir }) => stacksOf(dir, budget, redact));
|
|
230
|
+
const workflows = stackLists.every((v) => v === null) ? null : stackLists.flatMap((v) => v ?? []);
|
|
231
|
+
const liveness = new Map(stateDirs.flatMap(({ dir }) => listLive(dir, now).map((r) => [r.id, r.state])));
|
|
232
|
+
// A conversation whose start-work frame names a plan with every row ticked is done.
|
|
233
|
+
const finishedPlans = new Set((plans ?? []).filter((p) => p.finished).map((p) => `${p.worktree}\u0000${p.plan}`));
|
|
234
|
+
const finishedIn = (id, root) => (workflows ?? []).some((f) => f.sessionId === id && f.ref?.plan && finishedPlans.has(`${redact(root)}\u0000${f.ref.plan}`));
|
|
235
|
+
|
|
236
|
+
const geminiDir = join(home, '.gemini', 'antigravity-cli');
|
|
237
|
+
const transcripts = owner.size ? findTranscripts(geminiDir, [...owner.keys()]) : { status: 'unknown', files: [] };
|
|
238
|
+
const sessions = [];
|
|
239
|
+
for (const { id, path } of transcripts.files) {
|
|
240
|
+
if (sessions.length >= limit || budget.exhausted) break;
|
|
241
|
+
const lines = readTranscriptLines(path, budget);
|
|
242
|
+
const session = lines ? sessionRecord(lines, { redact, now, cwd: owner.get(id), live: liveness.get(id) ?? null, finished: finishedIn(id, owner.get(id)) }) : null;
|
|
243
|
+
if (!session || (session.lastMs !== null && now - session.lastMs > sinceMs)) continue;
|
|
244
|
+
session.sessionId = id;
|
|
245
|
+
session.id8 = id.slice(0, 8);
|
|
246
|
+
session.root = owner.get(id);
|
|
247
|
+
if (here && resolve(session.cwd).normalize('NFC') !== start.normalize('NFC')) continue;
|
|
248
|
+
sessions.push(session);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const commits = collectEach((r) => commitsOf(r, sinceMs, now, exec, redact));
|
|
252
|
+
const branches = new Map(roots.map((r) => [r, branchOf(r, exec)]));
|
|
253
|
+
|
|
254
|
+
for (const session of sessions) {
|
|
255
|
+
const frames = (workflows ?? []).filter((f) => f.sessionId === session.sessionId);
|
|
256
|
+
const top = frames.at(-1);
|
|
257
|
+
if (frames.some((f) => f.status === 'paused') && session.status !== 'waiting-on-user') {
|
|
258
|
+
session.status = 'waiting-on-user';
|
|
259
|
+
session.waitingReason = 'paused workflow';
|
|
260
|
+
}
|
|
261
|
+
session.progress = top?.progress ?? progressOf(null, null);
|
|
262
|
+
const branch = branches.get(session.root);
|
|
263
|
+
if (branch) session.branch = redact(branch);
|
|
264
|
+
session.done.commits = (commits ?? [])
|
|
265
|
+
.filter((c) => session.lastMs !== null && Date.parse(session.started) <= c.atMs && c.atMs <= session.lastMs + 5 * 60_000)
|
|
266
|
+
.slice(0, 5)
|
|
267
|
+
.map(({ hash, subject }) => ({ hash, subject }));
|
|
268
|
+
}
|
|
269
|
+
sessions.sort((a, b) => statusRank[a.status] - statusRank[b.status] || (b.lastMs ?? 0) - (a.lastMs ?? 0));
|
|
270
|
+
|
|
271
|
+
// Plans changed inside the window, this folder's first, newest first; a plan nobody touched lately is history,
|
|
272
|
+
// and so is a finished plan of another folder. This folder's finished plans count as done.
|
|
273
|
+
const recent = (p) => p.mtime !== null && now - p.mtime <= sinceMs && (p.local || !p.finished);
|
|
274
|
+
const orderedPlans = (plans ?? []).filter(recent).sort((a, b) => Number(b.local) - Number(a.local) || (b.mtime ?? 0) - (a.mtime ?? 0));
|
|
275
|
+
const shownPlans = orderedPlans.slice(0, PLAN_LIMIT);
|
|
276
|
+
const localGoals = (litgoal ?? []).filter((g) => g.local);
|
|
277
|
+
const roadmapItems = [...orderedPlans.filter((p) => p.local).map((p) => p.progress), ...localGoals.map((g) => g.progress)];
|
|
278
|
+
const data = {
|
|
279
|
+
version: 1,
|
|
280
|
+
generatedAt: new Date(now).toISOString(),
|
|
281
|
+
scope: { here, since: sinceMs === parseSince(since) ? since : DEFAULT_SINCE, max: limit, worktrees: roots.map(redact) },
|
|
282
|
+
sources: {
|
|
283
|
+
transcripts: transcripts.status,
|
|
284
|
+
litgoal: known(litgoal),
|
|
285
|
+
plans: known(plans),
|
|
286
|
+
handoffs: handoffs.length ? 'ok' : 'unknown',
|
|
287
|
+
git: known(commits),
|
|
288
|
+
workflowStack: known(workflows),
|
|
289
|
+
},
|
|
290
|
+
budget: { bytesRead: budget.used, limit: budget.limit, exhausted: budget.exhausted },
|
|
291
|
+
summary: {
|
|
292
|
+
sessions: sessions.length,
|
|
293
|
+
waitingOnUser: sessions.filter((s) => s.status === 'waiting-on-user').length,
|
|
294
|
+
active: sessions.filter((s) => s.status === 'active').length,
|
|
295
|
+
},
|
|
296
|
+
sessions: sessions.map(({ cwd: _cwd, lastMs: _lastMs, root: _root, sessionId: id, ...rest }) => ({ ...rest, self: Boolean(sessionId) && id === sessionId })),
|
|
297
|
+
roadmap: {
|
|
298
|
+
plans: shownPlans,
|
|
299
|
+
plansOmitted: orderedPlans.length - shownPlans.length,
|
|
300
|
+
plansSkipped: skipped.count,
|
|
301
|
+
// Another folder's finished objective is history.
|
|
302
|
+
litgoal: (litgoal ?? []).filter((g) => g.local || g.status !== 'complete'),
|
|
303
|
+
progress: roadmapItems.length ? aggregateProgress(roadmapItems) : progressOf(null, null),
|
|
304
|
+
},
|
|
305
|
+
workflows: (workflows ?? []).map((f) => ({ ...f, self: Boolean(sessionId) && f.sessionId === sessionId })),
|
|
306
|
+
// A start-work run is a start-work frame on a workflow stack; agy keeps no other record of one.
|
|
307
|
+
startWork: (workflows ?? []).filter((f) => f.skill === 'start-work').map((f) => ({ sessionId: f.sessionId, status: f.status, plan: f.ref?.plan ?? null })),
|
|
308
|
+
handoffs,
|
|
309
|
+
commits: (commits ?? []).slice(0, 20).map(({ atMs: _atMs, ...c }) => c),
|
|
310
|
+
};
|
|
311
|
+
const next = chooseNextStep(data, sessionId);
|
|
312
|
+
data.next = next;
|
|
313
|
+
data.nextRecorded = false;
|
|
314
|
+
if (record && sessionId) {
|
|
315
|
+
try {
|
|
316
|
+
// The same root PreInvocation hands takeNextStep, so `go` finds what this brief offered.
|
|
317
|
+
writeNextStep(stateRoot(env), sessionId, next, new Date(now));
|
|
318
|
+
data.nextRecorded = true;
|
|
319
|
+
} catch {
|
|
320
|
+
data.nextRecorded = false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
for (const f of data.workflows) delete f.sessionId;
|
|
324
|
+
for (const w of data.startWork) delete w.sessionId;
|
|
325
|
+
return data;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// The brief as Markdown (brief.mjs). `width` sizes the next-step box.
|
|
329
|
+
export const renderRewind = (data, { lang = 'en', width = 72 } = {}) => renderBrief(data, { lang, width: Math.max(40, Math.min(width, 100)) });
|
|
330
|
+
|
|
331
|
+
export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, stdout = process.stdout, stderr = process.stderr } = {}) => {
|
|
332
|
+
const options = { cwd, env, here: false, since: DEFAULT_SINCE, max: DEFAULT_MAX, sessionId: null };
|
|
333
|
+
let json = false;
|
|
334
|
+
let lang = 'en';
|
|
335
|
+
let width = Math.min(Number(stdout.columns) || 72, 72);
|
|
336
|
+
const usage = 'Usage: rewind.mjs [--brief|--json] [--lang en|ko] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]';
|
|
337
|
+
if (args.some((a) => a === '--help' || a === '-h')) {
|
|
338
|
+
stdout.write(`${usage}\n`);
|
|
339
|
+
return 0;
|
|
340
|
+
}
|
|
341
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
342
|
+
const arg = args[i];
|
|
343
|
+
if (arg === '--json') json = true;
|
|
344
|
+
else if (arg === '--brief') json = false;
|
|
345
|
+
else if (arg === '--lang' && ['en', 'ko'].includes(args[i + 1])) lang = args[++i];
|
|
346
|
+
else if (arg === '--here') options.here = true;
|
|
347
|
+
else if (arg === '--since' && parseSince(args[i + 1])) options.since = args[++i];
|
|
348
|
+
else if (arg === '--max' && /^\d{1,2}$/u.test(args[i + 1] ?? '')) options.max = Number(args[++i]);
|
|
349
|
+
else if (arg === '--session' && /^[A-Za-z0-9._:-]{1,160}$/u.test(args[i + 1] ?? '')) options.sessionId = args[++i];
|
|
350
|
+
else if (arg === '--width' && /^\d{2,3}$/u.test(args[i + 1] ?? '')) width = Number(args[++i]);
|
|
351
|
+
else {
|
|
352
|
+
stderr.write(`rewind: unknown argument ${JSON.stringify(basename(String(arg)))}. ${usage}\n`);
|
|
353
|
+
return 64;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const data = collectRewind(options);
|
|
357
|
+
stdout.write(json ? `${JSON.stringify(data, null, 2)}\n` : renderRewind(data, { lang, width }));
|
|
358
|
+
return 0;
|
|
359
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Progress gauges for the lit-adhd brief (D9). Code draws them so the model copies them verbatim:
|
|
2
|
+
// `[▉▉▉░░] 3/5`, one cell per item up to ten, scaled above that. Returns null when either number
|
|
3
|
+
// is unknown — a gauge appears only when both numbers are real.
|
|
4
|
+
|
|
5
|
+
const MAX_CELLS = 10;
|
|
6
|
+
const known = (value) => Number.isInteger(value) && value >= 0;
|
|
7
|
+
|
|
8
|
+
export const gauge = (done, total) => {
|
|
9
|
+
if (!known(total) || !known(done)) return null;
|
|
10
|
+
const k = Math.min(done, total);
|
|
11
|
+
const cells = Math.min(total, MAX_CELLS);
|
|
12
|
+
let filled = k;
|
|
13
|
+
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)));
|
|
14
|
+
return `[${'▉'.repeat(filled)}${'░'.repeat(cells - filled)}] ${k}/${total}`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const progressOf = (done, total, remaining) => ({
|
|
18
|
+
done: known(done) ? done : null,
|
|
19
|
+
total: known(total) ? total : null,
|
|
20
|
+
gauge: gauge(done, total),
|
|
21
|
+
remaining: Array.isArray(remaining) && remaining.length ? remaining : known(total) && known(done) && done >= total ? [] : null,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const aggregateProgress = (items) => {
|
|
25
|
+
const done = items.reduce((sum, item) => sum + (known(item.done) ? item.done : 0), 0);
|
|
26
|
+
const total = items.every((item) => known(item.total)) ? items.reduce((sum, item) => sum + item.total, 0) : null;
|
|
27
|
+
return { done, total, gauge: gauge(done, total) };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const charWidth = (codePoint) => {
|
|
31
|
+
if (codePoint === 0 || codePoint < 32 || (codePoint >= 0x7f && codePoint < 0xa0)) return 0;
|
|
32
|
+
if (/\p{Mn}|\p{Me}|\p{Cf}/u.test(String.fromCodePoint(codePoint)) || (codePoint >= 0x1160 && codePoint <= 0x11ff)) return 0;
|
|
33
|
+
if ((codePoint >= 0x1100 && codePoint <= 0x115f) || (codePoint >= 0x2e80 && codePoint <= 0xa4cf)
|
|
34
|
+
|| (codePoint >= 0xac00 && codePoint <= 0xd7a3) || (codePoint >= 0xf900 && codePoint <= 0xfaff)
|
|
35
|
+
|| (codePoint >= 0xfe30 && codePoint <= 0xfe4f) || (codePoint >= 0xff00 && codePoint <= 0xff60)
|
|
36
|
+
|| (codePoint >= 0xffe0 && codePoint <= 0xffe6) || (codePoint >= 0x1f300 && codePoint <= 0x1faff)
|
|
37
|
+
|| (codePoint >= 0x20000 && codePoint <= 0x3fffd)) return 2;
|
|
38
|
+
return 1;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const displayWidth = (text) => [...String(text)].reduce((sum, ch) => sum + charWidth(ch.codePointAt(0)), 0);
|
|
42
|
+
|
|
43
|
+
export const clipToWidth = (text, width) => {
|
|
44
|
+
const value = String(text);
|
|
45
|
+
if (displayWidth(value) <= width) return value;
|
|
46
|
+
let out = '';
|
|
47
|
+
let used = 0;
|
|
48
|
+
for (const ch of value) {
|
|
49
|
+
const w = charWidth(ch.codePointAt(0));
|
|
50
|
+
if (used + w > width - 1) break;
|
|
51
|
+
out += ch;
|
|
52
|
+
used += w;
|
|
53
|
+
}
|
|
54
|
+
return `${out}…`;
|
|
55
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The one next step a lit-adhd brief offers, chosen by fixed priority over the collected records,
|
|
2
|
+
// and the small record `go` later reads back within 30 minutes:
|
|
3
|
+
// 1. this session's paused spine frame -> resume-frame (`lit continue`)
|
|
4
|
+
// 2. this session's active start-work -> continue-work
|
|
5
|
+
// 3. a single open plan with no work -> start-plan (`lit start plans/<plan>.md`)
|
|
6
|
+
// 4. otherwise -> none
|
|
7
|
+
// A start-work approval is typed as `lit approve` when the run asks for it; agy keeps no record of a
|
|
8
|
+
// pending one for a brief to offer.
|
|
9
|
+
|
|
10
|
+
import { closeSync, constants, fstatSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { dirname, join } from 'node:path';
|
|
12
|
+
import { safeId } from '../common.mjs';
|
|
13
|
+
|
|
14
|
+
export const chooseNextStep = (data, sessionId) => {
|
|
15
|
+
const ownStack = data.workflows.find((f) => f.sessionId === sessionId && f.role === 'spine' && f.status === 'paused');
|
|
16
|
+
if (sessionId && ownStack) {
|
|
17
|
+
return { kind: 'resume-frame', target: { skill: ownStack.skill, stage: ownStack.stage, progress: ownStack.progress.gauge ?? `${ownStack.progress.done ?? 0} done` }, say: 'lit continue' };
|
|
18
|
+
}
|
|
19
|
+
const own = data.startWork.find((w) => w.status === 'active' && sessionId && w.sessionId === sessionId);
|
|
20
|
+
if (own) return { kind: 'continue-work', target: { plan: own.plan }, say: 'go' };
|
|
21
|
+
const running = data.startWork.some((w) => ['active', 'paused'].includes(w.status));
|
|
22
|
+
const open = data.roadmap.plans.filter((p) => p.local && p.progress.total !== null && p.progress.done < p.progress.total);
|
|
23
|
+
if (!running && open.length === 1) {
|
|
24
|
+
return { kind: 'start-plan', target: { plan: open[0].plan }, say: 'go', command: `lit start ${open[0].plan}` };
|
|
25
|
+
}
|
|
26
|
+
return { kind: 'none', target: null };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const nextStepPath = (root, conversationId) => {
|
|
30
|
+
const id = safeId(conversationId);
|
|
31
|
+
if (!id) return null;
|
|
32
|
+
return join(root, 'adhd', `next-${id}.json`);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const writeNextStep = (root, conversationId, step, now = new Date()) => {
|
|
36
|
+
const path = nextStepPath(root, conversationId);
|
|
37
|
+
if (!path) return null;
|
|
38
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
39
|
+
const staging = `${path}.${process.pid}.tmp`;
|
|
40
|
+
writeFileSync(staging, `${JSON.stringify({ kind: step.kind, target: step.target, at: now.toISOString() })}\n`);
|
|
41
|
+
renameSync(staging, path);
|
|
42
|
+
return path;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const GO_PROMPT = /^\s*(?:(?:lit\s+)?go|ㄱㄱ|고|진행)[\s.!?]*$/iu;
|
|
46
|
+
export const isGoPrompt = (prompt) => typeof prompt === 'string' && prompt.length <= 64 && GO_PROMPT.test(prompt);
|
|
47
|
+
|
|
48
|
+
export const NEXT_STEP_MAX_AGE_MS = 30 * 60_000;
|
|
49
|
+
const KINDS = new Set(['resume-frame', 'continue-work', 'start-plan', 'none']);
|
|
50
|
+
|
|
51
|
+
export const takeNextStep = (root, conversationId, now = Date.now()) => {
|
|
52
|
+
const path = nextStepPath(root, conversationId);
|
|
53
|
+
if (!path) return null;
|
|
54
|
+
let text;
|
|
55
|
+
try {
|
|
56
|
+
const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
57
|
+
try {
|
|
58
|
+
const stat = fstatSync(fd);
|
|
59
|
+
if (!stat.isFile() || stat.size > 16_384) return null;
|
|
60
|
+
text = readFileSync(fd, 'utf8');
|
|
61
|
+
} finally {
|
|
62
|
+
closeSync(fd);
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
} finally {
|
|
67
|
+
try { unlinkSync(path); } catch { /* nothing to consume */ }
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const record = JSON.parse(text);
|
|
71
|
+
const age = now - Date.parse(record.at);
|
|
72
|
+
if (!KINDS.has(record.kind) || !(age >= -60_000 && age <= NEXT_STEP_MAX_AGE_MS)) return null;
|
|
73
|
+
return { kind: record.kind, target: record.target && typeof record.target === 'object' ? record.target : null };
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Redaction for every string the lit-adhd collector emits. Credential shapes, URI userinfo,
|
|
2
|
+
// secret-named NAME=value pairs and quoted "name": value pairs, one-time codes beside an auth word,
|
|
3
|
+
// environment values of 8+ characters, and the home directory. Shorter environment values are left
|
|
4
|
+
// alone: masking every short value would erase ordinary words.
|
|
5
|
+
|
|
6
|
+
const MASK = '[redacted]';
|
|
7
|
+
const SECRET_NAME = /KEY|TOKEN|SECRET|PASS|AUTH|COOKIE/iu;
|
|
8
|
+
const ASSIGNMENT = /\b([A-Za-z_][A-Za-z0-9_]*)=("[^"]*"|'[^']*'|[^\s"'`]+)/gu;
|
|
9
|
+
// A quoted key (JSON, a dict literal) names a secret when it ends in one; `author` does not.
|
|
10
|
+
const QUOTED_PAIR = /(["'])([A-Za-z_][A-Za-z0-9_-]*)\1(\s*:\s*)("(?:[^"\\]|\\.)*"|'[^']*'|[^\s,}\]]+)/gu;
|
|
11
|
+
const SECRET_KEY = /(?:key|token|secret|passw(?:or)?d|passphrase|cookie|credentials?|authorization|auth)$/iu;
|
|
12
|
+
const ONE_TIME = [
|
|
13
|
+
/\b((?:otp|passcode|pin|2fa|mfa|one[- ]time (?:code|password)|verification code|auth(?:entication)? code)\b[\s:=#-]*)\d{4,8}\b/giu,
|
|
14
|
+
/(인증\s*(?:번호|코드)\s*[:=]?\s*)\d{4,8}(?!\d)/gu,
|
|
15
|
+
];
|
|
16
|
+
// Terminal control: ESC/CSI/OSC sequences, other C0/C1 controls and bidi overrides would act on the
|
|
17
|
+
// terminal that shows the brief, so they go before anything else. Tab and newline stay.
|
|
18
|
+
const OSC = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?/gu;
|
|
19
|
+
const CSI = /(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]/gu;
|
|
20
|
+
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/gu;
|
|
21
|
+
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;
|
|
22
|
+
|
|
23
|
+
const SHAPES = [
|
|
24
|
+
/(?<![A-Za-z0-9_])(?:ghp|gho|ghu|ghs|ghr|github_pat)_[A-Za-z0-9_]{20,}(?![A-Za-z0-9_])/gu,
|
|
25
|
+
/(?<![A-Za-z0-9_])(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,}(?![A-Za-z0-9_])/gu,
|
|
26
|
+
/\bsk-[A-Za-z0-9_-]{20,}\b/gu,
|
|
27
|
+
/(?<![A-Za-z0-9_])npm_[A-Za-z0-9]{20,}(?![A-Za-z0-9_])/gu,
|
|
28
|
+
/(?<![A-Z0-9])(?:AKIA|ASIA)[A-Z0-9]{16}(?![A-Z0-9])/gu,
|
|
29
|
+
/(?<![A-Za-z0-9_])xox[baprs]-[A-Za-z0-9-]{10,}(?![A-Za-z0-9_-])/gu,
|
|
30
|
+
/(?<![A-Za-z0-9_])AIza[0-9A-Za-z_-]{20,}(?![A-Za-z0-9_])/gu,
|
|
31
|
+
/\bbearer\s+[A-Za-z0-9._~+/=-]{12,}(?=$|[^A-Za-z0-9._~+/=-])/giu,
|
|
32
|
+
/\b(?:password|passwd|secret|token|api[_-]?key|access[_-]?token)\s*[:=]\s*[^\s,;]+/giu,
|
|
33
|
+
];
|
|
34
|
+
const USERINFO = /(?<![A-Za-z0-9+.-])(?:[A-Za-z][A-Za-z0-9+.-]*:)?\/\/[^/?#\s]+@/gu;
|
|
35
|
+
|
|
36
|
+
const envSecrets = (env) => Object.entries(env ?? {})
|
|
37
|
+
.filter(([name, value]) => typeof value === 'string' && value.length >= 8 && !PLAIN_ENV_NAMES.test(name)
|
|
38
|
+
&& !/^[~/]/u.test(value) && !value.includes(':/') && !/^(?:true|false|\d+)$/iu.test(value))
|
|
39
|
+
.map(([, value]) => value)
|
|
40
|
+
.sort((a, b) => b.length - a.length);
|
|
41
|
+
|
|
42
|
+
export const makeRedactor = ({ env = process.env, home = env?.HOME } = {}) => {
|
|
43
|
+
const values = envSecrets(env);
|
|
44
|
+
return (input) => {
|
|
45
|
+
if (typeof input !== 'string' || input === '') return input;
|
|
46
|
+
let text = input.replace(OSC, '').replace(CSI, '').replace(CONTROL, '');
|
|
47
|
+
for (const value of values) if (text.includes(value)) text = text.split(value).join(MASK);
|
|
48
|
+
text = text.replace(USERINFO, (match) => match.replace(/\/\/[^/?#\s]+@/u, `//${MASK}@`));
|
|
49
|
+
text = text.replace(ASSIGNMENT, (match, name) => (SECRET_NAME.test(name) ? `${name}=${MASK}` : match));
|
|
50
|
+
text = text.replace(QUOTED_PAIR, (match, quote, name, sep, value) => {
|
|
51
|
+
if (!SECRET_KEY.test(name)) return match;
|
|
52
|
+
const q = /^["']/u.test(value) ? value[0] : '';
|
|
53
|
+
return `${quote}${name}${quote}${sep}${q}${MASK}${q}`;
|
|
54
|
+
});
|
|
55
|
+
for (const pattern of ONE_TIME) text = text.replace(pattern, (match, lead) => `${lead}${MASK}`);
|
|
56
|
+
for (const pattern of SHAPES) text = text.replace(pattern, MASK);
|
|
57
|
+
if (typeof home === 'string' && home.length > 1) text = text.split(home).join('~');
|
|
58
|
+
return text;
|
|
59
|
+
};
|
|
60
|
+
};
|