estimetry 0.1.1 → 0.2.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +45 -15
  3. package/dist/application/contracts/estimetry-command.js +34 -0
  4. package/dist/application/contracts/skill-mention.js +20 -0
  5. package/dist/application/estimetry.js +2 -0
  6. package/dist/application/hooks/context-limit.js +10 -2
  7. package/dist/application/hooks/hook-context.js +12 -4
  8. package/dist/application/hooks/receive-session-hook.js +15 -4
  9. package/dist/application/hooks/session-end-import.js +6 -7
  10. package/dist/application/ports/estimetry-runner.js +2 -0
  11. package/dist/application/project/init-defaults.js +17 -4
  12. package/dist/application/project/init-project.js +6 -2
  13. package/dist/application/project/install-copy.js +12 -3
  14. package/dist/application/project/show-init-choices.js +1 -1
  15. package/dist/application/project/tool-notices.js +8 -0
  16. package/dist/application/project/upgrade-plan.js +1 -1
  17. package/dist/application/task/import-session-logs.js +4 -1
  18. package/dist/bootstrap/container.js +38 -17
  19. package/dist/bootstrap/hook-receiver.js +7 -14
  20. package/dist/bootstrap/main.js +1 -1
  21. package/dist/domain/code/code-classes.js +1 -1
  22. package/dist/domain/progress/progress-record-parser.js +6 -0
  23. package/dist/domain/progress/session-log.js +2 -1
  24. package/dist/domain/usage/task-usage.js +24 -7
  25. package/dist/infrastructure/git/git-commit-hook-installer.js +16 -28
  26. package/dist/integrations/tools/claude-code/claude-code-adapter.js +32 -48
  27. package/dist/integrations/tools/claude-code/hook-events.js +4 -0
  28. package/dist/integrations/tools/claude-code/hook-translation.js +16 -34
  29. package/dist/integrations/tools/claude-code/importer/claude-code-logs.js +1 -1
  30. package/dist/integrations/tools/claude-code/skill-file.js +7 -19
  31. package/dist/integrations/tools/codex/codex-adapter.js +161 -0
  32. package/dist/integrations/tools/codex/hook-events.js +23 -0
  33. package/dist/integrations/tools/codex/hook-translation.js +76 -0
  34. package/dist/integrations/tools/codex/hook-trust.js +69 -0
  35. package/dist/integrations/tools/codex/importer/codex-logs.js +208 -0
  36. package/dist/integrations/tools/codex/importer/rollout-parser.js +163 -0
  37. package/dist/integrations/tools/codex/sandbox-rules.js +38 -0
  38. package/dist/integrations/tools/codex/skill-file.js +22 -0
  39. package/dist/integrations/tools/codex/trust-tables.js +96 -0
  40. package/dist/integrations/tools/content/commands.js +27 -20
  41. package/dist/integrations/tools/shared/generated-file.js +26 -0
  42. package/dist/integrations/tools/shared/hook-payload.js +33 -0
  43. package/dist/integrations/tools/{claude-code → shared}/hook-settings.js +40 -16
  44. package/dist/integrations/tools/shared/instructions-block.js +39 -0
  45. package/dist/integrations/tools/shared/skills-plan.js +39 -0
  46. package/dist/interface/cli/commands/hook-command.js +1 -1
  47. package/dist/interface/cli/commands/init-command.js +16 -7
  48. package/dist/interface/cli/commands/status-command.js +5 -2
  49. package/dist/interface/cli/presenters/text/closing-text.js +7 -3
  50. package/dist/interface/cli/presenters/text/notices-text.js +1 -0
  51. package/dist/interface/cli/presenters/text/task-text.js +1 -1
  52. package/dist/interface/cli/presenters/text-presenter.js +3 -3
  53. package/package.json +1 -1
  54. package/dist/integrations/tools/claude-code/claude-md.js +0 -28
  55. /package/dist/integrations/tools/{claude-code/importer → shared}/log-lines.js +0 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to estimetry. Versions follow [semantic versioning](https://
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.2.0 — 2026-11-21
8
+
9
+ - **Codex.** `estimetry init --tools codex`, or picking Codex in `init`, sets up the hooks of Codex (in `~/.codex/hooks.json`, or `.codex/hooks.json` of the project with `--shared-hooks`) and the `emt-…` skills (in `~/.agents/skills`, or `.agents/skills`), called as `$emt-…`. Sessions of Codex are measured like those of Claude Code, and both tools may serve one task. Codex runs a hook only once you trust it, and the agent's commands in a sandbox: in a terminal `init` asks whether to trust the estimetry hooks and to let the task commands (`emt start`, `extra`, `close`…) out of the sandbox, and records both with yes or `--trust-hooks` (`~/.codex/config.toml`, `~/.codex/rules/estimetry.rules`). `emt upgrade` trusts again the hooks it changes when you trusted them before; `emt status` warns while they are not trusted. Requires Codex 0.145 or newer.
10
+ - The rollouts of Codex sessions are imported at the session end and before a task closes: turns, subagents and tokens by model. Codex records no cost, so its sessions count in tokens only, and the cost of a task says by how many sessions it is counted (`cost from 1 of 2 sessions`, or `not reported`). Cards get `usage.withCost`.
11
+ - `init` without `--tools` now sets up the tools found on this machine (`~/.claude`, `~/.codex`) when none is installed in the project yet, instead of every tool.
12
+ - The texts outside an agent name the skills without the slash of Claude Code (`skill emt-retro`); the context the hooks give an agent names them as its tool calls them.
13
+ - The journal: `log.session` records may carry `costReported: false` and a `cacheWrite` count; records of 0.1 read as before, and 0.1 reads the new ones, though it counts a Codex session as costing nothing.
14
+ - Run `emt upgrade` once: the skills are written again.
15
+
16
+ ## 0.1.2 — 2026-11-12
17
+
18
+ - The hooks `init` writes run the installation of estimetry that ran it, by the paths of its Node.js and entry point, and fall back to `estimetry` on `PATH`. A version manager (asdf, nvm) that picks another Node.js for a project, or one without estimetry, no longer stops the Claude Code hooks or the `post-commit` hook. Settings and hooks the project commits keep the plain `estimetry hook …`. Run `emt upgrade` once to rewrite the hooks.
19
+
7
20
  ## 0.1.1 — 2026-11-12
8
21
 
9
22
  - The npm page shows the English README: the Russian one is now `README-ru.md`, which npm does not pack.
package/README.md CHANGED
@@ -11,14 +11,14 @@ The CLI is `estimetry`, with the short alias `emt`.
11
11
  You need:
12
12
  - Node.js 22.12 or newer;
13
13
  - git;
14
- - [Claude Code](https://docs.claude.com/en/docs/claude-code) — the only AI tool estimetry supports for now.
14
+ - an AI tool: [Claude Code](https://docs.claude.com/en/docs/claude-code), [Codex](https://github.com/openai/codex) 0.145 or newer, or both.
15
15
 
16
16
  ```sh
17
17
  npm install -g estimetry
18
18
  emt --version
19
19
  ```
20
20
 
21
- Install it globally: the hooks of Claude Code call `estimetry` from `PATH`.
21
+ Install it globally. The hooks `init` writes run this installation by its paths, so neither a version manager (asdf, nvm) that picks another Node.js for a project nor a program without your shell's `PATH` stops them.
22
22
 
23
23
  To update later: `npm install -g estimetry@latest`, then `emt upgrade` once (see [After upgrading estimetry](#after-upgrading-estimetry)).
24
24
 
@@ -26,11 +26,13 @@ To update later: `npm install -g estimetry@latest`, then `emt upgrade` once (see
26
26
 
27
27
  ## Getting started
28
28
 
29
- 1. In the root of a repository, run `estimetry init`. It sets up the Claude Code hooks and the `/emt-…` skills.
30
- 2. Start a new Claude Code session there and ask how long a task will take, or run `/emt-estimate`. The agent creates the task, estimates it by parts and saves the estimate once you approve it.
29
+ 1. In the root of a repository, run `estimetry init`. It sets up the hooks and the `emt-…` skills of the AI tools it finds on your machine. Codex runs a hook only once you trust it: init asks whether to trust the estimetry hooks for you.
30
+ 2. Start a new session there and ask how long a task will take, or run `/emt-estimate`. The agent creates the task, estimates it by parts and saves the estimate once you approve it.
31
31
  3. Run `/emt-start` and work as usual. The hooks measure the time of the agents and your own time; `emt status` shows it.
32
32
  4. When the work is done, run `/emt-close`. The agent closes the task and asks you why the fact differs from the estimate.
33
33
 
34
+ The skills are the same in both tools: Claude Code calls them as `/emt-…`, Codex as `$emt-…` (`$emt-estimate`, `$emt-start`). This README names them the Claude Code way.
35
+
34
36
  Every closed task makes the next estimate more grounded: `emt similar` finds past tasks like the new one, and `emt calibrate` gives your own coefficient once there are enough of them.
35
37
 
36
38
  ## Help
@@ -50,7 +52,7 @@ estimetry init
50
52
  ```
51
53
 
52
54
  In a terminal it asks a few questions:
53
- - which AI tools to set up (Claude Code for now);
55
+ - which AI tools to set up: Claude Code, Codex, or both;
54
56
  - the development process (OpenSpec or none);
55
57
  - how to share data with your team;
56
58
  - whether to install a git hook.
@@ -59,15 +61,35 @@ In a terminal it asks a few questions:
59
61
 
60
62
  ### What it installs
61
63
 
64
+ By default init sets up the tools already installed in the project, else those it finds on this machine (`~/.claude`, `~/.codex`), else all of them.
65
+
66
+ **Claude Code:**
67
+
62
68
  | What | Where | Who gets it |
63
69
  |---|---|---|
64
- | Hooks for 12 Claude Code events, each running `estimetry hook claude-code <event>` | `.claude/settings.local.json` | you |
70
+ | Hooks for 12 Claude Code events, each running this installation (`<node> <estimetry> hook claude-code <event>`, else `estimetry hook claude-code <event>` from `PATH`) | `.claude/settings.local.json` | you |
65
71
  | Skills `estimetry`, `emt-estimate`, `emt-start`, `emt-extra`, `emt-parallel`, `emt-manual`, `emt-close`, `emt-retro` (also the `/emt-…` commands) | `~/.claude/skills/` (or `$CLAUDE_CONFIG_DIR/skills/`) | you, in every project |
66
- | Project id and development process | `.estimetry/config.yaml` | the team; commit it so clones of the repository are one project |
67
72
 
68
73
  With `--shared-hooks` the hooks go to `.claude/settings.json` and the skills to `.claude/skills/` of the project. A reminder to run `/emt-estimate` before naming a deadline is added to `CLAUDE.md`, between `<!-- estimetry:start -->` and `<!-- estimetry:end -->`. These are files the project commits, so the whole team gets them.
69
74
 
70
- With `--track-commits` a `post-commit` hook is installed into the repository's hooks directory. This respects `core.hooksPath`, worktrees and husky (`.husky/post-commit`). An existing hook keeps its content: estimetry adds its own block between `# >>> estimetry >>>` and `# <<< estimetry <<<`. The hook runs estimetry in the background, so commits never wait for it. Colleagues without estimetry see nothing. A commit from a program that does not get your shell's `PATH` (an IDE started from the Dock on macOS) is recorded too: a personal hook (in `.git`, or a hooks directory outside the repository) falls back to the Node.js, estimetry and data directory `init` ran with. After switching Node.js versions, run `emt upgrade` so it points to the new ones. A hook the project commits (husky, `core.hooksPath` inside the repository) holds no paths of your machine and needs `estimetry` on `PATH`.
75
+ **Codex:**
76
+
77
+ | What | Where | Who gets it |
78
+ |---|---|---|
79
+ | Hooks for 10 Codex events, each running this installation (`<node> <estimetry> hook codex <event>`, else `estimetry hook codex <event>` from `PATH`) | `~/.codex/hooks.json` (or `$CODEX_HOME/hooks.json`) | you, in every project |
80
+ | The same skills, called as `$emt-…` | `~/.agents/skills/` | you, in every project |
81
+ | With your consent: a trust of each hook | `~/.codex/config.toml`, `[hooks.state."…"]` | you |
82
+ | With your consent: a rule that lets the task commands (`emt start`, `extra`, `close`…) run outside the sandbox of Codex | `~/.codex/rules/estimetry.rules`, also with `--shared-hooks` | you |
83
+
84
+ Codex has no personal settings inside a project, so the hooks of a personal install serve every project on the machine; in a project without estimetry they do nothing. With `--shared-hooks` the hooks go to `.codex/hooks.json` and the skills to `.agents/skills/` of the project, and the reminder to run `$emt-estimate` goes to `AGENTS.md`. Codex reads the hooks of a project only once you trust the project.
85
+
86
+ **Both:**
87
+
88
+ | What | Where | Who gets it |
89
+ |---|---|---|
90
+ | Project id and development process | `.estimetry/config.yaml` | the team; commit it so clones of the repository are one project |
91
+
92
+ With `--track-commits` a `post-commit` hook is installed into the repository's hooks directory. This respects `core.hooksPath`, worktrees and husky (`.husky/post-commit`). An existing hook keeps its content: estimetry adds its own block between `# >>> estimetry >>>` and `# <<< estimetry <<<`. The hook runs estimetry in the background, so commits never wait for it. Colleagues without estimetry see nothing. A personal hook (in `.git`, or a hooks directory outside the repository) runs this installation by its paths, like the Claude Code hooks, so a commit from an IDE started from the Dock is recorded too. A hook the project commits (husky, `core.hooksPath` inside the repository) holds no paths of your machine and needs `estimetry` on `PATH`.
71
93
 
72
94
  No task data ever goes into the repository. Tasks, estimates and the event journal live in `~/.local/share/estimetry/`, or in `ESTIMETRY_HOME` if set.
73
95
 
@@ -75,11 +97,12 @@ No task data ever goes into the repository. Tasks, estimates and the event journ
75
97
 
76
98
  | Flag | Meaning |
77
99
  |---|---|
78
- | `--tools <ids>` | AI tools, comma-separated: `claude-code` (alias `claude`) |
100
+ | `--tools <ids>` | AI tools, comma-separated: `claude-code` (alias `claude`), `codex` (alias `openai-codex`) |
79
101
  | `--flow <id>` | `openspec` or `none`; detected by default (`openspec/` in the root means OpenSpec) |
80
102
  | `--share <mode>` | `none`, `calibration` or `cards`; only saved for now |
81
103
  | `--track-commits` / `--no-track-commits` | install or remove the git hook |
82
104
  | `--shared-hooks` / `--no-shared-hooks` | install for the whole team or for yourself only |
105
+ | `--trust-hooks` / `--no-trust-hooks` | trust the hooks in tools that ask for it (Codex) and let the task commands run outside their sandbox; asked in a terminal, not done without one |
83
106
  | `--force` | overwrite generated skills you have edited |
84
107
  | `--no-interactive` | do not ask questions |
85
108
  | `--json` | print the report as JSON |
@@ -89,9 +112,12 @@ A repeated run keeps what is installed: once the git hook or the shared install
89
112
  ### Good to know
90
113
 
91
114
  - **Your edits to generated skills are kept.** Every generated skill carries `metadata.generatedBy` and a hash of its content. If you edit one, init keeps your version and reports it as `skipped`; `--force` overwrites it. A file of the same name that estimetry did not create is never touched.
92
- - **A rewritten hook is yours.** estimetry recognises its hooks by the command prefix `estimetry hook claude-code`. If you change that command, init treats the hook as yours and adds its own next to it.
115
+ - **Codex runs a hook only once you trust it, and the agent's commands in a sandbox.** Neither the CLI nor the VS Code extension of Codex always asks, so the hooks may stay silent. In a terminal init asks whether to trust them; with yes (or `--trust-hooks`) it records the trust in `~/.codex/config.toml`, as `/hooks` in Codex would, and adds a rule that lets the task commands write to the store of estimetry without asking: the sandbox allows writes only inside the project. `init`, `upgrade` and `rebuild` stay outside the rule; `close` and `renegotiate` are in it, so the agent closes a task without a prompt of Codex, only after you agree in the conversation. The rule is yours even with a shared install, and it is also the mark of your consent: `emt upgrade` trusts again the hooks it changes while the rule is there, and `--no-trust-hooks` takes it away (the trusts Codex keeps stay; take them back in `/hooks`). Without a terminal nothing is trusted unless you pass `--trust-hooks`. A `config.toml` with an inline or dotted `hooks` table or a multi-line string is not changed: then trust the hooks in `/hooks`. The rule allows `emt` by name: keep project directories (direnv `./bin`, `node_modules/.bin`) out of your `PATH` in Codex, or the agent could put an `emt` of its own there. `emt status` warns while they are not trusted.
116
+ - **Personal and shared Codex hooks together run twice.** Codex adds up the hooks of every file. The fact stays right, since repeated events are dropped, but init warns and you may remove the estimetry hooks from `~/.codex/hooks.json`.
117
+ - **Codex may copy Claude Code settings.** Its migration of Claude Code settings (hooks, skills) can bring the Claude Code hooks of estimetry into Codex. Set up Codex with `estimetry init --tools codex` instead, and remove such copies.
118
+ - **A rewritten hook is yours.** estimetry recognises its hooks by the command it writes: the paths of the installation that fall back to `estimetry hook claude-code` (or `hook codex`), or that prefix alone. If you change that command, init treats the hook as yours and adds its own next to it.
93
119
  - **`settings.local.json` may not be ignored by git.** Claude Code adds `**/.claude/settings.local.json` to your global git excludes only when it writes that file itself. If init creates it and git does not ignore it, init offers to add the same line. With `--no-interactive` it only warns.
94
- - **Hooks need `estimetry` on `PATH`.** When run through `npx`, the hooks will not find it, and init warns about that.
120
+ - **Hooks run the installation that ran `init`.** `npm install -g` under the same Node.js replaces it in place. After installing estimetry under another Node.js, or removing the one that ran `init`, run `emt upgrade`: until then the hooks run the old installation or fall back to `estimetry` on `PATH`. Run through `npx`, or on Windows, init writes no paths, and the hooks need `estimetry` on `PATH`. The hooks also keep the data directory of that `init` unless `ESTIMETRY_HOME` is set where they run: an `init` with a temporary `ESTIMETRY_HOME` sends the hooks of the project there too.
95
121
 
96
122
  ## Estimating a task
97
123
 
@@ -121,7 +147,7 @@ emt calibrate --type feature --revise # for a revision of a task in progress
121
147
 
122
148
  ## Measuring a task
123
149
 
124
- Once a task is started (`emt start`), the Claude Code hooks record its sessions into the task's journal. `emt status` shows the fact measured so far: the time of the agents, your own time, and how certain the numbers are.
150
+ Once a task is started (`emt start`), the hooks of Claude Code and Codex record its sessions into the task's journal; sessions of both tools may serve one task. `emt status` shows the fact measured so far: the time of the agents, your own time, and how certain the numbers are.
125
151
 
126
152
  ### What counts
127
153
 
@@ -157,6 +183,8 @@ The cost is the total Claude Code itself records in the session log, at API pric
157
183
 
158
184
  Sessions that ended before you installed this version are read when the task closes. Claude Code deletes logs after 30 days; for longer tasks raise `cleanupPeriodDays` in its settings.
159
185
 
186
+ **Codex** keeps a rollout of every session in `~/.codex/sessions/`. estimetry reads it in the same way: turns, subagents and tokens by model. Codex records no cost, so its sessions count in tokens only. The cost of a task then stands for its Claude Code sessions, and the status says by how many: `cost from 1 of 2 sessions`, or `not reported` when there are none. Codex compresses rollouts older than a week, and those are not read; the end of a session imports its rollout long before that. The internal subagents of Codex (such as the review of commands before you approve them) leave no hooks and are not counted.
187
+
160
188
  ### Which task a session serves
161
189
 
162
190
  - **One task in progress** — a session binds to it by itself.
@@ -165,7 +193,7 @@ Sessions that ended before you installed this version are read when the task clo
165
193
 
166
194
  ### Restarts and parallel sessions
167
195
 
168
- The hooks find the project by the directory Claude Code runs in, not by the session id.
196
+ The hooks find the project by the directory the AI tool runs in, not by the session id. In Codex a session begins with its first prompt, not when Codex starts: Codex tells the hooks of a session only then.
169
197
 
170
198
  - **After a restart** (VS Code, a crash, a reboot) the new session has a new id and binds again by the rules above: with one task in progress, time goes on into it without anything to do. With several, answer the agent which task it is: once attached, the work the new session did since the task started counts too.
171
199
  - **A turn cut off by a crash** gets no end. Its tail is closed by the idle threshold and shows as uncertainty (`± …` in `emt status`). The time between the crash and the restart does not count.
@@ -307,7 +335,7 @@ The journal keeps when things happened, not what was said or done: no prompt tex
307
335
 
308
336
  Run `emt upgrade` once, from any directory. It sets estimetry up again in every working copy of every registered project on this machine (worktrees included), each with the choices it already has: tools, flow, a personal or shared install, the commit hook. It shows what will change and asks first; without a terminal it needs `--yes`. A copy where estimetry was never set up is skipped, and so is one that is not on this machine. With a shared install the plan warns that the files it changes are committed by the project. To update a single project instead, run `emt init` inside it.
309
337
 
310
- Until then the hooks keep working: they run the new `estimetry` from `PATH`; only what `init` wrote is old — the hook settings in each project, the skills and, with a shared install, the reminder in `CLAUDE.md`. At the start of a session in a project set up by an older version, the agent is told to suggest `emt upgrade`; it never runs it on its own.
338
+ Until then the hooks keep working: an update under the same Node.js replaces the installation they run; only what `init` wrote is old — the hook settings in each project, the skills and, with a shared install, the reminder in `CLAUDE.md` or `AGENTS.md`. Codex asks to trust its hooks again after `emt upgrade` changes them. At the start of a session in a project set up by an older version, the agent is told to suggest `emt upgrade`; it never runs it on its own.
311
339
 
312
340
  Update every installed copy of estimetry at once. Cards written by an older version are rebuilt from the journals on the next closing, `emt task show` or `emt rebuild`. A newer card stops an older estimetry from rewriting `calibration.json` and is reported instead; versions before this check skip such cards silently, so close no task with them.
313
341
 
@@ -320,13 +348,15 @@ Every command and flag, by stage, as `emt --help` lists them. `estimetry` and `e
320
348
  ### Setup
321
349
 
322
350
  - **`emt init`** — set up estimetry in this project: hooks, skills and commands of the AI tool, project config
323
- - `--tools <ids>` — AI tools, comma-separated (claude-code)
351
+ - `--tools <ids>` — AI tools, comma-separated: claude-code, codex (default: installed, else found on this machine)
324
352
  - `--flow <id>` — development process: openspec or none (default: detected)
325
353
  - `--share <mode>` — sharing with the team: none, calibration, cards
326
354
  - `--track-commits` — install a git post-commit hook
327
355
  - `--no-track-commits` — remove the git post-commit hook
328
356
  - `--shared-hooks` — install for the whole team, into files the project commits
329
357
  - `--no-shared-hooks` — install for yourself only (default)
358
+ - `--trust-hooks` — trust the hooks in tools that ask for it (Codex) and let its task commands run outside their sandbox
359
+ - `--no-trust-hooks` — trust nothing, take away the rule for the task commands (without either flag: kept as it is)
330
360
  - `--force` — overwrite generated skills you have edited
331
361
  - `--no-interactive` — do not ask; use flags and defaults
332
362
  - **`emt upgrade`** — after updating estimetry: set it up again in every project on this machine, each with its own choices
@@ -0,0 +1,34 @@
1
+ /** The first word of a command with the paths of an installation. */
2
+ const RUNNER_MARKER = 'estimetry_home=';
3
+ /**
4
+ * A POSIX shell command that runs `estimetry <args>` (estimetry-command, one
5
+ * rule for every hook): this installation by its paths while they exist, else
6
+ * `estimetry` from PATH. ESTIMETRY_HOME set by the user wins over the one of `init`.
7
+ */
8
+ export function estimetryCommand(runner, args) {
9
+ const fromPath = `estimetry ${args}`;
10
+ if (runner === undefined) {
11
+ return fromPath;
12
+ }
13
+ const node = quoted(runner.node);
14
+ const main = quoted(runner.main);
15
+ return (`${RUNNER_MARKER}${quoted(runner.home)}; ` +
16
+ `if [ -x ${node} ] && [ -f ${main} ]; then ESTIMETRY_HOME="\${ESTIMETRY_HOME:-$estimetry_home}" ${node} ${main} ${args}; ` +
17
+ `else ${fromPath}; fi`);
18
+ }
19
+ /**
20
+ * Whether a command is one `estimetryCommand` writes for these arguments, in
21
+ * either form, or a command of an older version (`estimetry <args> …`): hooks
22
+ * are recognised on reinstall by the same rule that writes them.
23
+ */
24
+ export function isEstimetryCommand(command, argsPrefix) {
25
+ const fromPath = `estimetry ${argsPrefix}`;
26
+ const plain = command === fromPath || command.startsWith(`${fromPath} `);
27
+ const withPaths = command.startsWith(RUNNER_MARKER) && command.includes(`; else ${fromPath} `) && command.endsWith('; fi');
28
+ return plain || withPaths;
29
+ }
30
+ /** A path for a POSIX shell in single quotes: spaces and quotes in it stay one word. */
31
+ function quoted(path) {
32
+ return `'${path.replaceAll("'", `'\\''`)}'`;
33
+ }
34
+ //# sourceMappingURL=estimetry-command.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A skill of estimetry named in a text for the agent, before the tool is known: the context of hooks and the
3
+ * bodies of skills mention a skill with this mark, and the tool's adapter turns it into the way its agent calls
4
+ * skills (`/emt-extra` in Claude Code, `$emt-extra` in Codex). One rule for every text.
5
+ */
6
+ export function skillMention(id) {
7
+ return `{{skill:${id}}}`;
8
+ }
9
+ const MENTION = /\{\{skill:([a-z][a-z0-9-]*)\}\}/g;
10
+ /** The text with every mention of a skill named by `skillRef`. */
11
+ export function nameSkills(text, skillRef) {
12
+ return text.replace(MENTION, (_mark, id) => skillRef(id));
13
+ }
14
+ /** Where a body of a skill takes the arguments the user gave with it. */
15
+ export const ARGUMENTS_MENTION = '{{arguments}}';
16
+ /** A body of a skill in a tool's form: its skills named by `skillRef`, its arguments as `args`. */
17
+ export function renderBody(body, skillRef, args) {
18
+ return nameSkills(body, skillRef).replaceAll(ARGUMENTS_MENTION, args);
19
+ }
20
+ //# sourceMappingURL=skill-mention.js.map
@@ -1,6 +1,7 @@
1
1
  import { ImportSessionLogs } from './task/import-session-logs.js';
2
2
  import { InitProject } from './project/init-project.js';
3
3
  import { ShowInitChoices } from './project/show-init-choices.js';
4
+ import { toolNotices } from './project/tool-notices.js';
4
5
  import { InstallCopy } from './project/install-copy.js';
5
6
  import { UpgradePlanner } from './project/upgrade-plan.js';
6
7
  import { ShowUpgradePlan } from './project/show-upgrade-plan.js';
@@ -92,6 +93,7 @@ function projectGroup(deps, core) {
92
93
  init: (input) => initProject.execute(input),
93
94
  upgradePlan: () => showUpgradePlan.execute(),
94
95
  upgrade: () => upgradeProjects.execute(),
96
+ notices: () => toolNotices(deps.install, deps.workspace.currentRoot()),
95
97
  };
96
98
  }
97
99
  function tasksGroup(deps, core) {
@@ -1,7 +1,15 @@
1
1
  /** The agent reads this; the tool shows it among system messages, so it stays short. */
2
2
  export const MAX_CONTEXT_LENGTH = 1000;
3
- /** Text for the agent cut to the limit, with an ellipsis when it was longer. */
3
+ /**
4
+ * Text for the agent cut to the limit, with an ellipsis when it was longer. A mention of a skill (`{{skill:…}}`) is
5
+ * named only after the cut, so a cut inside one drops the whole mark rather than leave a piece of it to the agent.
6
+ */
4
7
  export function cut(text, limit = MAX_CONTEXT_LENGTH) {
5
- return text.length <= limit ? text : `${text.slice(0, Math.max(0, limit - 1))}…`;
8
+ if (text.length <= limit) {
9
+ return text;
10
+ }
11
+ const head = text.slice(0, Math.max(0, limit - 1));
12
+ const open = head.lastIndexOf('{{');
13
+ return `${open > head.lastIndexOf('}}') ? head.slice(0, open) : head}…`;
6
14
  }
7
15
  //# sourceMappingURL=context-limit.js.map
@@ -1,7 +1,15 @@
1
+ import { skillMention } from '../contracts/skill-mention.js';
1
2
  import { cut, MAX_CONTEXT_LENGTH } from './context-limit.js';
2
- export const EXTRA_REMINDER = 'estimetry: if the work has gone beyond the plan, record it with /emt-extra.';
3
+ /**
4
+ * Texts for the agent name skills with `skillMention`: the receiver names them the way the tool calls them.
5
+ * A mention is longer than any name it becomes, so a text cut to the limit stays within it.
6
+ */
7
+ export const EXTRA_REMINDER = `estimetry: if the work has gone beyond the plan, record it with ${skillMention('emt-extra')}.`;
3
8
  /** First line of every session start: estimates go through the protocol, never a guess (estimate mode, design §5.1). */
4
- export const ESTIMATE_REMINDER = 'estimetry: before you name an effort or a deadline for a task, run /emt-estimate.';
9
+ export const ESTIMATE_REMINDER = `estimetry: before you name an effort or a deadline for a task, run ${skillMention('emt-estimate')}.`;
10
+ const START = skillMention('emt-start');
11
+ const CLOSE = skillMention('emt-close');
12
+ const NO_TASK = `estimetry: no task is in progress in this project, so the time of this session is not counted. Start one with ${START}.`;
5
13
  /** The copy of the session was set up by an older estimetry (claude-code-hooks spec): the agent suggests, never runs, `emt upgrade`. */
6
14
  export function upgradeText(current, installed) {
7
15
  return (`estimetry: estimetry ${current} is installed, but this project was set up by ${installed ?? 'an older version'}. ` +
@@ -28,7 +36,7 @@ export function sessionStartContext(input) {
28
36
  }
29
37
  return cut(`${head}${list()}${ask}`, budget);
30
38
  }
31
- return 'estimetry: no task is in progress in this project, so the time of this session is not counted. Start one with /emt-start.';
39
+ return NO_TASK;
32
40
  }
33
41
  /**
34
42
  * A change of the task was completed (task-closing spec). The agent asks; the
@@ -42,7 +50,7 @@ export function closeProposalText(input) {
42
50
  ];
43
51
  return cut(`estimetry: change ${input.change} of task ${input.task} was completed at ${when}` +
44
52
  (plan.length === 0 ? '' : `; ${plan.join(', ')}`) +
45
- `. If it was the last change of the task, ask the user whether to close it (/emt-close); close only after they agree.`);
53
+ `. If it was the last change of the task, ask the user whether to close it (${CLOSE}); close only after they agree.`);
46
54
  }
47
55
  function duration(minutes) {
48
56
  const whole = Math.round(minutes);
@@ -1,4 +1,5 @@
1
1
  import { InvalidValue } from '../../domain/shared/domain-error.js';
2
+ import { nameSkills } from '../contracts/skill-mention.js';
2
3
  /**
3
4
  * A hook of an AI tool's session: the call becomes activity of the session's
4
5
  * task, then its kind decides what follows — the context of a session start or
@@ -29,7 +30,7 @@ export class ReceiveSessionHook {
29
30
  throw new InvalidValue(`${adapter.id} ${event}: stdin is not JSON`); // its content is never repeated
30
31
  }
31
32
  const translation = adapter.translate(event, payload);
32
- const located = this.locator.locate(call.projectDir ?? translation.cwd ?? call.cwd);
33
+ const located = this.locator.locate(projectDirOf(adapter, call) ?? translation.cwd ?? call.cwd);
33
34
  const resolved = this.sessionTask.resolve(translation.session, located, translation.kind, now);
34
35
  if (resolved === undefined) {
35
36
  return undefined; // not an estimetry project
@@ -37,17 +38,27 @@ export class ReceiveSessionHook {
37
38
  this.recorder.record(adapter.id, translation, resolved, now);
38
39
  switch (translation.kind) {
39
40
  case 'session-start':
40
- return adapter.renderContext(event, await this.start.text(translation.session, resolved, now));
41
+ return render(adapter, event, await this.start.text(translation.session, resolved, now));
41
42
  case 'session-end':
42
- await this.end.run(adapter.id, translation.session, translation.transcript);
43
+ await this.end.run(adapter, translation.session, translation.transcript);
43
44
  return undefined;
44
45
  case 'prompt': {
45
46
  const text = await this.prompt.text(translation.session, resolved, now);
46
- return text === undefined ? undefined : adapter.renderContext(event, text);
47
+ return text === undefined ? undefined : render(adapter, event, text);
47
48
  }
48
49
  default:
49
50
  return undefined;
50
51
  }
51
52
  }
52
53
  }
54
+ /** The project root the tool names in its own environment variable; an empty one names none. */
55
+ function projectDirOf(adapter, call) {
56
+ const variable = adapter.projectDirVariable;
57
+ const value = variable === undefined ? undefined : call.environment?.(variable);
58
+ return value === '' ? undefined : value;
59
+ }
60
+ /** The context in the tool's format, with the skills named the way its agent calls them. */
61
+ function render(adapter, event, text) {
62
+ return adapter.renderContext(event, nameSkills(text, (id) => adapter.skillRef(id)));
63
+ }
53
64
  //# sourceMappingURL=receive-session-hook.js.map
@@ -1,10 +1,9 @@
1
1
  import { isInProgress } from '../../domain/task/task-status.js';
2
2
  import { servedTasks } from '../ports/session-bindings.js';
3
- /** The session end imports the session's log in the hook itself, within this time (claude-code-hooks spec). */
4
- export const SESSION_END_IMPORT_BUDGET_MS = 5_000;
5
3
  /**
6
- * The log of an ended session goes into every task in progress it served.
7
- * Past the budget the import gives up; the closing of the task catches up.
4
+ * The log of an ended session goes into every task in progress it served, in the hook itself, within the budget
5
+ * of the tool (it waits for the session end hook only so long). Past it the import gives up; the closing of the task
6
+ * catches up.
8
7
  */
9
8
  export class SessionEndImport {
10
9
  bindings;
@@ -17,7 +16,7 @@ export class SessionEndImport {
17
16
  this.tasks = tasks;
18
17
  this.logs = logs;
19
18
  }
20
- async run(source, session, transcript) {
19
+ async run(tool, session, transcript) {
21
20
  if (this.logs === undefined) {
22
21
  return;
23
22
  }
@@ -33,10 +32,10 @@ export class SessionEndImport {
33
32
  const path = transcript ?? binding?.transcript;
34
33
  (await this.logs()).execute({
35
34
  session,
36
- source,
35
+ source: tool.id,
37
36
  ...(path === undefined ? {} : { path }),
38
37
  tasks,
39
- budgetMs: SESSION_END_IMPORT_BUDGET_MS,
38
+ budgetMs: tool.sessionEndBudgetMs,
40
39
  });
41
40
  }
42
41
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=estimetry-runner.js.map
@@ -1,11 +1,24 @@
1
- /** The tools installed in the copy now. */
1
+ /**
2
+ * The tools installed in the copy now. An install of the user outside the copy (`machineWide`) is there for every
3
+ * copy, so it counts only for a copy without a shared install: it must not make a team's copy install it for the team.
4
+ */
2
5
  export function installedTools(deps, root) {
3
- return deps.registries.tools.all().filter((tool) => tool.state(root, deps.files).installed);
6
+ const states = deps.registries.tools.all().map((tool) => ({ tool, state: tool.state(root, deps.files) }));
7
+ const sharedHere = states.some(({ state }) => state.installed && state.shared);
8
+ return states.filter(({ state }) => state.installed && !(state.machineWide === true && sharedHere)).map(({ tool }) => tool);
4
9
  }
5
- /** The tools already installed in the project, else every tool. */
10
+ /**
11
+ * The tools already installed in the project, else the tools found on this machine, else every tool. An install of
12
+ * the user outside the copy alone does not make the copy's choice: then the tools found on the machine join it.
13
+ */
6
14
  export function defaultTools(deps, root) {
7
15
  const installed = installedTools(deps, root);
8
- return installed.length > 0 ? installed : [...deps.registries.tools.all()];
16
+ if (installed.some((tool) => tool.state(root, deps.files).machineWide !== true)) {
17
+ return installed;
18
+ }
19
+ const all = deps.registries.tools.all();
20
+ const found = all.filter((tool) => tool.present(deps.files) || installed.includes(tool));
21
+ return found.length > 0 ? found : [...all];
9
22
  }
10
23
  /** Whether these tools have a shared install in the copy: then it stays shared. */
11
24
  export function isSharedInstall(deps, root, tools) {
@@ -24,7 +24,9 @@ export class InitProject {
24
24
  */
25
25
  execute(input) {
26
26
  const root = this.workspace.currentRoot();
27
- const tools = input.tools === undefined ? defaultTools(this.deps, root) : this.toolsById(input.tools);
27
+ // A shared install puts the files into the team's repository: an install of the user's own does not go there by itself.
28
+ const defaults = defaultTools(this.deps, root).filter((tool) => input.shared !== true || tool.state(root, this.deps.files).machineWide !== true);
29
+ const tools = input.tools === undefined ? defaults : this.toolsById(input.tools);
28
30
  const flow = this.flowById(input.flow ?? defaultFlow(this.deps, this.projectConfig, root));
29
31
  const share = this.shareMode(input.share ?? this.deps.sharing.mode() ?? 'none');
30
32
  const shared = input.shared ?? isSharedInstall(this.deps, root, tools);
@@ -53,6 +55,7 @@ export class InitProject {
53
55
  trackCommits,
54
56
  force: input.force ?? false,
55
57
  ...(input.excludePersonalFiles === undefined ? {} : { excludePersonalFiles: input.excludePersonalFiles }),
58
+ ...(input.trustHooks === undefined ? {} : { trust: input.trustHooks }),
56
59
  });
57
60
  const project = this.projects.update(this.currentProject.register(registration).id, (registered) => {
58
61
  const fingerprint = this.workspace.fingerprint();
@@ -63,7 +66,8 @@ export class InitProject {
63
66
  if (this.deps.sharing.mode() !== share) {
64
67
  this.deps.sharing.save(share);
65
68
  }
66
- if (!this.deps.commands.has(HOOK_COMMAND)) {
69
+ // Personal hooks run this installation by its paths; shared ones, and all without paths (npx, Windows), need PATH.
70
+ if ((shared || this.deps.installation.runner === undefined) && !this.deps.commands.has(HOOK_COMMAND)) {
67
71
  warnings.push(`${HOOK_COMMAND} is not on PATH, so the hooks will not run until the package is installed globally (npm install -g estimetry)`);
68
72
  }
69
73
  return {
@@ -16,9 +16,18 @@ export class InstallCopy {
16
16
  }
17
17
  plan(choices) {
18
18
  const { root } = choices;
19
+ const { version, runner } = this.deps.installation;
20
+ const context = {
21
+ projectRoot: root,
22
+ files: this.deps.files,
23
+ shared: choices.shared,
24
+ force: choices.force,
25
+ version,
26
+ ...(choices.trust === undefined ? {} : { trust: choices.trust }),
27
+ };
19
28
  const plan = mergePlans([
20
- ...choices.tools.map((tool) => tool.plan({ projectRoot: root, files: this.deps.files, shared: choices.shared, force: choices.force, version: this.deps.version })),
21
- this.deps.git.commitHook.plan(root, choices.trackCommits),
29
+ ...choices.tools.map((tool) => tool.plan(runner === undefined ? context : { ...context, runner })),
30
+ this.deps.git.commitHook.plan(root, choices.trackCommits, runner),
22
31
  { changes: [this.projectConfig.plan(root, { project: choices.project, flow: choices.flow.id })], skipped: [], warnings: [] },
23
32
  choices.shared ? EMPTY_PLAN : this.excludePersonalFiles(root, choices.tools, choices.excludePersonalFiles),
24
33
  ]);
@@ -51,7 +60,7 @@ export class InstallCopy {
51
60
  this.deps.files.write(change.path, change.content, change.executable ? { executable: true } : {});
52
61
  }
53
62
  }
54
- this.versions.record(plan.root, this.deps.version);
63
+ this.versions.record(plan.root, this.deps.installation.version);
55
64
  }
56
65
  statusOf(change) {
57
66
  const current = this.deps.files.read(change.path);
@@ -14,7 +14,7 @@ export class ShowInitChoices {
14
14
  const tools = defaultTools(this.deps, root);
15
15
  return {
16
16
  projectRoot: root,
17
- tools: this.deps.registries.tools.all().map(({ id, title }) => ({ id, title })),
17
+ tools: this.deps.registries.tools.all().map(({ id, title, asksTrust }) => ({ id, title, asksTrust })),
18
18
  flows: this.deps.registries.flows.all().map(({ id, title }) => ({ id, title })),
19
19
  defaults: {
20
20
  tools: tools.map((tool) => tool.id),
@@ -0,0 +1,8 @@
1
+ /** What the tools installed in the copy still need from the user for their hooks to run (trust them in Codex). */
2
+ export function toolNotices(deps, root) {
3
+ return deps.registries.tools.all().flatMap((tool) => {
4
+ const state = tool.state(root, deps.files);
5
+ return state.installed && state.notice !== undefined ? [state.notice] : [];
6
+ });
7
+ }
8
+ //# sourceMappingURL=tool-notices.js.map
@@ -45,7 +45,7 @@ export class UpgradePlanner {
45
45
  copies.push({ ...result, files, warnings });
46
46
  }
47
47
  }
48
- return { version: this.deps.version, copies, skipped };
48
+ return { version: this.deps.installation.version, copies, skipped };
49
49
  }
50
50
  copy(project, root) {
51
51
  const id = project.id.value;
@@ -63,7 +63,8 @@ export class ImportSessionLogs {
63
63
  from: offset,
64
64
  turns,
65
65
  agents,
66
- cost: read.cost,
66
+ cost: read.cost ?? [],
67
+ costReported: read.cost !== undefined,
67
68
  skipped: read.skipped,
68
69
  });
69
70
  this.deps.state.write(request.session, task.id, { fingerprint: read.fingerprint, next: read.next });
@@ -118,6 +119,8 @@ export class ImportSessionLogs {
118
119
  turns: part.turns,
119
120
  agents: part.agents,
120
121
  cost: i === 0 ? content.cost : [],
122
+ // Written only when false: records of a tool with a cost stay as before, and old readers read them.
123
+ ...(content.costReported === false ? { costReported: false } : {}),
121
124
  skipped: i === 0 ? content.skipped : 0,
122
125
  };
123
126
  this.deps.journal.appendRecord(journalEntry('log.session', data, { ...this.deps.meta.at(at), project: task.project, task: task.id }));