agent-personalizer 0.4.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/LICENSE +21 -0
- package/README.md +155 -0
- package/bin/agent-personalizer.js +388 -0
- package/check/forbidden.example.txt +31 -0
- package/check/gate.cjs +349 -0
- package/docs/companions.md +62 -0
- package/docs/paste-guide.md +66 -0
- package/docs/tiers.md +89 -0
- package/examples/freelance-illustrator/.agent-personalizer.json +52 -0
- package/examples/freelance-illustrator/AGENTS.md +180 -0
- package/examples/freelance-illustrator/AGENT_ONBOARDING.md +70 -0
- package/examples/freelance-illustrator/CLAUDE.md +184 -0
- package/examples/freelance-illustrator/USER.md +49 -0
- package/examples/freelance-illustrator/notes/README.md +39 -0
- package/examples/freelance-illustrator/notes/decisions.md +18 -0
- package/examples/freelance-illustrator/notes/inbox/2026-09-03-shot-list-for-six-prints.md +14 -0
- package/examples/freelance-illustrator/notes/inbox/README.md +19 -0
- package/examples/freelance-illustrator/notes/sessions/2026-W36.md +41 -0
- package/examples/freelance-illustrator/rules/00-read-the-profile-first.md +24 -0
- package/examples/freelance-illustrator/rules/10-evidence-before-assertion.md +24 -0
- package/examples/freelance-illustrator/rules/20-one-owner-per-rule.md +24 -0
- package/examples/freelance-illustrator/rules/30-folder-index-is-part-of-the-change.md +26 -0
- package/examples/freelance-illustrator/rules/40-sign-every-edit.md +25 -0
- package/examples/freelance-illustrator/rules/50-output-style.md +21 -0
- package/examples/freelance-illustrator/rules/60-act-or-ask.md +30 -0
- package/hooks/README.md +39 -0
- package/hooks/claude-code/session-start.sh +14 -0
- package/package.json +49 -0
- package/render/onboarding.cjs +360 -0
- package/render/render.cjs +559 -0
- package/render/targets.json +57 -0
- package/rules/00-read-the-profile-first.md +24 -0
- package/rules/10-evidence-before-assertion.md +24 -0
- package/rules/20-one-owner-per-rule.md +24 -0
- package/rules/30-folder-index-is-part-of-the-change.md +26 -0
- package/rules/40-sign-every-edit.md +25 -0
- package/rules/50-output-style.md +21 -0
- package/rules/60-act-or-ask.md +30 -0
- package/rules/README.md +55 -0
- package/templates/AGENTS.md +30 -0
- package/templates/CLAUDE.md +30 -0
- package/templates/FOLDER_README.md +35 -0
- package/templates/INBOX_README.md +19 -0
- package/templates/USER.md +52 -0
- package/templates/decisions-log.md +16 -0
- package/templates/session-log.md +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AunySillyMe
|
|
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/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# agent-personalizer
|
|
2
|
+
|
|
3
|
+
[](https://github.com/aunysillyme/agent-personalizer/actions/workflows/harness.yml) [](https://github.com/aunysillyme/agent-personalizer/blob/main/CHANGELOG.md) [](LICENSE)
|
|
4
|
+
|
|
5
|
+
### Personalize any AI with dynamic instructions. One profile, one rule source, rendered everywhere.
|
|
6
|
+
|
|
7
|
+
Most people set up custom instructions once, in one app, and still get generic output. The instructions decay over a long chat, the AI forgets where things are, every app has its own copy that drifts, and the AI treats its own guesses about you as your rulings.
|
|
8
|
+
|
|
9
|
+
This repo is the fix, in four levels. Stop at the level you need.
|
|
10
|
+
|
|
11
|
+
| Level | You have | You get |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| **1. One profile** | one AI, one app | three files: a profile of you (`USER.md`), an agent onboarding file written from your answers (`AGENT_ONBOARDING.md`), and a home file the AI reads first (`CLAUDE.md` or `AGENTS.md`) with the rules rendered into it. Plus the installer's own `.agent-personalizer.json`. Nothing else. |
|
|
14
|
+
| **2. Dynamic docs** | a notes folder the AI may edit | templates and rules for the AI to follow: folder indexes it keeps current, a weekly session log, a decisions log, a signature on every edit (if you want one), an inbox convention (one file per item, deleted when done). Instructions, not automation: the AI does the keeping. |
|
|
15
|
+
| **3. Mechanisms** | a coding agent (Claude Code, Codex, Cursor) | the automation: your own copy of `rules/` to edit, one rule source rendered per AI, a session-start contract that puts your rules in context at decision time, a drift check that fails loudly, a forbidden-string gate. |
|
|
16
|
+
| **4. Hand-off** | several AIs | reading material only for now: pointers to the multi-agent layer (routing, task bundles, verified CLI runs) and to two companion tools that enforce what this repo can only state. |
|
|
17
|
+
|
|
18
|
+
Everything here is the generalized shape of a system that runs in production every day. The examples are invented. The failures the rules prevent are real.
|
|
19
|
+
|
|
20
|
+
**What this tool does, and does not do.** It writes files: a profile, an onboarding manual generated from your answers, rule files, rendered instruction files, a session-start hook, a drift check and a privacy gate. Those are the implemented parts and the harness tests every one of them. What it does not do: make an AI comply. Text in a file, or injected at session start, is the strongest placement available, and the stories in `docs/tiers.md` are one setup's experience of what held; they are not a measured guarantee across models or hosts, and nothing here measures compliance. Anything described as the AI "keeping" or "doing" is an instruction the AI is given, not a process this repo runs. The two [companion tools](#companion-tools) are where a rule becomes something a machine enforces.
|
|
21
|
+
|
|
22
|
+
**Privacy:** the tool itself runs entirely on your machine: no network calls, no telemetry, no environment variables read, writes only into the folder you name. The one network step is `npx` fetching the package from GitHub through npm before the tool runs; nothing in this repo opens a connection after that. Runs on macOS and Linux, and the Node entry points (installer, renderer, gate) are smoke-tested on Windows in CI; the harness and the session hook are POSIX shell, so on Windows run those under WSL or Git Bash.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx github:aunysillyme/agent-personalizer
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The installer asks which AIs you use and which level you want, then writes only the matching files into the folder you point it at. It never writes secrets. `--help` lists every flag; `--quick` asks the seven questions that change behaviour and defaults the rest; `--answers file.json` (or `--answers -` from stdin) scripts it.
|
|
33
|
+
|
|
34
|
+
No Node? Copy `templates/USER.md` and `templates/CLAUDE.md` (or `templates/AGENTS.md`) into your project by hand. That is level 1.
|
|
35
|
+
|
|
36
|
+
If `npx` stops with `EPERM` and a note about root-owned files in `~/.npm`, npm cannot write its cache. Point it at a local one for this run, no `sudo` needed:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm_config_cache=./.npm-cache npx github:aunysillyme/agent-personalizer
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## The five tiers (why this works)
|
|
45
|
+
|
|
46
|
+
Your instructions live in five places, each with one job and one failure it prevents. Read [docs/tiers.md](docs/tiers.md) before writing a rule.
|
|
47
|
+
|
|
48
|
+
| Tier | What | Prevents |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| 1 | Style in the system prompt | rules decaying over a long chat |
|
|
51
|
+
| 2 | One always-loaded home file | the AI not knowing where anything is |
|
|
52
|
+
| 3 | Session-start injection | a tool's own instructions beating yours at the moment of decision |
|
|
53
|
+
| 4 | One owning document per rule | the same rule drifting in five copies |
|
|
54
|
+
| 5 | Memory with a status on every fact | the AI treating its own guess as your ruling |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Where each rendered file goes
|
|
59
|
+
|
|
60
|
+
[docs/paste-guide.md](docs/paste-guide.md): which file each AI reads and how (Claude Code and Codex, Cursor and Gemini read theirs from the folder automatically; claude.ai and ChatGPT take a paste), and what to re-paste when you change an answer.
|
|
61
|
+
|
|
62
|
+
## The agent onboarding file
|
|
63
|
+
|
|
64
|
+
The installer asks you how an AI should work with you, then writes the answers to `AGENT_ONBOARDING.md`: how to talk to you, how to shape output, what to read first and in what order, where it may write, how to save a file, and what it must always ask before doing. It is generated from your answers in `.agent-personalizer.json`, so every AI you point at the folder gets the same manual, and re-running the installer changes it everywhere at once.
|
|
65
|
+
|
|
66
|
+
- **Interactive**: run the installer without `--yes` and answer the questions. Enter accepts the default.
|
|
67
|
+
- **Scripted**: `--answers my-answers.json` (see [`test/fixtures/answers.json`](test/fixtures/answers.json) for the shape). Unknown keys, wrong types or unknown choices are refused before anything is written.
|
|
68
|
+
- **Defaults**: `--defaults` or `--yes`. The defaults are one working setup: direct, short, one-line corrections, settle facts yourself and ask only when the answer changes what gets built, verdict first, bullets, evidence inline, sign every edit, always ask before delete / publish / send / spend / settings / standing rules. Every one is a question you can answer differently.
|
|
69
|
+
|
|
70
|
+
`USER.md` is generated from the same answers the first time and is then yours to edit. Re-running with changed answers regenerates `AGENT_ONBOARDING.md` and every rendered block; `USER.md` is regenerated only if you never edited it (it still equals the render of the previous answers), otherwise it is kept and the installer names the answers that changed so you can carry them over by hand. Two rules depend on answers: the signature rule renders only when you answered yes, and the output-style rule defers to your stated shape instead of imposing one. The session-start contract carries a short version of the onboarding block, restrictions first, so it is present at the moment of decision, not only in a file.
|
|
71
|
+
|
|
72
|
+
ChatGPT has two custom-instruction boxes with a character budget, so its render is the compact profile plus the onboarding block and only the `inject: true` rules, each box measured against the budget, and written twice: inside `chatgpt-custom-instructions.md` with the counts, and as two plain paste files, `chatgpt-box1.txt` and `chatgpt-box2.txt`. `render.cjs --strict` exits 1 instead of writing when a box is over budget, for people who wire the render into CI. Nothing is cut silently: an over-budget box is written in full and flagged, ordered so the last lines are the cheapest to trim. For the rest of the rules, use a ChatGPT Project and upload `AGENT_ONBOARDING.md` and `rules/` as files.
|
|
73
|
+
|
|
74
|
+
## Level 1: one file
|
|
75
|
+
|
|
76
|
+
1. Fill in [`templates/USER.md`](templates/USER.md), or let the installer generate it from your onboarding answers. Who you are, how to talk to you, how firmly you mean things, how you want output shaped.
|
|
77
|
+
2. Copy [`templates/CLAUDE.md`](templates/CLAUDE.md) for Claude, or [`templates/AGENTS.md`](templates/AGENTS.md) for Codex, Cursor and most other coding agents. Both are pointers: they tell the AI to read `USER.md` first and where everything else lives.
|
|
78
|
+
3. Paste the `USER.md` body into the "custom instructions" box of any chat app that has one.
|
|
79
|
+
|
|
80
|
+
**The one idea in level 1:** the home file carries pointers, not hand-maintained copies. Text you retype drifts. A pointer does not, and neither does a block the renderer regenerates and `--check` compares (level 3): that block is a generated snapshot, with one owner and a drift check, which is the other acceptable shape.
|
|
81
|
+
|
|
82
|
+
## Level 2: dynamic docs
|
|
83
|
+
|
|
84
|
+
The AI edits your notes under rules that keep them trustworthy. Templates in [`templates/`](templates/):
|
|
85
|
+
|
|
86
|
+
- **`FOLDER_README.md`**: every folder has an index. Any write to a folder means the index is corrected in the same pass. A stale index is worse than none, because the AI believes it.
|
|
87
|
+
- **`session-log.md`**: one note per week. Each session appends a dated section: decisions, corrections, preferences learned.
|
|
88
|
+
- **`decisions-log.md`**: one running file. What was decided, why, when. Read before re-deciding anything.
|
|
89
|
+
- **Signature line**: every AI edit ends with `Last edited by: <ai> <model> <date> · <ten words>`. One line, overwritten, never stacked.
|
|
90
|
+
- **Inbox pattern**: the AI drops notes in an inbox folder, one file per item. Finished items are deleted, not marked done. A resolved file in an inbox reads as open to the next agent.
|
|
91
|
+
|
|
92
|
+
A worked week for an invented user is in [`examples/freelance-illustrator/`](examples/freelance-illustrator/).
|
|
93
|
+
|
|
94
|
+
## Level 3: mechanisms
|
|
95
|
+
|
|
96
|
+
Three pieces, all in this repo, no dependencies beyond Node.
|
|
97
|
+
|
|
98
|
+
- **Rule source + renderer.** Each rule is one file in [`rules/`](rules/), copied into your folder at level 3 (levels 1 and 2 render from the package's rules and copy nothing), with three fenced blocks: `universal` (any AI), `personal` (your curation), `binding:<ai>` (tool names and paths for one AI). [`render/render.cjs`](render/render.cjs) renders `USER.md` plus the rules into `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, ChatGPT custom-instruction boxes, or a plain system prompt. A rule can say `requires: signature=yes` and then renders only when the answer matches. `--check` fails if any rendered file drifted from its source. The runtime files are `.cjs` so they run inside a `"type": "module"` project too.
|
|
99
|
+
- **Session-start contract.** [`hooks/`](hooks/) shows how to inject the rules in full at the start of every Claude Code session, and the plain-prompt fallback for AIs without hooks. The contract carries the onboarding block first, in order of consequence (always-ask, off-limits, write policy, then style), so a token budget trims style before it trims a restriction. Injection puts the text in context; whether the model follows it is host- and model-dependent.
|
|
100
|
+
- **Drift check.** `node render/render.cjs --dir . --check` in CI or a pre-commit hook (`npm run check` inside this repo). It compares each rendered block with what the sources would render now: it detects rendering drift, not whether two hand-written files agree in meaning.
|
|
101
|
+
- **Forbidden-string gate.** [`check/gate.cjs`](check/gate.cjs) scans every file git would ship (or every file under a folder, with `--all`), text and file paths, for the exact strings in a gitignored list, never follows symlinks, and fails closed when the list is missing. This repo runs it on itself before every push. Copy `check/forbidden.example.txt` to `check/forbidden.local.txt` and fill it in. It is a check for the strings you listed, not a proof that no personal data ships: unknown terms, git history and binary files are outside it.
|
|
102
|
+
|
|
103
|
+
## Companion tools
|
|
104
|
+
|
|
105
|
+
Two companions turn the onboarding answers from advice into enforcement. Neither is required. [docs/companions.md](docs/companions.md) has the detail and a table of how each note tool is reached.
|
|
106
|
+
|
|
107
|
+
- **[obsidian-tc](https://github.com/The-40-Thieves/obsidian-tc)** for Obsidian vaults: governed MCP access. Your **off-limits** answer becomes a folder ACL, your **always-ask** answer becomes its human-in-the-loop list, and destructive tools fail closed until you confirm. `npx obsidian-tc /path/to/vault`.
|
|
108
|
+
- **[The Context Layer](https://sierracatalina.com/context-layer)** by Sierra Catalina: purpose-bound context with receipts. Capture → normalize → vault → decide → bundle → act; memory writes remain proposals. Your **write policy** and **off-limits** answers are its decide and vault stages in miniature. Read the essay first, then run the starter.
|
|
109
|
+
|
|
110
|
+
## Level 4: hand-off
|
|
111
|
+
|
|
112
|
+
Once you run several AIs, personalization is not the problem any more; routing is. That is a separate layer: which model handles which task, task bundles for every delegation, and CLI runs that only count as success when a deliverable exists. It is being built as its own repo and will link from here when it ships. This repo stays the beginner tier of that stack.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Every rule carries its story
|
|
117
|
+
|
|
118
|
+
Open any file in [`rules/`](rules/). Each ends with an `origin` block: the failure that produced the rule and the failure it prevents. Rules without a story get argued with. Rules with one get followed, by people and by models. When you write your own, fill the block in. It is the most useful thing in the file.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Repo map
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
templates/ USER.md, CLAUDE.md, AGENTS.md, FOLDER_README.md, session-log.md, decisions-log.md, INBOX_README.md
|
|
126
|
+
render/onboarding.cjs the interview questions, their defaults, and the USER.md / AGENT_ONBOARDING.md / contract renders
|
|
127
|
+
rules/ example rules in the three-fence format, plus the format spec
|
|
128
|
+
render/ render.cjs and the target table
|
|
129
|
+
hooks/ Claude Code session-start contract, plain-prompt fallback
|
|
130
|
+
check/ gate.cjs, the forbidden-string gate this repo runs on itself
|
|
131
|
+
bin/ the npx installer
|
|
132
|
+
examples/ one invented user, end to end
|
|
133
|
+
docs/ tiers.md, companions.md, paste-guide.md
|
|
134
|
+
CHANGELOG.md keyed on audit rounds
|
|
135
|
+
.github/ harness.yml: the checks on every push and PR, Ubuntu and macOS x Node 18/20/22, plus a Windows smoke job; publish.yml: npm with provenance, manual, dormant
|
|
136
|
+
test/ run.sh: 82 checks, exact exit codes, adversarial fixtures (symlinks, traversal, malformed markers, CRLF, partial renders)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Changelog
|
|
140
|
+
|
|
141
|
+
[CHANGELOG.md](CHANGELOG.md). Every entry names the audit round that produced it.
|
|
142
|
+
|
|
143
|
+
## Contributing
|
|
144
|
+
|
|
145
|
+
Open an issue with the failure you hit, not the feature you want. Rules come from failures. [CONTRIBUTING.md](CONTRIBUTING.md) has the checks, the rule format and how to add a notes tool or an AI target. Every push and pull request runs the harness on Ubuntu and macOS ([.github/workflows/harness.yml](.github/workflows/harness.yml)); the privacy gate against a real forbidden list stays local by design, so CI shows that one check as a skip.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT ([LICENSE](LICENSE)). You may use, change, share and sell copies for any purpose; keep the notice; no warranty, no endorsement implied. Attribution is appreciated, not required: *Built with agent-personalizer (https://github.com/aunysillyme/agent-personalizer)*.
|
|
152
|
+
|
|
153
|
+
Security reports: [SECURITY.md](SECURITY.md). Contributing: [CONTRIBUTING.md](CONTRIBUTING.md). Releases: [RELEASING.md](RELEASING.md).
|
|
154
|
+
|
|
155
|
+
Built in public by [@AunySillyMe](https://x.com/AunySillyMe).
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/*
|
|
4
|
+
agent-personalizer installer.
|
|
5
|
+
|
|
6
|
+
npx github:aunysillyme/agent-personalizer [--dir <folder>] [--ai claude,agents,gemini,chatgpt,prompt] [--level 1|2|3|4]
|
|
7
|
+
[--answers <file.json>] [--defaults] [--yes]
|
|
8
|
+
|
|
9
|
+
Interactive when flags are missing and stdin is a terminal. Non-interactive with flags.
|
|
10
|
+
The ONBOARDING INTERVIEW (how to talk to you, output shape, what to read first, where the AI
|
|
11
|
+
may write, how to save, what to ask before doing) runs interactively, or takes --answers
|
|
12
|
+
<file.json>, or --defaults / --yes to accept every default. The answers are stored under
|
|
13
|
+
"onboarding" in .agent-personalizer.json and rendered to AGENT_ONBOARDING.md; USER.md is
|
|
14
|
+
generated from the same answers when it does not exist yet.
|
|
15
|
+
Level 1 writes USER.md, AGENT_ONBOARDING.md and the home file(s); the rules render into the home
|
|
16
|
+
file from the package's own rules/ and nothing is copied. Level 3 copies rules/ (yours to edit from
|
|
17
|
+
then on) with the renderer, hook and gate. .agent-personalizer.json stores only the answers that
|
|
18
|
+
differ from the defaults.
|
|
19
|
+
Writes only the files for the chosen AIs and level. Never overwrites a file that exists
|
|
20
|
+
(except the marker block inside rendered files it owns, .agent-personalizer.json, which
|
|
21
|
+
is its own record and is merged, never blindly replaced, and USER.md when, and only when,
|
|
22
|
+
the answers changed and the file still equals the render of the previous answers byte for
|
|
23
|
+
byte; an edited USER.md is kept and the changed answers are named as a conflict).
|
|
24
|
+
PREFLIGHT: every path is probed and every existing rendered target is decoded and its marker
|
|
25
|
+
block checked BEFORE the first write, so a refusal leaves the folder as it was. The notes
|
|
26
|
+
folder the scaffold creates and the home files point at is your notes_path (disk tools) or
|
|
27
|
+
notes/ (the fallback); a cloud tool gets no local notes folder at all. Refuses to write through any
|
|
28
|
+
symlink or outside the install folder (the folder you name is followed once, via realpath;
|
|
29
|
+
nothing beneath it may be a symlink). Reads no environment variables. Writes no secrets.
|
|
30
|
+
|
|
31
|
+
exit codes: 0 ok · 1 unexpected error · 2 refused or invalid input
|
|
32
|
+
*/
|
|
33
|
+
const fs = require('fs');
|
|
34
|
+
const path = require('path');
|
|
35
|
+
const readline = require('readline');
|
|
36
|
+
const { execFileSync } = require('child_process');
|
|
37
|
+
|
|
38
|
+
const PKG = path.resolve(__dirname, '..');
|
|
39
|
+
const onboarding = require(path.join(PKG, 'render', 'onboarding.cjs'));
|
|
40
|
+
const markers = require(path.join(PKG, 'render', 'render.cjs')); // markerState, for the preflight; render.cjs runs nothing on require
|
|
41
|
+
const AIS = ['claude', 'agents', 'gemini', 'chatgpt', 'prompt'];
|
|
42
|
+
const AI_LABEL = { claude: 'Claude (Claude Code, Claude apps)', agents: 'Codex / Cursor / anything that reads AGENTS.md', gemini: 'Gemini', chatgpt: 'ChatGPT custom instructions', prompt: 'a plain system prompt (shareable, no profile)' };
|
|
43
|
+
|
|
44
|
+
function die(msg) { console.error(`agent-personalizer: ${msg}`); process.exit(2); }
|
|
45
|
+
|
|
46
|
+
const VALUE_OPTS = ['--dir', '--ai', '--level', '--answers'];
|
|
47
|
+
const FLAG_OPTS = ['--yes', '--defaults', '--quick', '--help', '--version'];
|
|
48
|
+
const USAGE = `agent-personalizer ${require(path.join(PKG, 'package.json')).version}
|
|
49
|
+
|
|
50
|
+
npx github:aunysillyme/agent-personalizer [--dir <folder>] [--ai claude,agents,gemini,chatgpt,prompt] [--level 1|2|3|4]
|
|
51
|
+
[--answers <file.json> | --answers - | --defaults] [--quick] [--yes]
|
|
52
|
+
[--help] [--version]
|
|
53
|
+
|
|
54
|
+
Interactive when flags are missing and stdin is a terminal; the onboarding interview runs then.
|
|
55
|
+
--quick ask only the seven questions that change behaviour (name, tone, length, notes tool and path,
|
|
56
|
+
write policy, always-ask); the rest take their defaults. Interactive only.
|
|
57
|
+
--answers a JSON file of answers, or "-" to read the JSON from stdin. Unknown keys and values are refused.
|
|
58
|
+
--defaults accept every default without asking.
|
|
59
|
+
--yes non-interactive: needs --dir, --ai and --level.
|
|
60
|
+
Levels: 1 profile + onboarding + home file(s) (rules render from the package) · 2 + the notes folder
|
|
61
|
+
3 + renderer, session-start hook, gate and a copy of rules/ to edit · 4 pointers to the multi-agent layer
|
|
62
|
+
exit codes: 0 ok · 1 unexpected error · 2 refused or invalid input
|
|
63
|
+
`;
|
|
64
|
+
/* Parse argv once, strictly: value options at most once each, flags at most once, nothing unknown. */
|
|
65
|
+
function parseArgs() {
|
|
66
|
+
const out = {};
|
|
67
|
+
const argv = process.argv.slice(2);
|
|
68
|
+
for (let i = 0; i < argv.length; i++) {
|
|
69
|
+
const a = argv[i];
|
|
70
|
+
if (VALUE_OPTS.includes(a)) {
|
|
71
|
+
if (a in out) die(`${a} given more than once`);
|
|
72
|
+
const v = argv[i + 1];
|
|
73
|
+
if (v === undefined || v === '' || v.startsWith('--')) die(`${a} needs a non-empty value`);
|
|
74
|
+
out[a] = v; i++;
|
|
75
|
+
} else if (FLAG_OPTS.includes(a)) {
|
|
76
|
+
if (a in out) die(`${a} given more than once`);
|
|
77
|
+
out[a] = true;
|
|
78
|
+
} else die(`unknown option "${a}" (known: ${[...VALUE_OPTS, ...FLAG_OPTS].join(', ')})`);
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
const ARGS = parseArgs();
|
|
83
|
+
function arg(name, dflt) { return name in ARGS ? ARGS[name] : dflt; }
|
|
84
|
+
if (ARGS['--help']) { process.stdout.write(USAGE); process.exit(0); }
|
|
85
|
+
if (ARGS['--version']) { process.stdout.write(require(path.join(PKG, 'package.json')).version + '\n'); process.exit(0); }
|
|
86
|
+
|
|
87
|
+
async function ask(q, dflt) {
|
|
88
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
89
|
+
const a = await new Promise(res => rl.question(`${q}${dflt ? ` [${dflt}]` : ''}: `, res));
|
|
90
|
+
rl.close();
|
|
91
|
+
return (a || dflt || '').trim();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Resolve <root>/<rel> such that every existing component is a real directory (never a
|
|
95
|
+
symlink) and the result stays inside the real root. Returns { full, exists }. A dangling
|
|
96
|
+
symlink counts as "exists" and is refused. */
|
|
97
|
+
function safeDest(root, rel) {
|
|
98
|
+
if (path.isAbsolute(rel) || rel.split('/').some(p => p === '..' || p === '')) die(`refusing path "${rel}"`);
|
|
99
|
+
const parts = rel.split('/');
|
|
100
|
+
let cur = root;
|
|
101
|
+
for (let i = 0; i < parts.length; i++) {
|
|
102
|
+
cur = path.join(cur, parts[i]);
|
|
103
|
+
let st = null;
|
|
104
|
+
try { st = fs.lstatSync(cur); } catch (_) { st = null; }
|
|
105
|
+
if (st && st.isSymbolicLink()) die(`${path.relative(root, cur)} is a symlink; refusing to write through it`);
|
|
106
|
+
if (i < parts.length - 1) {
|
|
107
|
+
if (st && !st.isDirectory()) die(`${path.relative(root, cur)} exists and is not a directory`);
|
|
108
|
+
if (!st) fs.mkdirSync(cur);
|
|
109
|
+
} else {
|
|
110
|
+
if (!(cur + path.sep).startsWith(root + path.sep)) die(`"${rel}" resolves outside the install folder`);
|
|
111
|
+
return { full: cur, exists: !!st };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
die('unreachable');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* safeDest without the mkdir: the same symlink and containment checks, nothing created. Used by the
|
|
118
|
+
preflight so a refusal leaves the folder exactly as it was. */
|
|
119
|
+
function probe(root, rel) {
|
|
120
|
+
if (path.isAbsolute(rel) || rel.split('/').some(p => p === '..' || p === '')) die(`refusing path "${rel}"`);
|
|
121
|
+
const parts = rel.split('/');
|
|
122
|
+
let cur = root;
|
|
123
|
+
for (let i = 0; i < parts.length; i++) {
|
|
124
|
+
cur = path.join(cur, parts[i]);
|
|
125
|
+
let st = null;
|
|
126
|
+
try { st = fs.lstatSync(cur); } catch (_) { st = null; }
|
|
127
|
+
if (st && st.isSymbolicLink()) die(`${path.relative(root, cur)} is a symlink; refusing to write through it`);
|
|
128
|
+
if (i < parts.length - 1) { if (st && !st.isDirectory()) die(`${path.relative(root, cur)} exists and is not a directory`); if (!st) return { full: path.join(root, rel), exists: false }; }
|
|
129
|
+
else { if (!(cur + path.sep).startsWith(root + path.sep)) die(`"${rel}" resolves outside the install folder`); return { full: cur, exists: !!st }; }
|
|
130
|
+
}
|
|
131
|
+
die('unreachable');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function copyIfAbsent(src, root, rel) {
|
|
135
|
+
const { full, exists } = safeDest(root, rel);
|
|
136
|
+
if (exists) { console.log(`kept ${rel} (exists)`); return false; }
|
|
137
|
+
fs.copyFileSync(src, full, fs.constants.COPYFILE_EXCL);
|
|
138
|
+
console.log(`wrote ${rel}`);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function main() {
|
|
143
|
+
const interactive = process.stdin.isTTY && !!!ARGS['--yes'];
|
|
144
|
+
let dir = arg('--dir', null);
|
|
145
|
+
let ais = arg('--ai', null);
|
|
146
|
+
let level = arg('--level', null);
|
|
147
|
+
|
|
148
|
+
if (interactive) {
|
|
149
|
+
console.log('\nagent-personalizer\n');
|
|
150
|
+
dir = dir || await ask('Folder to install into', '.');
|
|
151
|
+
console.log('\nWhich AIs do you use? Comma-separated from:');
|
|
152
|
+
for (const k of AIS) console.log(` ${k.padEnd(8)} ${AI_LABEL[k]}`);
|
|
153
|
+
ais = ais || await ask('\nAIs', 'claude,agents');
|
|
154
|
+
console.log('\nLevels: 1 one file · 2 dynamic docs · 3 mechanisms (renderer, hook, check) · 4 hand-off pointers');
|
|
155
|
+
level = level || await ask('Level', '1');
|
|
156
|
+
}
|
|
157
|
+
if (!dir || !ais || !level) die('non-interactive run needs --dir, --ai and --level (and --yes)');
|
|
158
|
+
if (!/^[1-4]$/.test(String(level))) die('level must be exactly 1, 2, 3 or 4');
|
|
159
|
+
level = Number(level);
|
|
160
|
+
const targets = String(ais).split(',').map(s => s.trim()).filter(Boolean);
|
|
161
|
+
const bad = targets.filter(t => !AIS.includes(t));
|
|
162
|
+
if (bad.length) die(`unknown AI: ${bad.join(', ')} (known: ${AIS.join(', ')})`);
|
|
163
|
+
if (!targets.length) die('no AIs chosen');
|
|
164
|
+
if (new Set(targets).size !== targets.length) die(`an AI is listed twice in --ai (${targets.join(',')}); list each once`);
|
|
165
|
+
|
|
166
|
+
// Onboarding answers: a file, the defaults, or the interview. Validated before anything is created.
|
|
167
|
+
let answers = null, answersSource = '';
|
|
168
|
+
const answersFile = arg('--answers', null);
|
|
169
|
+
if (answersFile && arg('--defaults', false)) die('--answers and --defaults are exclusive');
|
|
170
|
+
if (arg('--quick', false) && (answersFile || arg('--defaults', false) || !interactive)) die('--quick is the short interview; it needs a terminal and no --answers, --defaults or --yes');
|
|
171
|
+
if (answersFile) {
|
|
172
|
+
let raw;
|
|
173
|
+
const label = answersFile === '-' ? 'stdin' : answersFile;
|
|
174
|
+
try { raw = JSON.parse(answersFile === '-' ? fs.readFileSync(0, 'utf8') : fs.readFileSync(path.resolve(answersFile), 'utf8')); } catch (e) { die(`--answers: cannot read ${label} as JSON (${e.message})`); }
|
|
175
|
+
try { answers = onboarding.validate(raw); } catch (e) { die(`--answers: ${e.message}`); }
|
|
176
|
+
answersSource = `from ${label}`;
|
|
177
|
+
} else if (arg('--defaults', false) || !interactive) {
|
|
178
|
+
answers = onboarding.defaults();
|
|
179
|
+
answersSource = 'defaults (pass --answers <file.json>, or run without --yes, to answer the interview)';
|
|
180
|
+
} else {
|
|
181
|
+
const quick = !!arg('--quick', false);
|
|
182
|
+
console.log(`\nOnboarding: how should an AI work with you? Enter accepts the default in brackets.${quick ? ' Quick interview: 7 questions, the rest default.' : ` ${onboarding.QUESTIONS.length} questions; --quick asks 7.`}\n`);
|
|
183
|
+
const raw = {};
|
|
184
|
+
for (const q of onboarding.QUESTIONS) {
|
|
185
|
+
if (quick && !onboarding.QUICK.includes(q.id)) continue;
|
|
186
|
+
if (q.options) for (const [v, l] of q.options) console.log(` ${v.padEnd(30)} ${l}`);
|
|
187
|
+
const dflt = Array.isArray(q.default) ? q.default.join(', ') : q.default;
|
|
188
|
+
raw[q.id] = onboarding.parseAnswer(q, await ask(q.ask, dflt || ''));
|
|
189
|
+
}
|
|
190
|
+
try { answers = onboarding.validate(raw); } catch (e) { die(`onboarding: ${e.message}`); }
|
|
191
|
+
answersSource = quick ? 'your quick-interview answers (the rest are defaults)' : 'your interview answers';
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The folder you name is followed once (realpath of its deepest EXISTING ancestor); the
|
|
195
|
+
// missing tail is created one level at a time, so nothing is ever created through a
|
|
196
|
+
// symlink that did not exist when you ran the command. Everything beneath root is then
|
|
197
|
+
// symlink-free by construction (safeDest refuses any).
|
|
198
|
+
const requested = path.resolve(String(dir));
|
|
199
|
+
let existing = requested; const missing = [];
|
|
200
|
+
while (!fs.existsSync(existing)) { missing.unshift(path.basename(existing)); const parent = path.dirname(existing); if (parent === existing) die(`cannot create ${requested}`); existing = parent; }
|
|
201
|
+
let root = fs.realpathSync(existing);
|
|
202
|
+
for (const part of missing) { root = path.join(root, part); fs.mkdirSync(root); }
|
|
203
|
+
if (!fs.lstatSync(root).isDirectory()) die(`--dir ${requested} is not a directory`);
|
|
204
|
+
// Config: the one file this installer rewrites. Read and VALIDATED here, before the first write, so a malformed
|
|
205
|
+
// stored config refuses the whole run and leaves the folder untouched. Existing onboarding answers are kept unless
|
|
206
|
+
// --answers or the interview supplied new ones; targets are merged; "onboarding" is always a target.
|
|
207
|
+
const { full: cfgPath, exists: cfgExists } = probe(root, '.agent-personalizer.json');
|
|
208
|
+
let cfg = { targets: [], level };
|
|
209
|
+
let prevAnswers = null;
|
|
210
|
+
if (cfgExists) {
|
|
211
|
+
try { cfg = JSON.parse(fs.readFileSync(cfgPath, 'utf8')); } catch (e) { die(`.agent-personalizer.json is not valid JSON (${e.message}); fix or remove it`); }
|
|
212
|
+
if (!cfg || typeof cfg !== 'object' || Array.isArray(cfg)) die('.agent-personalizer.json must be an object');
|
|
213
|
+
if ('targets' in cfg) {
|
|
214
|
+
if (!Array.isArray(cfg.targets)) die('.agent-personalizer.json "targets" must be a list');
|
|
215
|
+
const KNOWN = [...AIS, 'onboarding'];
|
|
216
|
+
const bad = cfg.targets.filter(t => !KNOWN.includes(t));
|
|
217
|
+
if (bad.length) die(`.agent-personalizer.json lists unknown target(s): ${bad.join(', ')} (known: ${KNOWN.join(', ')}); fix or remove them`);
|
|
218
|
+
if (new Set(cfg.targets).size !== cfg.targets.length) die('.agent-personalizer.json lists a target twice');
|
|
219
|
+
}
|
|
220
|
+
if ('level' in cfg && !(Number.isInteger(cfg.level) && cfg.level >= 1 && cfg.level <= 4)) die(`.agent-personalizer.json "level" must be an integer 1-4 (found ${JSON.stringify(cfg.level)})`);
|
|
221
|
+
if (cfg.onboarding) {
|
|
222
|
+
try { prevAnswers = onboarding.validate(cfg.onboarding); } catch (e) { die(`.agent-personalizer.json onboarding answers: ${e.message}`); }
|
|
223
|
+
if (!answersFile && answersSource.startsWith('defaults')) { answers = prevAnswers; answersSource = 'kept from .agent-personalizer.json'; }
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const allTargets = [...new Set([...(Array.isArray(cfg.targets) ? cfg.targets : []), ...targets, 'onboarding'])];
|
|
227
|
+
const base = onboarding.baseFor(answers); // the folder scaffolds and home-file pointers use
|
|
228
|
+
const kind = onboarding.kindOf(answers);
|
|
229
|
+
|
|
230
|
+
console.log(`\nInstalling level ${level} for ${targets.join(', ')} into ${root}\nOnboarding answers: ${answersSource}\n`);
|
|
231
|
+
|
|
232
|
+
// ---- PLAN: every file this run would create, computed before anything is written ----
|
|
233
|
+
const plan = []; // { rel, src | text }
|
|
234
|
+
// signature=no: the signature rule file is not installed (a `requires:` rule that is absent cannot drift back in),
|
|
235
|
+
// and every copied markdown loses its `Last edited by:` template line and its pointer to the rule.
|
|
236
|
+
const noSig = answers.signature === 'no';
|
|
237
|
+
const stripSig = (t) => noSig ? t.split('\n').filter(l => !l.includes('40-sign-every-edit.md') && !/^Last edited by:/.test(l)).join('\n') : t;
|
|
238
|
+
const mdCopy = (rel, src) => plan.push({ rel, text: stripSig(fs.readFileSync(src, 'utf8')) });
|
|
239
|
+
// rules/ is copied at level 3, where it becomes yours to edit; levels 1 and 2 render from the package's rules
|
|
240
|
+
if (level >= 3) for (const f of fs.readdirSync(path.join(PKG, 'rules')).sort()) {
|
|
241
|
+
if (noSig && f === '40-sign-every-edit.md') continue;
|
|
242
|
+
mdCopy(`rules/${f}`, path.join(PKG, 'rules', f));
|
|
243
|
+
}
|
|
244
|
+
const home = (name) => {
|
|
245
|
+
let t = fs.readFileSync(path.join(PKG, 'templates', name), 'utf8');
|
|
246
|
+
if (level < 3) {
|
|
247
|
+
// no local rules/: the pointers point at the rendered block below, which carries the full text
|
|
248
|
+
t = t.split('\n').filter(l => !/Rules, one file each, the owning copy/.test(l)).join('\n');
|
|
249
|
+
t = t.replace(/`\[owner: rules\/[^\]]+\]`/g, '`[owner: the rendered block below]`');
|
|
250
|
+
}
|
|
251
|
+
if (kind === 'disk') { if (base !== 'notes') t = t.replace(/\bnotes\//g, `${base}/`); }
|
|
252
|
+
else {
|
|
253
|
+
// cloud, read-only and unknown tools: one line pointing at the onboarding file instead of four local paths
|
|
254
|
+
const tool = onboarding.kindOf(answers) === 'cloud' ? 'reached through its connector, no local files' : 'local fallback folder `notes/`';
|
|
255
|
+
let done = false;
|
|
256
|
+
t = t.split('\n').filter(l => { if (!/`notes\//.test(l)) return true; if (done) return false; done = true; return true; })
|
|
257
|
+
.map(l => /`notes\//.test(l) ? `- Notes: see \`AGENT_ONBOARDING.md\` § Where you may write (${tool})` : l).join('\n');
|
|
258
|
+
}
|
|
259
|
+
return stripSig(t);
|
|
260
|
+
};
|
|
261
|
+
if (targets.includes('claude')) plan.push({ rel: 'CLAUDE.md', text: home('CLAUDE.md') });
|
|
262
|
+
if (targets.includes('agents')) plan.push({ rel: 'AGENTS.md', text: home('AGENTS.md') });
|
|
263
|
+
if (level >= 2 && kind !== 'cloud') { // a cloud tool's notes are not local files; no folder named after a workspace
|
|
264
|
+
mdCopy(`${base}/README.md`, path.join(PKG, 'templates', 'FOLDER_README.md'));
|
|
265
|
+
mdCopy(`${base}/sessions/TEMPLATE-week.md`, path.join(PKG, 'templates', 'session-log.md'));
|
|
266
|
+
mdCopy(`${base}/decisions.md`, path.join(PKG, 'templates', 'decisions-log.md'));
|
|
267
|
+
mdCopy(`${base}/inbox/README.md`, path.join(PKG, 'templates', 'INBOX_README.md'));
|
|
268
|
+
}
|
|
269
|
+
if (level >= 3) {
|
|
270
|
+
for (const rel of ['render/render.cjs', 'render/targets.json', 'render/onboarding.cjs', 'hooks/README.md', 'hooks/claude-code/session-start.sh', 'check/gate.cjs', 'check/forbidden.example.txt'])
|
|
271
|
+
plan.push({ rel, src: path.join(PKG, rel) });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ---- PREFLIGHT: refuse now, with nothing written, everything the renderer would refuse later ----
|
|
275
|
+
for (const p of plan) probe(root, p.rel); // symlinks and non-directories on the way
|
|
276
|
+
// sources already in the folder (a kept rules/ file, a kept USER.md): parsed exactly as the renderer will parse them
|
|
277
|
+
markers.DIE_THROWS = true;
|
|
278
|
+
try { markers.preflightSources(root); }
|
|
279
|
+
catch (e) { if (e instanceof markers.Refusal) die(`${e.message}. The renderer would refuse this folder; nothing was written`); throw e; }
|
|
280
|
+
finally { markers.DIE_THROWS = false; }
|
|
281
|
+
const TARGETS = JSON.parse(fs.readFileSync(path.join(PKG, 'render', 'targets.json'), 'utf8'));
|
|
282
|
+
for (const t of allTargets) {
|
|
283
|
+
const rel = TARGETS[t].file;
|
|
284
|
+
const { full, exists } = probe(root, rel);
|
|
285
|
+
if (exists) {
|
|
286
|
+
const st = fs.lstatSync(full);
|
|
287
|
+
if (!st.isFile()) die(`${rel} exists and is not a regular file; nothing was written`);
|
|
288
|
+
let text; try { text = new TextDecoder('utf-8', { fatal: true }).decode(fs.readFileSync(full)); } catch (_) { die(`${rel} is not valid UTF-8; the renderer would refuse it. Nothing was written`); }
|
|
289
|
+
const ms = markers.markerState(text, rel);
|
|
290
|
+
if (ms.kind === 'malformed') die(`${rel}: malformed marker block (${ms.begins} begin, ${ms.ends} end). Fix it by hand; nothing was written`);
|
|
291
|
+
try { fs.accessSync(full, fs.constants.W_OK); } catch (_) { die(`${rel} is not writable; nothing was written`); }
|
|
292
|
+
} else {
|
|
293
|
+
// the nearest existing ancestor must be writable (the renderer creates the file there)
|
|
294
|
+
let d = path.dirname(full); while (!fs.existsSync(d)) d = path.dirname(d);
|
|
295
|
+
try { fs.accessSync(d, fs.constants.W_OK); } catch (_) { die(`${path.relative(root, d) || '.'} is not writable; nothing was written`); }
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// USER.md: yours once it exists. Regenerated only when it still equals the render of the PREVIOUS
|
|
299
|
+
// answers byte for byte (you never touched it) and the answers changed. Otherwise kept, and any
|
|
300
|
+
// changed answer that the kept file still carries the old value of is named as a conflict.
|
|
301
|
+
const user = probe(root, 'USER.md');
|
|
302
|
+
let userAction = 'create';
|
|
303
|
+
const changedKeys = prevAnswers ? Object.keys(answers).filter(k => JSON.stringify(answers[k]) !== JSON.stringify(prevAnswers[k])) : [];
|
|
304
|
+
if (user.exists) {
|
|
305
|
+
if (!fs.lstatSync(user.full).isFile()) die('USER.md exists and is not a regular file');
|
|
306
|
+
if (changedKeys.length) {
|
|
307
|
+
const current = fs.readFileSync(user.full, 'utf8');
|
|
308
|
+
userAction = current === onboarding.renderUser(prevAnswers) ? 'regenerate' : 'conflict';
|
|
309
|
+
} else userAction = 'keep';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Upgrade from level 1 or 2: the home files' pointer lines the installer wrote say "the rendered block
|
|
313
|
+
// below"; now that rules/ arrives, the same lines are repointed at their files. Only lines that equal an
|
|
314
|
+
// installer-written line byte for byte are touched; anything the user edited is left alone.
|
|
315
|
+
const upgrades = [];
|
|
316
|
+
if (level >= 3) for (const name of ['CLAUDE.md', 'AGENTS.md']) {
|
|
317
|
+
if (!(name === 'CLAUDE.md' ? targets.includes('claude') : targets.includes('agents'))) continue;
|
|
318
|
+
const { full, exists } = probe(root, name);
|
|
319
|
+
if (!exists || !fs.lstatSync(full).isFile()) continue;
|
|
320
|
+
const tmpl = stripSig(fs.readFileSync(path.join(PKG, 'templates', name), 'utf8')).split('\n');
|
|
321
|
+
const cur = fs.readFileSync(full, 'utf8');
|
|
322
|
+
const lines = cur.split('\n');
|
|
323
|
+
let changed = false;
|
|
324
|
+
for (const t of tmpl) {
|
|
325
|
+
if (!/`\[owner: rules\/[^\]]+\]`/.test(t)) continue;
|
|
326
|
+
const placeholder = t.replace(/`\[owner: rules\/[^\]]+\]`/g, '`[owner: the rendered block below]`');
|
|
327
|
+
for (let i = 0; i < lines.length; i++) if (lines[i] === placeholder) { lines[i] = t; changed = true; }
|
|
328
|
+
}
|
|
329
|
+
const rulesLine = tmpl.find(l => /Rules, one file each, the owning copy/.test(l));
|
|
330
|
+
const anchorIdx = lines.findIndex(l => /AGENT_ONBOARDING\.md`$/.test(l) && /^- /.test(l));
|
|
331
|
+
if (rulesLine && !lines.includes(rulesLine) && anchorIdx !== -1 && changed) { lines.splice(anchorIdx + 1, 0, rulesLine); }
|
|
332
|
+
if (changed) { try { fs.accessSync(full, fs.constants.W_OK); } catch (_) { die(`${name} is not writable; nothing was written`); } upgrades.push({ name, full, text: lines.join('\n') }); }
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ---- WRITE ----
|
|
336
|
+
for (const u of upgrades) { fs.writeFileSync(u.full, u.text); console.log(`update ${u.name} (rule pointers now name rules/, which this level installs)`); }
|
|
337
|
+
if (userAction === 'create') { fs.writeFileSync(user.full, onboarding.renderUser(answers), { flag: 'wx' }); console.log('wrote USER.md (from your answers)'); }
|
|
338
|
+
else if (userAction === 'regenerate') { fs.writeFileSync(user.full, onboarding.renderUser(answers)); console.log(`update USER.md (regenerated: it matched your previous answers byte for byte; changed: ${changedKeys.join(', ')})`); }
|
|
339
|
+
else if (userAction === 'conflict') {
|
|
340
|
+
console.log(`kept USER.md (you edited it, so it was not regenerated)`);
|
|
341
|
+
console.log(` ANSWERS CHANGED: ${changedKeys.join(', ')}. USER.md still carries the old value(s) and the rendered profile sections come from USER.md.`);
|
|
342
|
+
console.log(` Fix by hand, or delete USER.md and re-run to regenerate it from the new answers. AGENT_ONBOARDING.md already carries the new answers.`);
|
|
343
|
+
} else console.log('kept USER.md (exists)');
|
|
344
|
+
for (const p of plan) {
|
|
345
|
+
if (p.src) copyIfAbsent(p.src, root, p.rel);
|
|
346
|
+
else {
|
|
347
|
+
const { full, exists } = safeDest(root, p.rel);
|
|
348
|
+
if (exists) console.log(`kept ${p.rel} (exists)`);
|
|
349
|
+
else { fs.writeFileSync(full, p.text, { flag: 'wx' }); console.log(`wrote ${p.rel}`); }
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (level >= 3) {
|
|
353
|
+
const hp = path.join(root, 'hooks', 'claude-code', 'session-start.sh');
|
|
354
|
+
const st = fs.lstatSync(hp);
|
|
355
|
+
if (!st.isFile() || st.isSymbolicLink()) die('hook file changed underneath the installer; not chmod-ing it');
|
|
356
|
+
fs.chmodSync(hp, 0o755);
|
|
357
|
+
}
|
|
358
|
+
cfg = { ...cfg, targets: allTargets, level: Math.max(level, cfg.level || 0), onboarding: onboarding.sparse(answers) }; // only what differs from the defaults
|
|
359
|
+
fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + '\n');
|
|
360
|
+
console.log(`${cfgExists ? 'update' : 'wrote '} .agent-personalizer.json (onboarding: ${answersSource})`);
|
|
361
|
+
|
|
362
|
+
// Render the FULL merged target list (what a plain `render.cjs --dir .` will use from now on), from the package's renderer.
|
|
363
|
+
execFileSync(process.execPath, [path.join(PKG, 'render', 'render.cjs'), '--dir', root, '--targets', allTargets.join(',')], { stdio: 'inherit' });
|
|
364
|
+
|
|
365
|
+
const DOCS = onboarding.DOCS;
|
|
366
|
+
// the rerun command a user can actually type: the npx form when this ran from npm's cache, else the local path that just worked
|
|
367
|
+
const SELF = /[\\/]_npx[\\/]|[\\/]node_modules[\\/]/.test(PKG) ? 'npx github:aunysillyme/agent-personalizer' : `node ${path.relative(process.cwd(), path.join(PKG, 'bin', 'agent-personalizer.js')) || 'bin/agent-personalizer.js'}`;
|
|
368
|
+
console.log('\nNext:');
|
|
369
|
+
console.log(' 1. Read AGENT_ONBOARDING.md once: that is what every AI will be told about working with you. Re-run this installer with new answers to change it.');
|
|
370
|
+
console.log(' USER.md is yours to edit freely; the onboarding file is regenerated from .agent-personalizer.json.');
|
|
371
|
+
console.log(level >= 3
|
|
372
|
+
? ' 2. Re-render after editing: node render/render.cjs --dir . (drift check: add --check)'
|
|
373
|
+
: ` 2. Re-render after editing by running this installer again (it keeps your files and only refreshes the rendered blocks):\n ${SELF} --dir . --ai ${targets.join(',')} --level ${level} --yes`);
|
|
374
|
+
if (level >= 2 && kind !== 'cloud') console.log(` 3. Read ${base}/README.md before letting an AI write into ${base}/.`);
|
|
375
|
+
if (level >= 3) console.log(' 4. Register hooks/claude-code/session-start.sh (see hooks/README.md) and copy check/forbidden.example.txt to check/forbidden.local.txt.');
|
|
376
|
+
if (level >= 4) console.log(' 5. Level 4 is pointers only for now: routing, task bundles and verified CLI runs live in the multi-agent layer, linked from the README when it ships.');
|
|
377
|
+
if (answers.notes_tool === 'obsidian') console.log(answers.obsidian_tc === 'yes'
|
|
378
|
+
? `\nCompanion: the onboarding file routes the AI through obsidian-tc; configure its folder ACLs from your off-limits answer and its human-in-the-loop list from your always-ask answer. See ${DOCS}/companions.md`
|
|
379
|
+
: `\nCompanion: your notes are an Obsidian vault and the AI will work on the folder directly. obsidian-tc would give it governed access (folder ACLs, human-in-the-loop, audit log): \`npx obsidian-tc /path/to/vault\`, then re-run this installer and answer yes. See ${DOCS}/companions.md`);
|
|
380
|
+
else if (answers.notes_tool === 'notion' || answers.notes_tool === 'google-docs') console.log(`\nCompanion: connect ${answers.notes_tool === 'notion' ? 'Notion' : 'Google Drive / Docs'} through your AI's own connector settings (where the app offers one); the onboarding file already names the door and the write posture, and tells the AI to make no filesystem writes for these notes. See ${DOCS}/companions.md`);
|
|
381
|
+
else if (answers.notes_tool === 'apple-notes') console.log(`\nCompanion: Apple Notes needs a separately installed local Apple Notes MCP; no AI app ships one built in. Until you connect one, the onboarding file already limits the AI to reading and creating new notes. See ${DOCS}/companions.md`);
|
|
382
|
+
else if (answers.notes_tool === 'other') console.log(`\nNote: "${answers.notes_tool_name || 'your notes tool'}" is unknown to this kit; the onboarding file tells the AI to ask before its first write there and to use the local fallback folder notes/ meanwhile.`);
|
|
383
|
+
else if (['onenote', 'evernote'].includes(answers.notes_tool)) console.log(`\nNote: ${answers.notes_tool} has no first-class agent door today; the onboarding file treats it as read-only. See ${DOCS}/companions.md`);
|
|
384
|
+
console.log(`Several agents? Read ${DOCS}/companions.md on the Context Layer: purpose-bound bundles and receipts for every delegation.`);
|
|
385
|
+
console.log('\nNothing here read an environment variable or wrote a secret.');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
main().catch(e => { if (e && e.status !== undefined) process.exit(e.status || 1); console.error(e.message); process.exit(1); });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copy this file to check/forbidden.local.txt and fill it in. The local file is
|
|
2
|
+
# gitignored on purpose: a list of your own identifiers must never ship in a
|
|
3
|
+
# public repo. The gate refuses to pass when the local file is missing.
|
|
4
|
+
#
|
|
5
|
+
# One term per line. Matching is case-insensitive substring. Blank lines and
|
|
6
|
+
# lines starting with # are ignored.
|
|
7
|
+
#
|
|
8
|
+
# allow:<exact text> whitelists that exact string wherever it appears. Use it
|
|
9
|
+
# only for attribution lines you have decided to keep (a licence copyright, a
|
|
10
|
+
# repo URL). Everything else about you stays forbidden.
|
|
11
|
+
|
|
12
|
+
# your names, handles, legal entities
|
|
13
|
+
Your Name
|
|
14
|
+
yourhandle
|
|
15
|
+
Your Company LLC
|
|
16
|
+
|
|
17
|
+
# your domains and emails
|
|
18
|
+
yourdomain.com
|
|
19
|
+
you@yourdomain.com
|
|
20
|
+
|
|
21
|
+
# clients, partners, private projects, private folder names
|
|
22
|
+
Client One
|
|
23
|
+
Project Codename
|
|
24
|
+
|
|
25
|
+
# infrastructure that identifies you
|
|
26
|
+
your-server-hostname
|
|
27
|
+
10.0.0.1
|
|
28
|
+
|
|
29
|
+
# attribution you keep on purpose
|
|
30
|
+
allow:Copyright (c) 2026 yourhandle
|
|
31
|
+
allow:https://github.com/yourhandle/your-repo
|