@litfamily/litclaude 1.0.43 → 1.0.45

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +8 -8
  3. package/README_ko-KR.md +8 -8
  4. package/bin/litclaude-ai.js +201 -5
  5. package/docs/assets/readme/badge-version.svg +1 -1
  6. package/package.json +1 -1
  7. package/plugins/litclaude/.claude-plugin/plugin.json +1 -1
  8. package/plugins/litclaude/agents/korean-prose-editor.md +2 -0
  9. package/plugins/litclaude/agents/korean-style-analyzer.md +2 -0
  10. package/plugins/litclaude/agents/librarian-researcher.md +2 -0
  11. package/plugins/litclaude/agents/lit-executor.md +2 -0
  12. package/plugins/litclaude/agents/lit-planner.md +2 -0
  13. package/plugins/litclaude/agents/lit-verifier.md +2 -0
  14. package/plugins/litclaude/agents/meaning-preservation-auditor.md +2 -0
  15. package/plugins/litclaude/agents/native-flow-reviewer.md +2 -0
  16. package/plugins/litclaude/agents/polish-orchestrator.md +2 -0
  17. package/plugins/litclaude/agents/qa-runner.md +2 -0
  18. package/plugins/litclaude/agents/quality-reviewer.md +2 -0
  19. package/plugins/litclaude/bin/litclaude-ai +1 -0
  20. package/plugins/litclaude/bin/litclaude-hook.js +31 -12
  21. package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
  22. package/plugins/litclaude/commands/litgoal.md +3 -1
  23. package/plugins/litclaude/hooks/hooks.json +1 -1
  24. package/plugins/litclaude/lib/agent-file/apply.mjs +150 -0
  25. package/plugins/litclaude/lib/agent-file/attribution.mjs +62 -0
  26. package/plugins/litclaude/lib/agent-file/block.md +12 -0
  27. package/plugins/litclaude/lib/agent-file/cli.mjs +71 -0
  28. package/plugins/litclaude/lib/agent-file/managed-block.mjs +82 -0
  29. package/plugins/litclaude/lib/agent-file/project-block.md +9 -0
  30. package/plugins/litclaude/lib/canonical-runtime-commitments.mjs +6 -6
  31. package/plugins/litclaude/lib/canonical-skill-resources.mjs +51 -48
  32. package/plugins/litclaude/lib/litgoal/autoloop.mjs +57 -8
  33. package/plugins/litclaude/lib/litgoal/cli.mjs +62 -1
  34. package/plugins/litclaude/lib/litgoal/freshness.mjs +55 -0
  35. package/plugins/litclaude/lib/litgoal/ledger.mjs +1 -1
  36. package/plugins/litclaude/lib/litgoal/state.mjs +1 -1
  37. package/plugins/litclaude/lib/litgoal/unknowns.mjs +44 -0
  38. package/plugins/litclaude/lib/mark-logo.png +0 -0
  39. package/plugins/litclaude/lib/mark.mjs +392 -0
  40. package/plugins/litclaude/lib/official-build.mjs +22 -0
  41. package/plugins/litclaude/lib/output_mark.py +132 -0
  42. package/plugins/litclaude/lib/render_pages.py +16 -0
  43. package/plugins/litclaude/lib/rewind/brief.mjs +12 -2
  44. package/plugins/litclaude/lib/rewind/collect.mjs +83 -12
  45. package/plugins/litclaude/lib/rewind/next-step.mjs +21 -3
  46. package/plugins/litclaude/lib/start-work-lifecycle.mjs +6 -4
  47. package/plugins/litclaude/skills/autoconference/SKILL.md +2 -0
  48. package/plugins/litclaude/skills/autoresearch/SKILL.md +2 -0
  49. package/plugins/litclaude/skills/browser-drive/SKILL.md +2 -0
  50. package/plugins/litclaude/skills/comment-checker/SKILL.md +2 -0
  51. package/plugins/litclaude/skills/debugging/SKILL.md +2 -0
  52. package/plugins/litclaude/skills/deep-interview/SKILL.md +2 -0
  53. package/plugins/litclaude/skills/frontend-ui-ux/SKILL.md +2 -0
  54. package/plugins/litclaude/skills/lit-adhd/SKILL.md +8 -4
  55. package/plugins/litclaude/skills/lit-brainstorm/SKILL.md +2 -0
  56. package/plugins/litclaude/skills/lit-burnoff/SKILL.md +2 -0
  57. package/plugins/litclaude/skills/lit-burnoff-file/SKILL.md +2 -0
  58. package/plugins/litclaude/skills/lit-code/SKILL.md +2 -0
  59. package/plugins/litclaude/skills/lit-commit/SKILL.md +2 -0
  60. package/plugins/litclaude/skills/lit-comprehend/SKILL.md +2 -0
  61. package/plugins/litclaude/skills/lit-crucible/SKILL.md +2 -0
  62. package/plugins/litclaude/skills/lit-diagram-drawer/SKILL.md +3 -1
  63. package/plugins/litclaude/skills/lit-diagram-drawer/scripts/export.mjs +35 -1
  64. package/plugins/litclaude/skills/lit-docx/SKILL.md +2 -0
  65. package/plugins/litclaude/skills/lit-docx/scripts/convert_md_to_docx.py +4 -1
  66. package/plugins/litclaude/skills/lit-docx/scripts/convert_md_to_pdf.py +2 -0
  67. package/plugins/litclaude/skills/lit-handoff/SKILL.md +2 -0
  68. package/plugins/litclaude/skills/lit-hijack/SKILL.md +2 -0
  69. package/plugins/litclaude/skills/lit-humanizer/SKILL.md +2 -0
  70. package/plugins/litclaude/skills/lit-init/SKILL.md +14 -0
  71. package/plugins/litclaude/skills/lit-loop/SKILL.md +2 -0
  72. package/plugins/litclaude/skills/lit-plan/SKILL.md +2 -0
  73. package/plugins/litclaude/skills/lit-pptx/SKILL.md +2 -0
  74. package/plugins/litclaude/skills/lit-pptx/scripts/lib/render-adapter-pptx.js +6 -1
  75. package/plugins/litclaude/skills/lit-recap/SKILL.md +2 -0
  76. package/plugins/litclaude/skills/lit-schematic/SKILL.md +3 -1
  77. package/plugins/litclaude/skills/lit-schematic/scripts/lib/sheet.mjs +10 -0
  78. package/plugins/litclaude/skills/lit-schematic/scripts/lib/svg.mjs +4 -0
  79. package/plugins/litclaude/skills/lit-schematic/scripts/motion.mjs +5 -2
  80. package/plugins/litclaude/skills/lit-schematic/scripts/render.mjs +20 -2
  81. package/plugins/litclaude/skills/lit-scientific-visualization/SKILL.md +2 -0
  82. package/plugins/litclaude/skills/lit-team/SKILL.md +2 -0
  83. package/plugins/litclaude/skills/lit-typographic-motion/SKILL.md +2 -0
  84. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/chrome.mjs +23 -2
  85. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-capture.mjs +14 -1
  86. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover.mjs +48 -2
  87. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/encode.mjs +8 -1
  88. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/end-card.mjs +128 -0
  89. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/pipeline.mjs +59 -14
  90. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-gate.mjs +7 -4
  91. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage.mjs +33 -8
  92. package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/init.js +13 -0
  93. package/plugins/litclaude/skills/lit-typographic-motion/references/studio.md +11 -0
  94. package/plugins/litclaude/skills/litgoal/SKILL.md +53 -1
  95. package/plugins/litclaude/skills/litresearch/SKILL.md +2 -0
  96. package/plugins/litclaude/skills/litwork/SKILL.md +2 -0
  97. package/plugins/litclaude/skills/lsp/SKILL.md +2 -0
  98. package/plugins/litclaude/skills/lsp-setup/SKILL.md +2 -0
  99. package/plugins/litclaude/skills/readme-studio/SKILL.md +3 -1
  100. package/plugins/litclaude/skills/readme-studio/templates/cover-source.json +1 -0
  101. package/plugins/litclaude/skills/readme-studio/templates/hyperframes-cover/index.html +3 -2
  102. package/plugins/litclaude/skills/readme-studio/templates/hyperframes-cover/package-lock.json +4 -4
  103. package/plugins/litclaude/skills/readme-studio/templates/remotion-cover/package-lock.json +3 -3
  104. package/plugins/litclaude/skills/readme-studio/templates/remotion-cover/package.json +2 -1
  105. package/plugins/litclaude/skills/readme-studio/templates/remotion-cover/src/index.tsx +4 -3
  106. package/plugins/litclaude/skills/refactor/SKILL.md +2 -0
  107. package/plugins/litclaude/skills/review-work/SKILL.md +2 -0
  108. package/plugins/litclaude/skills/rules/SKILL.md +2 -0
  109. package/plugins/litclaude/skills/start-work/SKILL.md +2 -0
  110. package/plugins/litclaude/skills/structural-search/SKILL.md +2 -0
  111. package/plugins/litclaude/skills/visual-qa/SKILL.md +2 -0
  112. package/plugins/litclaude/skills/wikify/SKILL.md +2 -0
  113. package/scripts/doctor.mjs +3 -1
  114. package/scripts/prepublish-test-gate.mjs +75 -22
@@ -31,8 +31,7 @@ import {
31
31
  DEFAULT_PROMPT_MAX_RULE_CHARS,
32
32
  } from "../lib/rules/constants.mjs";
33
33
  import { litgoalGoalsPath } from "../lib/litgoal/paths.mjs";
34
- import { readLitgoalState } from "../lib/litgoal/state.mjs";
35
- import { completeAutoloopGoal, evaluateAutoloop, readAutoloopState, writeAutoloopState } from "../lib/litgoal/autoloop.mjs";
34
+ import { completeAutoloopGoal, evaluateAutoloop, handAutoloopToUser, readAutoloopState, refreshAutoloopState, writeAutoloopState } from "../lib/litgoal/autoloop.mjs";
36
35
  import { buildNativeGoalBindingGuidance, normalizeGoalObjective } from "../lib/native-goal-binding.mjs";
37
36
  import { automaticUpdateCachePath, runAutomaticUpdate } from "../lib/automatic-update.mjs";
38
37
  import {
@@ -50,6 +49,7 @@ import {
50
49
  recordStartWorkSubagentStart,
51
50
  recordStartWorkSubagentStop,
52
51
  resumeStartWorkFromUserPrompt,
52
+ StartWorkLifecycleError,
53
53
  startWorkStructuredContext,
54
54
  } from "../lib/start-work-lifecycle.mjs";
55
55
  import { formatResolvedPlanNotice, resolveLatestDurablePlan } from "../lib/durable-plan.mjs";
@@ -373,10 +373,13 @@ const llmContractContext = [
373
373
  // SessionStart is a new context boundary and therefore loads the full contract again.
374
374
  const llmContractReference = "Reader-facing contract reference: the contract loaded at SessionStart applies; reader mode by default.";
375
375
 
376
+ // The notice line that ends every SKILL.md (copyright and fingerprint) belongs to the file, not the prompt.
377
+ const skillNoticeLine = /\n*<!-- LitClaude © \d{4} wjgoarxiv · MIT · github\.com\/wjgoarxiv\/litclaude · fp:[0-9a-f]{12} -->$/u;
378
+
376
379
  const staticSkillBodyContext = ({ skillId, safetyBlock }) => {
377
380
  if (!skillId || safetyBlock) return [];
378
381
  try {
379
- const body = readFileSync(new URL(`../skills/${skillId}/SKILL.md`, import.meta.url), "utf8").trim();
382
+ const body = readFileSync(new URL(`../skills/${skillId}/SKILL.md`, import.meta.url), "utf8").trim().replace(skillNoticeLine, "");
380
383
  if (!body) return [];
381
384
  return [
382
385
  `<litclaude-skill-body name="${skillId}">
@@ -1372,6 +1375,10 @@ const invocationContext = (invoked, invocation) => {
1372
1375
  if (invoked.nothing) {
1373
1376
  return [`Nothing in this session's start-work is waiting for approval, so \`lit ${invoked.nothing}\` changed nothing. Tell the user that in one sentence and start no other work.`, "LitClaude start-work had nothing to approve."];
1374
1377
  }
1378
+ if (invoked.busy) {
1379
+ const typed = invoked.busy === "start" ? "start-work command" : `\`lit ${invoked.busy}\``;
1380
+ return [`Another LitClaude session or command is updating this project's start-work state right now, so this ${typed} changed nothing. Tell the user in one sentence to send the same prompt again in a few seconds, and start no other work.`, "LitClaude start-work is busy; send it again."];
1381
+ }
1375
1382
  if (invoked.choose) {
1376
1383
  const list = invoked.choose.length ? `Open plans: ${invoked.choose.map(clipPath).join(", ")}.` : "No plan under plans/ has an open task.";
1377
1384
  return [`LitClaude did not start start-work: ${invocation?.plan ? "that plan" : "no single open plan"} could be chosen. ${list} Ask the user which plan to run with \`/litclaude:start-work <plan>\`; do not implement anything from this prompt.`, "LitClaude start-work needs a plan name."];
@@ -1724,20 +1731,29 @@ switch (eventName) {
1724
1731
  const own = resolveProjectStateRoot(cwd);
1725
1732
  const above = relative(found, own);
1726
1733
  const lifecycleRoot = above && !above.startsWith("..") && !isAbsolute(above) ? own : found;
1734
+ // The host drops this hook's answer at its time limit, so a lock another session holds gets a
1735
+ // short wait and a "busy, send it again" reply instead of the full lock wait.
1736
+ process.env.LITCLAUDE_START_WORK_LOCK_TIMEOUT_MS ??= "1500";
1737
+ const lockBusy = (error) => error instanceof StartWorkLifecycleError && error.status === 75;
1727
1738
  try {
1728
1739
  if (invocation.kind === "start" && invocation.plan) {
1729
1740
  adoption = adoptStartWork(lifecycleRoot, { sessionId: input.session_id, plan: invocation.plan, promptId: input.prompt_id });
1730
1741
  }
1731
- } catch {
1742
+ } catch (error) {
1732
1743
  adoption = null;
1744
+ if (lockBusy(error)) invoked = { busy: invocation.kind };
1733
1745
  }
1734
1746
  if (!adoption) {
1735
- try {
1736
- invoked = invocation.kind === "start"
1737
- ? startWorkFromInvocation(lifecycleRoot, { sessionId: input.session_id, promptId: input.prompt_id, plan: invocation.plan })
1738
- : (invocation.kind === "approve" ? approveStartWorkBoundary : denyStartWorkBoundary)(lifecycleRoot, { sessionId: input.session_id, promptId: input.prompt_id }) ?? { nothing: invocation.kind };
1739
- } catch (error) {
1740
- invoked = { failed: error instanceof Error ? error.message : "lifecycle validation failed" };
1747
+ if (!invoked) {
1748
+ try {
1749
+ invoked = invocation.kind === "start"
1750
+ ? startWorkFromInvocation(lifecycleRoot, { sessionId: input.session_id, promptId: input.prompt_id, plan: invocation.plan })
1751
+ : (invocation.kind === "approve" ? approveStartWorkBoundary : denyStartWorkBoundary)(lifecycleRoot, { sessionId: input.session_id, promptId: input.prompt_id }) ?? { nothing: invocation.kind };
1752
+ } catch (error) {
1753
+ invoked = lockBusy(error)
1754
+ ? { busy: invocation.kind }
1755
+ : { failed: error instanceof Error ? error.message : "lifecycle validation failed" };
1756
+ }
1741
1757
  }
1742
1758
  invoked = { ...invoked, lifecycleRoot, sessionId: input.session_id };
1743
1759
  }
@@ -2161,7 +2177,7 @@ switch (eventName) {
2161
2177
  try {
2162
2178
  const cwd = typeof input.cwd === "string" ? input.cwd : process.cwd();
2163
2179
  const stateRoot = resolveProjectStateRoot(cwd);
2164
- const state = readLitgoalState(litgoalGoalsPath(stateRoot), null);
2180
+ const state = existsSync(litgoalGoalsPath(stateRoot)) ? refreshAutoloopState(stateRoot) : null;
2165
2181
  const autoloopState = readAutoloopState(stateRoot);
2166
2182
  decision = evaluateAutoloop({ env: process.env, state, autoloopState });
2167
2183
  if (decision.action === "block") {
@@ -2171,6 +2187,9 @@ switch (eventName) {
2171
2187
  console.log(JSON.stringify({ decision: "block", reason: decision.reason }));
2172
2188
  } else if (decision.action === "cap") {
2173
2189
  console.log(JSON.stringify({ continue: false, stopReason: decision.stopReason }));
2190
+ } else if (decision.action === "handoff") {
2191
+ handAutoloopToUser(stateRoot, decision.stopReason);
2192
+ console.log(JSON.stringify({ continue: false, stopReason: decision.stopReason }));
2174
2193
  } else if (
2175
2194
  decision.why !== "kill-switch"
2176
2195
  && (decision.why === "all-criteria-pass"
@@ -2183,7 +2202,7 @@ switch (eventName) {
2183
2202
  // Any error -> allow stop (no output).
2184
2203
  }
2185
2204
  // Automatic handoff runs last, so it only takes a stop that nothing else wanted to continue.
2186
- if (decision?.action !== "block" && decision?.action !== "cap") {
2205
+ if (decision?.action !== "block" && decision?.action !== "cap" && decision?.action !== "handoff") {
2187
2206
  try {
2188
2207
  const cwd = typeof input.cwd === "string" ? input.cwd : process.cwd();
2189
2208
  const handoff = evaluateAutoHandoffStop({
@@ -9,7 +9,7 @@ import {
9
9
  } from "../lib/wikify-knowledge.mjs";
10
10
 
11
11
  const protocolVersion = "2024-11-05";
12
- const serverVersion = "1.0.43";
12
+ const serverVersion = "1.0.45";
13
13
 
14
14
  const publicSourceReadTool = {
15
15
  name: "public_source_read",
@@ -83,12 +83,14 @@ complete.
83
83
 
84
84
  Prefer the package CLI for durable local state:
85
85
  `litclaude-ai litgoal create-goals`, `status`, `criteria`,
86
- `record-evidence`, `checkpoint`, `steer`, and `record-review-blockers`.
86
+ `record-evidence` (with `--inputs` / `--reviewed` to bind a pass to file hashes), `checkpoint`,
87
+ `steer`, `record-review-blockers`, and `unknown add|resolve|list` for the KK/KU/UK/UU register.
87
88
  The installed alias may also be invoked as:
88
89
 
89
90
  ```bash
90
91
  litclaude litgoal create-goals --brief "<brief>" --json
91
92
  litclaude litgoal record-evidence --criterion <id> --status pass --json '{"artifact":"...","cleanup":"..."}'
93
+ litclaude litgoal unknown add --kind KU --text "<question>" --probe "<check>" --critical --json
92
94
  litclaude litgoal checkpoint --status active --note "<progress>" --json
93
95
  litclaude litgoal steer --kind scope --note "<what changed and why>" --json
94
96
  ```
@@ -19,7 +19,7 @@
19
19
  {
20
20
  "type": "command",
21
21
  "command": "node \"${CLAUDE_PLUGIN_ROOT}/bin/litclaude-hook.js\" user-prompt-submit",
22
- "timeout": 5,
22
+ "timeout": 10,
23
23
  "statusMessage": "checking LitClaude workflow and bounded-authority lifecycle"
24
24
  }
25
25
  ]
@@ -0,0 +1,150 @@
1
+ // The LitFamily block on disk: the global `CLAUDE.md` that Claude Code reads every session, and a
2
+ // project's `AGENTS.md`. Writes are atomic (temporary file, then rename) and keep the file's mode; a
3
+ // symlinked, non-regular or non-UTF-8 file is refused rather than rewritten; a file system error comes
4
+ // back as `refused-io` instead of stopping the installer. The user's original global file is copied
5
+ // once, the first time a block goes in. The on/off setting is `agentFile` in LitClaude's own
6
+ // config.json; LITCLAUDE_AGENT_FILE overrides it.
7
+
8
+ import { randomUUID } from "node:crypto";
9
+ import { chmodSync, copyFileSync, lstatSync, mkdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
10
+ import { dirname, join } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+
13
+ import { readLitConfigKey, writeLitConfigKey } from "../mark.mjs";
14
+ import { ATTRIBUTION_LINE } from "./attribution.mjs";
15
+ import { inspectBlock, ManagedBlockError, removeBlock, upsertBlock } from "./managed-block.mjs";
16
+
17
+ export const AGENT_FILE_ID = "litclaude";
18
+ export const AGENT_FILE_MODES = Object.freeze(["on", "off"]);
19
+ // The global block is read on every turn of every session, so it stays small.
20
+ export const AGENT_FILE_MAX_BYTES = 1200;
21
+
22
+ const here = dirname(fileURLToPath(import.meta.url));
23
+ const BODIES = { global: "block.md", project: "project-block.md" };
24
+
25
+ /**
26
+ * The shipped block text: `global` for CLAUDE.md, `project` for a repo's AGENTS.md. With attribution
27
+ * `off` it carries the no-attribution line, before the global block's closing off-switch line.
28
+ */
29
+ export const agentFileBody = (kind = "global", { attribution = "keep" } = {}) => {
30
+ const body = readFileSync(join(here, BODIES[kind]), "utf8");
31
+ if (attribution !== "off") return body;
32
+ const offSwitch = body.indexOf("\n- Turn this block off");
33
+ return offSwitch === -1
34
+ ? `${body.replace(/\n*$/u, "\n")}${ATTRIBUTION_LINE}\n`
35
+ : `${body.slice(0, offSwitch + 1)}${ATTRIBUTION_LINE}\n${body.slice(offSwitch + 1)}`;
36
+ };
37
+
38
+ export const readAgentFileMode = ({ env = process.env, litHome }) => {
39
+ const override = String(env.LITCLAUDE_AGENT_FILE ?? "").trim().toLowerCase();
40
+ if (AGENT_FILE_MODES.includes(override)) return override;
41
+ const stored = readLitConfigKey(litHome, "agentFile");
42
+ return AGENT_FILE_MODES.includes(stored) ? stored : "on";
43
+ };
44
+
45
+ export const writeAgentFileMode = (litHome, mode) => {
46
+ if (!AGENT_FILE_MODES.includes(mode)) throw new Error(`agentFile takes one of: ${AGENT_FILE_MODES.join(", ")}`);
47
+ return writeLitConfigKey(litHome, "agentFile", mode);
48
+ };
49
+
50
+ // "missing", "file", "symlink" or "other", without following a link.
51
+ const entryKind = (path) => {
52
+ try {
53
+ const stats = lstatSync(path);
54
+ return stats.isSymbolicLink() ? "symlink" : stats.isFile() ? "file" : "other";
55
+ } catch (error) {
56
+ if (error.code === "ENOENT") return "missing";
57
+ throw error;
58
+ }
59
+ };
60
+
61
+ // The file's text, or null when it is not UTF-8 (a UTF-16 file from Notepad, Latin-1): rewriting
62
+ // those would corrupt the user's bytes outside the markers.
63
+ const readUtf8 = (path) => {
64
+ const bytes = readFileSync(path);
65
+ if (bytes.includes(0) || (bytes[0] === 0xff && bytes[1] === 0xfe) || (bytes[0] === 0xfe && bytes[1] === 0xff)) return null;
66
+ try {
67
+ return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
68
+ } catch {
69
+ return null;
70
+ }
71
+ };
72
+
73
+ // A unique staging name, so a leftover from a crashed run never blocks the next one, removed on failure.
74
+ const writeAtomic = (path, text, { createParent }) => {
75
+ if (createParent) mkdirSync(dirname(path), { recursive: true });
76
+ const staging = `${path}.litfamily-${randomUUID()}.tmp`;
77
+ let mode = null;
78
+ try {
79
+ mode = statSync(path).mode & 0o7777;
80
+ } catch {
81
+ // A new file takes the default mode.
82
+ }
83
+ try {
84
+ writeFileSync(staging, text, { flag: "wx" });
85
+ if (mode !== null) chmodSync(staging, mode);
86
+ renameSync(staging, path);
87
+ } finally {
88
+ try {
89
+ unlinkSync(staging);
90
+ } catch {
91
+ // Renamed into place, or never written.
92
+ }
93
+ }
94
+ };
95
+
96
+ /**
97
+ * Installs or removes block `id` in `path`. Returns `{status, path, backup?, preview?}` with status
98
+ * created | updated | unchanged | removed | absent | dry-run | refused-symlink | refused-not-file |
99
+ * refused-not-utf8 | refused-malformed | refused-io. `backup: false` skips the first-insert copy (a
100
+ * repo's AGENTS.md, where a copy would sit beside tracked files); `createParent: false` never makes
101
+ * the folder.
102
+ */
103
+ export const applyAgentFile = ({ path, id = AGENT_FILE_ID, version, body, action, dryRun = false, now = new Date(), backup = true, createParent = true }) => {
104
+ try {
105
+ const kind = entryKind(path);
106
+ if (kind === "symlink") return { status: "refused-symlink", path };
107
+ if (kind === "other") return { status: "refused-not-file", path };
108
+ const text = kind === "file" ? readUtf8(path) : "";
109
+ if (text === null) return { status: "refused-not-utf8", path };
110
+ let next;
111
+ try {
112
+ next = action === "uninstall" ? removeBlock(text, id) : upsertBlock(text, { id, version, body }, { created: kind === "missing" });
113
+ } catch (error) {
114
+ if (error instanceof ManagedBlockError) return { status: "refused-malformed", path };
115
+ throw error;
116
+ }
117
+ if (!next.changed) return { status: action === "uninstall" ? "absent" : "unchanged", path };
118
+ if (dryRun) return { status: "dry-run", path, preview: next.text };
119
+ if (action === "uninstall") {
120
+ if (next.text === "" && next.created) unlinkSync(path);
121
+ else writeAtomic(path, next.text, { createParent: false });
122
+ return { status: "removed", path };
123
+ }
124
+ let copy;
125
+ if (backup && kind === "file" && inspectBlock(text, id).state === "absent") {
126
+ copy = `${path}.litfamily-backup-${now.toISOString().replace(/[:.]/gu, "-")}`;
127
+ copyFileSync(path, copy);
128
+ }
129
+ writeAtomic(path, next.text, { createParent });
130
+ return { status: kind === "file" ? "updated" : "created", path, ...(copy ? { backup: copy } : {}) };
131
+ } catch (error) {
132
+ return { status: "refused-io", path, error: error?.code ?? error?.message };
133
+ }
134
+ };
135
+
136
+ /**
137
+ * `present v=<x>` (current), `stale v=<x>` (an older install's block), `absent`, `malformed`, or
138
+ * `symlink` / `not-file` / `not-utf8` for a file LitClaude will not write.
139
+ */
140
+ export const agentFileState = ({ path, id = AGENT_FILE_ID, version }) => {
141
+ const kind = entryKind(path);
142
+ if (kind === "missing") return "absent";
143
+ if (kind === "symlink") return "symlink";
144
+ if (kind === "other") return "not-file";
145
+ const text = readUtf8(path);
146
+ if (text === null) return "not-utf8";
147
+ const found = inspectBlock(text, id);
148
+ if (found.state !== "present") return found.state;
149
+ return `${found.version === version ? "present" : "stale"} v=${found.version}`;
150
+ };
@@ -0,0 +1,62 @@
1
+ // The attribution switch. `keep` (the default) leaves Claude Code's own Co-Authored-By trailer and pull
2
+ // request line as the host writes them; `off` hides them through Claude Code's native `attribution`
3
+ // setting and adds one line to the LitFamily block. The object form below hides all three parts on every
4
+ // Claude Code version (`attribution: false` needs 2.1.281, and older versions skip the whole file).
5
+ // Before the first change LitClaude keeps the user's earlier value in its own settings record, and
6
+ // restoring puts exactly that value back.
7
+
8
+ import { readLitConfigKey, writeLitConfigKey } from "../mark.mjs";
9
+
10
+ export const ATTRIBUTION_MODES = Object.freeze(["keep", "off"]);
11
+ export const HIDDEN_ATTRIBUTION = Object.freeze({ commit: "", pr: "", sessionUrl: false });
12
+ export const ATTRIBUTION_LINE = "- Do not add `Co-Authored-By` lines or other AI attribution to commits or pull requests.";
13
+
14
+ /** The stored choice, or undefined when the user never made one. */
15
+ export const storedAttributionMode = (litHome) => {
16
+ const stored = readLitConfigKey(litHome, "attribution");
17
+ return ATTRIBUTION_MODES.includes(stored) ? stored : undefined;
18
+ };
19
+
20
+ export const readAttributionMode = ({ env = process.env, litHome }) => {
21
+ const override = String(env.LITCLAUDE_ATTRIBUTION ?? "").trim().toLowerCase();
22
+ if (ATTRIBUTION_MODES.includes(override)) return override;
23
+ return storedAttributionMode(litHome) ?? "keep";
24
+ };
25
+
26
+ export const writeAttributionMode = (litHome, mode) => {
27
+ if (!ATTRIBUTION_MODES.includes(mode)) throw new Error(`attribution takes one of: ${ATTRIBUTION_MODES.join(", ")}`);
28
+ return writeLitConfigKey(litHome, "attribution", mode);
29
+ };
30
+
31
+ const isHidden = (value) => JSON.stringify(value) === JSON.stringify(HIDDEN_ATTRIBUTION);
32
+
33
+ /**
34
+ * Hides attribution in `settings`; `record` (LitClaude's settings entry) keeps the earlier value once.
35
+ * When LitClaude hid it before and the user has since set their own value, that value wins: nothing is
36
+ * changed and the result is `user-changed` (otherwise `hidden`).
37
+ */
38
+ export const applyAttribution = (settings, record) => {
39
+ if (Object.hasOwn(record, "attributionPrior")) {
40
+ if (Object.hasOwn(settings, "attribution") && !isHidden(settings.attribution)) return "user-changed";
41
+ } else {
42
+ record.attributionPrior = Object.hasOwn(settings, "attribution")
43
+ ? { had: true, value: structuredClone(settings.attribution) }
44
+ : { had: false };
45
+ }
46
+ settings.attribution = { ...HIDDEN_ATTRIBUTION };
47
+ return "hidden";
48
+ };
49
+
50
+ /**
51
+ * Puts back the value `applyAttribution` replaced, but only while the setting still holds what
52
+ * LitClaude wrote; a value the user set since, or one LitClaude never touched, is left alone.
53
+ */
54
+ export const restoreAttribution = (settings, record) => {
55
+ if (!record || !Object.hasOwn(record, "attributionPrior")) return;
56
+ const prior = record.attributionPrior;
57
+ if (isHidden(settings.attribution)) {
58
+ if (prior?.had) settings.attribution = prior.value;
59
+ else delete settings.attribution;
60
+ }
61
+ delete record.attributionPrior;
62
+ };
@@ -0,0 +1,12 @@
1
+ ## LitFamily · LitClaude
2
+
3
+ LitClaude adds the lit workflows to Claude Code (lit-plan, start-work, lit-loop, review-work, lit-adhd,
4
+ litresearch). Its hooks load the full rules on each turn, so this block only sets the ground rules.
5
+
6
+ - `lit` at the start of a prompt is LitClaude's activation word, not the Lit web library.
7
+ - Plans live in `plans/`, the session handoff in `HANDOFF.md`, run state in `.litclaude/`. Read them
8
+ before resuming work in a repo.
9
+ - Never push, publish, tag or bump a version without the user's explicit yes for that action.
10
+ - Call work done only after its tests pass and the changed surface was checked for real.
11
+ - In a new repo, `lit init` writes a short project `AGENTS.md` with these conventions.
12
+ - Turn this block off with `litclaude-ai config agentFile off`.
@@ -0,0 +1,71 @@
1
+ // `agent-file project [--dir <path>]`, shared by the npm CLI and the plugin's in-session `litclaude-ai`
2
+ // (lit-init runs it inside a session): the project block in the repo's AGENTS.md, plus a CLAUDE.md that
3
+ // imports it when the repo has none. An existing CLAUDE.md is the user's and is left alone.
4
+
5
+ import { lstatSync, readFileSync, statSync, writeFileSync } from "node:fs";
6
+ import { dirname, join, resolve } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ import { markLitHome } from "../mark.mjs";
10
+ import { AGENT_FILE_ID, agentFileBody, applyAgentFile } from "./apply.mjs";
11
+ import { readAttributionMode } from "./attribution.mjs";
12
+
13
+ const manifestPath = join(dirname(fileURLToPath(import.meta.url)), "..", "..", ".claude-plugin", "plugin.json");
14
+ const pluginVersion = () => JSON.parse(readFileSync(manifestPath, "utf8")).version;
15
+
16
+ export const agentFileLine = (result) => `AGENT_FILE: ${result.status} ${result.path}${result.backup ? ` (backup: ${result.backup})` : ""}`;
17
+
18
+ /** Returns the exit code; prints `AGENT_FILE:` lines. */
19
+ export const runAgentFileCli = (rest, { cwd = process.cwd(), dryRun = false, out = process.stdout, err = process.stderr } = {}) => {
20
+ const [sub, ...args] = rest;
21
+ if (sub === "--help" || sub === "-h") {
22
+ out.write("Usage: litclaude-ai agent-file project [--dir <path>]\n");
23
+ return 0;
24
+ }
25
+ if (sub !== "project") {
26
+ err.write("Usage: litclaude-ai agent-file project [--dir <path>]\n");
27
+ return 64;
28
+ }
29
+ let dir = cwd;
30
+ for (let index = 0; index < args.length; index += 1) {
31
+ if (args[index] === "--dir" && args[index + 1]) {
32
+ dir = resolve(cwd, args[index + 1]);
33
+ index += 1;
34
+ continue;
35
+ }
36
+ err.write(`Unknown agent-file option: ${args[index]}\n`);
37
+ return 64;
38
+ }
39
+ let isDirectory = false;
40
+ try {
41
+ isDirectory = statSync(dir).isDirectory();
42
+ } catch {
43
+ // Missing: reported below, never created.
44
+ }
45
+ if (!isDirectory) {
46
+ err.write(`agent-file: ${dir} is not an existing folder\n`);
47
+ return 64;
48
+ }
49
+ const body = agentFileBody("project", { attribution: readAttributionMode({ litHome: markLitHome() }) });
50
+ // No backup copy here: in a repo it would sit untracked beside AGENTS.md and could be committed.
51
+ const agents = applyAgentFile({ path: join(dir, "AGENTS.md"), id: AGENT_FILE_ID, version: pluginVersion(), body, action: "install", dryRun, backup: false, createParent: false });
52
+ out.write(`${agentFileLine(agents)}\n`);
53
+ if (agents.status.startsWith("refused")) return 1;
54
+ const claude = join(dir, "CLAUDE.md");
55
+ let claudeKind = "missing";
56
+ try {
57
+ const stats = lstatSync(claude);
58
+ claudeKind = stats.isSymbolicLink() ? "symlink" : stats.isFile() ? "file" : "other";
59
+ } catch {
60
+ // Missing.
61
+ }
62
+ if (claudeKind === "missing") {
63
+ if (!dryRun) writeFileSync(claude, "@AGENTS.md\n", { flag: "wx" });
64
+ out.write(`AGENT_FILE: ${dryRun ? "dry-run" : "created"} ${claude} (imports AGENTS.md)\n`);
65
+ } else if (claudeKind !== "file") {
66
+ out.write(`AGENT_FILE: ${claudeKind === "symlink" ? "refused-symlink" : "refused-not-file"} ${claude}; left as it is\n`);
67
+ } else if (!readFileSync(claude, "utf8").includes("@AGENTS.md")) {
68
+ out.write(`AGENT_FILE: kept ${claude}; add \`@AGENTS.md\` to it so Claude Code loads the project block\n`);
69
+ }
70
+ return 0;
71
+ };
@@ -0,0 +1,82 @@
1
+ // A LitFamily block inside a user-owned instruction file (CLAUDE.md, AGENTS.md): the lines between
2
+ // `<!-- litfamily:<id>:start v=<version> … -->` and `<!-- litfamily:<id>:end -->`. Only those lines are
3
+ // ever written; the user's text before and after them stays byte for byte. The start marker records
4
+ // what was added in front of the block (`pre=`, hex) and whether the file was created for it (`new=1`),
5
+ // so removing the block takes back exactly that and an add-then-remove returns the original bytes,
6
+ // whatever the file's line endings. A start without its end, or two of either, is malformed: it is
7
+ // reported and refused, never guessed at.
8
+
9
+ export class ManagedBlockError extends Error {}
10
+
11
+ const startPrefix = (id) => `<!-- litfamily:${id}:start`;
12
+ const endMarker = (id) => `<!-- litfamily:${id}:end -->`;
13
+ const eolOf = (text) => (text.includes("\r\n") ? "\r\n" : "\n");
14
+ const START_LINE = /^<!-- litfamily:[^:\s]+:start v=(\S+)((?: [a-z]+=[0-9a-f]*)*) -->/u;
15
+
16
+ const occurrences = (text, needle) => {
17
+ const found = [];
18
+ for (let at = text.indexOf(needle); at !== -1; at = text.indexOf(needle, at + needle.length)) found.push(at);
19
+ return found;
20
+ };
21
+
22
+ // The block's span `[start, end)`, end just past the end marker, and its recorded attributes; or null.
23
+ const locate = (text, id) => {
24
+ const starts = occurrences(text, startPrefix(id));
25
+ const ends = occurrences(text, endMarker(id));
26
+ if (starts.length === 0 && ends.length === 0) return null;
27
+ if (starts.length !== 1 || ends.length !== 1 || ends[0] < starts[0]) {
28
+ throw new ManagedBlockError(`malformed LitFamily ${id} block: expected one start and one end marker`);
29
+ }
30
+ const head = START_LINE.exec(text.slice(starts[0]));
31
+ if (!head) throw new ManagedBlockError(`malformed LitFamily ${id} block: unreadable start marker`);
32
+ const attrs = Object.fromEntries(head[2].trim().split(" ").filter(Boolean).map((pair) => pair.split("=")));
33
+ return {
34
+ start: starts[0],
35
+ end: ends[0] + endMarker(id).length,
36
+ version: head[1],
37
+ pre: attrs.pre ? Buffer.from(attrs.pre, "hex").toString("utf8") : "",
38
+ created: attrs.new === "1",
39
+ };
40
+ };
41
+
42
+ const render = ({ id, version, body }, eol, { pre, created }) => [
43
+ `${startPrefix(id)} v=${version}${pre ? ` pre=${Buffer.from(pre, "utf8").toString("hex")}` : ""}${created ? " new=1" : ""} -->`,
44
+ ...String(body).replace(/\r?\n$/u, "").split(/\r?\n/u),
45
+ endMarker(id),
46
+ ].join(eol);
47
+
48
+ /** `{state: "absent" | "present" | "malformed", version, created}` for block `id` in `text`. */
49
+ export const inspectBlock = (text, id) => {
50
+ let span;
51
+ try {
52
+ span = locate(text, id);
53
+ } catch {
54
+ return { state: "malformed", version: null, created: false };
55
+ }
56
+ return span ? { state: "present", version: span.version, created: span.created } : { state: "absent", version: null, created: false };
57
+ };
58
+
59
+ /** Adds or replaces block `id`; `created` marks a file made for the block. Returns `{text, changed}`. */
60
+ export const upsertBlock = (text, block, { created = false } = {}) => {
61
+ const eol = eolOf(text);
62
+ const span = locate(text, block.id);
63
+ if (span) {
64
+ const rendered = render(block, eol, span);
65
+ const next = `${text.slice(0, span.start)}${rendered}${text.slice(span.end)}`;
66
+ return { text: next, changed: next !== text };
67
+ }
68
+ const pre = text === "" ? "" : `${text.endsWith("\n") ? "" : eol}${eol}`;
69
+ return { text: `${text}${pre}${render(block, eol, { pre, created })}${eol}`, changed: true };
70
+ };
71
+
72
+ /** Removes block `id`, the line ending after it and what was added before it; `created` is from its marker. */
73
+ export const removeBlock = (text, id) => {
74
+ const span = locate(text, id);
75
+ if (!span) return { text, changed: false, created: false };
76
+ let before = text.slice(0, span.start);
77
+ let after = text.slice(span.end);
78
+ const eol = after.startsWith("\r\n") ? "\r\n" : after.startsWith("\n") ? "\n" : "";
79
+ after = after.slice(eol.length);
80
+ if (span.pre && before.endsWith(span.pre)) before = before.slice(0, -span.pre.length);
81
+ return { text: `${before}${after}`, changed: true, created: span.created };
82
+ };
@@ -0,0 +1,9 @@
1
+ ## LitFamily · project conventions
2
+
3
+ This repo is worked with LitClaude's lit workflows (lit-plan, start-work, lit-loop, review-work).
4
+
5
+ - Plans live in `plans/`, the session handoff in `HANDOFF.md`, run state in `.litclaude/` (keep it out
6
+ of commits). Read the handoff and the active plan before resuming.
7
+ - Never push, publish, tag or bump a version without the user's explicit yes for that action.
8
+ - Pair every behaviour change with a test that failed first, and check the changed surface for real
9
+ before calling it done.
@@ -24,21 +24,21 @@ export const CANONICAL_RUNTIME_COMMITMENTS = Object.freeze(new Map([
24
24
  export const CANONICAL_RUNTIME_ADAPTER_COMMITMENTS = Object.freeze([
25
25
  Object.freeze({
26
26
  path: "skills/autoresearch/SKILL.md",
27
- size: 8055,
27
+ size: 8153,
28
28
  executable: false,
29
- sha256: "2b69c53bade3851cfb9c770bce80afe5f9e75b9629719e9ba95a4b0045eaf5b3",
29
+ sha256: "be86f3e098fb74ac1ce99a4ece476837e31967b0e3b1886f5252164727ae87b4",
30
30
  }),
31
31
  Object.freeze({
32
32
  path: "skills/autoconference/SKILL.md",
33
- size: 8159,
33
+ size: 8257,
34
34
  executable: false,
35
- sha256: "e034a0232d59bea9f9ed27bb8844a7ee039dd5c7d38aeaffaa32e7ee63daa5ad",
35
+ sha256: "8d129faef0613c46baff2fe56d26813a957685b000d335f3cb455d5b4b8ec124",
36
36
  }),
37
37
  Object.freeze({
38
38
  path: "skills/wikify/SKILL.md",
39
- size: 10111,
39
+ size: 10209,
40
40
  executable: false,
41
- sha256: "0a0b4f881c107fdec9cf6d1740cfdc17cb913c5f8fa12cf5000997e06b5652e4",
41
+ sha256: "a6b49977361587bd506dd77fe70406baa07efdad2ce9743b65b94334163f8b89",
42
42
  }),
43
43
  Object.freeze({
44
44
  path: "commands/autoresearch.md",