public-ai-sync 0.0.2 → 0.0.8
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 +43 -4
- package/lib/config.mjs +1 -0
- package/lib/prune.mjs +13 -9
- package/lib/run.mjs +30 -5
- package/lib/wire.mjs +9 -5
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -14,12 +14,51 @@ Default target: `.public-ai/`
|
|
|
14
14
|
Default source: `https://github.com/CodyTVWeber/Public-AI`
|
|
15
15
|
Default paths: `rules`, `skills`, `AI-setup`, `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `PRIVACY.md`, `.claude`, `.func-size`, `.mr-size`, `scripts`
|
|
16
16
|
|
|
17
|
+
Install is not a full consumer setup. Linked files are gitignored. CI, Husky, linter ignore lists, and size floors still need the steps in **Wire a consumer**.
|
|
18
|
+
|
|
19
|
+
## Wire a consumer
|
|
20
|
+
|
|
21
|
+
Empty git repo with a `package.json`:
|
|
22
|
+
|
|
23
|
+
1. `npm install --save-dev public-ai-sync`
|
|
24
|
+
2. Confirm `.public-ai/` is filled and root links exist (`rules`, `skills`, `scripts/lint`, `.claude/settings.json`)
|
|
25
|
+
3. Copy [github-ai-guardrails-npm.yml](../../skills/setup-repo/assets/ci/github-ai-guardrails-npm.yml) (or the GitLab sibling) into the consumer CI. The job **must** `npm ci` before any linked script; those paths are gitignored
|
|
26
|
+
4. Point git hooks at `skills/setup-repo/assets/scripts/check-clean-code.sh` (pre-commit) and `skills/setup-repo/assets/scripts/pre-push-gate.sh` (pre-push). Husky example:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
skills/setup-repo/assets/scripts/check-clean-code.sh || exit $?
|
|
30
|
+
skills/setup-repo/assets/scripts/pre-push-gate.sh || exit $?
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
5. Ignore synced trees in the product linter / formatter / test runner: `.public-ai/**`, `skills/**`, `rules/**`, `AI-setup/**`, `scripts/lint/**`, `scripts/guard/**`, `scripts/tests/**`
|
|
34
|
+
6. JS/TS: import `cleanCodeRules` from `skills/setup-repo/assets/lint/eslint.clean-code.js` (exists after `npm ci`). Spread into a flat-config entry; relax for tests
|
|
35
|
+
7. Paste [AGENTS.guardrails-sync.md](../../skills/setup-repo/assets/AGENTS.guardrails-sync.md) into consumer `AGENTS.md` (keep a real `AGENTS.md` if the product index must stay tracked)
|
|
36
|
+
|
|
37
|
+
### Defaults to omit or keep
|
|
38
|
+
|
|
39
|
+
| Path | Default in this pack | Consumer that wants hard product floors |
|
|
40
|
+
| --- | --- | --- |
|
|
41
|
+
| `.mr-size` | `risk: low` → size hard caps become advisory | Omit from `publicAiSync.paths` (leave unlinked) |
|
|
42
|
+
| `.func-size` | `size: b` → function warn 20 / error 40 | Omit; keep profile `a` (40/80) or `c` (50/100) via env / own file |
|
|
43
|
+
| `AGENTS.md`, `CLAUDE.md` | Whole-file link when the name is free | Omit when the consumer already has a real file |
|
|
44
|
+
| `PRIVACY.md`, `scripts/check-privacy.sh` | Privacy grep for this public pack | Omit or leave unhooked on a private product repo |
|
|
45
|
+
| `scripts/install-hooks.sh` | Privacy + language (Bash/JS only) + skill-catalog + size | Skip: Husky / `core.hooksPath` already set, or `PUBLIC_AI_SYNC_SKIP_HOOKS=1`. Language check fails on Python and other languages |
|
|
46
|
+
|
|
47
|
+
`scripts/` and `.claude/` merge as real directories: each child is linked; a real child file stays. Other default paths link as a whole, or stay if a real file or directory already occupies the name.
|
|
48
|
+
|
|
49
|
+
### Already has files
|
|
50
|
+
|
|
51
|
+
- Real `AGENTS.md`, `CLAUDE.md`, `.claude/settings.json`, Husky: left in place
|
|
52
|
+
- `.claude/rules` is linked next to a real `.claude/`
|
|
53
|
+
- Tracked `scripts/install-hooks.sh` that is not a pack link runs as-is (a no-op stub keeps Husky even on an empty `.husky` miss)
|
|
54
|
+
- Product skills stay in `.claude/skills/`; pack skills live at gitignored `skills/`
|
|
55
|
+
|
|
17
56
|
## What install does
|
|
18
57
|
|
|
19
58
|
1. Copy the default paths into the target folder (atomic replace: staging, then swap)
|
|
20
|
-
2. Create relative symlinks at the consumer root so `$CLAUDE_PROJECT_DIR` hooks resolve. `.claude
|
|
59
|
+
2. Create relative symlinks at the consumer root so `$CLAUDE_PROJECT_DIR` hooks resolve. `.claude` and `scripts/` stay real directories; each child is linked. `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `PRIVACY.md`, `rules`, `skills`, `AI-setup`, `.func-size`, and `.mr-size` link as a whole when those names are free. An existing non-link file is left in place
|
|
21
60
|
3. Gitignore the target and every link this package created
|
|
22
|
-
4. Run `scripts/install-hooks.sh` when that script is present. A consumer that is not a git repo, or that already has a foreign hook plus a `.bak`, does not fail the install
|
|
61
|
+
4. Run `scripts/install-hooks.sh` when that script is present **and** the consumer has no `.husky/` directory and no `core.hooksPath`. A consumer that is not a git repo, or that already has a foreign hook plus a `.bak`, does not fail the install
|
|
23
62
|
5. Add `public-ai:*` npm scripts when those names are free: `public-ai:sync` (manual re-run), `public-ai:lint-docs`, `public-ai:lint-explainer`, `public-ai:lint`, `public-ai:check-languages`, `public-ai:check-copies`, `public-ai:check-duplicates`, `public-ai:check-skill-catalog`, `public-ai:check-1k-cross`, `public-ai:verdict-parse`, `public-ai:code-quality`, `public-ai:privacy`, and `public-ai:install-hooks`. Consumer `postinstall` and `prepare` scripts are not added
|
|
24
63
|
|
|
25
64
|
## Config
|
|
@@ -37,13 +76,13 @@ Consumer `package.json`:
|
|
|
37
76
|
}
|
|
38
77
|
```
|
|
39
78
|
|
|
40
|
-
Env (wins over `package.json`): `PUBLIC_AI_SYNC_SOURCE`, `PUBLIC_AI_SYNC_REF`, `PUBLIC_AI_SYNC_TARGET`, `PUBLIC_AI_SYNC_PATHS` (comma list), `PUBLIC_AI_SYNC_ROOT`, `PUBLIC_AI_SYNC_SKIP=1`.
|
|
79
|
+
Env (wins over `package.json`): `PUBLIC_AI_SYNC_SOURCE`, `PUBLIC_AI_SYNC_REF`, `PUBLIC_AI_SYNC_TARGET`, `PUBLIC_AI_SYNC_PATHS` (comma list), `PUBLIC_AI_SYNC_ROOT`, `PUBLIC_AI_SYNC_SKIP=1`, `PUBLIC_AI_SYNC_SKIP_HOOKS=1`.
|
|
41
80
|
|
|
42
81
|
`source` is a git URL or a local directory. Omit `paths` to take the full default list. A supplied env or `publicAiSync.paths` list is used even when every entry canonicalizes away; an empty list then fails at materialize instead of installing the defaults.
|
|
43
82
|
|
|
44
83
|
## Gitignore
|
|
45
84
|
|
|
46
|
-
The package ships `gitignore.snippet`. `npx public-ai-sync ignore` rewrites the managed block between `# public-ai-sync` and `# end public-ai-sync` from the target path. A full sync rewrites that block from the target and the links this run kept. Lines after the end marker stay. Root names are anchored (`/AGENTS.md`).
|
|
85
|
+
The package ships `gitignore.snippet`. `npx public-ai-sync ignore` rewrites the managed block between `# public-ai-sync` and `# end public-ai-sync` from the target path. A full sync rewrites that block from the target and the links this run kept. Lines after the end marker stay. Root names are anchored (`/AGENTS.md`). Owned links and files are listed without a trailing slash so Git ignores the symlink itself, not only a real directory.
|
|
47
86
|
|
|
48
87
|
## Failures
|
|
49
88
|
|
package/lib/config.mjs
CHANGED
|
@@ -29,6 +29,7 @@ export function loadConfig(env = process.env) {
|
|
|
29
29
|
|| DEFAULT_TARGET;
|
|
30
30
|
return {
|
|
31
31
|
skip: envFlag(env.PUBLIC_AI_SYNC_SKIP) || skipSelf(root, pkg),
|
|
32
|
+
skipHooks: envFlag(env.PUBLIC_AI_SYNC_SKIP_HOOKS),
|
|
32
33
|
root,
|
|
33
34
|
source: resolveSource(root, source),
|
|
34
35
|
ref: env.PUBLIC_AI_SYNC_REF || field.ref || DEFAULT_REF,
|
package/lib/prune.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
11
11
|
import { DEFAULT_PATHS, canonicalRel } from "./config.mjs";
|
|
12
12
|
|
|
13
|
-
export const
|
|
13
|
+
export const MERGE_TOPS = ["scripts", ".claude"];
|
|
14
14
|
const SKIP_NAMES = new Set(["node_modules", ".git", ".public-ai"]);
|
|
15
15
|
const WIRED_NAME = ".wired";
|
|
16
16
|
|
|
@@ -78,7 +78,7 @@ function candidateRels(job) {
|
|
|
78
78
|
...DEFAULT_PATHS,
|
|
79
79
|
...job.cfg.paths,
|
|
80
80
|
...rootLinkRels(job.cfg),
|
|
81
|
-
...
|
|
81
|
+
...mergeOwnedRels(job.cfg.root),
|
|
82
82
|
...(job.previous || []),
|
|
83
83
|
];
|
|
84
84
|
}
|
|
@@ -108,16 +108,20 @@ function ownedRootRel(cfg, name) {
|
|
|
108
108
|
return [name];
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
function
|
|
112
|
-
|
|
111
|
+
function mergeOwnedRels(root) {
|
|
112
|
+
return MERGE_TOPS.flatMap((top) => ownedRelsUnder(root, top));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function ownedRelsUnder(root, top) {
|
|
116
|
+
const dir = join(root, top);
|
|
113
117
|
if (!realDir(dir)) return [];
|
|
114
|
-
return readdirSync(dir).flatMap((name) =>
|
|
118
|
+
return readdirSync(dir).flatMap((name) => nestedMergeRels({ root, top, name }));
|
|
115
119
|
}
|
|
116
120
|
|
|
117
|
-
function
|
|
118
|
-
if (skipName(name)) return [];
|
|
119
|
-
const rel = join(
|
|
120
|
-
const dest = join(root, rel);
|
|
121
|
+
function nestedMergeRels(job) {
|
|
122
|
+
if (skipName(job.name)) return [];
|
|
123
|
+
const rel = join(job.top, job.name);
|
|
124
|
+
const dest = join(job.root, rel);
|
|
121
125
|
if (!realDir(dest)) return [rel];
|
|
122
126
|
return [rel, ...readdirSync(dest).flatMap((child) => nestedChildRel(rel, child))];
|
|
123
127
|
}
|
package/lib/run.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { ensureGitignore } from "./gitignore.mjs";
|
|
|
8
8
|
import { replaceTarget } from "./replace-target.mjs";
|
|
9
9
|
import { rmIfExists } from "./fs-util.mjs";
|
|
10
10
|
import { TOOLS, runTool } from "./tools.mjs";
|
|
11
|
-
import { readWired } from "./prune.mjs";
|
|
11
|
+
import { isRealDir, readWired } from "./prune.mjs";
|
|
12
12
|
import { wireConsumer } from "./wire.mjs";
|
|
13
13
|
|
|
14
14
|
export function run(argv, env = process.env) {
|
|
@@ -48,17 +48,42 @@ function fillThenSwap(cfg, work) {
|
|
|
48
48
|
replaceTarget(staging, cfg.target);
|
|
49
49
|
const links = wireConsumer(cfg, previous);
|
|
50
50
|
ensureGitignore(cfg.root, [cfg.targetRel, ...links]);
|
|
51
|
-
installGitHooks(cfg
|
|
51
|
+
installGitHooks(cfg);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function installGitHooks(
|
|
55
|
-
const script = join(root, "scripts", "install-hooks.sh");
|
|
54
|
+
function installGitHooks(cfg) {
|
|
55
|
+
const script = join(cfg.root, "scripts", "install-hooks.sh");
|
|
56
56
|
if (!existsSync(script)) return;
|
|
57
|
-
const
|
|
57
|
+
const reason = skipHooksReason(cfg);
|
|
58
|
+
if (reason) {
|
|
59
|
+
process.stderr.write(`public-ai-sync: skip git hooks (${reason})\n`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const result = spawnSync("bash", [script], { cwd: cfg.root, encoding: "utf8" });
|
|
58
63
|
if (result.status === 0) return;
|
|
59
64
|
process.stderr.write(`public-ai-sync: git hooks not installed (${exitLabel(result)})\n`);
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
function skipHooksReason(cfg) {
|
|
68
|
+
if (cfg.skipHooks) return "PUBLIC_AI_SYNC_SKIP_HOOKS";
|
|
69
|
+
if (isRealDir(join(cfg.root, ".husky"))) return ".husky present";
|
|
70
|
+
const hooksPath = readHooksPath(cfg.root);
|
|
71
|
+
if (hooksPath) return `core.hooksPath=${hooksPath}`;
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function readHooksPath(root) {
|
|
76
|
+
const result = spawnSync("git", ["-C", root, "config", "--get", "core.hooksPath"], {
|
|
77
|
+
encoding: "utf8",
|
|
78
|
+
});
|
|
79
|
+
return hooksPathFrom(result);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function hooksPathFrom(result) {
|
|
83
|
+
if (result.status !== 0) return "";
|
|
84
|
+
return (result.stdout || "").trim();
|
|
85
|
+
}
|
|
86
|
+
|
|
62
87
|
function exitLabel(result) {
|
|
63
88
|
if (result.status == null) return result.error?.message || "failed";
|
|
64
89
|
return `exit ${result.status}`;
|
package/lib/wire.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { dirname, join, relative } from "node:path";
|
|
10
10
|
import { npmScripts } from "./tools.mjs";
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
MERGE_TOPS,
|
|
13
13
|
dropOwnedTree,
|
|
14
14
|
hasLstat,
|
|
15
15
|
isOurLink,
|
|
@@ -35,10 +35,14 @@ function wirePath(job) {
|
|
|
35
35
|
dropOwnedTree(join(job.cfg.root, job.rel), job.cfg.target);
|
|
36
36
|
return [];
|
|
37
37
|
}
|
|
38
|
-
if (job.rel
|
|
38
|
+
if (isMergeRoot(job.rel)) return mergeDir(job);
|
|
39
39
|
return placeLink(job, src);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function isMergeRoot(rel) {
|
|
43
|
+
return MERGE_TOPS.includes(rel);
|
|
44
|
+
}
|
|
45
|
+
|
|
42
46
|
function mergeDir(job) {
|
|
43
47
|
const srcDir = join(job.cfg.target, job.rel);
|
|
44
48
|
const destDir = join(job.cfg.root, job.rel);
|
|
@@ -75,11 +79,11 @@ function refreshOrSkip(state) {
|
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
function canMerge(state) {
|
|
78
|
-
return
|
|
82
|
+
return underMergeTop(state.job.rel) && isRealDir(state.dest) && isRealDir(state.src);
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
function
|
|
82
|
-
return rel ===
|
|
85
|
+
function underMergeTop(rel) {
|
|
86
|
+
return MERGE_TOPS.some((top) => rel === top || rel.startsWith(`${top}/`));
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
function linkChildren(state) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "public-ai-sync",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Dev dependency that installs the public AI environment into a consuming repo on install",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/CodyTVWeber/Public-AI",
|
|
10
|
+
"directory": "packages/public-ai-sync"
|
|
11
|
+
},
|
|
7
12
|
"bin": {
|
|
8
13
|
"public-ai-sync": "./bin/sync.mjs"
|
|
9
14
|
},
|