dw-kit 1.3.4 → 1.3.6

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.
@@ -0,0 +1,104 @@
1
+ #!/bin/bash
2
+ # .claude/hooks/supply-chain-scan.sh
3
+ # Fires after Claude Code Write/Edit. If the file is a lockfile, runs `dw security-scan --quick`
4
+ # to detect known-vulnerable dependency pins (offline IoC + advisory snapshot check).
5
+ # Non-blocking — never aborts the parent tool call. Emits telemetry.
6
+ # Reference: ADR-0005 (AI-Native Supply-Chain Guard). Sunset review 2026-08-12.
7
+
8
+ set -e
9
+
10
+ PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(pwd)}"
11
+ TELEMETRY_SCRIPT="$PROJECT_DIR/.claude/hooks/telemetry-log.sh"
12
+
13
+ if [ "${DW_NO_TELEMETRY:-}" != "1" ] && [ -x "$TELEMETRY_SCRIPT" ]; then
14
+ "$TELEMETRY_SCRIPT" hook supply-chain-scan >/dev/null 2>&1 || true
15
+ fi
16
+
17
+ if [ "${DW_SC_GUARD_DISABLED:-}" = "1" ]; then
18
+ exit 0
19
+ fi
20
+
21
+ INPUT=$(cat)
22
+
23
+ FILE_PATH=$(echo "$INPUT" | node -e "
24
+ let d='';
25
+ process.stdin.on('data',c=>d+=c).on('end',()=>{
26
+ try{
27
+ const data=JSON.parse(d);
28
+ const p=data.file_path||data.path||data.filePath||(data.tool_input&&(data.tool_input.file_path||data.tool_input.path))||'';
29
+ process.stdout.write(p);
30
+ }catch(e){}
31
+ });
32
+ " 2>/dev/null || true)
33
+
34
+ [ -z "$FILE_PATH" ] && exit 0
35
+
36
+ # Match: package-lock.json, npm-shrinkwrap.json (case-insensitive).
37
+ # pnpm-lock.yaml and yarn.lock are out-of-scope per ADR-0005 v1.3.5.
38
+ BASENAME=$(basename "$FILE_PATH")
39
+ case "$BASENAME" in
40
+ package-lock.json|npm-shrinkwrap.json)
41
+ ;;
42
+ *)
43
+ exit 0
44
+ ;;
45
+ esac
46
+
47
+ # Find the project root that contains the lockfile (in case PROJECT_DIR differs)
48
+ LOCKFILE_DIR=$(dirname "$FILE_PATH")
49
+ [ -d "$LOCKFILE_DIR" ] || exit 0
50
+
51
+ # Locate dw binary — prefer local node_modules, fall back to global PATH
52
+ DW_BIN=""
53
+ if command -v dw >/dev/null 2>&1; then
54
+ DW_BIN="dw"
55
+ elif [ -f "$PROJECT_DIR/bin/dw.mjs" ]; then
56
+ DW_BIN="node $PROJECT_DIR/bin/dw.mjs"
57
+ else
58
+ exit 0
59
+ fi
60
+
61
+ START_TS=$(date +%s%N 2>/dev/null || date +%s)
62
+
63
+ # Pillar 3 (ADR-0006): heuristic-only mode probes ONLY the NEW/bumped packages
64
+ # from the lockfile diff against npm registry metadata. Cached 1h per package
65
+ # so repeat edits hit cache. This is the AI-Native moat — catches zero-day-ish
66
+ # at the edit boundary, before OSV indexes and before any TL fixture bump.
67
+ set +e
68
+ SCAN_OUTPUT=$(cd "$LOCKFILE_DIR" && $DW_BIN security-scan --heuristic-only 2>&1)
69
+ SCAN_EXIT=$?
70
+ set -e
71
+
72
+ END_TS=$(date +%s%N 2>/dev/null || date +%s)
73
+ LATENCY_MS=$(( (END_TS - START_TS) / 1000000 ))
74
+
75
+ case "$SCAN_EXIT" in
76
+ 0)
77
+ # Clean — silent unless verbose
78
+ if [ "${DW_SC_GUARD_VERBOSE:-}" = "1" ]; then
79
+ echo "✓ supply-chain-scan: clean (no heuristic flags on NEW/bumped packages in $BASENAME)" >&2
80
+ fi
81
+ ;;
82
+ 1)
83
+ # Mid-risk heuristic flags — warn, do not block
84
+ echo "" >&2
85
+ echo "⚠ supply-chain-scan: heuristic flags on NEW/bumped packages in $BASENAME" >&2
86
+ echo "$SCAN_OUTPUT" | tail -30 >&2
87
+ echo " (advisory — not blocking; run \`dw security-scan\` for full pillar 1+2+3 report)" >&2
88
+ ;;
89
+ 2)
90
+ # HIGH-risk heuristic flag (score ≥80) — loud warning, still non-blocking
91
+ echo "" >&2
92
+ echo "⚠ supply-chain-scan: HIGH-RISK heuristic flag on NEW/bumped package in $BASENAME" >&2
93
+ echo "$SCAN_OUTPUT" | tail -40 >&2
94
+ echo " ADVISORY ONLY — review before commit. Public sunset review 2026-08-12 (ADR-0005)." >&2
95
+ ;;
96
+ *)
97
+ # Setup error (no lockfile, network failure) — quiet hint
98
+ if [ "${DW_SC_GUARD_VERBOSE:-}" = "1" ]; then
99
+ echo "supply-chain-scan: heuristic check skipped or errored — run \`dw security-scan\` manually" >&2
100
+ fi
101
+ ;;
102
+ esac
103
+
104
+ exit 0
@@ -99,6 +99,10 @@
99
99
  {
100
100
  "type": "command",
101
101
  "command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/post-write.sh\""
102
+ },
103
+ {
104
+ "type": "command",
105
+ "command": "bash \"$CLAUDE_PROJECT_DIR/.claude/hooks/supply-chain-scan.sh\""
102
106
  }
103
107
  ]
104
108
  }
@@ -0,0 +1,157 @@
1
+ {
2
+ "schema_version": "1.0",
3
+ "fetched_at": "2026-05-12T09:57:47.323Z",
4
+ "source": "osv.dev",
5
+ "ecosystem": "npm",
6
+ "package_count": 13,
7
+ "advisory_count": 2,
8
+ "advisories": [
9
+ {
10
+ "id": "GHSA-q3j6-qgpj-74h6",
11
+ "summary": "fast-uri vulnerable to path traversal via percent-encoded dot segments",
12
+ "details": "### Impact\n\n`fast-uri` v3.1.0 and earlier decodes percent-encoded path separators (`%2F`) and dot segments (`%2E`) before applying dot-segment removal in `normalize()` and `equal()`. This makes encoded path data behave like real `/` and `..`, so distinct URIs collapse onto the same normalized path.\n\nFor example, `http://example.com/public/%2e%2e/admin` normalizes to `http://example.com/admin`, and `equal()` considers them the same URI.\n\nApplications that normalize or compare attacker-controlled URLs to enforce path-based policy can be bypassed. A path that looks confined under an allowed prefix can normalize to a different location.\n\n### Patches\n\nUpgrade to `fast-uri` >= 3.1.1.\n\n### Workarounds\n\nNone. Upgrade to the patched version.",
13
+ "aliases": [
14
+ "CVE-2026-6321"
15
+ ],
16
+ "modified": "2026-05-09T16:44:22.524341929Z",
17
+ "published": "2026-05-08T17:15:09Z",
18
+ "related": [
19
+ "CGA-9j5f-2hwm-8hfc"
20
+ ],
21
+ "database_specific": {
22
+ "cwe_ids": [
23
+ "CWE-22"
24
+ ],
25
+ "github_reviewed": true,
26
+ "github_reviewed_at": "2026-05-08T17:15:09Z",
27
+ "severity": "HIGH",
28
+ "nvd_published_at": "2026-05-04T20:16:20Z"
29
+ },
30
+ "references": [
31
+ {
32
+ "type": "WEB",
33
+ "url": "https://github.com/fastify/fast-uri/security/advisories/GHSA-q3j6-qgpj-74h6"
34
+ },
35
+ {
36
+ "type": "ADVISORY",
37
+ "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-6321"
38
+ },
39
+ {
40
+ "type": "WEB",
41
+ "url": "https://cna.openjsf.org/security-advisories.html"
42
+ },
43
+ {
44
+ "type": "PACKAGE",
45
+ "url": "https://github.com/fastify/fast-uri"
46
+ }
47
+ ],
48
+ "affected": [
49
+ {
50
+ "package": {
51
+ "name": "fast-uri",
52
+ "ecosystem": "npm",
53
+ "purl": "pkg:npm/fast-uri"
54
+ },
55
+ "ranges": [
56
+ {
57
+ "type": "SEMVER",
58
+ "events": [
59
+ {
60
+ "introduced": "0"
61
+ },
62
+ {
63
+ "fixed": "3.1.1"
64
+ }
65
+ ]
66
+ }
67
+ ],
68
+ "database_specific": {
69
+ "source": "https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/05/GHSA-q3j6-qgpj-74h6/GHSA-q3j6-qgpj-74h6.json",
70
+ "last_known_affected_version_range": "<= 3.1.0"
71
+ }
72
+ }
73
+ ],
74
+ "schema_version": "1.7.5",
75
+ "severity": [
76
+ {
77
+ "type": "CVSS_V3",
78
+ "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
79
+ }
80
+ ]
81
+ },
82
+ {
83
+ "id": "GHSA-v39h-62p7-jpjc",
84
+ "summary": "fast-uri vulnerable to host confusion via percent-encoded authority delimiters",
85
+ "details": "### Impact\n\n`fast-uri` v3.1.1 and earlier decodes percent-encoded authority delimiters (`%40` as `@`, `%3A` as `:`) inside the host component and serializes them back as raw characters. This changes the URI structure, turning a hostname into userinfo plus a different host.\n\nFor example, `http://trusted.com%40evil.com/` normalizes to `http://trusted.com@evil.com/`, which reparses as host `evil.com` with userinfo `trusted.com`.\n\nApplications that normalize untrusted URLs before host allowlist checks, redirect validation, or outbound request routing can be steered to a different authority than the original URL appeared to contain.\n\n### Patches\n\nUpgrade to `fast-uri` >= 3.1.2.\n\n### Workarounds\n\nNone. Upgrade to the patched version.",
86
+ "aliases": [
87
+ "CVE-2026-6322"
88
+ ],
89
+ "modified": "2026-05-10T04:44:28.903255090Z",
90
+ "published": "2026-05-08T19:13:01Z",
91
+ "related": [
92
+ "CGA-5vr9-c8qr-fqvg"
93
+ ],
94
+ "database_specific": {
95
+ "cwe_ids": [
96
+ "CWE-436"
97
+ ],
98
+ "github_reviewed": true,
99
+ "github_reviewed_at": "2026-05-08T19:13:01Z",
100
+ "severity": "HIGH",
101
+ "nvd_published_at": "2026-05-05T11:16:33Z"
102
+ },
103
+ "references": [
104
+ {
105
+ "type": "WEB",
106
+ "url": "https://github.com/fastify/fast-uri/security/advisories/GHSA-v39h-62p7-jpjc"
107
+ },
108
+ {
109
+ "type": "ADVISORY",
110
+ "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-6322"
111
+ },
112
+ {
113
+ "type": "WEB",
114
+ "url": "https://cna.openjsf.org/security-advisories.html"
115
+ },
116
+ {
117
+ "type": "PACKAGE",
118
+ "url": "https://github.com/fastify/fast-uri"
119
+ }
120
+ ],
121
+ "affected": [
122
+ {
123
+ "package": {
124
+ "name": "fast-uri",
125
+ "ecosystem": "npm",
126
+ "purl": "pkg:npm/fast-uri"
127
+ },
128
+ "ranges": [
129
+ {
130
+ "type": "SEMVER",
131
+ "events": [
132
+ {
133
+ "introduced": "0"
134
+ },
135
+ {
136
+ "fixed": "3.1.2"
137
+ }
138
+ ]
139
+ }
140
+ ],
141
+ "database_specific": {
142
+ "source": "https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/05/GHSA-v39h-62p7-jpjc/GHSA-v39h-62p7-jpjc.json",
143
+ "last_known_affected_version_range": "<= 3.1.1"
144
+ }
145
+ }
146
+ ],
147
+ "schema_version": "1.7.5",
148
+ "severity": [
149
+ {
150
+ "type": "CVSS_V3",
151
+ "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
152
+ }
153
+ ]
154
+ }
155
+ ],
156
+ "snapshot_sha": "sha256:0b6ca61019fb234c"
157
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "schema_version": "1.1",
3
+ "updated": "2026-05-14",
4
+ "purpose": "Curated namespace patterns under ACTIVE incident — wired into default scan (v1.3.6+) AND pre-install scan. Auto-expires per active_until. TL updates when new incident requires fixture-level warning before OSV propagation. Per ADR-0006: pillar 2 of the 3-pillar guard architecture; pillar 3 (NEW-package heuristic) catches incidents BEFORE TL bump.",
5
+ "namespaces": [
6
+ {
7
+ "pattern": "@tanstack/",
8
+ "reason": "Active incident 2026-05-11 — Mini Shai-Hulud worm (CVE-2026-45321 / GHSA-g7cv-rxg3-hmpx). 84 malicious versions across 42 @tanstack/* packages published 2026-05-11 19:20-19:26 UTC. Worm self-propagated to 169+ packages.",
9
+ "advisory": "https://github.com/advisories/GHSA-g7cv-rxg3-hmpx",
10
+ "active_until": "2026-11-11",
11
+ "severity": "critical",
12
+ "affected_range": {
13
+ "type": "SEMVER",
14
+ "events": [{ "introduced": "1.169.5" }, { "fixed": "1.169.9" }]
15
+ },
16
+ "guidance": "Affected: 1.169.5-1.169.8. Safe: 1.169.9+. Verify SLSA provenance attestation matches expected publisher. If lockfile already pins affected range: rotate ALL credentials (npm tokens, GitHub PATs, SSH keys, cloud keys, Claude/AI configs) before continuing."
17
+ },
18
+ {
19
+ "pattern": "@uipath/",
20
+ "reason": "Worm spread vector from TanStack incident (2026-05-11) — 70+ @uipath/* packages compromised via stolen npm OIDC tokens.",
21
+ "advisory": "https://github.com/advisories/GHSA-g7cv-rxg3-hmpx",
22
+ "active_until": "2026-11-11",
23
+ "severity": "critical",
24
+ "guidance": "Verify each @uipath/* install against official UiPath release notes. Worm SLSA attestations are VALID — provenance check alone is insufficient. Cross-reference with UiPath security bulletin. (No affected_range — range still under investigation; treat all recent versions as suspect.)"
25
+ },
26
+ {
27
+ "pattern": "@mistralai/",
28
+ "reason": "Worm spread vector (2026-05-11) — @mistralai/mistralai 2.2.3-2.2.4 compromised on both npm and PyPI.",
29
+ "advisory": "https://github.com/advisories/GHSA-g7cv-rxg3-hmpx",
30
+ "active_until": "2026-11-11",
31
+ "severity": "critical",
32
+ "affected_range": {
33
+ "type": "SEMVER",
34
+ "events": [{ "introduced": "2.2.3" }, { "fixed": "2.2.5" }]
35
+ },
36
+ "guidance": "Affected: 2.2.3-2.2.4. Pin to 2.2.2 or 2.2.5+."
37
+ },
38
+ {
39
+ "pattern": "@opensearch-project/opensearch",
40
+ "reason": "Worm spread vector (2026-05-11) — @opensearch-project/opensearch 3.6.2 compromised (1.3M weekly downloads).",
41
+ "advisory": "https://github.com/advisories/GHSA-g7cv-rxg3-hmpx",
42
+ "active_until": "2026-11-11",
43
+ "severity": "critical",
44
+ "affected_range": {
45
+ "type": "SEMVER",
46
+ "events": [{ "introduced": "3.6.2" }, { "fixed": "3.6.3" }]
47
+ },
48
+ "guidance": "Affected: 3.6.2 only. Pin to 3.6.1 or 3.6.3+."
49
+ }
50
+ ],
51
+ "maintenance_note": "Per ADR-0005 + ADR-0006: this fixture handles the 'TL knows about incident' window (post-incident, pre-OSV-propagation). Pillar 3 (NEW-package heuristic, ADR-0006) handles the 'nobody knows yet' window. TL prunes entries past active_until on regular release cycles."
52
+ }
package/CLAUDE.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Workflow toolkit codebase. Rules live in `.claude/rules/` (auto-loaded).
4
4
 
5
5
  **v2.0 direction:** Context-First SDLC Governance Layer (5 pillars — see `.dw/core/PILLARS.md`)
6
- **Current:** v1.4.0-dev · v1.3.0 ready to ship · ADR-0001 active
6
+ **Current:** v1.3.6 (released 2026-05-14) · ADR-0001 active · ADR-0005 + ADR-0006 Accepted (Supply-Chain Guard 3-pillar AI-Native; sunset review 2026-08-12 per pillar) · v1.4 cuts pending telemetry
7
7
 
8
8
  ---
9
9
 
@@ -30,6 +30,8 @@ src/
30
30
  tasks/ Active + archive/ (Bridges pillar — via tracking.md)
31
31
  metrics/ Local telemetry (events.jsonl)
32
32
  config/ dw.config.yml
33
+ security/ IoC namespace fixture (Guards pillar — ADR-0005)
34
+ research/ Investigation notes, RFC-style proposals, voter panel outputs
33
35
  ```
34
36
 
35
37
  ## Dev Notes
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > An AI development workflow toolkit for teams using agentic IDEs (Claude Code, Cursor) — from idea to review-ready commits.
4
4
 
5
- **v1.3** · `npm install -g dw-kit` · [Docs](docs/README.md) · [Get started](docs/get-started.md) · [Cheatsheet](docs/cheatsheet.md) · [Migration v1.3](MIGRATION-v1.3.md) · [Changelog](CHANGELOG.md)
5
+ **v1.3.6** · `npm install -g dw-kit` · [Docs](docs/README.md) · [Get started](docs/get-started.md) · [Cheatsheet](docs/cheatsheet.md) · [Migration v1.3](MIGRATION-v1.3.md) · [Changelog](CHANGELOG.md)
6
6
 
7
7
  ---
8
8
 
@@ -36,10 +36,34 @@ It’s designed for collaboration (Dev / Tech Lead / QA / PM) and keeps work aud
36
36
 
37
37
  ## Release notes
38
38
 
39
- - v1.2.0 notes: [`CHANGELOG.md#v120--2026-04-09`](CHANGELOG.md#v120--2026-04-09)
39
+ - **v1.3.6** (2026-05-14) — Supply-Chain Guard upgraded to 3-pillar architecture: OSV snapshot + curated IoC fixture (version-aware, wired into default scan) + **AI-Native NEW-package heuristic** that catches zero-day-ish risk at the AI-edit boundary. See [`CHANGELOG.md#v136--2026-05-14`](CHANGELOG.md#v136--2026-05-14) and [ADR-0006](.dw/decisions/0006-supply-chain-guard-heuristic.md).
40
+ - v1.3.5 (2026-05-12) — AI-Native Supply-Chain Guard: `dw security-scan` CLI + OSV.dev auto-sync + Edit-lockfile hook + scoped `.gitignore` for end-user projects. See [ADR-0005](.dw/decisions/0005-supply-chain-guard.md). Public 90-day sunset review committed for 2026-08-12.
41
+ - v1.3.4 (2026-04-21) — `/dw:plan` Quick Debate (red/blue self-critique), depth-driven activation
42
+ - v1.3.3 (2026-04-21) — Writer skills v1/v2 compatibility fix
43
+ - v1.3.0 (2026-04-21) — 5-pillar governance layer + telemetry foundation + ADRs + v2 task docs ([ADR-0001](.dw/decisions/0001-v2-pragmatic-lean.md))
44
+ - v1.2.0 (2026-04-09) — [`CHANGELOG.md#v120--2026-04-09`](CHANGELOG.md#v120--2026-04-09)
40
45
  - Full changelog: `CHANGELOG.md`
41
46
  - Latest release notes: [GitHub Releases](https://github.com/dv-workflow/dv-workflow/releases)
42
47
 
48
+ ### What's in v1.3.6 for your team
49
+
50
+ Reaction time when a supply-chain incident drops goes from 24-72 hours (wait for OSV index + npm publish cycle) to **~1 hour** (AI edits lockfile → hook fires → heuristic flags BEFORE anyone knows).
51
+
52
+ - **3-pillar default scan** — `dw security-scan` now runs OSV snapshot + curated IoC fixture + AI-Native heuristic in one go. Heuristic only probes NEW/bumped packages from `git show HEAD:package-lock.json` diff — typical edit = 1-5 packages probed, not 1000+.
53
+ - **npm registry metadata heuristic** — composite scoring on `recent_publish` (<72h), `popular_package` (≥10k weekly DL), `maintainer_change_recent`, `major_version_jump`, `typo_squat`. Per-package metadata cached 1h. Tunable threshold via `.dw/config/dw.config.yml`.
54
+ - **Version-aware IoC fixture** — `affected_range` per entry. Concrete versions out-of-range are skipped (no false positives). Range specs (`^1.169.0`) emit ambiguity warnings with severity downgrade.
55
+ - **Hook fires `dw security-scan --heuristic-only`** on Claude Code lockfile edit — fast diff-only check.
56
+ - **Telemetry per pillar** — `source: 'osv' | 'fixture' | 'heuristic'` tracked separately so the 2026-08-12 sunset review attributes catches to the right pillar.
57
+ - **`>1000 packages`** crash bug from v1.3.5 fixed (chunked OSV batches).
58
+
59
+ ### What's in v1.3.5 for your team
60
+
61
+ - **`dw security-scan`** — scan for known supply-chain advisories against your project's `package-lock.json` (full match) or `package.json` (pre-install approximate). Uses [OSV.dev](https://osv.dev/) as data source (multi-maintainer upstream feed; no solo-curated bundle to go stale).
62
+ - **AI-aware hook** — fires when Claude Code edits a lockfile. Auto-wired by `dw init --preset team` or `--preset enterprise`; opt-in OFF for `--preset solo`.
63
+ - **Scoped `.gitignore`** — `dw init` and `dw upgrade` write `.dw/.gitignore` and `.claude/.gitignore` managed blocks. Framework files stay out of your repo; tasks/decisions/docs/config stay in.
64
+ - **`dw doctor`** has a new security section that fails loud if advisory snapshot is stale (>7 days) or schema-incompatible.
65
+ - **Sunset rule** — feature retires silently in v1.4.x if 90-day telemetry shows zero real catches OR >5% false-positive rate. Disciplined experiment, not panic ship.
66
+
43
67
  ---
44
68
 
45
69
  ## Install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dw-kit",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "AI development workflow toolkit — structured, quality-assured, team-ready. From requirements to dashboard.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,6 +14,7 @@
14
14
  ".dw/core/",
15
15
  ".dw/config/",
16
16
  ".dw/adapters/",
17
+ ".dw/security/",
17
18
  ".claude/agents/",
18
19
  ".claude/hooks/",
19
20
  ".claude/rules/",
package/src/cli.mjs CHANGED
@@ -101,6 +101,36 @@ export function run(argv) {
101
101
  await dashboardCommand(opts);
102
102
  });
103
103
 
104
+ program
105
+ .command('security-scan')
106
+ .alias('scan')
107
+ .description('Scan project: 3-pillar supply-chain guard (OSV + fixture + AI-Native heuristic). Auto-syncs OSV snapshot if missing or stale.')
108
+ .option('--quick', 'Offline mode — use existing snapshot only (default behavior)')
109
+ .option('--update-db', 'Fetch fresh advisory snapshot from OSV.dev before scanning')
110
+ .option('--pre-install', 'Scan package.json without lockfile (OSV name-only + namespace fixture)')
111
+ .option('--offline', 'Skip network in --pre-install mode + skip pillar 3 heuristic')
112
+ .option('--no-heuristic', 'Skip pillar 3 (AI-Native NEW-package heuristic). Default: enabled on lockfile diff.')
113
+ .option('--heuristic-only', 'Run ONLY pillar 3 (used by hook). Skips OSV + fixture pillars.')
114
+ .option('--json', 'Output machine-readable JSON')
115
+ .option('--install-hook', 'Wire supply-chain-scan.sh into .claude/settings.json PostToolUse (idempotent)')
116
+ .option('--uninstall-hook', 'Remove supply-chain-scan.sh entry from .claude/settings.json')
117
+ .action(async (opts) => {
118
+ if (opts.installHook || opts.uninstallHook) {
119
+ const { installHookInProject, uninstallHookFromProject } = await import('./lib/sc-install.mjs');
120
+ const r = opts.uninstallHook ? uninstallHookFromProject() : installHookInProject();
121
+ if (!r.ok) {
122
+ console.error(chalk.red(`✗ ${r.error}`));
123
+ process.exit(1);
124
+ }
125
+ if (r.action === 'added') console.log(chalk.green(`✓ Hook wired into ${r.path}`));
126
+ else if (r.action === 'removed') console.log(chalk.green(`✓ Removed ${r.count} entry from ${r.path}`));
127
+ else console.log(chalk.dim(` (no-op: ${r.reason})`));
128
+ return;
129
+ }
130
+ const { securityScanCommand } = await import('./commands/security-scan.mjs');
131
+ await securityScanCommand(opts);
132
+ });
133
+
104
134
  program
105
135
  .command('claude-vn-fix')
106
136
  .description('Patch Claude CLI to fix Vietnamese IME (local, with backup/restore)')
@@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url';
4
4
  import { header, ok, warn, err, info, log } from '../lib/ui.mjs';
5
5
  import { loadConfig, getToolkitVersions } from '../lib/config.mjs';
6
6
  import { detectPlatform, platformLabel } from '../lib/platform.mjs';
7
+ import { snapshotInfo } from '../lib/sc-sync.mjs';
7
8
 
8
9
  const TOOLKIT_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..', '..');
9
10
 
@@ -150,6 +151,26 @@ export async function doctorCommand() {
150
151
  }
151
152
  }
152
153
 
154
+ info('Supply-Chain Guard (ADR-0005, opt-in)');
155
+ const sc = snapshotInfo(projectDir);
156
+ if (!sc.exists) {
157
+ log(' Advisory snapshot — not yet created');
158
+ log(' Run `dw security-scan --update-db` to fetch from OSV.dev (opt-in feature)');
159
+ } else {
160
+ if (!sc.schema_compatible) {
161
+ err(`Advisory snapshot schema mismatch — expected 1.0, got ${sc.schema_version || 'unknown'}`);
162
+ log(' Run `dw security-scan --update-db` to refresh');
163
+ issues++;
164
+ } else if (sc.stale) {
165
+ warn(`Advisory snapshot stale: ${sc.age_days.toFixed(1)} days old (>7d threshold)`);
166
+ log(` Source: ${sc.source} (${sc.ecosystem}), advisories=${sc.advisory_count}`);
167
+ log(' Run `dw security-scan --update-db` to refresh');
168
+ warnings++;
169
+ } else {
170
+ ok(`Advisory snapshot — ${sc.age_days.toFixed(1)}d old, ${sc.advisory_count} advisories (${sc.source})`);
171
+ }
172
+ }
173
+
153
174
  console.log();
154
175
  header('Diagnosis');
155
176
  if (issues === 0 && warnings === 0) {
@@ -5,6 +5,7 @@ import { banner, ok, warn, info, log, ask, choose } from '../lib/ui.mjs';
5
5
  import { buildConfig, writeConfig } from '../lib/config.mjs';
6
6
  import { copyDir, copyFile, ensureDir } from '../lib/copy.mjs';
7
7
  import { detectPlatform, platformLabel } from '../lib/platform.mjs';
8
+ import { ensureDwGitignore, ensureClaudeGitignore } from '../lib/gitignore.mjs';
8
9
 
9
10
  const TOOLKIT_ROOT = resolve(fileURLToPath(import.meta.url), '..', '..', '..');
10
11
 
@@ -82,7 +83,7 @@ export async function initCommand(opts) {
82
83
  ok(`Platform: ${platformLabel(adapter)}`);
83
84
 
84
85
  info('Setting up project...');
85
- await setupProject(projectDir, { projectName, depth, roles, language, adapter });
86
+ await setupProject(projectDir, { projectName, depth, roles, language, adapter, presetKey: opts.preset });
86
87
 
87
88
  printSummary({ projectName, depth, roles, language, adapter });
88
89
  }
@@ -135,7 +136,7 @@ function normalizeRolesForDepth(parsedRoles, depth) {
135
136
  return merged;
136
137
  }
137
138
 
138
- async function setupProject(projectDir, { projectName, depth, roles, language, adapter }) {
139
+ async function setupProject(projectDir, { projectName, depth, roles, language, adapter, presetKey }) {
139
140
  copyCoreDocs(projectDir);
140
141
  copyConfig(projectDir, { projectName, depth, roles, language });
141
142
  copyAdapterStructure(projectDir);
@@ -143,6 +144,7 @@ async function setupProject(projectDir, { projectName, depth, roles, language, a
143
144
  if (adapter === 'claude-cli') {
144
145
  copyClaudeFiles(projectDir);
145
146
  createMinimalCLAUDEmd(projectDir, projectName);
147
+ await maybeInstallSupplyChainHook(projectDir, presetKey);
146
148
  } else if (adapter === 'cursor') {
147
149
  copyCursorFiles(projectDir);
148
150
  copyGenericAdapter(projectDir);
@@ -152,6 +154,91 @@ async function setupProject(projectDir, { projectName, depth, roles, language, a
152
154
 
153
155
  createRuntimeDirs(projectDir);
154
156
  updateGitignore(projectDir);
157
+ writeScopedGitignores(projectDir, adapter);
158
+ }
159
+
160
+ function writeScopedGitignores(projectDir, adapter) {
161
+ try {
162
+ const dwR = ensureDwGitignore(projectDir);
163
+ if (dwR.action !== 'noop') ok(`.dw/.gitignore ${dwR.action}`);
164
+ if (adapter === 'claude-cli') {
165
+ const cR = ensureClaudeGitignore(projectDir);
166
+ if (cR.action !== 'noop') ok(`.claude/.gitignore ${cR.action}`);
167
+ }
168
+ } catch (e) {
169
+ warn(`Scoped gitignore: ${e.message}`);
170
+ }
171
+ }
172
+
173
+ async function maybeInstallSupplyChainHook(projectDir, presetKey) {
174
+ const preset = presetKey ? PRESETS[presetKey] : null;
175
+ const { installHookInProject, uninstallHookFromProject } = await import('../lib/sc-install.mjs');
176
+
177
+ if (preset && preset.hooksProfile === 'safety-only') {
178
+ // Solo preset — explicitly uninstall hook even if template provided it (TW5: opt-in OFF)
179
+ const result = uninstallHookFromProject(projectDir);
180
+ if (result.ok && result.action === 'removed') {
181
+ log(' Supply-chain guard: hook removed from settings (solo preset — opt-in OFF per ADR-0005 TW5)');
182
+ } else {
183
+ log(' Supply-chain guard: skipped (solo preset — opt-in OFF per ADR-0005 TW5)');
184
+ }
185
+ log(' Enable later: `dw security-scan --install-hook`');
186
+ return;
187
+ }
188
+
189
+ const result = installHookInProject(projectDir);
190
+ if (!result.ok) {
191
+ warn(`Supply-chain hook wiring skipped: ${result.error}`);
192
+ return;
193
+ }
194
+ if (result.action === 'added') {
195
+ ok('Supply-chain guard hook wired (ADR-0005 — opt-in flag enabled)');
196
+ }
197
+
198
+ // UX: offer one-time OSV snapshot sync so end-user doesn't need to know
199
+ // `--update-db` exists. Lazy auto-refresh in `dw scan` covers the case
200
+ // when user declines, but offering during init gets snapshot ready upfront.
201
+ await maybeBootstrapOsvSnapshot(projectDir);
202
+ }
203
+
204
+ async function maybeBootstrapOsvSnapshot(projectDir) {
205
+ // Non-TTY (CI / scripted): default yes so the snapshot exists for next scan.
206
+ // TTY: prompt user, default yes.
207
+ let shouldSync = true;
208
+ if (process.stdin.isTTY && !process.env.DW_INIT_NO_PROMPT) {
209
+ try {
210
+ const { prompt } = await import('enquirer');
211
+ const answer = await prompt({
212
+ type: 'confirm',
213
+ name: 'syncNow',
214
+ message: 'Sync OSV advisory snapshot now? (recommended first-time; ~10-30s)',
215
+ initial: true,
216
+ });
217
+ shouldSync = !!answer.syncNow;
218
+ } catch {
219
+ shouldSync = true;
220
+ }
221
+ }
222
+ if (!shouldSync) {
223
+ log(' Skipped. First `dw scan` will auto-sync if needed.');
224
+ return;
225
+ }
226
+
227
+ const { findLockfile } = await import('../lib/sc-scanner.mjs');
228
+ if (!findLockfile(projectDir)) {
229
+ log(' No lockfile yet — first `dw scan` will sync after `npm install` runs.');
230
+ return;
231
+ }
232
+ log(' Syncing OSV snapshot...');
233
+ try {
234
+ const { syncSnapshotForProject } = await import('../lib/sc-sync.mjs');
235
+ const start = Date.now();
236
+ const res = await syncSnapshotForProject(projectDir);
237
+ const partialNote = res.partial ? ` (PARTIAL ${res.chunks.failed}/${res.chunks.total})` : '';
238
+ ok(`OSV snapshot ready — ${res.advisoryCount} advisories for ${res.packageCount} packages (${Date.now() - start}ms)${partialNote}`);
239
+ } catch (e) {
240
+ warn(`OSV sync skipped: ${e.message}. Will retry on first \`dw scan\`.`);
241
+ }
155
242
  }
156
243
 
157
244
  function copyCoreDocs(projectDir) {