safeword 0.30.3 → 0.32.0

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 (39) hide show
  1. package/dist/{check-VBN3JZIG.js → check-PNWSVUZG.js} +2 -2
  2. package/dist/{chunk-BKF5HT4X.js → chunk-DSPWQAEB.js} +2 -2
  3. package/dist/{chunk-A52DHYLS.js → chunk-UPAH2FHH.js} +137 -24
  4. package/dist/chunk-UPAH2FHH.js.map +1 -0
  5. package/dist/{chunk-7K3S3EYP.js → chunk-X3QSXFLN.js} +6 -2
  6. package/dist/{chunk-7K3S3EYP.js.map → chunk-X3QSXFLN.js.map} +1 -1
  7. package/dist/cli.js +6 -6
  8. package/dist/{diff-BAVMQXPM.js → diff-HVRE7MNA.js} +2 -2
  9. package/dist/{reset-PK4EDGHL.js → reset-7DSNGPUW.js} +2 -2
  10. package/dist/{setup-OYB44GSY.js → setup-R7LE7DTG.js} +4 -4
  11. package/dist/{sync-config-YCLEY5IN.js → sync-config-D77T4OIV.js} +2 -2
  12. package/dist/{upgrade-HPCP322I.js → upgrade-V5ZS6LTQ.js} +3 -3
  13. package/package.json +6 -6
  14. package/templates/commands/audit.md +8 -0
  15. package/templates/commands/verify.md +58 -16
  16. package/templates/cursor/rules/safeword-brainstorming.mdc +6 -0
  17. package/templates/cursor/rules/safeword-elicitation.mdc +6 -0
  18. package/templates/cursor/rules/safeword-tdd-review.mdc +6 -0
  19. package/templates/hooks/lib/quality.ts +91 -70
  20. package/templates/hooks/lib/skill-invocation-log.ts +87 -0
  21. package/templates/hooks/lib/update-cache.ts +71 -0
  22. package/templates/hooks/lib/version.ts +79 -0
  23. package/templates/hooks/pre-tool-git-bare-fix.sh +38 -0
  24. package/templates/hooks/session-auto-upgrade.ts +153 -0
  25. package/templates/hooks/session-update-check.ts +81 -0
  26. package/templates/hooks/stop-quality.ts +46 -3
  27. package/templates/skills/audit/SKILL.md +9 -1
  28. package/templates/skills/bdd/DISCOVERY.md +2 -0
  29. package/templates/skills/debug/SKILL.md +2 -0
  30. package/templates/skills/elicit/SKILL.md +84 -0
  31. package/templates/skills/verify/SKILL.md +60 -39
  32. package/dist/chunk-A52DHYLS.js.map +0 -1
  33. /package/dist/{check-VBN3JZIG.js.map → check-PNWSVUZG.js.map} +0 -0
  34. /package/dist/{chunk-BKF5HT4X.js.map → chunk-DSPWQAEB.js.map} +0 -0
  35. /package/dist/{diff-BAVMQXPM.js.map → diff-HVRE7MNA.js.map} +0 -0
  36. /package/dist/{reset-PK4EDGHL.js.map → reset-7DSNGPUW.js.map} +0 -0
  37. /package/dist/{setup-OYB44GSY.js.map → setup-R7LE7DTG.js.map} +0 -0
  38. /package/dist/{sync-config-YCLEY5IN.js.map → sync-config-D77T4OIV.js.map} +0 -0
  39. /package/dist/{upgrade-HPCP322I.js.map → upgrade-V5ZS6LTQ.js.map} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  createProjectContext,
7
7
  getMissingPacks,
8
8
  reconcile
9
- } from "./chunk-A52DHYLS.js";
9
+ } from "./chunk-UPAH2FHH.js";
10
10
  import "./chunk-YVZL7WO5.js";
11
11
  import {
12
12
  VERSION
@@ -189,4 +189,4 @@ async function check(options) {
189
189
  export {
190
190
  check
191
191
  };
192
- //# sourceMappingURL=check-VBN3JZIG.js.map
192
+ //# sourceMappingURL=check-PNWSVUZG.js.map
@@ -3,7 +3,7 @@ import {
3
3
  addInstalledPack,
4
4
  isGitRepo,
5
5
  isPackInstalled
6
- } from "./chunk-A52DHYLS.js";
6
+ } from "./chunk-UPAH2FHH.js";
7
7
 
8
8
  // src/packs/install.ts
9
9
  function installPack(packId, cwd) {
@@ -21,4 +21,4 @@ function installPack(packId, cwd) {
21
21
  export {
22
22
  installPack
23
23
  };
24
- //# sourceMappingURL=chunk-BKF5HT4X.js.map
24
+ //# sourceMappingURL=chunk-DSPWQAEB.js.map
@@ -33,6 +33,7 @@ function setupGoTooling() {
33
33
 
34
34
  // src/packs/config.ts
35
35
  import nodePath from "path";
36
+ import process2 from "process";
36
37
  var CONFIG_PATH = ".safeword/config.json";
37
38
  function readConfig(cwd) {
38
39
  const configPath = nodePath.join(cwd, CONFIG_PATH);
@@ -533,17 +534,6 @@ function planOwnedFileWrites(files, ctx) {
533
534
  function planManagedFileWrites(files, ctx) {
534
535
  return planFileWrites(files, ctx, (filePath, c) => exists(nodePath7.join(c.cwd, filePath)));
535
536
  }
536
- function planTextPatchesWithCreation(patches, ctx) {
537
- const actions = planTextPatches(patches, ctx.isGitRepo);
538
- const created = [];
539
- for (const [filePath, definition] of Object.entries(patches)) {
540
- if (shouldSkipForNonGit(filePath, ctx.isGitRepo)) continue;
541
- if (definition.createIfMissing && !exists(nodePath7.join(ctx.cwd, filePath))) {
542
- created.push(filePath);
543
- }
544
- }
545
- return { actions, created };
546
- }
547
537
  function planExistingDirectoriesRemoval(directories, cwd) {
548
538
  const actions = [];
549
539
  const removed = [];
@@ -638,9 +628,13 @@ function computeInstallPlan(schema, ctx) {
638
628
  for (const [filePath, definition] of Object.entries(schema.jsonMerges)) {
639
629
  actions.push({ type: "json-merge", path: filePath, definition });
640
630
  }
641
- const patches = planTextPatchesWithCreation(schema.textPatches, ctx);
642
- actions.push(...patches.actions);
643
- wouldCreate.push(...patches.created);
631
+ const textPatchActions = planTextPatches(schema.textPatches, ctx.isGitRepo);
632
+ actions.push(...textPatchActions);
633
+ for (const action of textPatchActions) {
634
+ if (action.type === "text-patch" && !exists(nodePath7.join(ctx.cwd, action.path))) {
635
+ wouldCreate.push(action.path);
636
+ }
637
+ }
644
638
  const packagesToInstall = computePackagesToInstall(
645
639
  schema,
646
640
  ctx.projectType,
@@ -1460,7 +1454,7 @@ var rustManagedFiles = {
1460
1454
  // src/packs/sql/dialect.ts
1461
1455
  import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
1462
1456
  import nodePath11 from "path";
1463
- import process2 from "process";
1457
+ import process3 from "process";
1464
1458
  import YAML2 from "yaml";
1465
1459
  var ADAPTER_TO_DIALECT = {
1466
1460
  postgres: "postgres",
@@ -1556,7 +1550,7 @@ function detectFromProfiles(cwd) {
1556
1550
  const candidates = [
1557
1551
  nodePath11.join(dbtProjectDirectory, "profiles.yml"),
1558
1552
  nodePath11.join(dbtProjectDirectory, "dbt", "profiles.yml"),
1559
- nodePath11.join(process2.env.HOME ?? "", ".dbt", "profiles.yml")
1553
+ nodePath11.join(process3.env.HOME ?? "", ".dbt", "profiles.yml")
1560
1554
  ];
1561
1555
  for (const profilesPath of candidates) {
1562
1556
  const adapterType = resolveProfileType(profilesPath, profileName);
@@ -1927,17 +1921,28 @@ var HOOKS_DIR = '"$CLAUDE_PROJECT_DIR"/.safeword/hooks';
1927
1921
  function hook(command) {
1928
1922
  return { hooks: [{ type: "command", command }] };
1929
1923
  }
1924
+ function asyncHook(command) {
1925
+ return { hooks: [{ type: "command", command, async: true }] };
1926
+ }
1930
1927
  function matchedHook(matcher, command) {
1931
1928
  return { matcher, hooks: [{ type: "command", command }] };
1932
1929
  }
1930
+ function matchedHookWithIf(matcher, ifRule, command) {
1931
+ return {
1932
+ matcher,
1933
+ hooks: [{ type: "command", if: ifRule, command }]
1934
+ };
1935
+ }
1933
1936
  var EDIT_TOOLS = "Edit|Write|MultiEdit|NotebookEdit";
1934
1937
  var SETTINGS_HOOKS = {
1935
1938
  SessionStart: [
1936
1939
  hook(`bash ${HOOKS_DIR}/session-bun-check.sh`),
1940
+ hook(`bun ${HOOKS_DIR}/session-auto-upgrade.ts`),
1937
1941
  hook(`bun ${HOOKS_DIR}/session-verify-agents.ts`),
1938
1942
  hook(`bun ${HOOKS_DIR}/session-version.ts`),
1939
1943
  hook(`bun ${HOOKS_DIR}/session-lint-check.ts`),
1940
- matchedHook("compact", `bun ${HOOKS_DIR}/session-compact-context.ts`)
1944
+ matchedHook("compact", `bun ${HOOKS_DIR}/session-compact-context.ts`),
1945
+ asyncHook(`bun ${HOOKS_DIR}/session-update-check.ts`)
1941
1946
  ],
1942
1947
  UserPromptSubmit: [
1943
1948
  hook(`bun ${HOOKS_DIR}/prompt-timestamp.ts`),
@@ -1946,7 +1951,11 @@ var SETTINGS_HOOKS = {
1946
1951
  Stop: [hook(`bun ${HOOKS_DIR}/stop-quality.ts`)],
1947
1952
  PreToolUse: [
1948
1953
  matchedHook(EDIT_TOOLS, `bun ${HOOKS_DIR}/pre-tool-quality.ts`),
1949
- matchedHook(EDIT_TOOLS, `bun ${HOOKS_DIR}/pre-tool-config-guard.ts`)
1954
+ matchedHook(EDIT_TOOLS, `bun ${HOOKS_DIR}/pre-tool-config-guard.ts`),
1955
+ // Defends ad-hoc git ops against Claude Code's parallel-worktree
1956
+ // core.bare=true race (anthropics/claude-code#58345). `if` filters at the
1957
+ // config level so non-git Bash calls incur zero hook-process spawn.
1958
+ matchedHookWithIf("Bash", "Bash(git *)", `bash ${HOOKS_DIR}/pre-tool-git-bare-fix.sh`)
1950
1959
  ],
1951
1960
  PostToolUse: [
1952
1961
  matchedHook(EDIT_TOOLS, `bun ${HOOKS_DIR}/post-tool-lint.ts`),
@@ -2268,6 +2277,62 @@ var typescriptPackages = {
2268
2277
  }
2269
2278
  };
2270
2279
 
2280
+ // src/owned-paths.ts
2281
+ function computeSafewordPathPrefixes(schema) {
2282
+ const allPaths = [
2283
+ ...Object.keys(schema.ownedFiles),
2284
+ ...Object.keys(schema.managedFiles),
2285
+ ...Object.keys(schema.jsonMerges),
2286
+ ...Object.keys(schema.textPatches)
2287
+ ];
2288
+ const prefixes = /* @__PURE__ */ new Set();
2289
+ for (const path2 of allPaths) {
2290
+ const slashIndex = path2.indexOf("/");
2291
+ prefixes.add(slashIndex === -1 ? path2 : path2.slice(0, slashIndex + 1));
2292
+ }
2293
+ return [...prefixes].toSorted((a, b) => a.localeCompare(b));
2294
+ }
2295
+ function generateOwnedPathsModule(schema) {
2296
+ const prefixes = computeSafewordPathPrefixes(schema);
2297
+ const entries = prefixes.map((prefix) => ` '${prefix}',`).join("\n");
2298
+ return `// Auto-generated by safeword from SAFEWORD_SCHEMA. Do not edit by hand.
2299
+ // Source: ownedFiles \u222A managedFiles \u222A jsonMerges \u222A textPatches \u2192 top-level prefixes.
2300
+ // Regenerated on every \`safeword setup\` and \`safeword upgrade\`.
2301
+
2302
+ export const SAFEWORD_PATHS: readonly string[] = [
2303
+ ${entries}
2304
+ ];
2305
+
2306
+ /**
2307
+ * Match a file path against the safeword-managed set. Directory prefixes
2308
+ * (entries ending in \`/\`) match by \`startsWith\`; bare file paths must
2309
+ * match exactly so e.g. \`package.json.bak\` does not match \`package.json\`.
2310
+ */
2311
+ export function isSafewordPath(file: string): boolean {
2312
+ for (const prefix of SAFEWORD_PATHS) {
2313
+ if (prefix.endsWith('/')) {
2314
+ if (file.startsWith(prefix)) return true;
2315
+ } else if (file === prefix) {
2316
+ return true;
2317
+ }
2318
+ }
2319
+ return false;
2320
+ }
2321
+
2322
+ /**
2323
+ * Pick the safeword-managed subset of files reported by \`git diff --name-only\`
2324
+ * (changed) and \`git ls-files --others --exclude-standard\` (untracked).
2325
+ * Used by the auto-upgrade hook to decide what to stage after \`safeword upgrade\`.
2326
+ */
2327
+ export function filterSafewordFiles(
2328
+ changedFiles: readonly string[],
2329
+ untrackedFiles: readonly string[],
2330
+ ): readonly string[] {
2331
+ return [...changedFiles, ...untrackedFiles].filter(f => isSafewordPath(f));
2332
+ }
2333
+ `;
2334
+ }
2335
+
2271
2336
  // src/templates/content.ts
2272
2337
  var AGENTS_MD_LINK = `**\u26A0\uFE0F ALWAYS READ FIRST:** \`.safeword/SAFEWORD.md\`
2273
2338
 
@@ -2493,8 +2558,18 @@ var SAFEWORD_SCHEMA = {
2493
2558
  ".safeword/hooks/lib/lint.ts": { template: "hooks/lib/lint.ts" },
2494
2559
  ".safeword/hooks/lib/quality.ts": { template: "hooks/lib/quality.ts" },
2495
2560
  ".safeword/hooks/lib/quality-state.ts": { template: "hooks/lib/quality-state.ts" },
2561
+ ".safeword/hooks/lib/skill-invocation-log.ts": {
2562
+ template: "hooks/lib/skill-invocation-log.ts"
2563
+ },
2496
2564
  ".safeword/hooks/lib/scenario-format.ts": { template: "hooks/lib/scenario-format.ts" },
2497
2565
  ".safeword/hooks/lib/test-runner.ts": { template: "hooks/lib/test-runner.ts" },
2566
+ ".safeword/hooks/lib/update-cache.ts": { template: "hooks/lib/update-cache.ts" },
2567
+ ".safeword/hooks/lib/version.ts": { template: "hooks/lib/version.ts" },
2568
+ // Generated at setup/upgrade from SAFEWORD_SCHEMA itself — the prefix list
2569
+ // the auto-upgrade hook uses to decide which files to stage. See owned-paths.ts.
2570
+ ".safeword/hooks/lib/owned-paths.ts": {
2571
+ generator: () => generateOwnedPathsModule(SAFEWORD_SCHEMA)
2572
+ },
2498
2573
  // Hooks - TypeScript with Bun runtime
2499
2574
  ".safeword/hooks/session-verify-agents.ts": {
2500
2575
  template: "hooks/session-verify-agents.ts"
@@ -2529,6 +2604,15 @@ var SAFEWORD_SCHEMA = {
2529
2604
  ".safeword/hooks/pre-tool-config-guard.ts": {
2530
2605
  template: "hooks/pre-tool-config-guard.ts"
2531
2606
  },
2607
+ ".safeword/hooks/pre-tool-git-bare-fix.sh": {
2608
+ template: "hooks/pre-tool-git-bare-fix.sh"
2609
+ },
2610
+ ".safeword/hooks/session-auto-upgrade.ts": {
2611
+ template: "hooks/session-auto-upgrade.ts"
2612
+ },
2613
+ ".safeword/hooks/session-update-check.ts": {
2614
+ template: "hooks/session-update-check.ts"
2615
+ },
2532
2616
  ".safeword/hooks/session-cleanup-quality.ts": {
2533
2617
  template: "hooks/session-cleanup-quality.ts"
2534
2618
  },
@@ -2652,6 +2736,9 @@ var SAFEWORD_SCHEMA = {
2652
2736
  ".claude/skills/brainstorm/SKILL.md": {
2653
2737
  template: "skills/brainstorm/SKILL.md"
2654
2738
  },
2739
+ ".claude/skills/elicit/SKILL.md": {
2740
+ template: "skills/elicit/SKILL.md"
2741
+ },
2655
2742
  ".claude/skills/tdd-review/SKILL.md": {
2656
2743
  template: "skills/tdd-review/SKILL.md"
2657
2744
  },
@@ -2659,15 +2746,24 @@ var SAFEWORD_SCHEMA = {
2659
2746
  ".cursor/rules/safeword-core.mdc": {
2660
2747
  template: "cursor/rules/safeword-core.mdc"
2661
2748
  },
2749
+ ".cursor/rules/safeword-brainstorming.mdc": {
2750
+ template: "cursor/rules/safeword-brainstorming.mdc"
2751
+ },
2662
2752
  ".cursor/rules/safeword-debugging.mdc": {
2663
2753
  template: "cursor/rules/safeword-debugging.mdc"
2664
2754
  },
2755
+ ".cursor/rules/safeword-elicitation.mdc": {
2756
+ template: "cursor/rules/safeword-elicitation.mdc"
2757
+ },
2665
2758
  ".cursor/rules/safeword-quality-reviewing.mdc": {
2666
2759
  template: "cursor/rules/safeword-quality-reviewing.mdc"
2667
2760
  },
2668
2761
  ".cursor/rules/safeword-refactoring.mdc": {
2669
2762
  template: "cursor/rules/safeword-refactoring.mdc"
2670
2763
  },
2764
+ ".cursor/rules/safeword-tdd-review.mdc": {
2765
+ template: "cursor/rules/safeword-tdd-review.mdc"
2766
+ },
2671
2767
  ".cursor/rules/safeword-testing.mdc": {
2672
2768
  template: "cursor/rules/safeword-testing.mdc"
2673
2769
  },
@@ -2800,8 +2896,7 @@ var SAFEWORD_SCHEMA = {
2800
2896
  "AGENTS.md": {
2801
2897
  operation: "prepend",
2802
2898
  content: AGENTS_MD_LINK,
2803
- marker: ".safeword/SAFEWORD.md",
2804
- createIfMissing: true
2899
+ marker: ".safeword/SAFEWORD.md"
2805
2900
  },
2806
2901
  "CLAUDE.md": {
2807
2902
  operation: "prepend",
@@ -2814,9 +2909,27 @@ var SAFEWORD_SCHEMA = {
2814
2909
  // backticks) still trigger prepending the new `@` import block on top.
2815
2910
  // Existing prose lingers harmlessly — agents skim it; only the import
2816
2911
  // is functionally load-bearing.
2817
- marker: "@./.safeword/SAFEWORD.md",
2818
- createIfMissing: false
2819
- // Only patch if exists, don't create (AGENTS.md is primary)
2912
+ marker: "@./.safeword/SAFEWORD.md"
2913
+ },
2914
+ ".gitignore": {
2915
+ operation: "append",
2916
+ content: "\n# Safeword - Local cache and transient state\n.safeword/.update-cache.json\n.safeword-project/quality-state*.json\n",
2917
+ marker: ".safeword/.update-cache.json"
2918
+ }
2919
+ },
2920
+ // Content predicate parity — files that must contain specific strings.
2921
+ // Different from ownedFiles (which requires byte equality between two files):
2922
+ // contracts assert one-way "this file must include these tokens" invariants.
2923
+ // Used by runParity() in src/parity.ts for both release tests and pre-commit
2924
+ // (see ticket 144). Path key = file relative to repo root.
2925
+ contracts: {
2926
+ "packages/cli/templates/hooks/lib/quality.ts": {
2927
+ // Cursor's stop hook imports QUALITY_REVIEW_MESSAGE. The export must exist
2928
+ // or Cursor users get a broken hook. The four marker strings (CONFIDENT,
2929
+ // BLOCKED, Tried:, Need:) define the binary-terminal shape from ticket 143.
2930
+ // Removing any of them would silently regress the prompt back to legacy
2931
+ // free-form review.
2932
+ requires: ["QUALITY_REVIEW_MESSAGE", "CONFIDENT", "BLOCKED", "Tried:", "Need:"]
2820
2933
  }
2821
2934
  },
2822
2935
  // NPM packages to install (JS/TS specific packages from typescript pack)
@@ -3018,4 +3131,4 @@ export {
3018
3131
  detectLanguages2,
3019
3132
  createProjectContext
3020
3133
  };
3021
- //# sourceMappingURL=chunk-A52DHYLS.js.map
3134
+ //# sourceMappingURL=chunk-UPAH2FHH.js.map