@coding-with-hassan/devkit 1.0.0-next.3 → 1.1.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.
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @coding-with-hassan/devkit
2
2
 
3
- CLI that wraps the developer workflow shared across Hassan's client projects: docker compose orchestration, postgres helpers, and the husky pre-commit hook.
3
+ The way of working of Hassan's client projects as one versioned package: parallel git worktrees with isolated Docker stacks, the pre-commit chain, a CI job with commit standards and an Nx cache, the Claude Code standards/agents/hooks, and the bilingual acceptance-test workbooks. A project installs it, fills one config block in `package.json`, runs `hassan-devkit init`, and picks up every later standard by bumping the version. Design: `docs/design/way-of-working.md`; decisions: `docs/adr/`.
4
+
5
+ New projects start from [hassan-devkit-template](https://github.com/CodiNG-With-Hassan/hassan-devkit-template), which is exactly what `init` produces on an Nx `apps/*` + `libs/*` pnpm workspace.
4
6
 
5
7
  ## Install
6
8
 
@@ -38,7 +40,7 @@ Optionally add a `docker.preUp` hook — a shell command `docker:up` runs from t
38
40
  }
39
41
  ```
40
42
 
41
- ## Wire it into your scripts
43
+ ## Wire it into your scripts (flat repos; Nx workspaces get this from `init`)
42
44
 
43
45
  ```json
44
46
  {
@@ -53,9 +55,9 @@ Optionally add a `docker.preUp` hook — a shell command `docker:up` runs from t
53
55
  }
54
56
  ```
55
57
 
56
- ## The way of working (1.0 line)
58
+ ## The way of working
57
59
 
58
- From 1.0 the CLI is the single delivery vehicle for the whole way of working — parallel worktrees with isolated stacks, the pre-commit chain, CI with commit standards, and the Claude Code layer. Design: `docs/design/way-of-working.md` and ADR 0001 in this repo. New features assume an **Nx `apps/*` + `libs/*` pnpm monorepo**; the `docker:*`, `db:*` and `hooks:*` commands above stay layout-agnostic.
60
+ Everything below assumes an **Nx `apps/*` + `libs/*` pnpm monorepo** (the template's shape); the `docker:*`, `db:*`, `i18n:check` and `hooks:*` commands further down stay layout-agnostic for the older flat repos. Requires Node ≥ 22.13.
59
61
 
60
62
  ### Configure once, derive the rest
61
63
 
@@ -153,7 +155,8 @@ Every project with an ESLint/Prettier config gets `pnpm -C <dir> exec …` entri
153
155
  `hassan-devkit claude:install` (run by `prepare` and by `init`) wires the house standards into Claude Code without copying content:
154
156
 
155
157
  - one `@import` line in the project's `CLAUDE.md` (`.claude/CLAUDE.md` when it exists) pulling `node_modules/@coding-with-hassan/devkit/claude/standards.md` — Docker via scripts, worktrees, commit/push consent + commit-writer, tickets, the acceptance-case quality gate, lint/format/CI parity, domain docs. In-repo imports load at launch without an approval dialog;
156
- - `.claude/agents/commit-writer.md` and `.claude/skills/implement-ticket/SKILL.md` as **stubs** whose body says "read the shipped file and follow it" — the stub never changes, the content ships with the devkit version;
158
+ - `.claude/agents/commit-writer.md` as a **stub** whose body says "read the shipped file and follow it" — the stub never changes, the content ships with the devkit version;
159
+ - one `.claude/skills/<name>/SKILL.md` stub per skill, same pattern: the house `implement-ticket` (body shipped by the devkit) and every skill of the project's `mattpocock-skills` dependency — `init` adds `github:mattpocock/skills#v1.2.3` to `devDependencies`, a GitHub tarball pinned to an upstream release tag that pnpm integrity-locks — except `implement` and `setup-matt-pocock-skills`, which the house skill and `init` replace. The stub copies the skill's frontmatter verbatim (user-invocable-only skills stay user-only) and points at the body under `node_modules`. Stubs are derived on every install and **gitignored** through a managed block, so nothing is committed and a bump changes nothing in git; they are what makes the skills reach every clone and the skill pickers that only scan `.claude/skills` (T3 Code). Renovate bumps the tag (the shared preset automerges it), so an upstream skills release needs no devkit release;
157
160
  - the PR-assignee `PreToolUse` deny hook merged idempotently into `.claude/settings.json`.
158
161
 
159
162
  Project-specific rules stay in the project's own `CLAUDE.md` below the import. A devkit bump therefore changes what Claude does with nothing to re-commit.
@@ -168,7 +171,19 @@ import { tc, type Area, type KnownIssue, type Readme } from '@coding-with-hassan
168
171
 
169
172
  `hassan-devkit test-cases:generate [--lang xx] [--testers file.json]` writes `test-cases-<suite>-<lang>.xlsx` per suite and language (`testCases.languages`, default `en`, `nl`; workbook UI strings ship for those two) next to the data, plus a personalised copy per tester (Tester column prefilled, credentials in the Read Me sheet). Each workbook has a Read Me, a Summary with per-area counts, one sheet per area with a Pass/Fail/Blocked/Skipped dropdown, and a Known Issues sheet. The workbooks are gitignored artifacts; commit the data files with the feature. The data files are TypeScript loaded through Node's built-in type stripping (Node ≥ 22.13, no `tsx`), which keeps import specifiers verbatim — hence the `type` modifiers above. `testCases.title` sets the project name in the Read Me title. `init` scaffolds a starter `tc-data-app.ts` when the section is configured and the directory is empty.
170
173
 
171
- ## Commands
174
+ ## Upgrading from 0.x
175
+
176
+ - **Node ≥ 22.13** (the acceptance-case generator loads TypeScript data with Node's type stripping).
177
+ - **Config block**: `hassan-devkit.db`, `docker.preUp` and `i18n` keep working; add `worktree`, `tracker`, `commits`, `ci`, `testCases` as needed — `hassan-devkit init --only config` writes the skeleton. Unknown keys are now rejected (`config:check`).
178
+ - **`hooks:install`** no longer runs `husky init` (which rewrote your `prepare` script); it (re)creates husky's per-checkout shims and skips inside container builds (`HUSKY=0`, no `.git`). The hook body gained the `ci:doctor` step for staged workflow files; `i18n:check` stays.
179
+ - **lint-staged**: replace `@coding-with-hassan/lint-staged-config` with `lint-staged.config.mjs` importing `@coding-with-hassan/devkit/lint-staged` (targets derived from the workspace; `init --only hooks` scaffolds it).
180
+ - **`docker:up`** runs `worktree:env` implicitly once `hassan-devkit.worktree` names ports or profiles; a `docker.preUp` hook that only refreshed `.env` can go. Managed `.env` keys are `DEVKIT_SLOT`, `DEVKIT_IMAGE_TAG`, `DEVKIT_BRANCH`, `DEVKIT_PORT_*` — rename them in your compose file.
181
+ - **CI**: `init --only ci --force` writes the thin workflow; delete hand-rolled affected/cache scripts. Commit scopes are derived from the workspace (`commits:show`).
182
+ - **Claude**: `init --only claude,agents` adds the standards import, the stubs, the PR-assignee hook and regenerates `docs/agents`; trim your `CLAUDE.md` to project specifics.
183
+ - **Skills** (1.1): `init --only config` adds the `mattpocock-skills` devDependency; `pnpm install` then writes the skill stubs and the `.gitignore` block, and `claude:install` prints the one-off `git rm --cached` for the `implement-ticket` stub you committed under 1.0. With the plugin still enabled in `~/.claude`, a bare `/grilling` runs the project stub and `/mattpocock-skills:grilling` the plugin (same body).
184
+ - Adopt piece by piece with `init --only <part>`; `ci:doctor` reports what is not adopted yet.
185
+
186
+ ## Layout-agnostic commands
172
187
 
173
188
  ### Docker
174
189
 
@@ -1,3 +1,8 @@
1
+ ---
2
+ name: implement-ticket
3
+ description: "Implement a piece of work based on a spec or set of tickets, the house way: in the ticket's worktree, with acceptance cases, without committing. (Model-invocable; renamed from the plugin's user-invocable 'implement' to avoid the name collision.)"
4
+ ---
5
+
1
6
  # implement-ticket (body shipped by @coding-with-hassan/devkit)
2
7
 
3
8
  Implement the work described by the user in the spec or tickets.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coding-with-hassan/devkit",
3
- "version": "1.0.0-next.3",
3
+ "version": "1.1.0",
4
4
  "description": "CLI for the developer workflow shared across Hassan's client projects: docker compose orchestration, db helpers, and husky hook installation.",
5
5
  "license": "MIT",
6
6
  "author": "Hassan Khousheish",
@@ -1,16 +1,43 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { existsSync } from 'node:fs';
3
+ import { join } from 'node:path';
1
4
  import { loadConfig } from '../core/config.js';
2
- import { claudePlans } from '../core/claude.js';
5
+ import { claudePlans, stubPath } from '../core/claude.js';
3
6
  import { applyPlan } from '../core/scaffold.js';
4
7
  import { exitOnFailure } from '../util/run.js';
5
8
 
6
9
  /**
7
10
  * `claude:install` — wire the Claude Code layer into this repo: the `@import` of the shipped
8
- * standards in CLAUDE.md, the agent/skill stubs and the PR-assignee hook. Idempotent; runs from
9
- * `prepare` so every checkout has it, and from `init`.
11
+ * standards in CLAUDE.md, the agent stub, one stub per skill (house + the project's
12
+ * `mattpocock-skills` dependency, gitignored through a managed block) and the PR-assignee hook.
13
+ * Idempotent; runs from `prepare` so every checkout has the stubs, and from `init`.
10
14
  */
11
- export async function installClaude({ cwd = process.cwd(), log = console.log, dryRun = false } = {}) {
15
+
16
+ /** Stub paths git still tracks: they predate the gitignore block and must be untracked once. */
17
+ function trackedStubs(root, plans) {
18
+ const stubs = plans.map((p) => p.path).filter((p) => p === stubPath(p.split('/')[2]));
19
+ if (stubs.length === 0) return [];
20
+ try {
21
+ const out = execFileSync('git', ['ls-files', '--', ...stubs], { cwd: root, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
22
+ return out.split('\n').filter(Boolean);
23
+ } catch {
24
+ return [];
25
+ }
26
+ }
27
+ export async function installClaude({ cwd = process.cwd(), env = process.env, log = console.log, dryRun = false } = {}) {
12
28
  const { root } = loadConfig({ cwd });
13
- const summary = applyPlan(root, claudePlans(root), { dryRun, log });
29
+ // Like hooks:install, this runs from `prepare` inside container image builds too (no .git,
30
+ // HUSKY=0): there is no Claude session to serve there, so do not write stubs into the image.
31
+ if (env.HUSKY === '0' || !existsSync(join(root, '.git'))) {
32
+ log('claude layer: no git checkout here (container build or export) — skipping');
33
+ return null;
34
+ }
35
+ const notes = [];
36
+ const plans = claudePlans(root, { notes });
37
+ const summary = applyPlan(root, plans, { dryRun, log });
38
+ const tracked = trackedStubs(root, plans);
39
+ if (tracked.length) notes.push(`skill stubs are generated and gitignored now — untrack the committed ones once: git rm --cached ${tracked.join(' ')}`);
40
+ for (const n of notes) log(` note: ${n}`);
14
41
  const touched = summary.created.length + summary.updated.length;
15
42
  log(touched ? `claude layer: ${touched} file(s) written` : 'claude layer: up to date');
16
43
  return summary;
@@ -18,7 +45,7 @@ export async function installClaude({ cwd = process.cwd(), log = console.log, dr
18
45
 
19
46
  export function registerClaude(cli) {
20
47
  cli
21
- .command('claude:install', 'Wire the Claude Code layer (standards import, agent/skill stubs, PR-assignee hook) into this repo')
48
+ .command('claude:install', 'Wire the Claude Code layer (standards import, agent stub, skill stubs from the devkit + mattpocock-skills, PR-assignee hook) into this repo')
22
49
  .option('--dry-run', 'Show what would change without writing')
23
50
  .action((opts) => exitOnFailure(installClaude({ dryRun: Boolean(opts.dryRun) })));
24
51
  }
@@ -4,7 +4,7 @@ import { COMPOSE_FILE, CONFIG_KEY, ENV_DIST_FILE, loadConfig, resolveConfig } fr
4
4
  import { managedValues, writeManagedBlock } from '../core/env-block.js';
5
5
  import { agentsDocs } from '../core/agents-docs.js';
6
6
  import { WORKFLOW_PATH, renderWorkflow } from '../core/ci/workflow.js';
7
- import { claudePlans } from '../core/claude.js';
7
+ import { SKILLS_PACKAGE, SKILLS_PACKAGE_SPEC, claudePlans } from '../core/claude.js';
8
8
  import { listDataFiles } from '../core/test-cases/generate.js';
9
9
  import { worktreeActive } from '../core/worktrees.js';
10
10
  import { applyPlan, formatJson, mergeMissing, planFile } from '../core/scaffold.js';
@@ -85,9 +85,11 @@ export const APP_README: Readme = {
85
85
  `;
86
86
 
87
87
  /**
88
- * Plan the package.json changes: config skeleton + default scripts, only where missing.
89
- * Docker scripts only make sense with a compose file, the `prepare` hook installer only
90
- * with husky as a dependency — a repo without them (this devkit repo itself) gets neither.
88
+ * Plan the package.json changes: config skeleton, default scripts and the Claude skills
89
+ * dependency, only where missing. Docker scripts only make sense with a compose file, the
90
+ * `prepare` hook installer only with husky as a dependency — a repo without them (this devkit
91
+ * repo itself) gets neither. The skills dependency is a GitHub tarball pinned to an upstream
92
+ * release tag: Renovate bumps the tag, `claude:install` derives the stubs from whatever is installed.
91
93
  */
92
94
  export function planPackageJson(root, pkg) {
93
95
  const next = structuredClone(pkg);
@@ -97,6 +99,10 @@ export function planPackageJson(root, pkg) {
97
99
  next.scripts ??= {};
98
100
  const scripts = { ...(existsSync(join(root, COMPOSE_FILE)) ? DOCKER_SCRIPTS : {}), ...(usesHusky(pkg) ? HOOK_SCRIPTS : CLAUDE_ONLY_SCRIPTS) };
99
101
  added.push(...mergeMissing(next.scripts, scripts, 'scripts'));
102
+ if (!next.dependencies?.[SKILLS_PACKAGE]) {
103
+ next.devDependencies ??= {};
104
+ added.push(...mergeMissing(next.devDependencies, { [SKILLS_PACKAGE]: SKILLS_PACKAGE_SPEC }, 'devDependencies'));
105
+ }
100
106
  return { plan: planFile(root, 'package.json', formatJson(next), { managed: true }), added, next };
101
107
  }
102
108
 
@@ -127,12 +133,12 @@ export function planEnvDist(root, config, rootName) {
127
133
  * repo can adopt the way of working one piece at a time (config first, the Claude layer last).
128
134
  */
129
135
  export const INIT_PARTS = {
130
- config: 'the hassan-devkit block and default scripts in package.json',
136
+ config: 'the hassan-devkit block, default scripts and the mattpocock-skills dependency in package.json',
131
137
  env: 'the slot-0 managed block in .env.dist',
132
138
  hooks: 'the pre-commit seam and lint-staged.config.mjs',
133
139
  agents: 'docs/agents/*.md rendered from the tracker config',
134
140
  ci: 'the thin .github/workflows/ci.yml',
135
- claude: 'the CLAUDE.md import, agent/skill stubs and the PR-assignee hook',
141
+ claude: 'the CLAUDE.md import, the agent stub, the gitignored skill stubs and the PR-assignee hook',
136
142
  'test-cases': 'a starter docs/testing data file',
137
143
  };
138
144
 
@@ -192,6 +198,7 @@ export async function init({ force = false, dryRun = false, only, cwd = process.
192
198
  for (const n of notes) log(` note: ${n}`);
193
199
  const next = [
194
200
  `Fill in "${CONFIG_KEY}" in package.json (ports, profiles, seeds, tracker) and re-run \`hassan-devkit init\` to refresh ${ENV_DIST_FILE}.`,
201
+ `Run \`pnpm install\` so the ${SKILLS_PACKAGE} dependency lands and \`prepare\` writes the skill stubs.`,
195
202
  'Check the result with `hassan-devkit config:show` and `hassan-devkit commits:show`.',
196
203
  ];
197
204
  log(`\nNext:\n - ${next.join('\n - ')}`);
@@ -1,17 +1,42 @@
1
- import { existsSync, readFileSync } from 'node:fs';
1
+ import { existsSync, readFileSync, readdirSync } from 'node:fs';
2
2
  import { join, posix } from 'node:path';
3
- import { formatJson, planFile } from './scaffold.js';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { formatJson, planFile, upsertMarkedBlock } from './scaffold.js';
4
5
 
5
6
  /**
6
7
  * The Claude Code layer. Nothing here is copied content: the project's `CLAUDE.md` imports the
7
8
  * standards text from `node_modules` and the agent/skill files are stubs that read the shipped
8
9
  * body at runtime, so a devkit bump changes what Claude does without a re-commit. Only the
9
10
  * settings hook is merged into a committed file, and that merge is idempotent.
11
+ *
12
+ * Skills come from two places and get the same treatment — one stub per skill, frontmatter
13
+ * copied verbatim from the body file (name, description, invocation flags: what Claude Code and
14
+ * the skill pickers read):
15
+ * - house skills shipped in this package under `claude/skills/<name>/`;
16
+ * - the mattpocock skills, installed in the PROJECT as the `mattpocock-skills` dependency
17
+ * (a GitHub tarball pinned to an upstream release tag; `init` adds it to `devDependencies`)
18
+ * and listed by its plugin manifest. Renovate bumps the tag, so an upstream release reaches
19
+ * every project without a devkit release.
20
+ * The stubs are derived on every install (`prepare` → `claude:install`) and gitignored through a
21
+ * managed block, so a version bump never leaves anything to commit.
10
22
  */
11
23
 
24
+ const PACKAGE_ROOT = fileURLToPath(new URL('../../', import.meta.url));
12
25
  export const PACKAGE_DIR = 'node_modules/@coding-with-hassan/devkit';
13
26
  export const STANDARDS_IMPORT_TARGET = `${PACKAGE_DIR}/claude/standards.md`;
14
27
  export const IMPORT_MARKER = '<!-- devkit standards: house rules shipped by @coding-with-hassan/devkit; project rules follow -->';
28
+ export const HOUSE_SKILLS_DIR = 'claude/skills';
29
+
30
+ /** The upstream skills as a project dependency: package name, pinned spec, and what not to expose. */
31
+ export const SKILLS_PACKAGE = 'mattpocock-skills';
32
+ export const SKILLS_PACKAGE_SPEC = 'github:mattpocock/skills#v1.2.3';
33
+ export const SKILLS_PACKAGE_DIR = `node_modules/${SKILLS_PACKAGE}`;
34
+ /** Upstream skills the house replaces: `implement` → `implement-ticket`; `init` writes what setup would. */
35
+ export const SKILLS_EXCLUDE = ['implement', 'setup-matt-pocock-skills'];
36
+
37
+ export const GITIGNORE_FILE = '.gitignore';
38
+ export const GITIGNORE_BEGIN = '# >>> hassan-devkit: Claude skill stubs — regenerated by `hassan-devkit claude:install` on every install, never committed';
39
+ export const GITIGNORE_END = '# <<< hassan-devkit';
15
40
 
16
41
  const AGENT_STUB = `---
17
42
  name: commit-writer
@@ -33,16 +58,6 @@ it exactly. That file is the agent's body; it ships with the installed devkit ve
33
58
  stub never needs to change.
34
59
  `;
35
60
 
36
- const SKILL_STUB = `---
37
- name: implement-ticket
38
- description: "Implement a piece of work based on a spec or set of tickets, the house way: in the ticket's worktree, with acceptance cases, without committing. (Model-invocable; renamed from the plugin's user-invocable 'implement' to avoid the name collision.)"
39
- ---
40
-
41
- Read \`${PACKAGE_DIR}/claude/skills/implement-ticket/SKILL.md\` (relative to the repo root)
42
- and follow it exactly. That file is the skill's body; it ships with the installed devkit
43
- version so this stub never needs to change.
44
- `;
45
-
46
61
  /** The PreToolUse hook that denies `gh pr create` without an assignee (team PR standard). */
47
62
  export const PR_ASSIGNEE_HOOK = {
48
63
  matcher: 'Bash',
@@ -89,14 +104,97 @@ export function claudeMdPath(root) {
89
104
  return '.claude/CLAUDE.md';
90
105
  }
91
106
 
92
- /** Plans for the whole Claude layer. */
93
- export function claudePlans(root) {
107
+ /**
108
+ * Read one skill folder: `{ name, frontmatter, hasSiblings }`. The frontmatter must exist and
109
+ * declare the folder's name — a body that fails this would yield a stub Claude Code refuses to
110
+ * load, silently, so it throws instead.
111
+ */
112
+ function readSkill(skillDir, label) {
113
+ const text = readFileSync(join(skillDir, 'SKILL.md'), 'utf8');
114
+ const match = text.match(/^---\n([\s\S]*?)\n---\n/);
115
+ if (!match) throw new Error(`${label}/SKILL.md has no frontmatter`);
116
+ const name = posix.basename(label);
117
+ const declared = match[1].match(/^name:\s*"?([^"\n]+?)"?\s*$/m)?.[1];
118
+ if (declared !== name) throw new Error(`${label}/SKILL.md declares name "${declared}", folder is "${name}"`);
119
+ // `agents/` holds Codex metadata, not something the body links to.
120
+ const hasSiblings = readdirSync(skillDir).some((f) => f !== 'SKILL.md' && f !== 'agents');
121
+ return { name, frontmatter: match[0], hasSiblings };
122
+ }
123
+
124
+ /** The skills shipped by this package (`claude/skills/<name>/SKILL.md`), sorted by name. */
125
+ export function houseSkills(packageRoot = PACKAGE_ROOT) {
126
+ const dir = join(packageRoot, HOUSE_SKILLS_DIR);
127
+ const skills = [];
128
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
129
+ if (!entry.isDirectory() || !existsSync(join(dir, entry.name, 'SKILL.md'))) continue;
130
+ const skill = readSkill(join(dir, entry.name), `${HOUSE_SKILLS_DIR}/${entry.name}`);
131
+ skills.push({ ...skill, source: 'devkit', bodyPath: `${PACKAGE_DIR}/${HOUSE_SKILLS_DIR}/${entry.name}/SKILL.md` });
132
+ }
133
+ return skills.sort((a, b) => a.name.localeCompare(b.name));
134
+ }
135
+
136
+ /**
137
+ * The skills of the project's installed `mattpocock-skills` dependency, from its plugin manifest
138
+ * (`.claude-plugin/plugin.json` → `skills[]`), minus `SKILLS_EXCLUDE`, sorted by name. Returns
139
+ * `[]` when the package is not installed (older project, or `pnpm install` not run yet).
140
+ */
141
+ export function packageSkills(root, { exclude = SKILLS_EXCLUDE } = {}) {
142
+ const manifestFile = join(root, SKILLS_PACKAGE_DIR, '.claude-plugin/plugin.json');
143
+ if (!existsSync(manifestFile)) return [];
144
+ const manifest = JSON.parse(readFileSync(manifestFile, 'utf8'));
145
+ const skills = [];
146
+ for (const rel of manifest.skills ?? []) {
147
+ const relPath = posix.normalize(rel);
148
+ const name = posix.basename(relPath);
149
+ if (exclude.includes(name)) continue;
150
+ const skill = readSkill(join(root, SKILLS_PACKAGE_DIR, relPath), `${SKILLS_PACKAGE_DIR}/${relPath}`);
151
+ skills.push({ ...skill, source: SKILLS_PACKAGE, bodyPath: posix.join(SKILLS_PACKAGE_DIR, relPath, 'SKILL.md') });
152
+ }
153
+ return skills.sort((a, b) => a.name.localeCompare(b.name));
154
+ }
155
+
156
+ /** Every skill that gets a stub: house first, then the dependency's. Names never collide today; a house skill wins if they do. */
157
+ export function allSkills(root, options) {
158
+ const house = houseSkills();
159
+ const taken = new Set(house.map((s) => s.name));
160
+ return [...house, ...packageSkills(root, options).filter((s) => !taken.has(s.name))];
161
+ }
162
+
163
+ /** Pure: the project stub for one skill (frontmatter verbatim, body = "read and follow"). */
164
+ export function skillStub({ frontmatter, hasSiblings, bodyPath, source }) {
165
+ const shipsWith = source === 'devkit' ? 'the installed devkit version' : `the installed \`${source}\` version`;
166
+ const siblings = hasSiblings ? ' Relative links in that file point at files in the same folder.' : '';
167
+ return `${frontmatter}
168
+ Read \`${bodyPath}\` (relative to the repo root)
169
+ and follow it exactly. That file is the skill's body; it ships with ${shipsWith} so this
170
+ stub never needs to change.${siblings}
171
+ `;
172
+ }
173
+
174
+ export const stubPath = (name) => `.claude/skills/${name}/SKILL.md`;
175
+
176
+ /** Pure: the `.gitignore` text with the managed block listing every generated stub folder. */
177
+ export function withSkillStubsIgnored(text, skillNames) {
178
+ const lines = [...skillNames].sort().map((name) => `.claude/skills/${name}/`);
179
+ return upsertMarkedBlock(text ?? '', GITIGNORE_BEGIN, GITIGNORE_END, lines);
180
+ }
181
+
182
+ /** Plans for the whole Claude layer. `notes` collects advice for the caller to print. */
183
+ export function claudePlans(root, { notes = [] } = {}) {
94
184
  const plans = [];
95
185
  const mdPath = claudeMdPath(root);
96
186
  const current = existsSync(join(root, mdPath)) ? readFileSync(join(root, mdPath), 'utf8') : '';
97
187
  plans.push(planFile(root, mdPath, withStandardsImport(current, posix.dirname(mdPath)), { managed: true }));
98
188
  plans.push(planFile(root, '.claude/agents/commit-writer.md', AGENT_STUB));
99
- plans.push(planFile(root, '.claude/skills/implement-ticket/SKILL.md', SKILL_STUB));
189
+ const skills = allSkills(root);
190
+ if (!skills.some((s) => s.source === SKILLS_PACKAGE)) {
191
+ notes.push(`${SKILLS_PACKAGE} is not installed — \`hassan-devkit init --only config\` adds it to devDependencies; then \`pnpm install\` writes the skill stubs`);
192
+ }
193
+ // Derived on every install: managed, so a bumped description flows without --force.
194
+ for (const skill of skills) plans.push(planFile(root, stubPath(skill.name), skillStub(skill), { managed: true }));
195
+ const gitignoreFile = join(root, GITIGNORE_FILE);
196
+ const gitignore = existsSync(gitignoreFile) ? readFileSync(gitignoreFile, 'utf8') : '';
197
+ plans.push(planFile(root, GITIGNORE_FILE, withSkillStubsIgnored(gitignore, skills.map((s) => s.name)), { managed: true }));
100
198
  const settingsFile = join(root, '.claude/settings.json');
101
199
  let settings = {};
102
200
  if (existsSync(settingsFile)) {
@@ -110,4 +208,4 @@ export function claudePlans(root) {
110
208
  return plans;
111
209
  }
112
210
 
113
- export { AGENT_STUB, SKILL_STUB };
211
+ export { AGENT_STUB };
@@ -36,6 +36,21 @@ export function upsertTrailingBlock(text, markerPrefix, block) {
36
36
  return `${head ? `${head}\n\n` : ''}${block.replace(/\s+$/, '')}\n`;
37
37
  }
38
38
 
39
+ /**
40
+ * Replace the lines between `begin` and `end` (both exact lines, kept) with `bodyLines`;
41
+ * append the whole block at the end when the markers are absent. Unlike the trailing block,
42
+ * text after the block survives — for files the project also edits by hand (`.gitignore`).
43
+ */
44
+ export function upsertMarkedBlock(text, begin, end, bodyLines) {
45
+ const block = [begin, ...bodyLines, end];
46
+ const lines = (text ?? '').split('\n');
47
+ const from = lines.indexOf(begin);
48
+ const to = lines.indexOf(end, from + 1);
49
+ if (from !== -1 && to !== -1) return [...lines.slice(0, from), ...block, ...lines.slice(to + 1)].join('\n');
50
+ const head = (text ?? '').replace(/\s+$/, '');
51
+ return `${head ? `${head}\n\n` : ''}${block.join('\n')}\n`;
52
+ }
53
+
39
54
  /** Minimal line diff (LCS) rendered as unified-ish `-`/`+` lines. */
40
55
  export function lineDiff(before, after) {
41
56
  const a = before.split('\n');
@@ -303,8 +303,10 @@ export function pruneImages(ctx) {
303
303
  .filter(Boolean);
304
304
  const targets = unreferencedImages(stack.listImages(), { repos: ownedImageRepos(ctx.compose), referencedTags, inUse: stack.imagesInUse() });
305
305
  for (const img of targets) {
306
+ // Two checkouts pruning at once race for the same tag: whoever finds it gone stays quiet.
307
+ if (!stack.imageExists(img)) continue;
306
308
  if (stack.removeImage(img)) ctx.log(`removed unreferenced dev image ${img}`);
307
- else ctx.note(`could not remove unreferenced dev image ${img}`);
309
+ else if (stack.imageExists(img)) ctx.note(`could not remove unreferenced dev image ${img}`);
308
310
  }
309
311
  }
310
312