@coding-with-hassan/devkit 1.0.0 → 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 +3 -1
- package/claude/skills/implement-ticket/SKILL.md +5 -0
- package/package.json +1 -1
- package/src/commands/claude.js +24 -5
- package/src/commands/init.js +13 -6
- package/src/core/claude.js +114 -16
- package/src/core/scaffold.js +15 -0
package/README.md
CHANGED
|
@@ -155,7 +155,8 @@ Every project with an ESLint/Prettier config gets `pnpm -C <dir> exec …` entri
|
|
|
155
155
|
`hassan-devkit claude:install` (run by `prepare` and by `init`) wires the house standards into Claude Code without copying content:
|
|
156
156
|
|
|
157
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;
|
|
158
|
-
- `.claude/agents/commit-writer.md`
|
|
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;
|
|
159
160
|
- the PR-assignee `PreToolUse` deny hook merged idempotently into `.claude/settings.json`.
|
|
160
161
|
|
|
161
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.
|
|
@@ -179,6 +180,7 @@ import { tc, type Area, type KnownIssue, type Readme } from '@coding-with-hassan
|
|
|
179
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.
|
|
180
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`).
|
|
181
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).
|
|
182
184
|
- Adopt piece by piece with `init --only <part>`; `ci:doctor` reports what is not adopted yet.
|
|
183
185
|
|
|
184
186
|
## Layout-agnostic commands
|
|
@@ -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.
|
|
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",
|
package/src/commands/claude.js
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { existsSync } from 'node:fs';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { loadConfig } from '../core/config.js';
|
|
4
|
-
import { claudePlans } from '../core/claude.js';
|
|
5
|
+
import { claudePlans, stubPath } from '../core/claude.js';
|
|
5
6
|
import { applyPlan } from '../core/scaffold.js';
|
|
6
7
|
import { exitOnFailure } from '../util/run.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* `claude:install` — wire the Claude Code layer into this repo: the `@import` of the shipped
|
|
10
|
-
* standards in CLAUDE.md, the agent
|
|
11
|
-
* `
|
|
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`.
|
|
12
14
|
*/
|
|
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
|
+
}
|
|
13
27
|
export async function installClaude({ cwd = process.cwd(), env = process.env, log = console.log, dryRun = false } = {}) {
|
|
14
28
|
const { root } = loadConfig({ cwd });
|
|
15
29
|
// Like hooks:install, this runs from `prepare` inside container image builds too (no .git,
|
|
@@ -18,7 +32,12 @@ export async function installClaude({ cwd = process.cwd(), env = process.env, lo
|
|
|
18
32
|
log('claude layer: no git checkout here (container build or export) — skipping');
|
|
19
33
|
return null;
|
|
20
34
|
}
|
|
21
|
-
const
|
|
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}`);
|
|
22
41
|
const touched = summary.created.length + summary.updated.length;
|
|
23
42
|
log(touched ? `claude layer: ${touched} file(s) written` : 'claude layer: up to date');
|
|
24
43
|
return summary;
|
|
@@ -26,7 +45,7 @@ export async function installClaude({ cwd = process.cwd(), env = process.env, lo
|
|
|
26
45
|
|
|
27
46
|
export function registerClaude(cli) {
|
|
28
47
|
cli
|
|
29
|
-
.command('claude:install', 'Wire the Claude Code layer (standards import, agent
|
|
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')
|
|
30
49
|
.option('--dry-run', 'Show what would change without writing')
|
|
31
50
|
.action((opts) => exitOnFailure(installClaude({ dryRun: Boolean(opts.dryRun) })));
|
|
32
51
|
}
|
package/src/commands/init.js
CHANGED
|
@@ -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
|
|
89
|
-
* Docker scripts only make sense with a compose file, the
|
|
90
|
-
* with husky as a dependency — a repo without them (this devkit
|
|
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
|
|
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
|
|
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 - ')}`);
|
package/src/core/claude.js
CHANGED
|
@@ -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 {
|
|
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
|
-
/**
|
|
93
|
-
|
|
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
|
-
|
|
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
|
|
211
|
+
export { AGENT_STUB };
|
package/src/core/scaffold.js
CHANGED
|
@@ -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');
|