@shadowclone/cli 0.0.5 → 0.0.7

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.
@@ -11,6 +11,16 @@
11
11
  ]
12
12
  }
13
13
  ],
14
+ "SubagentStart": [
15
+ {
16
+ "hooks": [
17
+ {
18
+ "type": "command",
19
+ "command": "bun run \"${CLAUDE_PLUGIN_ROOT}/dist/shadowclone.js\" hook session-start"
20
+ }
21
+ ]
22
+ }
23
+ ],
14
24
  "SessionEnd": [
15
25
  {
16
26
  "hooks": [
package/README.md CHANGED
@@ -1,196 +1,104 @@
1
1
  # shadowclone
2
2
 
3
- Memory and alignment compiler for AI coding agents.
3
+ Shadowclone learns engineering preferences from coding-agent sessions you choose to share with it. It turns explicit guidance and corrections into an editable profile, and keeps a portable personal skill library in sync. Claude Code, Codex, Cursor, and Antigravity can receive that profile in ordinary sessions. Supported delegated runs use the same guidance.
4
4
 
5
- Shadowclone reads historical coding sessions already on your disk (Claude Code, Codex, Cursor), mines your steering habits without sending raw transcripts to any server, and compiles an editable profile into the agents you already use.
5
+ The profile adds context to an existing model; it does not train a new one or guarantee that every instruction will be followed. With separate learning consent, useful sessions can update the guidance for later work. [Why I built it](docs/motivation.md).
6
6
 
7
- Developers who install the profile see a measurable action delta against unprofiled runs on their held-out corpus: the agent stops asking for confirmations you never gave, runs the tests you run, and avoids the tools you refuse.
7
+ ## Privacy comes first
8
8
 
9
- Verify the delta directly on your own machine:
9
+ Every source has its own setting, defaults off, and appears by name before consent. The default setup asks one grouped question for detected session sources, Git remote names, and existing agent context. It asks separately about skills and background learning. `init --advanced` offers individual source choices. The paths that may be read are:
10
10
 
11
- ```bash
12
- shadowclone eval --sessions 10
13
- ```
14
-
15
- ## Architectural scope: what shadowclone is and is not
16
-
17
- **Not an agent runtime.**
18
- Shadowclone does not provide an LLM chat loop, an autonomous worker daemon, or an IDE extension. It compiles behavioral profiles and subagents for the agent CLIs you already install, authenticate, and pay for.
19
-
20
- **A memory and alignment compiler.**
21
- Every turn where you interrupted an agent, refused a tool, corrected a proposal, or chose one implementation over another is an alignment signal. Shadowclone indexes those moments locally and distills them into plain markdown rules scoped by repository origin.
22
-
23
- ## The pipeline
24
-
25
- ```
26
- observe -> index -> signal -> distill -> profile -> dispatch / eval
27
- | |
28
- zero tokens user's subscription
29
- ```
30
-
31
- | Stage | Module | Function |
32
- | --- | --- | --- |
33
- | observe | `src/observe/` | Normalizes agent transcripts into one incremental event stream |
34
- | index | `src/index/` | Rebuildable SQLite cache of byte offsets and event kinds, never text |
35
- | signal | `src/signal/` | Detects interruptions, plan changes, and tool refusals in pure code |
36
- | distill | `src/distill/` | Distills high-signal moments into rules via your installed agent CLI |
37
- | profile | `src/profile/` | Plain markdown rules and subagents scoped to git origins |
38
- | dispatch | `src/dispatch/` | Executes unattended tasks on isolated worktrees with receipts |
39
- | eval | `src/eval/` | Replays historical prompts through baseline vs clone to score behavioral deltas |
40
-
41
- Model calls run through `claude`, `codex`, or `cursor-agent`. There is no shadowclone API key, no telemetry, and no hosted server.
11
+ | Source | Path |
12
+ | --- | --- |
13
+ | Claude Code sessions | `~/.claude/projects/` |
14
+ | Claude prompt history | `~/.claude/history.jsonl` |
15
+ | Codex sessions | `~/.codex/sessions/` or `$CODEX_HOME/sessions/` when set |
16
+ | Cursor chats | `~/.cursor/chats/` |
17
+ | Antigravity logs | `~/.gemini/antigravity-cli/brain/` |
18
+ | Shell history | `~/.zsh_history`, `~/.bash_history` |
19
+ | Repository guidance | root `CLAUDE.md`, `AGENTS.md`, `.cursorrules`, and direct `SKILL.md` files under `.claude/skills/` and `.agents/skills/` |
20
+ | Agent context | `~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md`, `~/.codex/AGENTS.override.md`, supported personal and repository skill roots, and `~/.claude/projects/<repo>/memory/` or `~/.codex/memories/`, only for consented evaluation |
21
+ | Skill library | `~/.claude/skills/`, `~/.agents/skills/`, `~/.codex/skills/`, `~/.cursor/skills/`, `~/.gemini/config/skills/`, configured repository roots, and selected provider plugin caches |
22
+ | Git metadata | repository Git remote names |
42
23
 
43
- ## Quickstart
24
+ Source detection checks whether a configured root has content. A directory check reads at most one entry to establish that fact and retains no name before consent. Agent transcripts can contain private code, credentials, internal hosts, and customer data. Shadowclone never copies raw transcripts into its store. Its SQLite index holds pointers and event kinds. Eligible excerpts pass through `resolveRedacted`, the single secret-redaction gate, before a model receives them. Tool results, file-read contents, thinking blocks, and data-access results are excluded from learning by category.
44
25
 
45
- Install the global CLI:
46
-
47
- ```bash
48
- npm i -g @shadowclone/cli
49
- ```
26
+ Learning sends eligible redacted excerpts through your own authenticated agent CLI. Evaluation also gives that CLI access to a disposable repository snapshot and sends generated code to judges without redaction. Use only repositories you are authorized to send to that provider. A remote action from `shadowclone run` needs separate approval for that run. There is no Shadowclone service, API key, account, or telemetry. The profile is Markdown under `~/.shadowclone/profile/`; you can read, edit, or delete it. `shadowclone forget --all` removes Shadowclone's local state and recorded integrations, preserving unrelated content and stopping on conflicting edits. Your original transcripts remain where your agents wrote them. [Privacy design](docs/architecture/05-privacy.md).
50
27
 
51
- Verify your environment and supported provider CLIs:
52
-
53
- ```bash
54
- shadowclone doctor
55
- ```
56
-
57
- Grant consent for desired transcript sources:
28
+ ## Install
58
29
 
59
30
  ```bash
31
+ npm install -g @shadowclone/cli
60
32
  shadowclone init
61
33
  ```
62
34
 
63
- Every source is off until it is enabled here, and two of them read files that are not transcripts:
64
-
65
- - **`git-metadata`** reads the git remote origin of a working directory, so rules can be scoped to the organization they were learned from. Without it every directory is treated as its own isolated origin.
66
- - **`agent-context`** reads the user's own `CLAUDE.md` or `AGENTS.md`, their skill markdown, and their agent memory directory. It exists so a transfer evaluation can freeze the same setup for both arms, and it is read only by `shadowclone eval`. Contents pass through redaction before they are written into a snapshot.
67
-
68
- Index your historical sessions and build your profile:
69
-
70
- ```bash
71
- shadowclone learn
72
- ```
73
-
74
- To preview without writing files or databases:
75
-
76
- ```bash
77
- shadowclone learn --dry-run
78
- ```
79
-
80
- To enable deep distillation through your authenticated agent CLI:
35
+ The commands below use the installed `shadowclone` binary. From this checkout, use `bun run cli` in its place.
81
36
 
82
- ```bash
83
- shadowclone learn --deep
84
- ```
37
+ `init` shows the detected agents and source paths, then asks three questions, each defaulting to yes:
85
38
 
86
- Install the compiled profile into the current repository:
39
+ 1. Learn how you work from these sessions?
40
+ 2. Keep your skills in sync across the detected agents?
41
+ 3. Keep improving in the background as you work?
87
42
 
88
- ```bash
89
- shadowclone install
90
- ```
91
-
92
- This writes `.claude/agents/shadowclone.md` and excludes it from git tracking.
43
+ Only detected transcript sources are enabled by the first answer. Setup then imports supported repository guidance if present, synchronizes consented skills, runs a first learning pass when background learning is enabled, and installs global native guidance for detected agents. The first pass selects recent unprocessed steering and limits model calls to 12 or 90 seconds; scanning local transcripts can take longer. Reaching a model budget does not block setup. Later sessions continue bounded learning when the agent marks a useful session. No extra `learn` command is required to finish setup.
93
44
 
94
- ## Transfer evaluation
45
+ Use `shadowclone init --advanced` for individual source choices and the seed guidance wizard. Run `shadowclone wizard` later to change seed preferences and starter skills. Run `shadowclone skills configure --global` or `--repo` to configure skill roots separately. Managed policy may limit any setting.
95
46
 
96
- Shadowclone measures whether the profile changes behavior, against tasks the user actually asked for:
47
+ ## How it works
97
48
 
98
- ```bash
99
- shadowclone eval --tasks 5 --engine codex
49
+ ```text
50
+ enabled transcripts -> local index -> steering episodes -> redacted reconciliation
51
+ -> editable profile
52
+ profile + personal skills -> native agents and clones -> new transcripts
100
53
  ```
101
54
 
102
- The evaluator selects historical requests that name an identifiable starting commit, rebuilds each one as an isolated git snapshot at that commit, and runs the task twice:
103
- 1. **Baseline run:** the agent with frozen instructions and no profile.
104
- 2. **Clone run:** the same agent with the profile learned from sessions strictly earlier than the task.
55
+ Plain `shadowclone learn` updates the local index and prints a structural report without model calls or profile writes. `shadowclone learn --deep` works through the oldest unprocessed episodes in bounded batches, proposes changes, and asks before applying them. `--deep --apply` accepts that local write without a prompt. Explicit reusable guidance can become active from one session; inferred behavior needs three independent sessions. The processed ledger lets later runs continue through older history. `shadowclone remember --repo "Use complete variable names."` records a direct preference immediately.
105
56
 
106
- Arm order alternates between repetitions, and the profile is learned only from evidence that predates the task and shares no session with it.
57
+ The first setup pass starts at the newest unprocessed episodes so the next session can benefit quickly. Reconciliation batches run concurrently, then apply results in their original order. Completed checkpoints let a later run reuse finished model work. All model calls use `claude`, `codex`, or `cursor-agent` under your existing authentication.
107
58
 
108
- Each run is graded two ways. The repository's own `test` and `typecheck` scripts run inside a `sandbox-exec` or `bubblewrap` boundary with no network. A blind judge then grades the observed files and actions twice with the requirement order reversed, and any disagreement between the two passes is recorded as uncertain rather than resolved.
59
+ Repository imports preserve your edits and rejected rules. The compiler selects global guidance, the matching Git remote owner, and the exact repository. Without Git metadata consent, working directories stay isolated. It caps compiled guidance at 16 KiB and drops whole blocks when needed.
109
60
 
110
- The command previews how many agent invocations it may spend and asks before starting. Pass `--yes` to skip the prompt, or `--json` for machine-readable output.
61
+ Native installation adds a small pointer and lifecycle hooks while preserving other instructions. Claude Code's `SessionStart` hook injects the current scoped profile into the main agent. Its `SubagentStart` hook gives spawned subagents that same profile without creating another learning request. Codex, Cursor, and Antigravity use their supported native delivery paths. A useful main-agent session can request bounded learning at session end. `shadowclone install --subagent` and `--auto-delegate` remain optional Claude repository modes.
111
62
 
112
- Receipts are written to `~/.shadowclone/eval/<evalId>/receipt.json` after every run, so `--eval-id <id>` resumes an interrupted evaluation against the same frozen tasks.
63
+ Portable skills live in `~/.agents/skills` and sync to supported provider locations. A single edited copy becomes the source for the next sync; divergent edits are reported as conflicts. Existing user skills and plugin packages are preserved. Skill assessment reads only enabled roots, sends redacted `SKILL.md` content through the chosen agent CLI, and leaves technical or routing changes for review. [Skill maintenance](docs/skill-maintenance.md).
113
64
 
114
- ## Unattended dispatch
65
+ ## Check the result
115
66
 
116
- Execute tasks in an isolated git worktree without touching your working tree:
67
+ `shadowclone doctor` reports installation and engine status. `shadowclone context` prints the compiled profile for the current scope. `shadowclone history` shows local revisions, and `shadowclone undo <revision-id>` restores one when no later edit conflicts.
117
68
 
118
- ```bash
119
- shadowclone run "fix the flaky test in src/auth.test.ts"
120
- ```
121
-
122
- The default dispatch mode creates a local worktree and branch, runs verification checks, and commits locally without pushing.
123
-
124
- Remote actions (push, open PR) require both a repository ceiling in `~/.shadowclone/config.toml` and an explicit per-run approval flag:
69
+ Transfer evaluation compares three matched setups: repository guidance only, that guidance plus the existing personal skill/context library, and both plus the Shadowclone profile. It freezes a source-backed coding-preference rubric before execution and saves three blinded votes per check. Correctness is graded separately. Missing grades are reported as ungraded, and a completed evaluation does not require Clone to win. [Evaluation design](docs/architecture/09-evaluation.md).
125
70
 
126
71
  ```bash
127
- shadowclone run "prepare release notes" --approve push
72
+ shadowclone eval --repo /path/to/repository --engine codex --model gpt-5.6-sol --reasoning-effort medium --tasks 3 --repeat 2
128
73
  ```
129
74
 
130
- ## Ground-truth privacy
75
+ `shadowclone run "fix the flaky test"` runs a headless clone in a local worktree and records a receipt. The invocation approves one worktree, branch, and local commit. Remote actions also need a matching repository policy ceiling and `--approve` for that run. No action approval carries to the next run. [Acting policy](docs/architecture/04-acting.md).
131
76
 
132
- Agent transcripts contain private code, environment variables, internal hosts, and customer data. Shadowclone protects data through structural guarantees:
77
+ ## Early evaluation results
133
78
 
134
- **Pointers instead of text copies.**
135
- The SQLite index stores file offsets, timestamps, and event kinds. Raw transcripts are never duplicated to a secondary store.
79
+ Across four small TypeScript tasks using GPT-5.6 Sol at medium reasoning effort, the recorded preference scores were:
136
80
 
137
- **Sliced secret redaction.**
138
- Distillation excerpts pass through a deterministic sliced replacer before reaching any model. Secrets keep identifying prefixes (such as `AKIA` or `sk_live_`) while stripping high-entropy characters, keeping code context intact without leaking credentials.
81
+ | Repository only (Bare) | Personal skills/context (Skills) | Skills/context + profile (Clone) |
82
+ | ---: | ---: | ---: |
83
+ | 55/68 (80.9%) | 59/68 (86.8%) | 62/68 (91.2%) |
139
84
 
140
- **Shannon entropy layer.**
141
- Tokens of 24 characters or more that reach 4.5 bits of entropy per character are sliced under the `shannon-entropy` label, even when they match no known vendor pattern. Long identifiers, file paths, and UUIDs measure below that threshold and stay readable.
85
+ These are guideline checks passed, not correctness or productivity scores. The skills were existing user-written or user-guided instructions, potentially outdated and not tuned for this comparison. This was one implementation per arm per task, with known judging limitations. Read [the tasks, setup, results, and caveats](evals.md) before drawing broader conclusions.
142
86
 
143
- **Third-party tool results are excluded.**
144
- Distillation inputs allowlist user prompts and developer steering corrections. Tool outputs from database queries, log dumps, and file reads are excluded by category rather than relying on regex filtering.
145
-
146
- **Single-command wipe.**
147
- Wipe the entire local index, profile, checkpoints, and receipts:
148
-
149
- ```bash
150
- shadowclone forget --all
151
- ```
152
-
153
- ## Enterprise governance
154
-
155
- Security teams can enforce policy ceilings fleet-wide via root-owned managed configuration:
156
- - **macOS:** `/Library/Application Support/shadowclone/managed.json`
157
- - **Linux:** `/etc/shadowclone/managed.json`
158
-
159
- ```json
160
- {
161
- "enabled": true,
162
- "allowedSources": ["claude-code"],
163
- "allowedEngines": ["claude-code"],
164
- "distillation": "local-only",
165
- "originScope": "strict",
166
- "blockedOrigins": ["github.com/acme/security-*"],
167
- "maxActionTier": "draft"
168
- }
169
- ```
170
-
171
- Managed policies act as an absolute ceiling. Users cannot enable unapproved sources or engines, and `enabled: false` enforces an immediate stop across the machine.
172
-
173
- ## CLI commands
174
-
175
- ```bash
176
- shadowclone init # Configure source consent and capabilities
177
- shadowclone learn [--deep] [--dry-run] # Index sessions and synthesize rules
178
- shadowclone doctor # Inspect active paths, engines, and policies
179
- shadowclone install # Install profile as .claude/agents/shadowclone.md
180
- shadowclone run <task> [--approve <action>] # Dispatch headless clone in a worktree
181
- shadowclone eval [--sessions N] [--json] # Measure behavioral deltas against baseline
182
- shadowclone mcp # Start stdio Model Context Protocol server
183
- shadowclone forget --all # Remove ~/.shadowclone/ completely
184
- ```
185
-
186
- ## Contributing
187
-
188
- Review `CONTRIBUTING.md` and `SECURITY.md`. All contributions must pass:
189
-
190
- ```bash
191
- bun run check
192
- ```
87
+ ## Commands
193
88
 
194
- ## License
89
+ | Command | Use |
90
+ | --- | --- |
91
+ | `shadowclone init [--advanced]` | Set consent and install detected integrations |
92
+ | `shadowclone import`, `shadowclone wizard` | Refresh repository guidance or seed choices |
93
+ | `shadowclone learn [--deep] [--dry-run] [--apply]` | Inspect history or reconcile guidance |
94
+ | `shadowclone skills`, `shadowclone skills update` | List starter guidance or maintain consented skills |
95
+ | `shadowclone skills pending`, `show`, `apply`, `reject` | Review skill proposals |
96
+ | `shadowclone learning enable|disable|status` | Control session learning |
97
+ | `shadowclone doctor`, `shadowclone context`, `shadowclone sync` | Inspect or refresh delivery |
98
+ | `shadowclone install [--agent <agent>|all] [--global|--repo]` | Install native guidance manually |
99
+ | `shadowclone uninstall [--global]` | Remove owned integrations |
100
+ | `shadowclone remember`, `history`, `undo` | Manage direct rules and revisions |
101
+ | `shadowclone eval`, `shadowclone run <task>` | Measure transfer or run a local clone |
102
+ | `shadowclone forget --all` | Remove all recorded Shadowclone state |
195
103
 
196
- MIT. See `LICENSE`.
104
+ Contributors can run `bun install` and `bun run check`. See [the architecture](docs/architecture/README.md), [design records](docs/design/README.md), [contribution guide](CONTRIBUTING.md), and [security policy](SECURITY.md). Shadowclone is MIT licensed.