create-jigo 0.0.0 → 1.15.18

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mapringg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/cli.mjs ADDED
@@ -0,0 +1,326 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { basename, dirname, join, resolve } from "node:path";
6
+ import { stdin, stdout } from "node:process";
7
+ import { createInterface } from "node:readline/promises";
8
+ import { parseArgs } from "node:util";
9
+
10
+ import { command, github, githubRepo } from "./github.mjs";
11
+ import { configure } from "./setup.mjs";
12
+
13
+ const TEMPLATE = "mapringg/monorepo";
14
+ const SETUP_BRANCH = "mapring/setup-jigo-";
15
+ const SETUP_TITLE = "Set up jigo";
16
+ const LOCAL_STATE = "mapring.creator";
17
+ const REPO_NAME = /^(?!\.{1,2}$)[a-z\d][a-z\d._-]{0,99}$/i;
18
+
19
+ const { values: flags } = parseArgs({
20
+ options: {
21
+ type: { type: "string" },
22
+ name: { type: "string" },
23
+ new: { type: "boolean" },
24
+ public: { type: "boolean" },
25
+ private: { type: "boolean" },
26
+ "no-wait": { type: "boolean" },
27
+ help: { type: "boolean", short: "h" },
28
+ },
29
+ });
30
+
31
+ const git = (cwd, args, options) => command(cwd, "git", args, options);
32
+ const gh = (cwd, args, options) => command(cwd, "gh", args, options);
33
+ const print = console.log;
34
+
35
+ async function ask(question, fallback) {
36
+ if (!stdin.isTTY) {
37
+ if (fallback) return fallback;
38
+ throw new Error(`Supply ${question} as a command-line option (see --help).`);
39
+ }
40
+ const prompt = createInterface({ input: stdin, output: stdout });
41
+ try {
42
+ return (await prompt.question(`${question}${fallback ? ` [${fallback}]` : ""} `)).trim() || fallback;
43
+ } finally {
44
+ prompt.close();
45
+ }
46
+ }
47
+
48
+ function stateAt(root) {
49
+ const state = git(root, ["config", "--local", "--get", LOCAL_STATE], { allowFailure: true });
50
+ return state.ok ? JSON.parse(state.output) : null;
51
+ }
52
+
53
+ function saveState(root, state) {
54
+ git(root, ["config", "--local", LOCAL_STATE, JSON.stringify(state)]);
55
+ }
56
+
57
+ function hasCommit(root) {
58
+ return git(root, ["rev-parse", "--verify", "HEAD"], { allowFailure: true }).ok;
59
+ }
60
+
61
+ function copyTemplate(root, scratch) {
62
+ const template = join(scratch, "template");
63
+ gh(root, ["repo", "clone", TEMPLATE, template, "--", "--depth=1", "--no-tags"], { stream: true });
64
+ const paths = git(template, ["ls-files", "-z"]).output.split("\0").filter(Boolean);
65
+ for (const path of paths) {
66
+ const to = join(root, path);
67
+ mkdirSync(dirname(to), { recursive: true });
68
+ cpSync(join(template, path), to, { dereference: false, verbatimSymlinks: true });
69
+ }
70
+ }
71
+
72
+ function checks(root, { updateLock, scripts }, initial) {
73
+ if (!existsSync(join(root, "package.json"))) return;
74
+ const runner = existsSync(join(root, "pnpm-lock.yaml"))
75
+ ? "pnpm"
76
+ : existsSync(join(root, "package-lock.json"))
77
+ ? "npm"
78
+ : null;
79
+ if (!runner) {
80
+ if (updateLock) throw new Error("Use pnpm or npm with a committed lockfile before adopting jigo.");
81
+ return;
82
+ }
83
+ if (updateLock) {
84
+ const args =
85
+ runner === "pnpm" ? ["install", "--lockfile-only", "--no-frozen-lockfile"] : ["install", "--package-lock-only"];
86
+ command(root, runner, args, { stream: true });
87
+ }
88
+ command(root, runner, runner === "pnpm" ? ["install", "--frozen-lockfile"] : ["ci"], { stream: true });
89
+ for (const script of ["lint", "format:check", "knip", ...(initial ? ["test"] : [])]) {
90
+ if (scripts.includes(script)) command(root, runner, ["run", script], { stream: true });
91
+ }
92
+ }
93
+
94
+ function configureProtection(host, base, check) {
95
+ if (host.requireCheck(base, check)) {
96
+ print(`GitHub requires ${check} on ${base}.`);
97
+ } else {
98
+ print(`GitHub Free cannot require ${check} on this private repo. Wait for a green check before merging.`);
99
+ }
100
+ }
101
+
102
+ function push(root, scratch, refs) {
103
+ const hooks = join(scratch, "empty-hooks");
104
+ mkdirSync(hooks, { recursive: true });
105
+ git(root, ["-c", `core.hooksPath=${hooks}`, "push", "-u", "origin", ...refs], { stream: true });
106
+ }
107
+
108
+ async function create(root, state, scratch) {
109
+ const host = github(root, state.repo);
110
+ let remote = host.lookup();
111
+ if (!hasCommit(root)) {
112
+ if (remote) throw new Error(`GitHub already has ${state.repo}. Use an existing checkout to adopt it.`);
113
+ if (!state.scaffolded) {
114
+ if (state.kind === "app") copyTemplate(root, scratch);
115
+ const readme = join(root, "README.md");
116
+ const title = `# ${basename(root)}`;
117
+ if (!existsSync(readme))
118
+ writeFileSync(
119
+ readme,
120
+ `${title}\n\nAdd a short project overview here.\n\n## Quick start\n\nAdd setup steps here.\n`,
121
+ );
122
+ else if (state.kind === "app")
123
+ writeFileSync(readme, readFileSync(readme, "utf8").replace(/^# monorepo\r?$/im, title));
124
+ saveState(root, { ...state, scaffolded: true });
125
+ }
126
+ const setup = configure(root, basename(root), { kind: state.kind, initial: true });
127
+ checks(root, setup, true);
128
+ git(root, ["add", "--all"]);
129
+ git(root, ["commit", "-m", "Initial commit"], { stream: true });
130
+ state.check = setup.check;
131
+ saveState(root, state);
132
+ }
133
+ const sha = git(root, ["rev-parse", "refs/heads/main"]).output;
134
+ if (!state.check) {
135
+ state.check = configure(root, basename(root), { kind: state.kind, initial: true }).check;
136
+ saveState(root, state);
137
+ }
138
+ if (!remote) {
139
+ gh(
140
+ root,
141
+ ["repo", "create", state.repo, state.visibility === "public" ? "--public" : "--private", "--source", root],
142
+ { stream: true },
143
+ );
144
+ remote = host.lookup();
145
+ }
146
+ if (!remote?.permissions?.admin) throw new Error(`Admin access is required for ${state.repo}.`);
147
+ if (remote.visibility !== state.visibility)
148
+ throw new Error(`Visibility differs for ${state.repo}. Review the existing GitHub repo.`);
149
+ if (!git(root, ["config", "--get", "remote.origin.url"], { allowFailure: true }).ok) {
150
+ git(root, ["remote", "add", "origin", remote.clone_url]);
151
+ }
152
+ if (
153
+ githubRepo(git(root, ["config", "--get", "remote.origin.url"]).output).toLowerCase() !== state.repo.toLowerCase()
154
+ ) {
155
+ throw new Error("The local origin points to a different repository.");
156
+ }
157
+ const refs = git(root, ["ls-remote", "--heads", "origin"]).output;
158
+ const current = refs
159
+ .split("\n")
160
+ .find((line) => line.endsWith("\trefs/heads/main"))
161
+ ?.split("\t")[0];
162
+ if (current && current !== sha)
163
+ throw new Error("GitHub main already has different content. Rerun from a checkout of that branch to adopt it.");
164
+ if (!current && refs) throw new Error("GitHub already has another branch. Use an existing checkout to adopt it.");
165
+ host.configureMerge(remote);
166
+ if (!current) push(root, scratch, ["main"]);
167
+ configureProtection(host, "main", state.check);
168
+ if (!flags["no-wait"]) await host.waitForCheck(sha, state.check);
169
+ git(root, ["config", "--local", "--unset", LOCAL_STATE]);
170
+ print(`${remote.html_url}\n${root}`);
171
+ }
172
+
173
+ function existingSource(root) {
174
+ const url = git(root, ["config", "--get", "remote.origin.url"]).output;
175
+ if (!url) throw new Error("Set a GitHub origin before adopting this repository.");
176
+ return { url, repo: githubRepo(url) };
177
+ }
178
+
179
+ function setupBody(check, local) {
180
+ return `## Summary
181
+
182
+ \`\`\`text
183
+ Repository
184
+ core: pr and capture skills, ${check}
185
+ typescript: when package.json exists
186
+ Squash merge
187
+ \`\`\`
188
+
189
+ ## Evidence
190
+
191
+ - **Before:** The repository was missing part of the jigo setup.
192
+ - **After:** The setup diff aligns the skill links and PR check. ${local}
193
+
194
+ ## Merge Danger
195
+
196
+ **Door:** two-way
197
+
198
+ **Blast Radius:** repository
199
+ `;
200
+ }
201
+
202
+ async function adopt(root, kind, scratch) {
203
+ const { url, repo } = existingSource(root);
204
+ const host = github(root, repo);
205
+ const remote = host.lookup();
206
+ if (!remote?.permissions?.admin) throw new Error(`Admin access is required for ${repo}.`);
207
+ const base = remote.default_branch;
208
+ const work = join(scratch, "checkout");
209
+ git(root, ["clone", "--single-branch", "--no-tags", "--branch", base, url, work], { stream: true });
210
+ const baseSha = git(work, ["rev-parse", "HEAD"]).output;
211
+ const branch = `${SETUP_BRANCH}${baseSha.slice(0, 12)}`;
212
+ const setup = configure(work, remote.name, { kind });
213
+ const { check } = setup;
214
+ const modified = git(work, ["status", "--porcelain"]).output;
215
+ host.configureMerge(remote);
216
+ if (!modified) {
217
+ configureProtection(host, base, check);
218
+ print(`Already aligned.\n${remote.html_url}\n${root}`);
219
+ return;
220
+ }
221
+ const open = host.pulls(base).find((pull) => !pull.isCrossRepository && pull.headRefName.startsWith(SETUP_BRANCH));
222
+ if (open) {
223
+ print(`Setup PR: ${open.url}`);
224
+ if (!flags["no-wait"]) await host.waitForCheck(open.headRefOid, check);
225
+ configureProtection(host, base, check);
226
+ return;
227
+ }
228
+ checks(work, setup, false);
229
+ git(work, ["add", "--update"]);
230
+ for (const file of [
231
+ "AGENTS.md",
232
+ ".oxlintrc.json",
233
+ ".claude/settings.json",
234
+ ".codex/hooks.json",
235
+ ".gitignore",
236
+ "mise.toml",
237
+ ".mise.toml",
238
+ "package.json",
239
+ "pnpm-lock.yaml",
240
+ "pnpm-workspace.yaml",
241
+ "package-lock.json",
242
+ ".github/workflows",
243
+ ".github/dependabot.yml",
244
+ ]) {
245
+ if (existsSync(join(work, file))) git(work, ["add", "--", file]);
246
+ }
247
+ const tree = git(work, ["write-tree"]).output;
248
+ const known = git(work, ["ls-remote", "--heads", "origin", `refs/heads/${branch}`]).output;
249
+ let head;
250
+ if (known) {
251
+ git(work, ["fetch", "origin", branch]);
252
+ head = git(work, ["rev-parse", "FETCH_HEAD"]).output;
253
+ const parents = git(work, ["show", "-s", "--format=%P", head]).output;
254
+ if (git(work, ["rev-parse", `${head}^{tree}`]).output !== tree || parents !== baseSha) {
255
+ throw new Error(`The existing setup branch ${branch} has different changes. Review it before rerunning.`);
256
+ }
257
+ } else {
258
+ git(work, ["switch", "-c", branch]);
259
+ git(work, ["commit", "-m", SETUP_TITLE], { stream: true });
260
+ head = git(work, ["rev-parse", "HEAD"]).output;
261
+ push(work, scratch, [branch]);
262
+ }
263
+ const evidence =
264
+ setup.scripts.length > 0
265
+ ? "Applicable local project checks passed."
266
+ : "The setup diff preserves the repository’s files and checks.";
267
+ const pr = host.createPull(base, branch, SETUP_TITLE, setupBody(check, evidence));
268
+ print(`Setup PR: ${pr}\n${root}`);
269
+ if (!flags["no-wait"]) await host.waitForCheck(head, check);
270
+ configureProtection(host, base, check);
271
+ }
272
+
273
+ async function main() {
274
+ if (flags.help) {
275
+ print(
276
+ "Usage: create-jigo [--type app|plain] [--new --name NAME] [--public|--private] [--no-wait]\n\nRun in an existing GitHub checkout to adopt it, or outside Git to create a repo.\nAdoption adds the core checks everywhere and the TypeScript layer when package.json exists.\n--type picks the template for a new repo: app for the monorepo, plain for an empty one.",
277
+ );
278
+ return;
279
+ }
280
+ if (flags.public && flags.private) throw new Error("Choose one visibility.");
281
+ const cwd = resolve(".");
282
+ const located = git(cwd, ["rev-parse", "--show-toplevel"], { allowFailure: true });
283
+ let root = located.ok && !flags.new && !flags.name ? located.output : null;
284
+ let state = root ? stateAt(root) : null;
285
+ if (!root) {
286
+ const name = flags.name ?? (await ask("Repository name"));
287
+ if (!name || !REPO_NAME.test(name))
288
+ throw new Error("Use a GitHub repository name with letters, numbers, periods, underscores, or hyphens.");
289
+ root = join(cwd, name);
290
+ if (existsSync(root) && readdirSync(root).length > 0) {
291
+ const child = git(root, ["rev-parse", "--show-toplevel"], { allowFailure: true });
292
+ if (!child.ok || child.output !== root)
293
+ throw new Error(`${root} already exists and is not an initialized setup folder.`);
294
+ state = stateAt(root);
295
+ } else {
296
+ const kind = flags.type ?? (await ask("App or plain?", "plain"));
297
+ if (!["app", "plain"].includes(kind)) throw new Error("Choose app or plain.");
298
+ const visibility = flags.public
299
+ ? "public"
300
+ : flags.private
301
+ ? "private"
302
+ : await ask("Private or public?", "private");
303
+ if (!["private", "public"].includes(visibility)) throw new Error("Choose private or public.");
304
+ const owner = gh(cwd, ["api", "user", "--jq", ".login"]).output;
305
+ mkdirSync(root, { recursive: true });
306
+ git(root, ["init", "-b", "main"], { stream: true });
307
+ state = { repo: `${owner}/${name}`, kind, visibility };
308
+ saveState(root, state);
309
+ }
310
+ }
311
+ const kind = state?.kind ?? (existsSync(join(root, "package.json")) ? "app" : "plain");
312
+ const scratch = mkdtempSync(join(tmpdir(), "create-jigo-"));
313
+ try {
314
+ if (state) await create(root, state, scratch);
315
+ else await adopt(root, kind, scratch);
316
+ } finally {
317
+ rmSync(scratch, { recursive: true, force: true });
318
+ }
319
+ }
320
+
321
+ try {
322
+ await main();
323
+ } catch (error) {
324
+ console.error(error.message);
325
+ process.exitCode = 1;
326
+ }
package/files.mjs ADDED
@@ -0,0 +1,14 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+
4
+ export const YAML = { flowCollectionPadding: false, lineWidth: 0 };
5
+
6
+ export function read(path) {
7
+ return existsSync(path) ? readFileSync(path, "utf8") : null;
8
+ }
9
+
10
+ export function write(path, text) {
11
+ if (read(path) === text) return;
12
+ mkdirSync(dirname(path), { recursive: true });
13
+ writeFileSync(path, text);
14
+ }
package/github.mjs ADDED
@@ -0,0 +1,128 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { setTimeout } from "node:timers/promises";
3
+
4
+ export function command(cwd, bin, args, options = {}) {
5
+ const result = spawnSync(bin, args, {
6
+ cwd,
7
+ encoding: "utf8",
8
+ stdio: options.stream ? "inherit" : ["pipe", "pipe", "pipe"],
9
+ input: options.input,
10
+ maxBuffer: 8 * 1024 * 1024,
11
+ });
12
+ if (result.error) throw result.error;
13
+ if (result.status !== 0 && !options.allowFailure) {
14
+ throw new Error(`${bin} ${args[0]} failed${result.stderr?.trim() ? `: ${result.stderr.trim()}` : "."}`);
15
+ }
16
+ return { ok: result.status === 0, output: result.stdout?.trim() ?? "", error: result.stderr?.trim() ?? "" };
17
+ }
18
+
19
+ export function github(cwd, repo) {
20
+ const endpoint = `repos/${repo}`;
21
+ const api = (path, method = "GET", body) => {
22
+ const args = ["api", "--method", method, path];
23
+ if (body !== undefined) args.push("--input", "-");
24
+ const result = command(cwd, "gh", args, { input: JSON.stringify(body), allowFailure: true });
25
+ if (result.ok) return result.output ? JSON.parse(result.output) : null;
26
+ const status = /HTTP (\d{3})/.exec(result.error)?.[1];
27
+ const message = result.error.split("\n")[0];
28
+ throw Object.assign(new Error(message || "GitHub API request failed."), { status });
29
+ };
30
+
31
+ return {
32
+ lookup() {
33
+ try {
34
+ return api(endpoint);
35
+ } catch (error) {
36
+ if (error.status === "404") return null;
37
+ throw error;
38
+ }
39
+ },
40
+ configureMerge(current) {
41
+ const desired = {
42
+ allow_merge_commit: false,
43
+ allow_rebase_merge: false,
44
+ allow_squash_merge: true,
45
+ squash_merge_commit_title: "PR_TITLE",
46
+ squash_merge_commit_message: "BLANK",
47
+ };
48
+ if (Object.entries(desired).some(([key, value]) => current[key] !== value)) api(endpoint, "PATCH", desired);
49
+ },
50
+ requireCheck(base, check) {
51
+ const path = `${endpoint}/branches/${encodeURIComponent(base)}/protection`;
52
+ const required = { strict: false, contexts: [check] };
53
+ try {
54
+ let protection = null;
55
+ try {
56
+ protection = api(path);
57
+ } catch (error) {
58
+ if (error.status !== "404") throw error;
59
+ }
60
+ if (!protection) {
61
+ api(path, "PUT", {
62
+ required_status_checks: required,
63
+ enforce_admins: false,
64
+ required_pull_request_reviews: null,
65
+ restrictions: null,
66
+ });
67
+ } else if (!protection.required_status_checks) {
68
+ api(`${path}/required_status_checks`, "PATCH", required);
69
+ } else if (!protection.required_status_checks.contexts.includes(check)) {
70
+ api(`${path}/required_status_checks/contexts`, "POST", { contexts: [check] });
71
+ }
72
+ return true;
73
+ } catch (error) {
74
+ if (/upgrade to github pro|make this repository public/i.test(error.message)) return false;
75
+ throw error;
76
+ }
77
+ },
78
+ pulls(base) {
79
+ const args = [
80
+ "pr",
81
+ "list",
82
+ "--repo",
83
+ repo,
84
+ "--state",
85
+ "open",
86
+ "--base",
87
+ base,
88
+ "--limit",
89
+ "100",
90
+ "--json",
91
+ "number,url,headRefName,headRefOid,isCrossRepository",
92
+ ];
93
+ return JSON.parse(command(cwd, "gh", args).output);
94
+ },
95
+ createPull(base, branch, title, body) {
96
+ return command(
97
+ cwd,
98
+ "gh",
99
+ ["pr", "create", "--repo", repo, "--base", base, "--head", branch, "--title", title, "--body-file", "-"],
100
+ { input: body },
101
+ ).output;
102
+ },
103
+ async waitForCheck(sha, check) {
104
+ const deadline = Date.now() + 15 * 60_000;
105
+ while (Date.now() < deadline) {
106
+ const name = new URLSearchParams({ check_name: check, filter: "latest", per_page: "30" });
107
+ const entries = api(`${endpoint}/commits/${sha}/check-runs?${name}`).check_runs;
108
+ if (entries.length && entries.every((entry) => entry.status === "completed")) {
109
+ const failed = entries.find((entry) => entry.conclusion !== "success");
110
+ if (failed) throw new Error(`${check} finished with ${failed.conclusion}. ${failed.html_url}`);
111
+ console.log(`${check} passed.`);
112
+ return;
113
+ }
114
+ await setTimeout(5000);
115
+ }
116
+ throw new Error(`Timed out waiting for ${check}. Rerun setup to resume checking.`);
117
+ },
118
+ };
119
+ }
120
+
121
+ export function githubRepo(url) {
122
+ const match =
123
+ /^(?:https:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/i.exec(
124
+ url,
125
+ );
126
+ if (!match) throw new Error("Use a github.com origin.");
127
+ return `${match[1]}/${match[2]}`;
128
+ }
package/package.json CHANGED
@@ -1,7 +1,25 @@
1
1
  {
2
2
  "name": "create-jigo",
3
- "version": "0.0.0",
4
- "description": "Coming soon",
3
+ "version": "1.15.18",
4
+ "description": "Create or adopt a GitHub repository that uses jigo.",
5
5
  "license": "MIT",
6
- "repository": "github:mapringg/jigo"
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/mapringg/jigo.git",
9
+ "directory": "packages/create-jigo"
10
+ },
11
+ "bin": {
12
+ "create-jigo": "./cli.mjs"
13
+ },
14
+ "files": [
15
+ "*.mjs",
16
+ "LICENSE"
17
+ ],
18
+ "type": "module",
19
+ "dependencies": {
20
+ "yaml": "2.9.1"
21
+ },
22
+ "engines": {
23
+ "node": ">=26"
24
+ }
7
25
  }
package/release.mjs ADDED
@@ -0,0 +1,73 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+
5
+ const REMOTE = "https://github.com/mapringg/jigo";
6
+ const MANIFEST = join(import.meta.dirname, "..", "..", "package.json");
7
+ const SEMVER_TAG = /^v(\d+)\.(\d+)\.(\d+)$/;
8
+
9
+ let tags;
10
+ let tag;
11
+
12
+ function remoteTags() {
13
+ tags ??= new Map(
14
+ execFileSync("git", ["ls-remote", "--tags", REMOTE], { encoding: "utf8" })
15
+ .trim()
16
+ .split("\n")
17
+ .filter(Boolean)
18
+ .map((line) => {
19
+ const [sha, ref] = line.split("\t");
20
+ return [ref.replace("refs/tags/", ""), sha];
21
+ }),
22
+ );
23
+ return tags;
24
+ }
25
+
26
+ function bundled() {
27
+ if (!existsSync(MANIFEST)) return null;
28
+ const manifest = JSON.parse(readFileSync(MANIFEST, "utf8"));
29
+ return manifest.name === "@mapringg/jigo" ? manifest : null;
30
+ }
31
+
32
+ function bundledTag() {
33
+ const manifest = bundled();
34
+ return manifest ? `v${manifest.version}` : null;
35
+ }
36
+
37
+ function newestTag() {
38
+ const released = [...remoteTags().keys()].filter((name) => SEMVER_TAG.test(name));
39
+ if (released.length === 0) throw new Error(`No jigo release tags found at ${REMOTE}.`);
40
+ const parts = (name) => SEMVER_TAG.exec(name).slice(1).map(Number);
41
+ return released.toSorted((a, b) => {
42
+ const [x, y] = [parts(a), parts(b)];
43
+ return y[0] - x[0] || y[1] - x[1] || y[2] - x[2];
44
+ })[0];
45
+ }
46
+
47
+ export function releaseTag() {
48
+ tag ??= bundledTag() ?? newestTag();
49
+ return tag;
50
+ }
51
+
52
+ export function releaseSha() {
53
+ const name = releaseTag();
54
+ const sha = remoteTags().get(`${name}^{}`) ?? remoteTags().get(name);
55
+ if (!sha) throw new Error(`jigo ${name} is not tagged yet. Run a tagged release of the creator.`);
56
+ return sha;
57
+ }
58
+
59
+ export function releasePeers() {
60
+ const manifest = bundled();
61
+ if (manifest) return manifest.peerDependencies ?? {};
62
+ const raw = execFileSync(
63
+ "gh",
64
+ [
65
+ "api",
66
+ "-H",
67
+ "Accept: application/vnd.github.raw",
68
+ `repos/mapringg/jigo/contents/package.json?ref=${releaseTag()}`,
69
+ ],
70
+ { encoding: "utf8" },
71
+ );
72
+ return JSON.parse(raw).peerDependencies ?? {};
73
+ }
package/setup.mjs ADDED
@@ -0,0 +1,266 @@
1
+ import { existsSync, readdirSync, unlinkSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { Document, isMap, isSeq, parseDocument } from "yaml";
5
+
6
+ import { read, write, YAML } from "./files.mjs";
7
+ import { releaseSha, releaseTag } from "./release.mjs";
8
+ import { configureTypescript, PACKAGE } from "./typescript.mjs";
9
+
10
+ const GROUP = "mapringg-jigo";
11
+ const AUTOMERGE = join(".github", "workflows", "jigo-updates.yml");
12
+ const LEGACY_AUTOMERGE = join(".github", "workflows", "standard-updates.yml");
13
+ const ACTION = "mapringg/jigo/.github/actions/check-pr@";
14
+ const LEGACY_ACTION = "mapringg/standard/.github/actions/check-pr@";
15
+ const CHECKOUT = "actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0";
16
+ const LEAKS =
17
+ "git archive HEAD | docker run --rm -i --entrypoint sh ghcr.io/gitleaks/gitleaks:v8.30.1 -c 'mkdir /tmp/repo && tar -x -C /tmp/repo && gitleaks dir /tmp/repo --no-banner --redact'";
18
+ const WORKSPACE_LEAKS =
19
+ 'docker run --rm -v "$PWD:/repo" ghcr.io/gitleaks/gitleaks:v8.30.1 dir /repo --no-banner --redact';
20
+ const IGNORE = ".DS_Store\nnode_modules/\n*.local.toml\n";
21
+ const EVENTS = ["opened", "synchronize", "reopened", "edited"];
22
+ const SKILLS =
23
+ /@mapringg\/(?:standard|jigo)\/\.claude\/skills\/(?:pr|capture|test-audit|review-(?:standard|jigo)|upgrade-(?:standard|jigo))\/SKILL\.md|github\.com\/mapringg\/(?:standard|jigo)\/blob\/[^/]+\/\.claude\/skills\/(?:pr|capture)\/SKILL\.md/;
24
+ const DEPENDABOT_MIGRATIONS = [
25
+ ["mapringg-standard", GROUP],
26
+ ["mapringg/standard*", "mapringg/jigo*"],
27
+ ["@mapringg/standard", PACKAGE],
28
+ ];
29
+
30
+ const usesAction = (step) => step.uses?.startsWith(ACTION) || step.uses?.startsWith(LEGACY_ACTION);
31
+
32
+ function agents(root, installed) {
33
+ const path = join(root, "AGENTS.md");
34
+ const skillsRoot = installed
35
+ ? `node_modules/${PACKAGE}/.claude/skills`
36
+ : "https://github.com/mapringg/jigo/blob/main/.claude/skills";
37
+ const original = read(path) ?? "# AGENTS.md\n";
38
+ const shared = original.split("\n").filter((line) => SKILLS.test(line));
39
+ if (
40
+ shared.length === 2 &&
41
+ ["pr", "capture"].every((skill) =>
42
+ shared.some((line) => line.includes(`[${skill}](${skillsRoot}/${skill}/SKILL.md)`)),
43
+ )
44
+ )
45
+ return;
46
+ const lines = original
47
+ .trimEnd()
48
+ .split("\n")
49
+ .filter((line) => !(/^\s*[-*] /.test(line) && SKILLS.test(line)));
50
+ const links = [
51
+ `- Use the [pr](${skillsRoot}/pr/SKILL.md) skill when writing a pull request.`,
52
+ `- Use the [capture](${skillsRoot}/capture/SKILL.md) skill when preparing pull request evidence.`,
53
+ ];
54
+ const sources = lines.indexOf("## Sources");
55
+ if (sources === -1) {
56
+ lines.push("", "## Sources", "", ...links);
57
+ } else {
58
+ let start = sources + 1;
59
+ while (lines[start] === "") start += 1;
60
+ lines.splice(sources + 1, start - sources - 1, "", ...links);
61
+ if (lines[sources + 4]?.startsWith("#")) lines.splice(sources + 4, 0, "");
62
+ }
63
+ write(path, `${lines.join("\n").trimEnd()}\n`);
64
+ }
65
+
66
+ function workflowFiles(root) {
67
+ const dir = join(root, ".github", "workflows");
68
+ if (!existsSync(dir)) return [];
69
+ return readdirSync(dir)
70
+ .filter((name) => /\.ya?ml$/.test(name))
71
+ .map((name) => {
72
+ const path = join(dir, name);
73
+ const doc = parseDocument(read(path));
74
+ if (doc.errors.length > 0) throw new Error(`Fix invalid workflow YAML in ${name} before adopting jigo.`);
75
+ return { path, name, doc, data: doc.toJS() ?? {} };
76
+ });
77
+ }
78
+
79
+ function hasPr(on) {
80
+ if (typeof on === "string") return on === "pull_request";
81
+ if (Array.isArray(on)) return on.includes("pull_request");
82
+ return Boolean(on && Object.hasOwn(on, "pull_request"));
83
+ }
84
+
85
+ function enablePrEdits(doc) {
86
+ const on = doc.get("on", true);
87
+ if (!isMap(on)) {
88
+ const values = isSeq(on) ? on.items.map((item) => item.value) : on?.value ? [on.value] : [];
89
+ doc.set("on", doc.createNode(Object.fromEntries(values.map((event) => [event, null]))));
90
+ }
91
+ const path = ["on", "pull_request"];
92
+ const existing = doc.getIn(path, true);
93
+ if (!isMap(existing)) doc.setIn(path, doc.createNode({}));
94
+ const types = doc.getIn([...path, "types"], true);
95
+ const events = isSeq(types) ? types.items.map((item) => item.value) : [];
96
+ if (EVENTS.some((event) => !events.includes(event))) {
97
+ const list = doc.createNode([...new Set([...events, ...EVENTS])]);
98
+ list.flow = !isSeq(types) || types.flow;
99
+ doc.setIn([...path, "types"], list);
100
+ }
101
+ }
102
+
103
+ function withLeakScan(text, id) {
104
+ const steps = parseDocument(text).getIn(["jobs", id, "steps"], true);
105
+ const checkout = steps.items.findIndex((item) => String(item.get?.("uses") ?? "").startsWith("actions/checkout@"));
106
+ const first = steps.items[0].range[0];
107
+ const lineStart = text.lastIndexOf("\n", first - 1) + 1;
108
+ const pad = " ".repeat(first - lineStart - 2);
109
+ const step = `${pad}- name: Scan for leaks\n${pad} run: ${LEAKS}\n`;
110
+ const at = checkout === -1 ? lineStart : steps.items[checkout].range[2];
111
+ const head = text.slice(0, at);
112
+ return `${head}${head.endsWith("\n") ? "" : "\n"}${step}${text.slice(at)}`;
113
+ }
114
+
115
+ function configureCheck(root, installed) {
116
+ const jobs = workflowFiles(root).flatMap((workflow) =>
117
+ Object.entries(workflow.data.jobs ?? {}).map(([id, job]) => ({ ...workflow, id, job })),
118
+ );
119
+ const candidates = jobs.filter(({ job }) => Array.isArray(job.steps));
120
+ const shared = candidates.find(({ job }) => job.steps.some(usesAction));
121
+ const lint =
122
+ installed &&
123
+ read(join(root, ".oxlintrc.json"))?.includes(`${PACKAGE}/`) &&
124
+ candidates.find(
125
+ ({ job, data }) =>
126
+ hasPr(data.on) &&
127
+ job.steps.some((s) => /(?:\bpnpm\s+(?:run\s+)?lint\b|\.githooks\/pre-push)/.test(s.run ?? "")),
128
+ );
129
+ const check = shared || lint;
130
+ if (check) {
131
+ const { doc, path, id, job } = check;
132
+ const before = doc.toString(YAML);
133
+ enablePrEdits(doc);
134
+ const actionIndex = job.steps.findIndex(usesAction);
135
+ if (
136
+ actionIndex !== -1 &&
137
+ job.steps[actionIndex].uses !== `${ACTION}${releaseTag()}` &&
138
+ job.steps[actionIndex].uses !== `${ACTION}${releaseSha()}`
139
+ ) {
140
+ const uses = doc.getIn(["jobs", id, "steps", actionIndex, "uses"], true);
141
+ uses.value = `${ACTION}${releaseSha()}`;
142
+ uses.comment = ` ${releaseTag()}`;
143
+ }
144
+ const ci = join(root, ".github", "workflows", "ci.yml");
145
+ const rename =
146
+ ["standard-pr.yml", "jigo-pr.yml"].includes(check.name) &&
147
+ ["Standard", "jigo"].includes(check.data.name) &&
148
+ !existsSync(ci);
149
+ if (rename) doc.set("name", "CI");
150
+ let text = doc.toString(YAML) === before ? read(path) : doc.toString(YAML);
151
+ text = text.replaceAll(`run: ${WORKSPACE_LEAKS}\n`, `run: ${LEAKS}\n`);
152
+ if (!job.steps.some((s) => s.run?.includes("gitleaks"))) text = withLeakScan(text, id);
153
+ write(rename ? ci : path, text);
154
+ if (rename) unlinkSync(path);
155
+ return {
156
+ name: job.name ?? id,
157
+ workflow: rename ? "CI" : (check.data.name ?? `.github/workflows/${check.name}`),
158
+ };
159
+ }
160
+ const name = jobs.some(({ id, job }) => (job.name ?? id).toLowerCase() === "check") ? "jigo PR" : "Check";
161
+ const ci = join(root, ".github", "workflows", "ci.yml");
162
+ const workflow = existsSync(ci) ? "jigo" : "CI";
163
+ const path = existsSync(ci) ? join(root, ".github", "workflows", "jigo-pr.yml") : ci;
164
+ if (existsSync(path)) throw new Error("Resolve the existing jigo-pr.yml before adopting jigo.");
165
+ write(
166
+ path,
167
+ `name: ${workflow}\n\non:\n pull_request:\n types: [${EVENTS.join(", ")}]\n push:\n branches: [main, develop]\n\npermissions:\n contents: read\n\njobs:\n check:\n name: ${name}\n runs-on: ubuntu-latest\n steps:\n - uses: ${CHECKOUT}\n with:\n fetch-depth: 0\n persist-credentials: false\n - name: Scan for leaks\n run: ${LEAKS}\n - run: test -s AGENTS.md\n - uses: ${ACTION}${releaseSha()} # ${releaseTag()}\n`,
168
+ );
169
+ return { name, workflow };
170
+ }
171
+
172
+ function updateEntry(ecosystem, pattern) {
173
+ return {
174
+ "package-ecosystem": ecosystem,
175
+ directory: "/",
176
+ schedule: { interval: "weekly" },
177
+ cooldown: { "default-days": 1 },
178
+ allow: [{ "dependency-name": pattern }],
179
+ groups: { [GROUP]: { patterns: [pattern] } },
180
+ };
181
+ }
182
+
183
+ function dependabot(root, installed) {
184
+ const path = join(root, ".github", "dependabot.yml");
185
+ const original = read(path);
186
+ const text = original && DEPENDABOT_MIGRATIONS.reduce((next, [from, to]) => next.replaceAll(from, to), original);
187
+ const doc = text === null ? new Document({ version: 2, updates: [] }) : parseDocument(text);
188
+ if (doc.errors.length > 0) throw new Error("Fix invalid YAML in dependabot.yml before adopting jigo.");
189
+ const before = text === original ? doc.toString(YAML) : null;
190
+ const wanted = [["github-actions", "mapringg/jigo*"], ...(installed ? [["npm", PACKAGE]] : [])];
191
+ const updates = doc.get("updates", true);
192
+ for (const [ecosystem, pattern] of wanted) {
193
+ const index = (updates?.items ?? []).findIndex((item) => {
194
+ const entry = item.toJSON();
195
+ const directories = entry.directories ?? [entry.directory];
196
+ return entry["package-ecosystem"] === ecosystem && directories.includes("/");
197
+ });
198
+ if (index === -1) {
199
+ doc.addIn(["updates"], doc.createNode(updateEntry(ecosystem, pattern)));
200
+ continue;
201
+ }
202
+ const groups = doc.getIn(["updates", index, "groups"], true);
203
+ if (isMap(groups) && groups.has(GROUP)) continue;
204
+ const rest = isMap(groups) ? groups.items : [];
205
+ const group = doc.createNode({ [GROUP]: { patterns: [pattern] } });
206
+ group.items.push(...rest);
207
+ doc.setIn(["updates", index, "groups"], group);
208
+ }
209
+ for (const index of doc.get("updates", true).items.keys()) {
210
+ if (doc.getIn(["updates", index, "schedule", "interval"]) !== "weekly") {
211
+ doc.setIn(["updates", index, "schedule", "interval"], "weekly");
212
+ doc.deleteIn(["updates", index, "schedule", "day"]);
213
+ }
214
+ if (!doc.hasIn(["updates", index, "cooldown"])) doc.setIn(["updates", index, "cooldown"], { "default-days": 1 });
215
+ }
216
+ if (doc.toString(YAML) !== before) write(path, doc.toString(YAML));
217
+ }
218
+
219
+ function automerge(root, workflow) {
220
+ if (existsSync(join(root, LEGACY_AUTOMERGE))) unlinkSync(join(root, LEGACY_AUTOMERGE));
221
+ write(
222
+ join(root, AUTOMERGE),
223
+ `name: jigo updates\n\non:\n workflow_run:\n workflows: [${JSON.stringify(workflow)}]\n types: [completed]\n\npermissions:\n contents: write\n pull-requests: write\n\njobs:\n merge:\n if: >-\n github.event.workflow_run.conclusion == 'success' &&\n github.event.workflow_run.event == 'pull_request' &&\n github.event.workflow_run.actor.login == 'dependabot[bot]' &&\n contains(github.event.workflow_run.head_branch, '${GROUP}')\n runs-on: ubuntu-latest\n steps:\n - env:\n GH_TOKEN: \${{ github.token }}\n BRANCH: \${{ github.event.workflow_run.head_branch }}\n SHA: \${{ github.event.workflow_run.head_sha }}\n run: gh pr merge "$BRANCH" --repo "$GITHUB_REPOSITORY" --squash --match-head-commit "$SHA"\n`,
224
+ );
225
+ }
226
+
227
+ function pinBrowser(root) {
228
+ const canonical = join(root, "mise.toml");
229
+ const alternate = join(root, ".mise.toml");
230
+ const path = existsSync(alternate) && !existsSync(canonical) ? alternate : canonical;
231
+ const contents = read(path) ?? "";
232
+ if (contents.includes("agent-browser")) return;
233
+ const tool = '"npm:agent-browser" = "0.43.0"\n';
234
+ const tools = /^\[tools\][ \t]*\n/m;
235
+ write(
236
+ path,
237
+ tools.test(contents)
238
+ ? contents.replace(tools, `$&${tool}`)
239
+ : `${contents ? `${contents.trimEnd()}\n\n` : ""}[tools]\n${tool}`,
240
+ );
241
+ }
242
+
243
+ export function configure(root, name, { kind = "plain", initial = false } = {}) {
244
+ const isNewApp = kind === "app" && initial;
245
+ const path = join(root, "package.json");
246
+ if (isNewApp) {
247
+ const original = read(path);
248
+ if (original)
249
+ write(path, original.replace(/"name":\s*"monorepo"/, `"name": ${JSON.stringify(name.toLowerCase())}`));
250
+ const deploy = join(root, ".github", "workflows", "deploy-production.yml");
251
+ const contents = read(deploy);
252
+ if (contents) {
253
+ const doc = parseDocument(contents);
254
+ doc.set("on", "workflow_dispatch");
255
+ write(deploy, doc.toString(YAML));
256
+ }
257
+ }
258
+ const typescript = existsSync(path) ? configureTypescript(root) : null;
259
+ if (kind === "app") pinBrowser(root);
260
+ if (!existsSync(join(root, ".gitignore"))) write(join(root, ".gitignore"), IGNORE);
261
+ agents(root, Boolean(typescript));
262
+ const check = configureCheck(root, Boolean(typescript));
263
+ dependabot(root, Boolean(typescript));
264
+ automerge(root, check.workflow);
265
+ return { check: check.name, updateLock: typescript?.updateLock ?? false, scripts: typescript?.scripts ?? [] };
266
+ }
package/typescript.mjs ADDED
@@ -0,0 +1,130 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { Document, isSeq, parseDocument } from "yaml";
5
+
6
+ import { read, write, YAML } from "./files.mjs";
7
+ import { releasePeers, releaseTag } from "./release.mjs";
8
+
9
+ export const PACKAGE = "@mapringg/jigo";
10
+ const CONFIGS = "node_modules/@mapringg/jigo/typescript";
11
+ const RULES = "jigo rules";
12
+ const SCRIPTS = {
13
+ lint: "oxlint",
14
+ format: `oxfmt -c ${CONFIGS}/oxfmt.json`,
15
+ "format:check": `oxfmt -c ${CONFIGS}/oxfmt.json --check`,
16
+ knip: `knip -c ${CONFIGS}/knip.json && knip -c ${CONFIGS}/knip.json --production`,
17
+ };
18
+ const OXLINTRC = `{ "extends": ["./${CONFIGS}/oxlint.json"] }\n`;
19
+ const MIGRATIONS = [
20
+ [/node_modules\/@mapringg\/standard\/(oxlint|oxfmt|knip)\.json/g, `${CONFIGS}/$1.json`],
21
+ [/\bstandard-rules\b/g, RULES],
22
+ [/"standard\//g, '"jigo/'],
23
+ [/@mapringg\/standard\b/g, PACKAGE],
24
+ ];
25
+ const MIGRATED = /^(?:package\.json|\.oxlintrc\.json|tsconfig[\w.-]*\.json|pnpm-workspace\.yaml|AGENTS\.md)$/;
26
+ const HOOK =
27
+ 'sh -c \'for d in "$(git rev-parse --show-toplevel 2>/dev/null)" "$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)/.."; do [ -x "$d/node_modules/.bin/jigo" ] && exec "$d/node_modules/.bin/jigo" ratchet "$@"; done; cat >/dev/null; [ "$1" = SessionStart ] && echo "{\\"systemMessage\\":\\"Agent guardrails are off until pnpm install runs.\\"}"; exit 0\' jigo-ratchet';
28
+ const WRITES = "Edit|MultiEdit|NotebookEdit|Write";
29
+ const HOOKS = {
30
+ claude: [
31
+ ["SessionStart", undefined, 10],
32
+ ["PreToolUse", "Bash", 10],
33
+ ["PreToolUse", WRITES, 10],
34
+ ["PostToolUse", "Bash", 10],
35
+ ["PostToolUseFailure", "Bash", 10],
36
+ ["Stop", undefined, 30],
37
+ ],
38
+ codex: [
39
+ ["SessionStart", undefined, 10],
40
+ ["PreToolUse", "Bash", 10],
41
+ ["PreToolUse", `${WRITES}|apply_patch`, 10],
42
+ ["PostToolUse", "Bash", 10],
43
+ ["Stop", undefined, 30],
44
+ ],
45
+ };
46
+
47
+ function migrate(root, dir = "") {
48
+ for (const entry of readdirSync(join(root, dir), { withFileTypes: true })) {
49
+ if (entry.name === "node_modules" || entry.name === ".git") continue;
50
+ const rel = dir ? `${dir}/${entry.name}` : entry.name;
51
+ if (entry.isDirectory()) migrate(root, rel);
52
+ else if (MIGRATED.test(entry.name)) {
53
+ const path = join(root, rel);
54
+ const text = read(path);
55
+ write(
56
+ path,
57
+ MIGRATIONS.reduce((next, [from, to]) => next.replace(from, to), text),
58
+ );
59
+ }
60
+ }
61
+ }
62
+
63
+ function install(root, manifest, text) {
64
+ const current = manifest.devDependencies?.[PACKAGE] ?? manifest.dependencies?.[PACKAGE];
65
+ const wanted = releaseTag().slice(1);
66
+ if (current === wanted && manifest.scripts?.prepare?.includes(RULES)) return false;
67
+ const indent = text.match(/^[ \t]+(?=")/m)?.[0] ?? "";
68
+ const next = { ...manifest };
69
+ if (typeof current === "string") {
70
+ const field = manifest.devDependencies?.[PACKAGE] === undefined ? "dependencies" : "devDependencies";
71
+ next[field] = { ...manifest[field], [PACKAGE]: wanted };
72
+ } else {
73
+ next.devDependencies = { ...manifest.devDependencies, [PACKAGE]: wanted };
74
+ for (const [name, version] of Object.entries(releasePeers()))
75
+ if (!manifest.dependencies?.[name] && !manifest.devDependencies?.[name]) next.devDependencies[name] = version;
76
+ next.scripts = { ...SCRIPTS, ...manifest.scripts };
77
+ }
78
+ const prepare = next.scripts?.prepare;
79
+ if (!prepare?.includes(RULES))
80
+ next.scripts = { ...next.scripts, prepare: prepare ? `${prepare} && ${RULES}` : RULES };
81
+ write(join(root, "package.json"), `${JSON.stringify(next, null, indent)}\n`);
82
+ return current !== wanted;
83
+ }
84
+
85
+ function trust(root) {
86
+ if (!existsSync(join(root, "pnpm-lock.yaml"))) return;
87
+ const path = join(root, "pnpm-workspace.yaml");
88
+ const contents = read(path);
89
+ const doc = contents ? parseDocument(contents) : new Document({});
90
+ const list = doc.get("minimumReleaseAgeExclude");
91
+ if (isSeq(list)) {
92
+ if (list.items.some((item) => String(item.value ?? item) === PACKAGE)) return;
93
+ list.add(doc.createNode(PACKAGE));
94
+ } else {
95
+ doc.set("minimumReleaseAgeExclude", doc.createNode([PACKAGE]));
96
+ }
97
+ write(path, doc.toString(YAML));
98
+ }
99
+
100
+ function addHooks(path, harness) {
101
+ const text = read(path);
102
+ const settings = text ? JSON.parse(text) : {};
103
+ if (JSON.stringify(settings.hooks ?? {}).includes("jigo-ratchet")) return;
104
+ const hooks = {};
105
+ for (const [event, groups] of Object.entries(settings.hooks ?? {})) {
106
+ const kept = groups.filter((group) => !JSON.stringify(group).includes("standard-ratchet"));
107
+ if (kept.length > 0) hooks[event] = kept;
108
+ }
109
+ for (const [event, matcher, timeout] of HOOKS[harness]) {
110
+ const command = `${HOOK} ${event}${harness === "codex" ? " --harness codex" : ""}`;
111
+ hooks[event] = [
112
+ ...(hooks[event] ?? []),
113
+ { ...(matcher ? { matcher } : {}), hooks: [{ type: "command", command, timeout }] },
114
+ ];
115
+ }
116
+ write(path, `${JSON.stringify({ ...settings, hooks }, null, 2)}\n`);
117
+ }
118
+
119
+ export function configureTypescript(root) {
120
+ migrate(root);
121
+ const path = join(root, "package.json");
122
+ const text = read(path);
123
+ const manifest = JSON.parse(text);
124
+ const updateLock = install(root, manifest, text);
125
+ if (!existsSync(join(root, ".oxlintrc.json"))) write(join(root, ".oxlintrc.json"), OXLINTRC);
126
+ trust(root);
127
+ addHooks(join(root, ".claude", "settings.json"), "claude");
128
+ addHooks(join(root, ".codex", "hooks.json"), "codex");
129
+ return { updateLock, scripts: Object.keys(manifest.scripts ?? {}) };
130
+ }
package/README.md DELETED
@@ -1 +0,0 @@
1
- # create-jigo\n\nComing soon.