@drafthq/draft 3.2.0 → 3.2.1

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.
@@ -12,7 +12,7 @@
12
12
  "name": "draft",
13
13
  "source": "./",
14
14
  "description": "Context-Driven Development: draft specs and plans before implementation. Structured workflows for features and fixes.",
15
- "version": "3.2.0",
15
+ "version": "3.2.1",
16
16
  "author": {
17
17
  "name": "mayurpise"
18
18
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "draft",
3
3
  "description": "Context-Driven Development: draft specs and plans before implementation. Structured workflows for features and fixes.",
4
- "version": "3.2.0",
4
+ "version": "3.2.1",
5
5
  "author": {
6
6
  "name": "mayurpise"
7
7
  },
@@ -4,6 +4,7 @@ const { spawnSync } = require('child_process');
4
4
  const fsx = require('./lib/fsx');
5
5
  const log = require('./lib/log');
6
6
  const { fetchGraph } = require('./lib/graph');
7
+ const { writePluginRootMarker } = require('./lib/marker');
7
8
 
8
9
  // A short ceiling so a wedged `claude --version` can't hang the installer
9
10
  // before we even reach the real (separately-timed) install steps.
@@ -107,6 +108,13 @@ function install(host, ctx) {
107
108
  fetchGraph(ctx);
108
109
  }
109
110
 
111
+ // Record the install path so skills can locate scripts/tools/ from the user's
112
+ // project cwd (best-effort; graph skills glob-fallback if the marker is absent).
113
+ if (!ctx.dryRun) {
114
+ const root = writePluginRootMarker(host.id);
115
+ if (root) log.note(`Recorded plugin path for graph tooling: ${root}`);
116
+ }
117
+
110
118
  (plan.notes || []).forEach((n) => log.note(n));
111
119
 
112
120
  if (ctx.dryRun) {
@@ -0,0 +1,93 @@
1
+ 'use strict';
2
+
3
+ // Write the install-path marker (~/.cache/draft/plugin-root) so a draft skill can
4
+ // locate its bundled scripts/tools/ from the user's project cwd. Skills run with
5
+ // cwd = the user's project and ${CLAUDE_PLUGIN_ROOT} is NOT exported into skill Bash,
6
+ // so without this marker resolution falls back to globbing the plugin cache. The
7
+ // marker is the fast, authoritative path; see core/shared/tool-resolver.md.
8
+ //
9
+ // Best-effort: any failure is swallowed — graph skills still resolve via the glob
10
+ // fallback, so a missing marker is never fatal.
11
+
12
+ const fs = require('fs');
13
+ const os = require('os');
14
+ const path = require('path');
15
+
16
+ // Resolve the installed draft plugin root for a given host, or null if unknown.
17
+ function resolvePluginRoot(hostId) {
18
+ const home = os.homedir();
19
+
20
+ if (hostId === 'claude-code') {
21
+ // 1. Claude Code's own registry holds the authoritative installPath.
22
+ const reg = path.join(home, '.claude', 'plugins', 'installed_plugins.json');
23
+ try {
24
+ const data = JSON.parse(fs.readFileSync(reg, 'utf8'));
25
+ const key = Object.keys(data.plugins || {}).find((k) => k.startsWith('draft@'));
26
+ const ip = key && data.plugins[key] && data.plugins[key][0] && data.plugins[key][0].installPath;
27
+ if (ip && fs.existsSync(path.join(ip, 'scripts', 'tools'))) return ip;
28
+ } catch {
29
+ /* registry missing or unparseable — fall through to the cache scan */
30
+ }
31
+ // 2. Fallback: newest versioned dir under the plugin cache.
32
+ return newestCacheRoot(path.join(home, '.claude', 'plugins', 'cache'));
33
+ }
34
+
35
+ if (hostId === 'cursor') {
36
+ const p = path.join(home, '.cursor', 'plugins', 'local', 'draft');
37
+ return fs.existsSync(path.join(p, 'scripts', 'tools')) ? p : null;
38
+ }
39
+
40
+ return null;
41
+ }
42
+
43
+ // Newest <cache>/<marketplace>/draft/<version> dir that carries scripts/tools.
44
+ function newestCacheRoot(cacheDir) {
45
+ try {
46
+ const candidates = [];
47
+ for (const mkt of fs.readdirSync(cacheDir)) {
48
+ const draftDir = path.join(cacheDir, mkt, 'draft');
49
+ let versions;
50
+ try {
51
+ versions = fs.readdirSync(draftDir);
52
+ } catch {
53
+ continue;
54
+ }
55
+ for (const v of versions) {
56
+ const root = path.join(draftDir, v);
57
+ if (fs.existsSync(path.join(root, 'scripts', 'tools'))) candidates.push({ v, root });
58
+ }
59
+ }
60
+ if (!candidates.length) return null;
61
+ candidates.sort((a, b) => compareVersions(a.v, b.v));
62
+ return candidates[candidates.length - 1].root;
63
+ } catch {
64
+ return null;
65
+ }
66
+ }
67
+
68
+ // Numeric-aware version compare (no semver dependency).
69
+ function compareVersions(a, b) {
70
+ const pa = String(a).split('.').map((n) => parseInt(n, 10) || 0);
71
+ const pb = String(b).split('.').map((n) => parseInt(n, 10) || 0);
72
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
73
+ const d = (pa[i] || 0) - (pb[i] || 0);
74
+ if (d) return d;
75
+ }
76
+ return 0;
77
+ }
78
+
79
+ // Write ~/.cache/draft/plugin-root for the host. Returns the path written, or null.
80
+ function writePluginRootMarker(hostId) {
81
+ try {
82
+ const root = resolvePluginRoot(hostId);
83
+ if (!root) return null;
84
+ const dest = path.join(os.homedir(), '.cache', 'draft', 'plugin-root');
85
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
86
+ fs.writeFileSync(dest, root + '\n');
87
+ return root;
88
+ } catch {
89
+ return null;
90
+ }
91
+ }
92
+
93
+ module.exports = { writePluginRootMarker, resolvePluginRoot };
@@ -180,8 +180,9 @@ Write the completed content to `draft/.ai-context.md`.
180
180
  After writing both output files, strip trailing whitespace and blank lines at EOF to prevent GitHub upload failures. Resolve the script via the canonical tool resolver (see [tool-resolver.md](tool-resolver.md)):
181
181
 
182
182
  ```bash
183
- DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
184
- [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
183
+ DRAFT_TOOLS="$(cat ~/.cache/draft/plugin-root 2>/dev/null)/scripts/tools"
184
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/cache/*/draft/*/scripts/tools 2>/dev/null | sort -V | tail -1)"
185
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/marketplaces/*draft*/scripts/tools 2>/dev/null | tail -1)"
185
186
  [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
186
187
  [ -x "$DRAFT_TOOLS/fix-whitespace.sh" ] && bash "$DRAFT_TOOLS/fix-whitespace.sh" draft/architecture.md draft/.ai-context.md draft/.ai-profile.md 2>/dev/null || true
187
188
  ```
@@ -16,8 +16,9 @@ Referenced by: All skills that generate Draft reports — including `/draft:bugh
16
16
  Use `git-metadata.sh` from the plugin install, resolved via the canonical tool resolver (see [tool-resolver.md](tool-resolver.md)):
17
17
 
18
18
  ```bash
19
- DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
20
- [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
19
+ DRAFT_TOOLS="$(cat ~/.cache/draft/plugin-root 2>/dev/null)/scripts/tools"
20
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/cache/*/draft/*/scripts/tools 2>/dev/null | sort -V | tail -1)"
21
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/marketplaces/*draft*/scripts/tools 2>/dev/null | tail -1)"
21
22
  [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
22
23
  bash "$DRAFT_TOOLS/git-metadata.sh" --yaml \
23
24
  --project "$PROJECT" --module "$MODULE" \
@@ -92,11 +92,12 @@ These fields are appended to `~/.draft/metrics.jsonl` along with the existing sk
92
92
 
93
93
  ## Tooling Wrappers
94
94
 
95
- For common query modes, prefer the deterministic wrappers that ship with the plugin. Resolve their location via the canonical tool resolver (see [tool-resolver.md](tool-resolver.md)) before invoking:
95
+ For common query modes, prefer the deterministic wrappers that ship with the plugin. Resolve their location via the canonical tool resolver (see [tool-resolver.md](tool-resolver.md)) before invoking. Skills run with cwd = the user's project and `${CLAUDE_PLUGIN_ROOT}` is **not** exported into skill Bash, so a bare `scripts/tools/foo.sh` fails — establish `DRAFT_TOOLS` once before the first helper call, in the same Bash session as your tool calls (re-establish it if you split helper calls into a separate, later Bash block):
96
96
 
97
97
  ```bash
98
- DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
99
- [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
98
+ DRAFT_TOOLS="$(cat ~/.cache/draft/plugin-root 2>/dev/null)/scripts/tools"
99
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/cache/*/draft/*/scripts/tools 2>/dev/null | sort -V | tail -1)"
100
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/marketplaces/*draft*/scripts/tools 2>/dev/null | tail -1)"
100
101
  [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
101
102
  ```
102
103
 
@@ -1,10 +1,77 @@
1
1
  ---
2
2
  shared: tool-resolver
3
- applies_to: quality + init + graph skills
3
+ applies_to: every skill that invokes scripts/tools/*
4
4
  ---
5
5
 
6
- # tool-resolver (Foundations Stub)
6
+ # tool-resolver
7
7
 
8
- Portable generalized stub per manifest §2.1. Full content will be expanded in later agent tranche or manual follow-up.
8
+ Canonical procedure for locating Draft's bundled shell helpers (`scripts/tools/*.sh`)
9
+ from inside a skill.
9
10
 
10
- See verification-gates.md and template-hygiene.md for usage contracts.
11
+ ## Why this exists
12
+
13
+ When Claude runs a draft skill, the shell's **working directory is the user's
14
+ project**, not the plugin. The helpers live inside the plugin install directory,
15
+ which on a marketplace/npm install is `~/.claude/plugins/cache/<marketplace>/draft/<version>/`
16
+ — never the cwd. `${CLAUDE_PLUGIN_ROOT}` is **not** exported into skill-driven Bash
17
+ (it is only set for hooks, MCP/LSP servers, and monitor commands), so a bare
18
+ `scripts/tools/foo.sh` or `${CLAUDE_PLUGIN_ROOT}/...` invocation silently fails.
19
+
20
+ Every skill MUST resolve `DRAFT_TOOLS` and invoke helpers as `"$DRAFT_TOOLS/<tool>.sh"`.
21
+
22
+ ## Resolution order
23
+
24
+ `DRAFT_TOOLS` resolves to the first directory that exists, in this order:
25
+
26
+ 1. `${DRAFT_PLUGIN_ROOT}/scripts/tools` — explicit override (testing / pinned installs)
27
+ 2. `$(cat ~/.cache/draft/plugin-root)/scripts/tools` — install marker written by `draft install` (authoritative)
28
+ 3. `${CLAUDE_PLUGIN_ROOT}/scripts/tools` — set in hook/MCP contexts; harmless to probe
29
+ 4. `installed_plugins.json → installPath` for `draft@*` — Claude Code's own registry (needs `jq`)
30
+ 5. `~/.claude/plugins/cache/*/draft/*/scripts/tools` — newest cache install (glob, `sort -V`)
31
+ 6. `~/.claude/plugins/marketplaces/*draft*/scripts/tools` — marketplace clone
32
+ 7. `~/.cursor/plugins/local/draft/scripts/tools` — Cursor local install
33
+ 8. `$PWD/scripts/tools` — dev / dogfooding (running inside the draft repo itself)
34
+
35
+ The marker (step 2) is the fast, authoritative path; steps 5–6 are the glob fallback
36
+ that keeps resolution working on installs predating the marker (no reinstall required).
37
+
38
+ ## Skill preamble (copy verbatim)
39
+
40
+ Establish `DRAFT_TOOLS` once, before the first helper call, in the **same Bash
41
+ session** that runs your tool calls — exactly as skills already define `REPO_ABS`
42
+ once and reuse it. Env vars do not persist across **separate** Bash tool
43
+ invocations (only the cwd does), so if you split helper calls into a later, separate
44
+ Bash block, re-establish `DRAFT_TOOLS` there too:
45
+
46
+ ```bash
47
+ DRAFT_TOOLS="$(cat ~/.cache/draft/plugin-root 2>/dev/null)/scripts/tools"
48
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/cache/*/draft/*/scripts/tools 2>/dev/null | sort -V | tail -1)"
49
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/marketplaces/*draft*/scripts/tools 2>/dev/null | tail -1)"
50
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
51
+ ```
52
+
53
+ Then invoke helpers through the variable:
54
+
55
+ ```bash
56
+ "$DRAFT_TOOLS/hotspot-rank.sh" --repo . --top 5
57
+ "$DRAFT_TOOLS/graph-arch.sh" --repo .
58
+ ```
59
+
60
+ The four-line inline preamble is self-contained and is the recommended form for
61
+ skills — it needs no marker file and no prior `source`. The full 8-step resolver
62
+ (adding the `${DRAFT_PLUGIN_ROOT}` override, `${CLAUDE_PLUGIN_ROOT}`, the jq-registry
63
+ lookup, and the Cursor path) is shipped as `scripts/tools/resolve-tools.sh` for tests
64
+ and for callers that prefer a single source of truth:
65
+
66
+ ```bash
67
+ DRAFT_TOOLS="$("$PWD/scripts/tools/resolve-tools.sh" 2>/dev/null)" # dev/dogfood
68
+ # installed: "$(cat ~/.cache/draft/plugin-root)/scripts/tools/resolve-tools.sh"
69
+ ```
70
+
71
+ ## The engine binary is separate
72
+
73
+ `DRAFT_TOOLS` locates the **wrapper scripts**. Each wrapper then resolves the
74
+ `codebase-memory-mcp` **engine binary** itself via `_lib.sh:find_memory_bin`
75
+ (`DRAFT_MEMORY_BIN` → `$PATH` → `~/.cache/draft/bin/` → vendored). Do not conflate
76
+ the two: a wrapper that runs but reports `source: unavailable` means the engine
77
+ binary is missing, not the wrapper.
@@ -111,8 +111,9 @@ validator chain via the canonical resolver pattern (see
111
111
  [core/shared/verification-gates.md](../../core/shared/verification-gates.md)):
112
112
 
113
113
  ```bash
114
- DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
115
- [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
114
+ DRAFT_TOOLS="$(cat ~/.cache/draft/plugin-root 2>/dev/null)/scripts/tools"
115
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/cache/*/draft/*/scripts/tools 2>/dev/null | sort -V | tail -1)"
116
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/marketplaces/*draft*/scripts/tools 2>/dev/null | tail -1)"
116
117
  [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
117
118
  "$DRAFT_TOOLS/check-track-hygiene.sh" .; "$DRAFT_TOOLS/verify-citations.sh" .
118
119
  "$DRAFT_TOOLS/verify-doc-anchors.sh" .; "$DRAFT_TOOLS/check-graph-usage-report.sh" .