noonsight 0.0.1 → 0.1.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/.claude-plugin/marketplace.json +19 -0
- package/.claude-plugin/plugin.json +14 -0
- package/README.md +271 -9
- package/dist/src/adapters/claude-code/classifier.js +138 -0
- package/dist/src/adapters/claude-code/code-edit.js +108 -0
- package/dist/src/adapters/claude-code/compat.js +31 -0
- package/dist/src/adapters/claude-code/definitions.js +347 -0
- package/dist/src/adapters/claude-code/fork.js +132 -0
- package/dist/src/adapters/claude-code/hook.js +652 -0
- package/dist/src/adapters/claude-code/install.js +186 -0
- package/dist/src/adapters/claude-code/launch.js +270 -0
- package/dist/src/adapters/claude-code/launcher.js +252 -0
- package/dist/src/adapters/claude-code/locations.js +115 -0
- package/dist/src/adapters/claude-code/managed.js +75 -0
- package/dist/src/adapters/claude-code/plugin-files.js +88 -0
- package/dist/src/adapters/claude-code/plugins.js +117 -0
- package/dist/src/adapters/claude-code/pointer.js +48 -0
- package/dist/src/adapters/claude-code/predict.js +271 -0
- package/dist/src/adapters/claude-code/routing.js +88 -0
- package/dist/src/adapters/claude-code/settings.js +189 -0
- package/dist/src/adapters/claude-code/subagents.js +666 -0
- package/dist/src/adapters/claude-code/triggers.js +88 -0
- package/dist/src/cli.js +157 -0
- package/dist/src/commands/accept.js +115 -0
- package/dist/src/commands/check.js +529 -0
- package/dist/src/commands/hook.js +73 -0
- package/dist/src/commands/init.js +29 -0
- package/dist/src/commands/install.js +370 -0
- package/dist/src/commands/models.js +213 -0
- package/dist/src/commands/receives.js +84 -0
- package/dist/src/commands/report.js +386 -0
- package/dist/src/commands/resolve.js +32 -0
- package/dist/src/commands/run.js +168 -0
- package/dist/src/commands/trust.js +70 -0
- package/dist/src/commands/usage.js +10 -0
- package/dist/src/commands/watch.js +154 -0
- package/dist/src/config/create.js +51 -0
- package/dist/src/config/json-schema.js +207 -0
- package/dist/src/config/load.js +758 -0
- package/dist/src/config/paths.js +42 -0
- package/dist/src/config/preset-changes.js +190 -0
- package/dist/src/config/project.js +354 -0
- package/dist/src/config/rewrite.js +112 -0
- package/dist/src/core/backtracking.js +330 -0
- package/dist/src/core/classify.js +66 -0
- package/dist/src/core/normalize.js +24 -0
- package/dist/src/core/overlap.js +39 -0
- package/dist/src/core/regex-sample.js +278 -0
- package/dist/src/core/resolve.js +201 -0
- package/dist/src/core/route.js +93 -0
- package/dist/src/core/scope.js +77 -0
- package/dist/src/core/triggers.js +30 -0
- package/dist/src/core/types.js +74 -0
- package/dist/src/state/agents.js +200 -0
- package/dist/src/state/claims.js +80 -0
- package/dist/src/state/files.js +84 -0
- package/dist/src/state/installs.js +29 -0
- package/dist/src/state/log.js +90 -0
- package/dist/src/state/node.js +35 -0
- package/dist/src/state/sessions.js +109 -0
- package/dist/src/state/triggers.js +57 -0
- package/dist/src/version.js +24 -0
- package/dist/src/watch/service.js +172 -0
- package/dist/src/watch/watcher.js +130 -0
- package/dist/src/wording.js +11 -0
- package/hooks/hooks.json +118 -0
- package/package.json +57 -7
- package/presets/claude/SOURCES.md +485 -0
- package/presets/claude/preset.json +432 -0
- package/presets/claude/rules/fable-5-2/code-ownership.md +1 -0
- package/presets/claude/rules/fable-5-2/finish-work.md +1 -0
- package/presets/claude/rules/fable-5-2/low-context-report.md +1 -0
- package/presets/claude/rules/fable-5-2/progress-updates.md +1 -0
- package/presets/claude/rules/haiku-5-5/carry-through.md +1 -0
- package/presets/claude/rules/haiku-5-5/search-recent-facts.md +1 -0
- package/presets/claude/rules/haiku-5-5/verify-changes.md +1 -0
- package/presets/claude/rules/opus-5-5/explore-before-acting.md +1 -0
- package/presets/claude/rules/opus-5-5/progress-updates.md +1 -0
- package/presets/claude/rules/opus-5-5/unattended-run.md +1 -0
- package/presets/claude/rules/sonnet-5-5/carry-through.md +1 -0
- package/presets/claude/rules/sonnet-5-5/check-current-facts.md +1 -0
- package/presets/claude/rules/sonnet-5-5/ideas-first.md +1 -0
- package/presets/claude/rules/sonnet-5-5/no-self-review-rounds.md +1 -0
- package/presets/claude/rules/sonnet-5-5/stay-in-scope.md +1 -0
- package/presets/claude/rules/sonnet-5-5/verify-changes.md +1 -0
- package/presets/claude/versions/1.3.0/preset.json +432 -0
- package/presets/claude/versions/1.3.0/rules/fable-5-2/code-ownership.md +1 -0
- package/presets/claude/versions/1.3.0/rules/fable-5-2/finish-work.md +1 -0
- package/presets/claude/versions/1.3.0/rules/fable-5-2/low-context-report.md +1 -0
- package/presets/claude/versions/1.3.0/rules/fable-5-2/progress-updates.md +1 -0
- package/presets/claude/versions/1.3.0/rules/haiku-5-5/carry-through.md +1 -0
- package/presets/claude/versions/1.3.0/rules/haiku-5-5/search-recent-facts.md +1 -0
- package/presets/claude/versions/1.3.0/rules/haiku-5-5/verify-changes.md +1 -0
- package/presets/claude/versions/1.3.0/rules/opus-5-5/explore-before-acting.md +1 -0
- package/presets/claude/versions/1.3.0/rules/opus-5-5/progress-updates.md +1 -0
- package/presets/claude/versions/1.3.0/rules/opus-5-5/unattended-run.md +1 -0
- package/presets/claude/versions/1.3.0/rules/sonnet-5-5/carry-through.md +1 -0
- package/presets/claude/versions/1.3.0/rules/sonnet-5-5/check-current-facts.md +1 -0
- package/presets/claude/versions/1.3.0/rules/sonnet-5-5/ideas-first.md +1 -0
- package/presets/claude/versions/1.3.0/rules/sonnet-5-5/no-self-review-rounds.md +1 -0
- package/presets/claude/versions/1.3.0/rules/sonnet-5-5/stay-in-scope.md +1 -0
- package/presets/claude/versions/1.3.0/rules/sonnet-5-5/verify-changes.md +1 -0
- package/schema/noonsight-project.schema.json +394 -0
- package/schema/noonsight.schema.json +425 -0
- package/schema/preset.schema.json +194 -0
- package/scripts/noonsight +68 -0
- package/skills/accept/SKILL.md +11 -0
- package/skills/check/SKILL.md +11 -0
- package/skills/models/SKILL.md +11 -0
- package/skills/report/SKILL.md +11 -0
- package/skills/resolve/SKILL.md +12 -0
- package/skills/setup/SKILL.md +15 -0
- package/skills/trust/SKILL.md +12 -0
- package/skills/untrust/SKILL.md +12 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "noonsight",
|
|
3
|
+
"owner": {
|
|
4
|
+
"name": "Bruno Santi"
|
|
5
|
+
},
|
|
6
|
+
"description": "The rules for the model each session runs on.",
|
|
7
|
+
"plugins": [
|
|
8
|
+
{
|
|
9
|
+
"name": "noonsight",
|
|
10
|
+
"source": {
|
|
11
|
+
"source": "npm",
|
|
12
|
+
"package": "noonsight",
|
|
13
|
+
"version": "0.1.0"
|
|
14
|
+
},
|
|
15
|
+
"description": "Hands every Claude Code session and subagent the rules for the model it actually runs on.",
|
|
16
|
+
"category": "productivity"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "noonsight",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Hands every Claude Code session and subagent the rules for the model it actually runs on.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Bruno Santi"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/bpsanti/noonsight#readme",
|
|
9
|
+
"repository": "https://github.com/bpsanti/noonsight",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"engines": {
|
|
12
|
+
"claude-code": ">=2.1.251"
|
|
13
|
+
}
|
|
14
|
+
}
|
package/README.md
CHANGED
|
@@ -1,19 +1,281 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/bpsanti/noonsight/main/docs/images/noonsight-lockup.svg#gh-light-mode-only" alt="noonsight" width="360">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/bpsanti/noonsight/main/docs/images/noonsight-lockup-dark.svg#gh-dark-mode-only" alt="noonsight" width="360">
|
|
4
|
+
</p>
|
|
5
|
+
|
|
1
6
|
# noonsight
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
**Every model has its own north.**
|
|
9
|
+
|
|
10
|
+
Anthropic publishes a prompting guide for each Claude model, and their advice differs from one model to the next ([S1](docs/sources.md#s1), [S2](docs/sources.md#s2)).
|
|
11
|
+
noonsight delivers instructions by model: each Claude Code session, and each subagent it starts, receives the rules written for the model it actually runs on, and receives them again when that model changes.
|
|
12
|
+
The rules are yours to write, for one model or for every model, for the whole machine or for one repository ([Your own rules](#your-own-rules)).
|
|
13
|
+
It ships a preset as a starting set, for Claude Fable 5.2, Opus 5.5, Sonnet 5.5 and Haiku 5.5, each rule taken from that model's guide with its source.
|
|
14
|
+
It works through Claude Code's own hooks, reads only local files (the optional classifier, off by default, is the one thing that uses the network), and records every delivery so you can check it.
|
|
15
|
+
|
|
16
|
+
## What it guarantees, and what it does not
|
|
17
|
+
|
|
18
|
+
**The guarantee.** Through Claude Code's hooks, noonsight puts the rules declared for a model into the requests of each session and subagent that runs on it, and again when that model changes or the conversation is compacted, cleared, resumed or forked.
|
|
19
|
+
That is delivery, not obedience: a delivered rule is context, and Claude Code says the same of `CLAUDE.md` ([S3](docs/sources.md#s3)).
|
|
20
|
+
Its known limits are part of it:
|
|
21
|
+
|
|
22
|
+
- A workflow's agents get nothing, foreground calls of one type that need different rules give their subagents nothing until each one's first Edit, Write or agent call, and a plugin noonsight does not read, such as one an organization syncs, leaves its subagents predicted on their parent's model ([docs/hooks.md](docs/hooks.md#what-the-prediction-does-not-see)).
|
|
23
|
+
- A conversation compacted with no response since and resumed with nothing that names a model runs on Claude Code's default model, which noonsight cannot tell ([docs/hooks.md](docs/hooks.md#sessionstart)); the corpus reproduces it, and it broke no session of the current run.
|
|
24
|
+
- In a session `noonsight run` started with rules, and only there, `/fork` is not available: Claude Code refuses to fork a session with a system prompt of its own ([docs/launcher.md](docs/launcher.md#other-text-in-the-system-prompt)).
|
|
25
|
+
- Agent teams, routing and the classifier are not measured ([limits](experiments/delivery/README.md#limits)).
|
|
26
|
+
- Claude Code changes how hooks behave, and each result holds for the version it ran on: delivery 2.1.330; rule effects 2.1.329, except Fable 5.2's, 2.1.328; the paid pilot 2.1.326 ([every run](docs/evidence.md#runs-and-versions)).
|
|
27
|
+
[docs/verification/claude-code.md](docs/verification/claude-code.md) dates facts about Claude Code, not results.
|
|
28
|
+
|
|
29
|
+
**What was measured.** The delivery benchmark's sessions are real, interactive Claude Code sessions, not simulated ones; only the Messages API is a local stand-in, so every request was read and no model answered ([experiments/delivery](experiments/delivery/README.md)).
|
|
30
|
+
Its current run (2026-11-23) generated 300 random sessions on the four models; 299 ran to the end, and one stopped on an unanswered turn.
|
|
31
|
+
Of these, 0 of 299 broke the invariant ([D18](docs/evidence.md#d18), Claude Code 2.1.330): every request with rules due held its model's rules, and no other model's rules left unretired.
|
|
32
|
+
That is 100% (3,090 of 3,090) of the requests with rules due, the subagents' 100% (763 of 763) among them ([D19](docs/evidence.md#d19), [D20](docs/evidence.md#d20), Claude Code 2.1.330).
|
|
33
|
+
Those requests include every one after a fork, after `/resume` typed in a session, in plan mode and after subagents that edit a file ([D21](docs/evidence.md#d21)), and every one of the sessions with a repository's configuration or started through `noonsight run` ([D22](docs/evidence.md#d22), Claude Code 2.1.330).
|
|
34
|
+
noonsight picks a rule by its model, scope, place and trigger, never by its text, so this covers your own rules too, though the sessions carried the preset's.
|
|
35
|
+
The benchmark found nine failures of noonsight, F1 to F9, on builds before the current run's, all fixed before it ([experiments/delivery](experiments/delivery/README.md#failures-found-and-a-limit)).
|
|
36
|
+
|
|
37
|
+
The native ways to give a model rules, on the run's first 60 sequences; noonsight's row is all its sessions, those 60 included (Claude Code 2.1.330):
|
|
38
|
+
|
|
39
|
+
| Every model's rules in | All requests with rules due, the main conversation's and the subagents' | Of those, the subagents' |
|
|
40
|
+
| --- | --- | --- |
|
|
41
|
+
| noonsight | [100% (3,090 of 3,090)](docs/evidence.md#d19) | [100% (763 of 763)](docs/evidence.md#d20) |
|
|
42
|
+
| A user `CLAUDE.md` | [88.2% (508 of 576)](docs/evidence.md#d25) | [46.9% (60 of 128)](docs/evidence.md#d28) |
|
|
43
|
+
| `.claude/rules`, one file per model | [76.3% (441 of 578)](docs/evidence.md#d26) | [46.9% (60 of 128)](docs/evidence.md#d28) |
|
|
44
|
+
| A skill per model | [0% (0 of 579)](docs/evidence.md#d27) | [0 of 128](docs/evidence.md#d29) |
|
|
45
|
+
|
|
46
|
+
What a `CLAUDE.md` missed were subagents only: it reached every request of the main conversation ([D34](docs/evidence.md#d34), Claude Code 2.1.330), and never reaches the built-in Explore and Plan subagents, as Claude Code documents ([S4](docs/sources.md#s4)).
|
|
47
|
+
It and `.claude/rules` also give every model the other models' rules, most of the rule text in their requests ([D30](docs/evidence.md#d30), Claude Code 2.1.330).
|
|
48
|
+
A skill guarantees only its description until the model decides to open it ([S5](docs/sources.md#s5)).
|
|
49
|
+
|
|
50
|
+
**What the preset delivers right after install** depends on the model and the place, and `noonsight install` writes it out for each model.
|
|
51
|
+
Of the preset's rules, 11 of its 16 rules list `attended`, the place where someone is watching ([The preset's rules](#the-presets-rules)).
|
|
52
|
+
Opus 5.5's and Fable 5.2's rules for that place ship off, so an attended session on either receives nothing from the preset until you turn one on with `enable`.
|
|
53
|
+
An attended session on Sonnet 5.5 or Haiku 5.5 receives `verify-changes` once it edits a code file its git repository tracks, and their other rules only with a scope, which [Your first delivered rule](#your-first-delivered-rule) shows.
|
|
54
|
+
A headless run, such as `claude -p` or the Agent SDK, is unattended by default and receives at its start `unattended-run` on Opus 5.5, `low-context-report` on Fable 5.2, and `carry-through` on Sonnet 5.5 and Haiku 5.5.
|
|
55
|
+
noonsight counts an interactive session as attended unless a variable of `session.unattended_when_env` is set, so set it to a CI's or an orchestrator's variable for the interactive sessions nobody watches.
|
|
56
|
+
Your own rules reach every place unless their `where` limits them.
|
|
57
|
+
|
|
58
|
+
## Your first delivered rule
|
|
59
|
+
|
|
60
|
+
noonsight needs Node.js 20 or newer and Claude Code.
|
|
61
|
+
Install it from npm, which puts `noonsight` on PATH; this is the recommended install, since `noonsight install` then reaches every Claude Code login of your account:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm install -g noonsight
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`npx noonsight install` works with nothing installed first, but the hooks then run the copy in npm's cache, and deliver nothing once that cache is cleared ([docs/install.md](docs/install.md#the-one-command)).
|
|
68
|
+
|
|
69
|
+
If you prefer installing noonsight as a Claude Code plugin, that works too (Claude Code 2.1.275 or later, and `npm` for the download):
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
/plugin install noonsight --marketplace bpsanti/noonsight
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then start a new session, whose start writes the configuration from the preset when there is none.
|
|
76
|
+
Each plugin install covers one Claude Code login, so a second login needs its own.
|
|
77
|
+
Having both the plugin and `noonsight install` is safe: each event is delivered once, by whichever copy runs first, and one of the two is enough ([docs/install.md](docs/install.md#as-a-claude-code-plugin)).
|
|
78
|
+
|
|
79
|
+
Then set it up.
|
|
80
|
+
This writes `~/.config/noonsight/noonsight.json` when there is none, adds the hooks to every Claude Code login of your account, keeping every other setting, and checks the result:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
noonsight install
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Its output writes out, for each model, what an attended session, an unattended session and a subagent receive with no scope, `nothing` included with the preset rules that are off there, and how to change it.
|
|
87
|
+
|
|
88
|
+
See the exact text a model receives in a scope, before any session runs:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
noonsight resolve claude-sonnet-5-5 routine
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Start a session in any project with that scope, and ask what it received:
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
NOONSIGHT_SCOPE=routine claude --model sonnet
|
|
98
|
+
> Which working rules did you receive from noonsight, and for which model?
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The model names `sonnet-5-5/stay-in-scope` and `sonnet-5-5/verify-changes`.
|
|
102
|
+
Leave the session, and confirm the delivery from noonsight's own log:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
noonsight report
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The report lists each rule with how often it was delivered, to which models, scopes and places, and the rules that are on but were never delivered ([docs/hooks.md](docs/hooks.md#the-decision-log)).
|
|
109
|
+
It reads deliveries from noonsight's decision log, which records what the hooks returned to Claude Code; it does not measure whether a rule changed what the model did, which takes an experiment such as those in [What the rules change](#what-the-rules-change).
|
|
110
|
+
`noonsight uninstall` takes the hooks out again; [docs/install.md](docs/install.md) covers every install and how to undo it.
|
|
111
|
+
|
|
112
|
+
## Your own rules
|
|
113
|
+
|
|
114
|
+
The preset is a starting set, and any rule can replace it or join it.
|
|
115
|
+
A rule is a Markdown file and an entry that names it: an `id`, the `file`, and, when the rule is not for every case, the `scopes`, the places (`where`) and the `triggers` it is for.
|
|
116
|
+
|
|
117
|
+
| Key | Values | How a session or subagent gets one |
|
|
118
|
+
| --- | --- | --- |
|
|
119
|
+
| `scopes` | The preset's `investigate`, `build`, `review`, `routine` and `digest`, any scope you declare under `scopes` with a `description` and `match` patterns, or `"*"` for every scope (the default) | A session from `NOONSIGHT_SCOPE` or `noonsight run --scope`; a subagent from the first `match` pattern found in its task, or from the classifier when you turn it on, since the preset's scopes have no patterns ([docs/configuration.md](docs/configuration.md#scopes)) |
|
|
120
|
+
| `where` | `attended`, `unattended`, `subagent`, or `all` for every place (the default); `session` is still read as the earlier name of `attended` | `unattended` for a headless run by default, or for a session started with a variable of `session.unattended_when_env` set; `subagent` for every subagent; `attended` otherwise, a session someone is watching |
|
|
121
|
+
| `triggers` | `code-edit`, the only one today; none by default | Once the session edits a code file its git repository already tracks, whatever its scope ([docs/configuration.md](docs/configuration.md#triggers)) |
|
|
122
|
+
|
|
123
|
+
For the machine, edit `~/.config/noonsight/noonsight.json`, which `noonsight install` wrote; a rule's `file` is relative to it:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"version": 1,
|
|
128
|
+
"preset_version": "1.3.1",
|
|
129
|
+
"models": {
|
|
130
|
+
"claude-opus-5-5": { "use": "preset", "add": [{ "id": "my/plan-first", "file": "rules/plan-first.md" }] },
|
|
131
|
+
"claude-sonnet-5-5": { "use": "preset" },
|
|
132
|
+
"claude-haiku-5-5": { "use": "custom", "add": [{ "id": "my/short-reports", "file": "rules/short-reports.md", "where": ["subagent"] }] },
|
|
133
|
+
"claude-fable-5-2": { "use": "none" }
|
|
134
|
+
},
|
|
135
|
+
"all_models": { "add": [{ "id": "team/commit-style", "file": "rules/commit-style.md" }] }
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- Opus 5.5 keeps the preset's rules and adds one of yours.
|
|
140
|
+
- Haiku 5.5 drops the preset's rules for one of yours, delivered only to its subagents.
|
|
141
|
+
- `all_models.add` gives one rule to every model declared with `preset` or `custom`; Fable 5.2, declared `none`, receives nothing.
|
|
142
|
+
|
|
143
|
+
For one repository, commit `.noonsight/noonsight.json` beside its rule files.
|
|
144
|
+
Each person who clones the repository runs `noonsight trust` once in it, and until then the file changes nothing:
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"version": 1,
|
|
149
|
+
"models": {
|
|
150
|
+
"claude-sonnet-5-5": { "add": [{ "id": "repo/run-the-tests", "file": "rules/run-the-tests.md", "triggers": ["code-edit"], "scopes": ["build"] }] }
|
|
151
|
+
},
|
|
152
|
+
"all_models": { "add": [{ "id": "repo/migrations", "file": "rules/migrations.md" }] }
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`noonsight check` validates both files, and `noonsight resolve <model> [scope] [place]` prints the exact text a model receives there.
|
|
157
|
+
[docs/usage.md](docs/usage.md#writing-a-rule) says how to write a rule, where it should live and how a [repository's rules](docs/usage.md#rules-for-one-repository) are shared, and [docs/configuration.md](docs/configuration.md#keys) gives every key.
|
|
158
|
+
|
|
159
|
+
## The preset's rules
|
|
160
|
+
|
|
161
|
+
Each rule of the preset, with the scopes and places it is for, the triggers that also deliver it, and whether it ships on.
|
|
162
|
+
`noonsight models` lists the same with each rule's source, effect and cost, and [presets/claude/SOURCES.md](presets/claude/SOURCES.md) says why each has its scopes and places.
|
|
163
|
+
|
|
164
|
+
| Rule | Scopes | Places | Triggers | Ships |
|
|
165
|
+
| --- | --- | --- | --- | --- |
|
|
166
|
+
| `fable-5-2/finish-work` | `investigate`, `build` | `subagent` | none | on |
|
|
167
|
+
| `fable-5-2/low-context-report` | every scope | `unattended`, `subagent` | none | on |
|
|
168
|
+
| `fable-5-2/code-ownership` | `build` | `attended`, `unattended` | none | off |
|
|
169
|
+
| `fable-5-2/progress-updates` | every scope | `attended` | none | off |
|
|
170
|
+
| `opus-5-5/unattended-run` | every scope | `unattended` | none | on |
|
|
171
|
+
| `opus-5-5/progress-updates` | every scope | `attended` | none | off |
|
|
172
|
+
| `opus-5-5/explore-before-acting` | every scope | `attended`, `unattended` | none | off |
|
|
173
|
+
| `sonnet-5-5/carry-through` | every scope | `unattended`, `subagent` | none | on |
|
|
174
|
+
| `sonnet-5-5/stay-in-scope` | `routine` | `attended`, `unattended`, `subagent` | none | on |
|
|
175
|
+
| `sonnet-5-5/verify-changes` | `investigate`, `build`, `routine` | `attended`, `unattended`, `subagent` | `code-edit` | on |
|
|
176
|
+
| `sonnet-5-5/no-self-review-rounds` | `build`, `routine` | `attended`, `unattended`, `subagent` | none | off |
|
|
177
|
+
| `sonnet-5-5/ideas-first` | every scope | `attended` | none | off |
|
|
178
|
+
| `sonnet-5-5/check-current-facts` | `investigate`, `digest` | `attended`, `unattended`, `subagent` | none | off |
|
|
179
|
+
| `haiku-5-5/carry-through` | every scope | `unattended`, `subagent` | none | on |
|
|
180
|
+
| `haiku-5-5/verify-changes` | `investigate`, `build`, `routine` | `attended`, `unattended`, `subagent` | `code-edit` | on |
|
|
181
|
+
| `haiku-5-5/search-recent-facts` | `investigate`, `digest` | `attended`, `unattended`, `subagent` | none | off |
|
|
182
|
+
|
|
183
|
+
Most of these rules list `attended`, the place where someone is watching.
|
|
184
|
+
Opus 5.5's and Fable 5.2's rules for that place ship off, by the preset's rule that a rule with a high cost, a described side effect or a narrow use ships off ([SOURCES.md](presets/claude/SOURCES.md#how-the-rules-were-chosen)): by Anthropic's guide, not our data, `fable-5-2/code-ownership` raises output tokens by about 70 to 80 percent and makes changes nobody asked for, and `fable-5-2/progress-updates` raises them by roughly 20 percent; `opus-5-5/progress-updates` adds updates whose cost the guide does not report, and `opus-5-5/explore-before-acting` is written for agents that work across connected apps.
|
|
185
|
+
To turn one on, name it in `enable` in `~/.config/noonsight/noonsight.json`:
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"version": 1,
|
|
190
|
+
"preset_version": "1.3.1",
|
|
191
|
+
"models": {
|
|
192
|
+
"claude-opus-5-5": { "use": "preset", "enable": ["opus-5-5/progress-updates"] }
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
`noonsight install` and `noonsight check` name, for each place a model receives nothing in, the preset rules that are off there.
|
|
198
|
+
|
|
199
|
+
## What the rules change
|
|
200
|
+
|
|
201
|
+
What a delivered rule changes depends on the rule, the model and the task.
|
|
202
|
+
The rule effect experiment ran the same task on the real models with a rule or the preset's rules delivered, and without any rule ([experiments/rules](experiments/rules/README.md)).
|
|
203
|
+
A row is the result of what its first cell names: a result of rules together is not a result of one of them.
|
|
204
|
+
Results and mean costs are with the rules against without; a result is the runs that ran the tests after their last edit, unless its cell says otherwise:
|
|
205
|
+
|
|
206
|
+
| Delivered | Model and task | Runs per arm | Result | Cost per run | Claude Code | Evidence |
|
|
207
|
+
| --- | --- | --- | --- | --- | --- | --- |
|
|
208
|
+
| `verify-changes`, **alone** | Sonnet 5.5, fix | 30 | 29 of 30 against 0 of 30 | $0.0505 against $0.0240 | 2.1.329 | [R3](docs/evidence.md#r3), [R6](docs/evidence.md#r6); without: [R14](docs/evidence.md#r14) |
|
|
209
|
+
| `verify-changes`, **alone** | Haiku 5.5, fix | 30 | 27 of 30 against 0 of 30 | $0.0033 against $0.0015 | 2.1.329 | [R3](docs/evidence.md#r3), [R7](docs/evidence.md#r7); without: [R14](docs/evidence.md#r14) |
|
|
210
|
+
| `verify-changes`, **alone** | Sonnet 5.5, bug | 30 | 30 of 30 against 11 of 30 | $0.0494 against $0.0321 | 2.1.329 | [R16](docs/evidence.md#r16), [R17](docs/evidence.md#r17); without: [R15](docs/evidence.md#r15) |
|
|
211
|
+
| `carry-through`, **alone** | Sonnet 5.5, bug | 30 | 30 of 30 against 11 of 30 | $0.0461 against $0.0321 | 2.1.329 | [R16](docs/evidence.md#r16), [R17](docs/evidence.md#r17); without: [R15](docs/evidence.md#r15) |
|
|
212
|
+
| `carry-through`, **alone** | Sonnet 5.5, backlog | 40 | 32 of 40 against 9 of 40 did every part | $0.2848 against $0.2920 | 2.1.329 | [R10](docs/evidence.md#r10), [R18](docs/evidence.md#r18) |
|
|
213
|
+
| `low-context-report`, **alone** | Fable 5.2, question, bug and feature | 30 each | 12.3 against 16.4, 17.8 against 20.1 and 12.2 against 16.2 words per sentence of its report | $0.3088 against $0.3005, $0.2061 against $0.2007 and $0.4642 against $0.5465 | 2.1.328 | [R9](docs/evidence.md#r9), [R19](docs/evidence.md#r19) |
|
|
214
|
+
| **The preset's three together**: `carry-through`, `stay-in-scope`, `verify-changes` | Sonnet 5.5, fix | 30 | 30 of 30 against 0 of 30 | $0.0378 against $0.0240 | 2.1.329 | [R14](docs/evidence.md#r14), [R6](docs/evidence.md#r6) |
|
|
215
|
+
| **The preset's two together**: `carry-through`, `verify-changes` | Sonnet 5.5, bug | 30 | 30 of 30 against 11 of 30 | $0.0513 against $0.0321 | 2.1.329 | [R15](docs/evidence.md#r15), [R17](docs/evidence.md#r17) |
|
|
216
|
+
| **The preset's two together**: `carry-through`, `verify-changes` | Haiku 5.5, fix | 30 | 27 of 30 against 0 of 30 | $0.0033 against $0.0015 | 2.1.329 | [R14](docs/evidence.md#r14), [R7](docs/evidence.md#r7) |
|
|
217
|
+
|
|
218
|
+
The fix is precise and in one file, the bug is known only by its symptom, and the backlog has 13 tickets, one with a decision left open.
|
|
219
|
+
|
|
220
|
+
- **Rules with a measured effect alone:** `verify-changes` (Sonnet 5.5, Haiku 5.5), `carry-through` (Sonnet 5.5) and `low-context-report` (Fable 5.2).
|
|
221
|
+
In these runs `stay-in-scope` came only with other rules.
|
|
222
|
+
- **No effect shown:** `carry-through` alone on the fix, for Sonnet 5.5 and Haiku 5.5 ([R3](docs/evidence.md#r3)), and on the backlog for Haiku 5.5 ([R11](docs/evidence.md#r11), Claude Code 2.1.329).
|
|
223
|
+
- No other rule of the preset, Opus 5.5's included, has a measured effect in [docs/evidence.md](docs/evidence.md#rule-effects), and a rule of your own has none until you measure it.
|
|
224
|
+
- **No quality gain shown:** in the run that measured the fix and the bug, every run passed its hidden check, with or without rules ([R8](docs/evidence.md#r8), Claude Code 2.1.329), and a paid pilot on public tasks, which delivered rules to the main conversation only, saw no measurable difference in the runs that passed: 133 of 144 without rules, 132 of 144 under noonsight and 133 of 144 with a `CLAUDE.md` of every model's rules ([B1](docs/evidence.md#b1), Claude Code 2.1.326).
|
|
225
|
+
|
|
226
|
+
The tasks are small: these are results on them, not general effects.
|
|
227
|
+
More on [what a rule costs](docs/usage.md#what-a-rule-costs), and on how each result compares with [what Anthropic published](docs/sources.md).
|
|
228
|
+
|
|
229
|
+
## Features
|
|
230
|
+
|
|
231
|
+
| Feature | How | More |
|
|
232
|
+
| --- | --- | --- |
|
|
233
|
+
| Rules per model, for sessions and subagents | The hooks, after `noonsight install` | [docs/hooks.md](docs/hooks.md) |
|
|
234
|
+
| A preset per current model, with sources | `"use": "preset"`, `enable`, `disable`, `replaces` | [presets/claude/SOURCES.md](presets/claude/SOURCES.md) |
|
|
235
|
+
| Your own rules, per model or for every model | `models.<id>.add`, `all_models.add` | [docs/configuration.md](docs/configuration.md#rules-for-every-model) |
|
|
236
|
+
| Rules for one repository | `.noonsight/noonsight.json`, `noonsight trust`, `projects.allow` | [docs/configuration.md](docs/configuration.md#project-configuration) |
|
|
237
|
+
| Rules for a kind of task | Scopes: `NOONSIGHT_SCOPE`, matchers, the optional classifier | [docs/configuration.md](docs/configuration.md#scopes) |
|
|
238
|
+
| Rules for a place | `where`: `attended`, `unattended`, `subagent`, `all` | [docs/configuration.md](docs/configuration.md#keys) |
|
|
239
|
+
| Rules on an action | Triggers: `code-edit` | [docs/configuration.md](docs/configuration.md#triggers) |
|
|
240
|
+
| Sessions the hooks do not reach | `noonsight run` | [docs/launcher.md](docs/launcher.md) |
|
|
241
|
+
| Model and effort by task (off by default) | `routing` | [docs/configuration.md](docs/configuration.md#routing) |
|
|
242
|
+
| Preset updates you review | `preset_version`, `on_preset_change`, `noonsight accept` | [docs/configuration.md](docs/configuration.md#preset-updates) |
|
|
243
|
+
| Checking what is delivered | `noonsight check`, `models`, `resolve`, `report` | [docs/hooks.md](docs/hooks.md#the-decision-log) |
|
|
244
|
+
| New Claude Code logins (off by default) | `noonsight watch enable` | [docs/install.md](docs/install.md#new-logins-as-they-appear-optional) |
|
|
245
|
+
| Turning it off for a session | `NOONSIGHT_DISABLE=1` | [docs/hooks.md](docs/hooks.md#turning-noonsight-off) |
|
|
246
|
+
|
|
247
|
+
The hooks never block anything, and use the network in one case only: the classifier, off unless you turn it on, sends the first 4,000 characters of a task to a small model through your own Claude Code login ([docs/configuration.md](docs/configuration.md#the-classifier)).
|
|
248
|
+
|
|
249
|
+
## Using it well
|
|
250
|
+
|
|
251
|
+
- Give noonsight what differs by model, by kind of task or by place, and leave in `CLAUDE.md` what every model should always have ([docs/usage.md](docs/usage.md#choosing-where-a-rule-lives)).
|
|
252
|
+
- Tell noonsight when nobody is watching, since the preset rules that ship on for Opus 5.5 and Fable 5.2 are for unattended runs and subagents only: headless runs are unattended by default, and `session.unattended_when_env`, set to your orchestrator's variable, covers the interactive sessions nobody watches; turn on their attended rules with `enable` if you want them; and give Sonnet 5.5 and Haiku 5.5 sessions a scope for their scoped rules ([docs/usage.md](docs/usage.md#setting-up-the-machine)).
|
|
253
|
+
- Write a rule as a check the model can pass, in plain words; Anthropic's best practices say the same, and the verify rules are an example ([What the rules change](#what-the-rules-change), [docs/usage.md](docs/usage.md#writing-a-rule)).
|
|
254
|
+
- Keep long rule text in a file and deliver one sentence pointing to it ([docs/usage.md](docs/usage.md#a-pointer-to-a-file)).
|
|
255
|
+
- Check what each model receives with `noonsight models` and what was delivered with `noonsight report`, and drop a rule that never changes anything you can see.
|
|
256
|
+
- Skip noonsight when every session runs one model with fixed rules: a `CLAUDE.md` is simpler, unless Explore or Plan subagents need the rules, which it does not reach ([docs/usage.md](docs/usage.md#when-not-to-use-noonsight)).
|
|
257
|
+
|
|
258
|
+
## How this README is checked
|
|
259
|
+
|
|
260
|
+
- Every measured number links to [docs/evidence.md](docs/evidence.md), which names the raw result file, how the number is computed from it, its date, its Claude Code version and whether a later run superseded it; `npm test` computes each number again from the file, in [test/evidence.test.ts](test/evidence.test.ts).
|
|
261
|
+
- Every quotation of Anthropic is in [docs/sources.md](docs/sources.md) with its link, its retrieval date and the literal excerpt; `NOONSIGHT_LIVE_SOURCES=1 npm run test:live` checks each excerpt against the live page.
|
|
262
|
+
- `npm test` runs the commands of [Your first delivered rule](#your-first-delivered-rule) in a sandbox, and fails when a command, option, configuration key, environment variable or hook event is missing from the documentation.
|
|
263
|
+
- `npm test` runs `noonsight check` on each configuration example of this README and of [docs/usage.md](docs/usage.md), with its rule files, and fails on any problem.
|
|
4
264
|
|
|
5
|
-
|
|
6
|
-
The project was previously named `sextant-ai`.
|
|
265
|
+
## Development
|
|
7
266
|
|
|
8
|
-
|
|
267
|
+
```bash
|
|
268
|
+
npm test # builds, then runs every test with node --test
|
|
269
|
+
npm run test:live # real interactive Claude Code sessions; needs claude and expect, sends no prompt
|
|
270
|
+
```
|
|
9
271
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
272
|
+
The live tests, the experiments and the benchmarks that need a login or spend usage say so in [docs/verification/claude-code.md](docs/verification/claude-code.md) and in each experiment's README.
|
|
273
|
+
There are no runtime dependencies; the only development dependencies are TypeScript and the Node.js type definitions.
|
|
274
|
+
noonsight was called sextant before; [docs/install.md](docs/install.md#moving-from-sextant) says how to move an install made under that name.
|
|
13
275
|
|
|
14
|
-
|
|
276
|
+
## Acknowledgements
|
|
15
277
|
|
|
16
|
-
|
|
278
|
+
Several ideas here (refuse a bad configuration instead of guessing, keep hooks fast, test through the public interface) come from [firstmate](https://github.com/kunchenguid/firstmate); no code was copied.
|
|
17
279
|
|
|
18
280
|
## License
|
|
19
281
|
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// The classifier in Claude Code: one `claude -p` call on a small model, with the login Claude Code
|
|
2
|
+
// already has, so noonsight never handles a credential. The question and the reading of the answer are
|
|
3
|
+
// the core's (core/classify.ts); this file runs the call and says what the decision log records.
|
|
4
|
+
//
|
|
5
|
+
// The call is bounded and kept apart from the session that asked:
|
|
6
|
+
// - It is stopped after classifier.timeout_ms, and a task it has not placed by then gets no scope.
|
|
7
|
+
// - It runs with NOONSIGHT_DISABLE=1, so noonsight's hooks, wherever they are installed, do nothing in
|
|
8
|
+
// the classifier's own session and never start a classifier from inside it.
|
|
9
|
+
// - --safe-mode leaves out the person's hooks, plugins, MCP servers and CLAUDE.md, --tools "" leaves
|
|
10
|
+
// it no tool, so it cannot start a subagent, and --no-session-persistence keeps it out of the
|
|
11
|
+
// person's session history.
|
|
12
|
+
import { spawnSync } from 'node:child_process';
|
|
13
|
+
import { classifierQuestion, readAnswer, wantsClassifier } from '../../core/classify.js';
|
|
14
|
+
import { EFFORT_ENV } from './routing.js';
|
|
15
|
+
/** The command the classifier runs, looked up on PATH as Claude Code's own hooks see it. */
|
|
16
|
+
export const CLASSIFIER_COMMAND = 'claude';
|
|
17
|
+
/**
|
|
18
|
+
* The task's scope: the one the explicit scope or the matchers chose, unless classifier.mode asks the
|
|
19
|
+
* classifier. Then the classifier's scope, or no scope when it fails, takes too long or answers
|
|
20
|
+
* outside the declared scopes.
|
|
21
|
+
*/
|
|
22
|
+
export function classifiedScope(config, req) {
|
|
23
|
+
const kept = { scope: req.chosen, fields: {}, failure: null };
|
|
24
|
+
if (!wantsClassifier(config, req.chosen))
|
|
25
|
+
return kept;
|
|
26
|
+
const replaced = req.chosen.scope !== null ? { matcher_scope: req.chosen.scope } : {};
|
|
27
|
+
if (req.text === null || req.text.trim() === '')
|
|
28
|
+
return { ...kept, fields: { classifier: 'no-task' } };
|
|
29
|
+
if (!req.matters())
|
|
30
|
+
return { ...kept, fields: { classifier: 'not-needed' } };
|
|
31
|
+
const c = classify(config, req.text, req.env);
|
|
32
|
+
const fields = { ...replaced, ...classificationFields(c) };
|
|
33
|
+
const scope = c.result === 'scoped' ? { scope: c.scope, source: 'classifier' } : { scope: null, source: null };
|
|
34
|
+
return { scope, fields, failure: 'error' in c ? describeFailure(c) : null };
|
|
35
|
+
}
|
|
36
|
+
/** Ask the classifier to place a task. Never throws: a call that goes wrong is a classification that failed. */
|
|
37
|
+
export function classify(config, text, env) {
|
|
38
|
+
const question = classifierQuestion(config, text);
|
|
39
|
+
const c = config.classifier;
|
|
40
|
+
const args = [
|
|
41
|
+
'-p',
|
|
42
|
+
'--model',
|
|
43
|
+
c.model,
|
|
44
|
+
'--effort',
|
|
45
|
+
c.effort,
|
|
46
|
+
'--system-prompt',
|
|
47
|
+
question.system,
|
|
48
|
+
'--json-schema',
|
|
49
|
+
JSON.stringify(question.schema),
|
|
50
|
+
'--output-format',
|
|
51
|
+
'json',
|
|
52
|
+
'--tools',
|
|
53
|
+
'',
|
|
54
|
+
'--no-session-persistence',
|
|
55
|
+
'--safe-mode',
|
|
56
|
+
];
|
|
57
|
+
const childEnv = {};
|
|
58
|
+
for (const [k, v] of Object.entries(env))
|
|
59
|
+
if (v !== undefined)
|
|
60
|
+
childEnv[k] = v;
|
|
61
|
+
// The classifier's own effort holds: this variable wins over --effort.
|
|
62
|
+
delete childEnv[EFFORT_ENV];
|
|
63
|
+
childEnv.NOONSIGHT_DISABLE = '1';
|
|
64
|
+
const started = Date.now();
|
|
65
|
+
const r = spawnSync(CLASSIFIER_COMMAND, args, {
|
|
66
|
+
input: question.task,
|
|
67
|
+
encoding: 'utf8',
|
|
68
|
+
env: childEnv,
|
|
69
|
+
timeout: c.timeoutMs,
|
|
70
|
+
killSignal: 'SIGKILL',
|
|
71
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
72
|
+
});
|
|
73
|
+
const ms = Date.now() - started;
|
|
74
|
+
const code = r.error?.code;
|
|
75
|
+
if (code === 'ETIMEDOUT')
|
|
76
|
+
return { result: 'timeout', ms, error: `no answer within ${c.timeoutMs} ms` };
|
|
77
|
+
if (code === 'ENOENT')
|
|
78
|
+
return { result: 'failed', ms, error: `${CLASSIFIER_COMMAND} is not on PATH` };
|
|
79
|
+
if (r.error !== undefined)
|
|
80
|
+
return { result: 'failed', ms, error: short(r.error.message) };
|
|
81
|
+
let out;
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(r.stdout);
|
|
84
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
85
|
+
throw new Error('not an object');
|
|
86
|
+
out = parsed;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
const said = short(r.stderr || r.stdout);
|
|
90
|
+
return { result: 'failed', ms, error: `${CLASSIFIER_COMMAND} exited with status ${r.status ?? 'none'}${said ? `: ${said}` : ''}` };
|
|
91
|
+
}
|
|
92
|
+
if (out.is_error === true || r.status !== 0)
|
|
93
|
+
return { result: 'failed', ms, error: short(String(out.result ?? out.subtype ?? `${CLASSIFIER_COMMAND} exited with status ${r.status ?? 'none'}`)) };
|
|
94
|
+
const cost = typeof out.total_cost_usd === 'number' ? { costUsd: out.total_cost_usd } : {};
|
|
95
|
+
const answer = readAnswer(config, out.structured_output ?? parseJson(out.result));
|
|
96
|
+
switch (answer.kind) {
|
|
97
|
+
case 'scoped':
|
|
98
|
+
return { result: 'scoped', scope: answer.scope, ms, ...cost };
|
|
99
|
+
case 'none':
|
|
100
|
+
return { result: 'none', ms, ...cost };
|
|
101
|
+
case 'invalid':
|
|
102
|
+
return { result: 'invalid', ms, error: answer.why };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** What the decision log records about a classification. */
|
|
106
|
+
export function classificationFields(c) {
|
|
107
|
+
return {
|
|
108
|
+
classifier: c.result,
|
|
109
|
+
classifier_ms: c.ms,
|
|
110
|
+
...('error' in c ? { classifier_error: c.error } : {}),
|
|
111
|
+
...('costUsd' in c && c.costUsd !== undefined ? { classifier_cost_usd: c.costUsd } : {}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function describeFailure(c) {
|
|
115
|
+
switch (c.result) {
|
|
116
|
+
case 'timeout':
|
|
117
|
+
return `it gave ${c.error}`;
|
|
118
|
+
case 'invalid':
|
|
119
|
+
return `its answer was not a declared scope: ${c.error}`;
|
|
120
|
+
case 'failed':
|
|
121
|
+
return `it failed: ${c.error}`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function parseJson(value) {
|
|
125
|
+
if (typeof value !== 'string')
|
|
126
|
+
return undefined;
|
|
127
|
+
try {
|
|
128
|
+
return JSON.parse(value);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function short(text) {
|
|
135
|
+
const line = text.trim().split('\n').find((l) => l.trim() !== '') ?? '';
|
|
136
|
+
return line.length > 200 ? `${line.slice(0, 200)}...` : line;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=classifier.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Whether an edit reveals the code-edit trigger: the session edited, with Edit or Write, a file with a
|
|
2
|
+
// code extension that the git repository holding it already tracks, where that repository is the
|
|
3
|
+
// session's project or one of its worktrees.
|
|
4
|
+
//
|
|
5
|
+
// Each condition keeps out an edit that does not show the session building:
|
|
6
|
+
// - a code extension keeps out reports, notes, documents, styles, data and settings (core/triggers.ts);
|
|
7
|
+
// - a tracked file keeps out every new file, so a script or a report the session writes for itself
|
|
8
|
+
// never counts, nor does a file git ignores, such as a build output or a temporary file;
|
|
9
|
+
// - the project's repository keeps out files elsewhere on the machine, such as another
|
|
10
|
+
// repository's, or a temporary directory's. The repository holding the file is asked, not the
|
|
11
|
+
// project's checkout, so an edit in a worktree of the project counts, including one under the
|
|
12
|
+
// project's own directory, which the checkout's index does not track: a session that moved into a
|
|
13
|
+
// worktree still has the original checkout as its project.
|
|
14
|
+
// The check runs git at most three times, each bounded: `git ls-files --error-unmatch` in the file's
|
|
15
|
+
// directory, then `git rev-parse --git-common-dir` there and in the project. Both read and change nothing.
|
|
16
|
+
import { spawnSync } from 'node:child_process';
|
|
17
|
+
import fs from 'node:fs';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import { hasCodeExtension } from '../../core/triggers.js';
|
|
20
|
+
import { EDIT_TOOLS } from './settings.js';
|
|
21
|
+
/** How long git may take before the edit counts as not revealing anything. */
|
|
22
|
+
export const GIT_TIMEOUT_MS = 3000;
|
|
23
|
+
/**
|
|
24
|
+
* Whether a PostToolUse input reveals code-edit. The project is CLAUDE_PROJECT_DIR, which Claude Code
|
|
25
|
+
* sets for its hooks, else the input's cwd. Two repositories are the same, or worktrees of each other,
|
|
26
|
+
* when they share their common git directory.
|
|
27
|
+
*/
|
|
28
|
+
export function codeEdit(input, env) {
|
|
29
|
+
const not = (why) => ({ kind: 'not', why });
|
|
30
|
+
const tool = typeof input.tool_name === 'string' ? input.tool_name : '';
|
|
31
|
+
if (!EDIT_TOOLS.includes(tool))
|
|
32
|
+
return not('not-edit-tool');
|
|
33
|
+
const cwd = typeof input.cwd === 'string' && input.cwd !== '' ? input.cwd : null;
|
|
34
|
+
const project = env.CLAUDE_PROJECT_DIR || cwd;
|
|
35
|
+
const file = real(namedFile(input));
|
|
36
|
+
if (file === null || !isFile(file))
|
|
37
|
+
return not('no-file');
|
|
38
|
+
if (!hasCodeExtension(file))
|
|
39
|
+
return not('not-code');
|
|
40
|
+
const projectDir = real(project ?? null);
|
|
41
|
+
if (projectDir === null)
|
|
42
|
+
return not('no-project');
|
|
43
|
+
const fileDir = path.dirname(file);
|
|
44
|
+
const tracked = trackedPath(fileDir, file, env);
|
|
45
|
+
if (tracked === null)
|
|
46
|
+
return not('untracked');
|
|
47
|
+
const repository = commonDir(fileDir, env);
|
|
48
|
+
if (repository === null || repository !== commonDir(projectDir, env))
|
|
49
|
+
return not('foreign');
|
|
50
|
+
return { kind: 'code', tool, file: tracked };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The file an edit names, as an absolute path. Claude Code asks for an absolute path; a relative one
|
|
54
|
+
* is read the way the tool would, from the cwd.
|
|
55
|
+
*/
|
|
56
|
+
export function namedFile(input) {
|
|
57
|
+
const toolInput = input.tool_input;
|
|
58
|
+
const named = toolInput !== null && typeof toolInput === 'object' ? toolInput.file_path : undefined;
|
|
59
|
+
if (typeof named !== 'string' || named === '')
|
|
60
|
+
return null;
|
|
61
|
+
if (path.isAbsolute(named))
|
|
62
|
+
return named;
|
|
63
|
+
return typeof input.cwd === 'string' && input.cwd !== '' ? path.resolve(input.cwd, named) : null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The file's path relative to its repository's root when the git repository of the directory tracks
|
|
67
|
+
* it; null when it does not, or git cannot tell. Paths are taken literally, so a name with "*" or "?"
|
|
68
|
+
* is never read as a pattern.
|
|
69
|
+
*/
|
|
70
|
+
function trackedPath(dir, file, env) {
|
|
71
|
+
const first = git(dir, ['ls-files', '--error-unmatch', '--full-name', '-z', '--', file], env)?.split('\0')[0];
|
|
72
|
+
return first ? first : null;
|
|
73
|
+
}
|
|
74
|
+
/** The real path of the common git directory of the repository holding the directory, or null when there is none. */
|
|
75
|
+
function commonDir(dir, env) {
|
|
76
|
+
const out = git(dir, ['rev-parse', '--git-common-dir'], env);
|
|
77
|
+
const named = out?.replace(/\n$/, '');
|
|
78
|
+
return named ? real(path.resolve(dir, named)) : null;
|
|
79
|
+
}
|
|
80
|
+
function git(dir, args, env) {
|
|
81
|
+
const r = spawnSync('git', ['--literal-pathspecs', '-C', dir, ...args], {
|
|
82
|
+
encoding: 'utf8',
|
|
83
|
+
env,
|
|
84
|
+
timeout: GIT_TIMEOUT_MS,
|
|
85
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
86
|
+
});
|
|
87
|
+
return r.status === 0 && typeof r.stdout === 'string' ? r.stdout : null;
|
|
88
|
+
}
|
|
89
|
+
/** The real path, with every symbolic link resolved, or null when it cannot be read. */
|
|
90
|
+
function real(p) {
|
|
91
|
+
if (p === null)
|
|
92
|
+
return null;
|
|
93
|
+
try {
|
|
94
|
+
return fs.realpathSync(p);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function isFile(file) {
|
|
101
|
+
try {
|
|
102
|
+
return fs.statSync(file).isFile();
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=code-edit.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// The Claude Code versions noonsight's hooks need, one line per feature, with the date each was checked
|
|
2
|
+
// against Claude Code's documentation. `noonsight check` compares the installed claude with these.
|
|
3
|
+
export const CLAUDE_CODE_FLOORS = [
|
|
4
|
+
{ version: '2.1.251', feature: 'the PostModelSwitch hook event', checked: '2026-11-14' },
|
|
5
|
+
];
|
|
6
|
+
export const MODEL_ALIASES_CHECKED = '2026-11-14';
|
|
7
|
+
export const MODEL_ALIASES = [
|
|
8
|
+
{ alias: 'opus', envVar: 'ANTHROPIC_DEFAULT_OPUS_MODEL', model: 'claude-opus-5-5', since: '2.1.280' },
|
|
9
|
+
{ alias: 'best', envVar: 'ANTHROPIC_DEFAULT_OPUS_MODEL', model: 'claude-opus-5-5', since: '2.1.321' },
|
|
10
|
+
{ alias: 'sonnet', envVar: 'ANTHROPIC_DEFAULT_SONNET_MODEL', model: 'claude-sonnet-5-5', since: '2.1.284' },
|
|
11
|
+
{ alias: 'haiku', envVar: 'ANTHROPIC_DEFAULT_HAIKU_MODEL', model: 'claude-haiku-5-5', since: '2.1.293' },
|
|
12
|
+
{ alias: 'fable', envVar: 'ANTHROPIC_DEFAULT_FABLE_MODEL', model: 'claude-fable-5-2', since: '2.1.321' },
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Model settings Claude Code resolves while the session runs, from the account, the organization or
|
|
16
|
+
* the plan mode, so the hook cannot tell which model they select.
|
|
17
|
+
*/
|
|
18
|
+
export const RUNTIME_MODEL_VALUES = ['default', 'opusplan'];
|
|
19
|
+
/**
|
|
20
|
+
* The environment variables that move Claude Code off the Anthropic API, where the aliases select
|
|
21
|
+
* other models (https://code.claude.com/docs/en/env-vars).
|
|
22
|
+
*/
|
|
23
|
+
export const PROVIDER_VARS = [
|
|
24
|
+
'CLAUDE_CODE_USE_BEDROCK',
|
|
25
|
+
'CLAUDE_CODE_USE_VERTEX',
|
|
26
|
+
'CLAUDE_CODE_USE_FOUNDRY',
|
|
27
|
+
'CLAUDE_CODE_USE_MANTLE',
|
|
28
|
+
'CLAUDE_CODE_USE_ANTHROPIC_AWS',
|
|
29
|
+
'CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD',
|
|
30
|
+
];
|
|
31
|
+
//# sourceMappingURL=compat.js.map
|