human-hindsight 0.0.0-stage → 1.6.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cc-hindsight contributors
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 CHANGED
@@ -1,3 +1,381 @@
1
- # Temporary Holding Version
1
+ # Human Hindsight
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **The prompt you'd write if you knew then what you know now.**
4
+
5
+ [![npm](https://img.shields.io/npm/v/human-hindsight?color=cb3837&logo=npm)](https://www.npmjs.com/package/human-hindsight)
6
+ [![CI](https://github.com/adityaarunsinghal/human-hindsight/actions/workflows/ci.yml/badge.svg)](https://github.com/adityaarunsinghal/human-hindsight/actions/workflows/ci.yml)
7
+ [![node](https://img.shields.io/node/v/human-hindsight?logo=node.js&color=339933)](https://nodejs.org)
8
+ [![license](https://img.shields.io/github/license/adityaarunsinghal/human-hindsight?color=blue)](LICENSE)
9
+ [![local-first](https://img.shields.io/badge/data-local--only-brightgreen)](#privacy--trust)
10
+
11
+ <p align="center">
12
+ <img src="https://raw.githubusercontent.com/adityaarunsinghal/human-hindsight/main/.github/assets/demo.gif" alt="Human Hindsight local prompt library" width="800">
13
+ </p>
14
+
15
+ ```bash
16
+ npx human-hindsight
17
+ ```
18
+
19
+ Human Hindsight mines your coding-agent session history (Claude Code, Codex, kiro-cli)
20
+ into two things you can use tomorrow morning:
21
+
22
+ 1. **A oneshot prompt library.** For each real task you've done, the realistic
23
+ ideal *first* prompt: everything you knew and wanted at t=0 but didn't say,
24
+ written in your own voice.
25
+ 2. **A distilled preference set.** The things you keep re-telling your agent
26
+ ("diagnose before acting", "pin the versions", "be terse"), surfaced as a
27
+ paste-ready `CLAUDE.md` or `AGENTS.md` block so every future session starts aligned.
28
+
29
+ Previously published as **cc-hindsight**. The `cc-hindsight` npm package is now a
30
+ deprecated compatibility command that forwards to the matching Human Hindsight
31
+ release. Existing libraries, edits, ratings, and checkpoints remain usable.
32
+
33
+ ### Upgrading from cc-hindsight
34
+
35
+ ```bash
36
+ npx human-hindsight@latest gui
37
+ # Or install the new command globally:
38
+ npm install -g human-hindsight
39
+ ```
40
+
41
+ No data move or re-distillation is required. Data-directory precedence is:
42
+ `--home` → `HUMAN_HINDSIGHT_HOME` → legacy `CC_HINDSIGHT_HOME` → an existing
43
+ `~/.human-hindsight` → an existing `~/.cc-hindsight` → `~/.human-hindsight` for
44
+ a fresh installation. If both directories exist, the new one wins; use
45
+ `--home` to choose explicitly. Directories are never merged automatically.
46
+
47
+ Updating the old npm package installs the small compatibility wrapper, so
48
+ `npx cc-hindsight@latest gui` also works. Both global commands can coexist:
49
+ the main package owns `human-hindsight`, and the wrapper owns `cc-hindsight`.
50
+ The GitHub repository was renamed in place; old repository links redirect.
51
+
52
+ ## The t=0 problem
53
+
54
+ You get better results the more context you front-load into your first prompt,
55
+ yet we underspecify at t=0 and spend the session steering: correcting course,
56
+ restating preferences, answering questions the agent shouldn't have had to ask.
57
+
58
+ And the cost repeats every session. Your working preferences are stable facts
59
+ about how you like to work, yet you re-derive and re-type them project after
60
+ project instead of stating them once, upfront, where every future session reads
61
+ them from the first message.
62
+
63
+ All the evidence of what you *should* have said is already on disk. Claude Code
64
+ saves session JSONL under `~/.claude/projects/`; Codex keeps rollouts under
65
+ `~/.codex/sessions/` and `~/.codex/archived_sessions/`; kiro-cli keeps its
66
+ own store under `~/.kiro/sessions` (both the flat `cli/<uuid>.jsonl` layout and
67
+ the newer per-session `<hash>/sess_<uuid>/messages.jsonl` layout). Plenty of
68
+ tools read that data for
69
+ dashboards and transcripts. **Nobody closes the loop from history back to
70
+ better prompting.**
71
+
72
+ **Before** (what you actually typed at t=0):
73
+
74
+ > help me script blocking a device on my home router
75
+
76
+ **After** (what human-hindsight distilled from how that session actually went):
77
+
78
+ > I want to automate my home router, starting with blocking a device. Get API
79
+ > access working first, and store any credentials securely instead of asking me
80
+ > to paste them in the clear. Anything that changes the network should be safe
81
+ > by default: show me what it'll do and let me confirm before it runs. Then
82
+ > prove it end-to-end on a real device. Research how others have done this
83
+ > first, and keep the setup written down so I can reproduce it.
84
+
85
+ The second prompt was knowable at t=0. You just hadn't written it yet.
86
+
87
+ ## Quickstart
88
+
89
+ One command builds the whole library and shows it to you when it's done:
90
+
91
+ ```bash
92
+ npx human-hindsight distill # offers to export first, then digest → cluster →
93
+ # author (asks before any runner call), then shows
94
+ # you the finished library
95
+ ```
96
+
97
+ Prefer to drive each stage yourself? The pipeline is just three verbs:
98
+
99
+ ```bash
100
+ npx human-hindsight # 1. scan: inventory your projects (read-only)
101
+ npx human-hindsight export # 2. export: human-only markdown per session
102
+ npx human-hindsight distill # 3. distill: digest → cluster → author (asks first)
103
+ ```
104
+
105
+ Then browse and curate the results:
106
+
107
+ ```bash
108
+ npx human-hindsight list # your library (✎ edited / ▲▼ rating badges)
109
+ npx human-hindsight gui # browse, search, and copy in your browser
110
+ npx human-hindsight show <slug> # read a oneshot
111
+ npx human-hindsight copy <slug> # → clipboard, paste into a fresh session
112
+ npx human-hindsight edit <slug> # open in $EDITOR; your edits are protected
113
+ npx human-hindsight rate <slug> up # record a verdict (up|down)
114
+ npx human-hindsight prune # remove orphaned entries (asks first)
115
+ npx human-hindsight preferences # → CLAUDE.md block
116
+ npx human-hindsight status # pipeline funnel + orphan/skip flags
117
+ npx human-hindsight retention # optional: preview longer local retention
118
+ ```
119
+
120
+ Requires Node ≥ 22 on macOS or Linux (Windows is untested and currently
121
+ unsupported). `scan` and `export` are fully deterministic: no LLM, no
122
+ network. `distill` uses your installed `claude`, `codex`, or `kiro-cli`,
123
+ with a consent prompt (or your explicit `--yes`).
124
+
125
+ ### A small local library viewer
126
+
127
+ ```bash
128
+ npx human-hindsight gui # start locally and open your browser
129
+ npx human-hindsight gui --no-open # print the address without opening it
130
+ npx human-hindsight gui --port 3210 # choose a port (default: any available port)
131
+ npx human-hindsight gui --home /path/to/library-home
132
+ ```
133
+
134
+ Search prompt titles and text, filter by domain, sort, and copy the prompt
135
+ body with one click. The viewer shows your existing library, including local
136
+ edits, ratings, and session counts. Use **Refresh** after changing files.
137
+ Light and dark appearance follow your system setting, and the layout works
138
+ on narrow screens. Press `/` to focus search.
139
+
140
+ The GUI uses Node's built-in HTTP server and bundled HTML/CSS/JavaScript:
141
+ no additional dependencies, frontend framework, database, or external assets.
142
+ It listens only on `127.0.0.1`, serves a read-only library API, and stops with
143
+ Ctrl+C. The GUI doesn't invoke an agent or modify your library.
144
+
145
+ ### Multiple backends (Claude Code + Codex + kiro-cli)
146
+
147
+ Every command takes `--source claude|codex|kiro|auto` (default `auto`: read
148
+ whichever stores exist). Select the source after the subcommand. Directory
149
+ flags work before or after it:
150
+
151
+ | Source | Directory flag | Environment variable | Default |
152
+ |---|---|---|---|
153
+ | Claude Code | `--claude-dir` | `CLAUDE_CONFIG_DIR` | `~/.claude` |
154
+ | Codex | `--codex-dir` | `CODEX_HOME` | `~/.codex` |
155
+ | kiro-cli | `--kiro-dir` | `KIRO_CONFIG_DIR` | `~/.kiro` |
156
+
157
+ Multiple stores merge into one library; the manifest tags each session's
158
+ `origin` and the export summary breaks the count down. Codex discovery includes
159
+ active and archived rollouts from the CLI, IDE extension, and app, grouped by
160
+ their working directory. Mirrored user/assistant events are paired, injected
161
+ context and subagent sessions are excluded, and human decisions and images
162
+ survive extraction. The kiro backend
163
+ reads both on-disk store layouts (the flat v2 store and the newer v3 per-session
164
+ store), preferring the v3 copy when a session was migrated into both.
165
+
166
+ `distill --runner claude|codex|kiro|auto` chooses which CLI does the distilling,
167
+ independently of `--source`. `auto` prefers the CLI matching an explicit source,
168
+ then falls back in the order Claude → Codex → Kiro. Models are passed through
169
+ with `--model`; without it, the chosen CLI uses its configured default.
170
+
171
+ ```bash
172
+ npx human-hindsight export --source codex
173
+ npx human-hindsight distill --source codex --runner codex
174
+ npx human-hindsight distill --source claude --runner codex
175
+ npx human-hindsight preferences --target codex # AGENTS.md; alias of --target agents
176
+ ```
177
+
178
+ `preferences --target claude|codex|kiro|agents` emits a `CLAUDE.md` block,
179
+ an `AGENTS.md` section, or a block for `~/.kiro/steering/`. An explicit Codex
180
+ source defaults to `AGENTS.md`. The Codex runner uses `codex exec` with a JSON
181
+ schema, a read-only sandbox, and ephemeral sessions; generated distill sessions
182
+ do not become new source history. Claude supports current `structured_output`
183
+ results as well as legacy `result` objects/strings and verbose event arrays.
184
+ It disables session persistence when the installed CLI advertises the flag.
185
+
186
+ ### Optional: keep more local history
187
+
188
+ ```bash
189
+ npx human-hindsight retention # read-only preview
190
+ npx human-hindsight retention --apply # preview, then confirm
191
+ npx human-hindsight retention --apply --yes # explicit opt-in for scripting
192
+ npx human-hindsight retention --source codex --apply
193
+ ```
194
+
195
+ The default reviews existing tool directories. An explicit `--source` can
196
+ create that tool's settings file. `--yes` alone never applies changes, and
197
+ `--dry-run` always keeps the command read-only.
198
+
199
+ - **Claude Code:** raises `cleanupPeriodDays` to 365,000 days (about 1,000
200
+ years), preserving an already longer value. Claude requires a positive whole
201
+ number; `0` is invalid. If desktop cleanup is capped, sets
202
+ `desktopSessionCleanupPeriodDays` to `0`, its supported no-age-limit value.
203
+ An absent desktop setting already has no age limit.
204
+ - **Codex:** sets `[history] persistence = "save-all"` and removes
205
+ `history.max_bytes`, leaving prompt history uncapped. This controls
206
+ `history.jsonl`; full session rollouts are stored separately. Avoid
207
+ `--ephemeral` for your own sessions you want to retain.
208
+ - **kiro-cli:** explains automatic persistence and `/chat save <path>` for
209
+ additional copies. Its public settings reference does not document a
210
+ retention-limit switch, so no configuration key is invented.
211
+
212
+ Applying creates owner-only backups next to existing configuration files, then
213
+ replaces each file atomically. Other settings are preserved; common Codex TOML
214
+ layouts retain comments, while unusual layouts may be reformatted after a
215
+ preview notice. Malformed configurations are left untouched.
216
+
217
+ Longer retention keeps prompt contents on disk longer and can use more space.
218
+ Restart running tools after applying settings. Project settings, profiles,
219
+ managed policy, and startup flags can override user defaults; this command
220
+ does not change those controls, remote retention, or telemetry. It cannot
221
+ recover already deleted history.
222
+
223
+ Setting references: [Claude retention](https://code.claude.com/docs/en/settings-reference#cleanupperioddays),
224
+ [Codex configuration](https://developers.openai.com/codex/config-reference),
225
+ and [Kiro conversation persistence](https://kiro.dev/docs/cli/chat/).
226
+
227
+ ## Privacy & trust
228
+
229
+ For a tool that reads your entire conversation history, auditability is the
230
+ product:
231
+
232
+ - **Local-only.** Everything is read from your disk and written to your disk
233
+ (`~/.human-hindsight`). No server, no accounts, no telemetry. The only network
234
+ traffic is through your chosen agent CLI during consented distillation or
235
+ preference consolidation.
236
+ - **Four runtime dependencies.** [`citty`](https://github.com/unjs/citty)
237
+ (zero-dependency CLI framework), [`zod`](https://zod.dev) (schema
238
+ validation), and [`@clack/prompts`](https://github.com/bombshell-dev/clack)
239
+ (progress spinners), plus [`smol-toml`](https://github.com/squirrelchat/smol-toml)
240
+ for safely preserving Codex configuration values during optional retention
241
+ edits. All four are
242
+ exact-pinned, and the entire transitive tree ships locked via
243
+ `npm-shrinkwrap.json`. The whole data path is small enough to audit in one
244
+ sitting.
245
+ - **Consent-gated LLM use.** `distill` states the exact invocation count and
246
+ waits for `[y/N]` before anything runs on your subscription/credits.
247
+ `--dry-run` shows the full plan for free. If you decline, it exits without
248
+ invoking anything (exit code 2).
249
+ - **Plain statement:** exports contain your raw prompts, including anything
250
+ sensitive you ever pasted into a session (keys, internal names, that one
251
+ angry message). They live in your home directory with your permissions, and
252
+ nothing ships them anywhere. A `--redact` option is on the roadmap.
253
+
254
+ ## How it works
255
+
256
+ ```mermaid
257
+ flowchart TD
258
+ A["~/.claude/projects/**/*.jsonl"] -->|"scan (read-only)"| B["inventory"]
259
+ X["~/.codex/{sessions,archived_sessions}/**/rollout-*.jsonl"] --> B
260
+ K["~/.kiro/sessions/"] --> B
261
+ A -->|"export (deterministic)"| C["exports/*.md + manifest.json"]
262
+ X --> C
263
+ K --> C
264
+ A -->|"anaphora + outcome evidence"| D["anaphora.json + outcomes.json"]
265
+ X --> D
266
+ K --> D
267
+ C --> E
268
+ D --> E
269
+ subgraph distill ["distill: opt-in, consent-gated, resumable"]
270
+ E["digest: 1 runner call / session"] --> F["cluster: 1 call"]
271
+ F --> G["author: 1 call / task"]
272
+ end
273
+ G --> H["library/&lt;slug&gt;/ oneshot + provenance"]
274
+ H --> I["list / show / copy / status"]
275
+ H --> J["preferences → CLAUDE.md / AGENTS.md / Kiro steering"]
276
+ ```
277
+
278
+ The extraction layer is a fidelity contract: eleven audited rules decide what
279
+ counts as human input (attachments typed while the agent was busy, recovered
280
+ slash commands, `[decision]` lines from option picks, `[image pasted]`
281
+ markers), with a regression fixture per rule. Fork/resume duplicates are
282
+ deduped globally. Short replies like "yes" and "option 2" get their antecedent
283
+ attached so the author stage knows what you approved. Sessions carry an
284
+ outcome classification, so a task where nothing ever succeeded gets skipped
285
+ instead of becoming a confident prompt that reproduces a failure path.
286
+
287
+ Authored oneshots pass a **"knowable at t=0" test**: they front-load intent,
288
+ constraints, preferences, and quality bars, while leaving out facts you only
289
+ discovered mid-session (paths, root causes, error messages). And they respect
290
+ an **effort budget**, staying around the length a motivated human would
291
+ actually type rather than ballooning into a 700-word spec.
292
+
293
+ Every distill stage checkpoints to disk after each unit of work: Ctrl-C loses
294
+ nothing, re-running resumes, `--fresh` resets deliberately, and `status` flags
295
+ library entries orphaned by re-clustering.
296
+
297
+ ## How it compares
298
+
299
+ | Tool | Reads `~/.claude` | Output | Direction |
300
+ |---|---|---|---|
301
+ | ccusage | ✓ | usage/cost tables | backward (metrics) |
302
+ | sniffly | ✓ | analytics dashboard | backward (behavior) |
303
+ | claude-code-transcripts | ✓ | shareable HTML transcripts | backward (record) |
304
+ | cctrace / exporters | ✓ | markdown/XML exports | backward (archive) |
305
+ | **human-hindsight** | ✓ | **oneshot prompt library + CLAUDE.md preferences** | **forward (better next session)** |
306
+
307
+ Closest kin is Simon Willison's `claude-code-transcripts`: same local-first
308
+ values, same belief that transcripts are undervalued artifacts. The difference
309
+ is the direction of gaze: it renders your sessions (backward, for others);
310
+ human-hindsight distills them (forward, for you).
311
+
312
+ ## FAQ
313
+
314
+ **Does my data leave my machine?**
315
+ The deterministic commands (`scan`, `export`, and `retention`) never touch the
316
+ network. `distill` and `preferences --consolidate` send content through your
317
+ chosen local agent CLI to its configured provider, using its authentication.
318
+
319
+ **What does distill cost?**
320
+ Whatever your chosen agent CLI costs you: it runs on your existing subscription or
321
+ API credits. The consent prompt states the exact invocation count up front
322
+ (one call per session digested, one to cluster, one per task authored), and
323
+ `--dry-run` prints the same plan without running anything. Checkpoints mean an
324
+ interrupted run isn't wasted money. Sessions too large for the input budget
325
+ (default 400k chars, `--input-budget`) are **refused before anything is
326
+ spent**. Re-run with `--truncate=extreme` to cut them (recorded in
327
+ provenance) or narrow the scope. Digest and author calls run 3 at a time by
328
+ default (`--concurrency`; `1` = sequential).
329
+
330
+ **Subscription or API?**
331
+ human-hindsight shells out to `claude -p`, `codex exec`, or `kiro-cli chat`;
332
+ however your chosen CLI is authenticated is how calls are billed. `--model`
333
+ passes through without pinning a model version.
334
+
335
+ **Why is a session missing from my exports?**
336
+ Sessions with zero human messages are skipped naturally, `--min-messages`
337
+ filters thin ones, and fork/resume copies are deduped into their original
338
+ session. Note that dedupe is global across all projects: with `--project`, a
339
+ message duplicated by fork/resume is attributed to its earliest session even
340
+ when that session is outside the filter. Run `export --verbose` to see every
341
+ dropped piece with a reason. If genuine human input was dropped, that's a
342
+ bug: file an extraction-fidelity report.
343
+
344
+ **Can I regenerate everything from scratch?**
345
+ `human-hindsight distill --fresh` clears the checkpoints (after confirming) and
346
+ re-runs. Old library entries from previous generations are flagged as orphans
347
+ in `status`.
348
+
349
+ ## Roadmap
350
+
351
+ - Claude Code **plugin packaging** for existing marketplaces (for
352
+ distribution, without standing up a separate marketplace)
353
+ - An in-session **skill variant** ("distill this session as we go")
354
+ - **Agent SDK** orchestration exploration
355
+ - **parentUuid-aware anaphora** (branch-correct antecedents on forked
356
+ conversations)
357
+ - **`--redact` patterns** for exports
358
+ - An opt-in **community oneshot showcase**
359
+
360
+ ## Development
361
+
362
+ ```bash
363
+ npm install
364
+ npm test # vitest: fixtures only, never reads your agent stores
365
+ npm run lint # biome
366
+ npm run typecheck # tsc --noEmit
367
+ npm run build # tsdown → dist/
368
+ ```
369
+
370
+ See [CONTRIBUTING.md](CONTRIBUTING.md), especially the guide to adding a
371
+ fixture when you hit an unhandled transcript shape.
372
+
373
+ ## License
374
+
375
+ [MIT](LICENSE)
376
+
377
+ ## Author
378
+
379
+ Built by [Aditya Singhal](https://adityasinghal.com). If human-hindsight surfaces
380
+ a pattern you didn't know you had, [I'd love to hear about
381
+ it](https://github.com/adityaarunsinghal/human-hindsight/issues).
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };