estimetry 0.1.2 → 0.3.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/CHANGELOG.md +20 -0
- package/README.md +88 -16
- package/dist/application/contracts/skill-mention.js +20 -0
- package/dist/application/estimetry.js +2 -0
- package/dist/application/hooks/context-limit.js +10 -2
- package/dist/application/hooks/hook-context.js +12 -4
- package/dist/application/hooks/receive-session-hook.js +15 -4
- package/dist/application/hooks/session-end-import.js +6 -7
- package/dist/application/project/init-defaults.js +17 -4
- package/dist/application/project/init-project.js +4 -1
- package/dist/application/project/install-copy.js +8 -1
- package/dist/application/project/show-init-choices.js +1 -1
- package/dist/application/project/tool-notices.js +8 -0
- package/dist/application/task/import-session-logs.js +4 -1
- package/dist/application/task/show-calibration.js +12 -8
- package/dist/application/task/task-cards.js +1 -1
- package/dist/bootstrap/container.js +23 -6
- package/dist/bootstrap/hook-receiver.js +7 -14
- package/dist/bootstrap/main.js +1 -1
- package/dist/domain/calibration/applicable-coefficient.js +35 -19
- package/dist/domain/calibration/calibration-policy.js +39 -0
- package/dist/domain/calibration/calibration.js +21 -36
- package/dist/domain/calibration/level-parts.js +41 -0
- package/dist/domain/calibration/ratio-samples.js +34 -0
- package/dist/domain/code/code-classes.js +1 -1
- package/dist/domain/estimate/estimate.js +22 -5
- package/dist/domain/progress/progress-record-parser.js +6 -0
- package/dist/domain/progress/session-log.js +2 -1
- package/dist/domain/usage/task-usage.js +24 -7
- package/dist/infrastructure/persistence/records.js +1 -1
- package/dist/infrastructure/persistence/yaml-config-store.js +6 -5
- package/dist/infrastructure/persistence/yaml-estimate-reader.js +20 -12
- package/dist/integrations/tools/claude-code/claude-code-adapter.js +29 -48
- package/dist/integrations/tools/claude-code/hook-events.js +4 -0
- package/dist/integrations/tools/claude-code/hook-translation.js +16 -34
- package/dist/integrations/tools/claude-code/importer/claude-code-logs.js +1 -1
- package/dist/integrations/tools/claude-code/skill-file.js +7 -19
- package/dist/integrations/tools/codex/codex-adapter.js +161 -0
- package/dist/integrations/tools/codex/hook-events.js +23 -0
- package/dist/integrations/tools/codex/hook-translation.js +76 -0
- package/dist/integrations/tools/codex/hook-trust.js +69 -0
- package/dist/integrations/tools/codex/importer/codex-logs.js +208 -0
- package/dist/integrations/tools/codex/importer/rollout-parser.js +163 -0
- package/dist/integrations/tools/codex/sandbox-rules.js +38 -0
- package/dist/integrations/tools/codex/skill-file.js +22 -0
- package/dist/integrations/tools/codex/trust-tables.js +96 -0
- package/dist/integrations/tools/content/commands.js +35 -26
- package/dist/integrations/tools/shared/generated-file.js +26 -0
- package/dist/integrations/tools/shared/hook-payload.js +33 -0
- package/dist/integrations/tools/{claude-code → shared}/hook-settings.js +37 -22
- package/dist/integrations/tools/shared/instructions-block.js +39 -0
- package/dist/integrations/tools/shared/skills-plan.js +39 -0
- package/dist/interface/cli/commands/calibrate-command.js +11 -0
- package/dist/interface/cli/commands/hook-command.js +1 -1
- package/dist/interface/cli/commands/init-command.js +16 -7
- package/dist/interface/cli/commands/status-command.js +5 -2
- package/dist/interface/cli/help.js +3 -1
- package/dist/interface/cli/presenters/text/closing-text.js +7 -3
- package/dist/interface/cli/presenters/text/estimate-text.js +35 -13
- package/dist/interface/cli/presenters/text/notices-text.js +1 -0
- package/dist/interface/cli/presenters/text/task-text.js +1 -1
- package/dist/interface/cli/presenters/text-presenter.js +3 -3
- package/package.json +1 -1
- package/dist/integrations/tools/claude-code/claude-md.js +0 -28
- /package/dist/integrations/tools/{claude-code/importer → shared}/log-lines.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { homedir, userInfo } from 'node:os';
|
|
4
4
|
import { basename, dirname, join, sep } from 'node:path';
|
|
@@ -33,6 +33,16 @@ function claudeConfigDir(environment) {
|
|
|
33
33
|
const configured = environment.env['CLAUDE_CONFIG_DIR'];
|
|
34
34
|
return configured !== undefined && configured !== '' ? configured : join(environment.homeDir, '.claude');
|
|
35
35
|
}
|
|
36
|
+
/** Codex keeps the user's hooks and config in `$CODEX_HOME`, else `~/.codex`; its skills in `~/.agents/skills`. */
|
|
37
|
+
export function codexDirs(environment) {
|
|
38
|
+
const configured = environment.env['CODEX_HOME'];
|
|
39
|
+
const home = configured !== undefined && configured !== '' ? configured : join(environment.homeDir, '.codex');
|
|
40
|
+
return {
|
|
41
|
+
// Codex keys the trust of a hook by the canonical path of its file: a symlinked CODEX_HOME must give the same key.
|
|
42
|
+
home: existsSync(home) ? realpathSync(home) : home,
|
|
43
|
+
userSkills: join(environment.homeDir, '.agents', 'skills'),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
36
46
|
/** Composition root: the only place that knows which implementation backs which port. */
|
|
37
47
|
export function createContainer(environment, options = {}) {
|
|
38
48
|
const layout = StorageLayout.resolve(environment);
|
|
@@ -44,17 +54,21 @@ export function createContainer(environment, options = {}) {
|
|
|
44
54
|
app: () => (app ??= buildApp(layout, environment, errors)),
|
|
45
55
|
hooks: async () => {
|
|
46
56
|
const { buildHookReceiver } = await import('./hook-receiver.js');
|
|
47
|
-
const
|
|
57
|
+
const toolDirs = { claude: claudeConfigDir(environment), codex: codexDirs(environment).home };
|
|
58
|
+
const receiver = buildHookReceiver(layout, errors, options.startedAt ?? Date.now(), toolDirs);
|
|
48
59
|
return { receive: (call) => receiver.execute(call) };
|
|
49
60
|
},
|
|
50
61
|
};
|
|
51
62
|
}
|
|
52
63
|
async function toolRegistry(environment) {
|
|
53
|
-
const [{ ToolAdapterRegistry }, { ClaudeCodeAdapter }] = await Promise.all([
|
|
64
|
+
const [{ ToolAdapterRegistry }, { ClaudeCodeAdapter }, { CodexAdapter }] = await Promise.all([
|
|
54
65
|
import('../integrations/tools/registry.js'),
|
|
55
66
|
import('../integrations/tools/claude-code/claude-code-adapter.js'),
|
|
67
|
+
import('../integrations/tools/codex/codex-adapter.js'),
|
|
56
68
|
]);
|
|
57
|
-
return new ToolAdapterRegistry()
|
|
69
|
+
return new ToolAdapterRegistry()
|
|
70
|
+
.register(new ClaudeCodeAdapter(claudeConfigDir(environment)))
|
|
71
|
+
.register(new CodexAdapter(codexDirs(environment)));
|
|
58
72
|
}
|
|
59
73
|
async function installDependencies(environment, sharing, layout) {
|
|
60
74
|
const [tools, { FlowRegistry }, { openSpecFlow }, { noneFlow }, { StackDetectorRegistry }, { nodeDetector }, { dartDetector }, { mavenDetector, gradleDetector }, { pythonDetector }, { goDetector }, { composeDetector }, { NodeProjectFiles }, { GitCommitHookInstaller }, { GitExcludesFile }, { PathCommandLocator },] = await Promise.all([
|
|
@@ -139,7 +153,7 @@ async function buildApp(layout, environment, errors) {
|
|
|
139
153
|
}
|
|
140
154
|
/** What closing a task needs besides the task: cards, calibration, proposals, the code volume, `HEAD` and the session logs. */
|
|
141
155
|
async function closingPorts(layout, environment) {
|
|
142
|
-
const [{ YamlCardStore }, { JsonCalibrationStore }, { FileCloseProposals }, { GitCodeMeasurer }, { FsGitHead }, { SessionLogReaderRegistry }, { ClaudeCodeLogs }, { YamlLogImportState },] = await Promise.all([
|
|
156
|
+
const [{ YamlCardStore }, { JsonCalibrationStore }, { FileCloseProposals }, { GitCodeMeasurer }, { FsGitHead }, { SessionLogReaderRegistry }, { ClaudeCodeLogs }, { CodexLogs }, { YamlLogImportState },] = await Promise.all([
|
|
143
157
|
import('../infrastructure/persistence/yaml-card-store.js'),
|
|
144
158
|
import('../infrastructure/persistence/json-calibration-store.js'),
|
|
145
159
|
import('../infrastructure/persistence/file-close-proposals.js'),
|
|
@@ -147,6 +161,7 @@ async function closingPorts(layout, environment) {
|
|
|
147
161
|
import('../infrastructure/git/fs-git-head.js'),
|
|
148
162
|
import('../integrations/tools/session-log-readers.js'),
|
|
149
163
|
import('../integrations/tools/claude-code/importer/claude-code-logs.js'),
|
|
164
|
+
import('../integrations/tools/codex/importer/codex-logs.js'),
|
|
150
165
|
import('../infrastructure/persistence/yaml-log-import-state.js'),
|
|
151
166
|
]);
|
|
152
167
|
return {
|
|
@@ -155,7 +170,9 @@ async function closingPorts(layout, environment) {
|
|
|
155
170
|
proposals: new FileCloseProposals(layout),
|
|
156
171
|
codeMeasurer: new GitCodeMeasurer(),
|
|
157
172
|
gitHead: new FsGitHead(),
|
|
158
|
-
logReaders: new SessionLogReaderRegistry()
|
|
173
|
+
logReaders: new SessionLogReaderRegistry()
|
|
174
|
+
.register(new ClaudeCodeLogs(claudeConfigDir(environment)))
|
|
175
|
+
.register(new CodexLogs(codexDirs(environment).home)),
|
|
159
176
|
logImportState: new YamlLogImportState(layout),
|
|
160
177
|
};
|
|
161
178
|
}
|
|
@@ -36,19 +36,11 @@ import { noneFlow } from '../integrations/flows/none/none-flow.js';
|
|
|
36
36
|
import { openSpecFlow } from '../integrations/flows/openspec/openspec-flow.js';
|
|
37
37
|
import { FlowRegistry } from '../integrations/flows/registry.js';
|
|
38
38
|
import { claudeCodeHooks } from '../integrations/tools/claude-code/hook-translation.js';
|
|
39
|
+
import { codexHooks } from '../integrations/tools/codex/hook-translation.js';
|
|
39
40
|
import { gitHooks } from '../integrations/tools/git/git-hooks.js';
|
|
40
41
|
import { HookAdapterRegistry } from '../integrations/tools/hook-adapters.js';
|
|
41
42
|
import { SessionWindow } from '../application/task/session-window.js';
|
|
42
|
-
|
|
43
|
-
* The hook receiver, apart from the composition of the facade: the container
|
|
44
|
-
* loads this module only for a hook, and a hook loads nothing of the other
|
|
45
|
-
* commands. What only one kind of call needs loads lazily within it.
|
|
46
|
-
*/
|
|
47
|
-
/**
|
|
48
|
-
* Only what a hook needs. The author comes from config.yaml alone: detecting it
|
|
49
|
-
* would run git, and init has written the profile already.
|
|
50
|
-
*/
|
|
51
|
-
export function buildHookReceiver(layout, errors, startedAt, claudeConfig) {
|
|
43
|
+
export function buildHookReceiver(layout, errors, startedAt, toolDirs) {
|
|
52
44
|
const config = new YamlConfigStore(layout, () => {
|
|
53
45
|
throw new Error(`no author profile in ${layout.configFile}; run estimetry init`);
|
|
54
46
|
});
|
|
@@ -75,8 +67,8 @@ export function buildHookReceiver(layout, errors, startedAt, claudeConfig) {
|
|
|
75
67
|
// Only the session start needs the fact, and only it loads the task repository and the calculator.
|
|
76
68
|
new SessionStartContext(() => hookFacts(layout, journal, config, plans), checkpoints, proposal, new UpgradeNotice(new YamlInstallVersions(layout), packageVersion)), new PromptContext(checkpoints, proposal),
|
|
77
69
|
// Only the session end parses a log, and only it loads the reader.
|
|
78
|
-
new SessionEndImport(bindings, tasks, () => hookLogs({ layout,
|
|
79
|
-
const adapters = new HookAdapterRegistry().register(claudeCodeHooks).register(gitHooks);
|
|
70
|
+
new SessionEndImport(bindings, tasks, () => hookLogs({ layout, toolDirs, journal, ids, config, errors })));
|
|
71
|
+
const adapters = new HookAdapterRegistry().register(claudeCodeHooks).register(codexHooks).register(gitHooks);
|
|
80
72
|
return new ReceiveHook(adapters, clock, new CommitRecords(locator, git, new CommitTask(bindings, tasks, recent), journal, meta), sessions);
|
|
81
73
|
}
|
|
82
74
|
/** The plan of a task for the text of a pending proposal to close it: percent done and unfinished groups. */
|
|
@@ -112,15 +104,16 @@ async function hookFacts(layout, journal, settings, plans) {
|
|
|
112
104
|
}
|
|
113
105
|
/** The importer of session logs for a session end. */
|
|
114
106
|
async function hookLogs(c) {
|
|
115
|
-
const [{ ImportSessionLogs }, { SessionLogReaderRegistry }, { ClaudeCodeLogs }, { YamlLogImportState }, { SystemClock }] = await Promise.all([
|
|
107
|
+
const [{ ImportSessionLogs }, { SessionLogReaderRegistry }, { ClaudeCodeLogs }, { CodexLogs }, { YamlLogImportState }, { SystemClock }] = await Promise.all([
|
|
116
108
|
import('../application/task/import-session-logs.js'),
|
|
117
109
|
import('../integrations/tools/session-log-readers.js'),
|
|
118
110
|
import('../integrations/tools/claude-code/importer/claude-code-logs.js'),
|
|
111
|
+
import('../integrations/tools/codex/importer/codex-logs.js'),
|
|
119
112
|
import('../infrastructure/persistence/yaml-log-import-state.js'),
|
|
120
113
|
import('../infrastructure/system/system-clock.js'),
|
|
121
114
|
]);
|
|
122
115
|
return new ImportSessionLogs({
|
|
123
|
-
readers: new SessionLogReaderRegistry().register(new ClaudeCodeLogs(c.
|
|
116
|
+
readers: new SessionLogReaderRegistry().register(new ClaudeCodeLogs(c.toolDirs.claude)).register(new CodexLogs(c.toolDirs.codex)),
|
|
124
117
|
state: new YamlLogImportState(c.layout),
|
|
125
118
|
journal: c.journal,
|
|
126
119
|
meta: new EventMetaSource(new SystemClock(), c.ids, c.config),
|
package/dist/bootstrap/main.js
CHANGED
|
@@ -1,26 +1,42 @@
|
|
|
1
|
+
import { authorCards } from './calibration.js';
|
|
2
|
+
import { levelParts } from './level-parts.js';
|
|
3
|
+
import { ratioSampling } from './ratio-samples.js';
|
|
4
|
+
import { median, round } from './statistics.js';
|
|
5
|
+
/** The spread of the ratio in logarithms the pessimistic coefficient reserves for: a factor of 2 at one task. */
|
|
6
|
+
const SIGMA = Math.log(2);
|
|
1
7
|
/**
|
|
2
|
-
* The coefficient an estimate may apply (calibration-query spec)
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
8
|
+
* The coefficient an estimate may apply (calibration-query spec), from all the
|
|
9
|
+
* cards: the author's are taken as calibration takes them (`authorCards`).
|
|
10
|
+
* Going down the levels (`levelParts`), each part shrinks towards the level
|
|
11
|
+
* above in logarithms by the weight of its own tasks; the overall part towards
|
|
12
|
+
* 1, an empty part equals the level above. The deepest level is applied: its
|
|
13
|
+
* part is its whole slice. A new estimate takes the main ratio; a revision of
|
|
14
|
+
* a task in progress, `revised`.
|
|
6
15
|
*/
|
|
7
|
-
export function applicableCoefficient(
|
|
8
|
-
|
|
16
|
+
export function applicableCoefficient(cards, query, policy) {
|
|
17
|
+
const own = authorCards(cards, query.author, query.aliases);
|
|
18
|
+
const parts = levelParts(ratioSampling(own, query.revise === true), query.estimate, policy);
|
|
19
|
+
const applied = parts.at(-1);
|
|
20
|
+
if (applied === undefined) {
|
|
9
21
|
return null;
|
|
10
22
|
}
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
let logarithm = 0;
|
|
24
|
+
for (const part of parts) {
|
|
25
|
+
const middle = median(part.ratios);
|
|
26
|
+
if (middle !== null) {
|
|
27
|
+
const weight = policy.partWeight(part.ratios.length);
|
|
28
|
+
logarithm = weight * Math.log(middle) + (1 - weight) * logarithm;
|
|
29
|
+
}
|
|
16
30
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
const n = applied.ratios.length;
|
|
32
|
+
const value = Math.exp(logarithm);
|
|
33
|
+
const upper = value * Math.exp(SIGMA / Math.sqrt(n));
|
|
34
|
+
return {
|
|
35
|
+
value: round(value),
|
|
36
|
+
pessimistic: round(value < 1 ? Math.min(1, upper) : upper),
|
|
37
|
+
slice: applied.slice,
|
|
38
|
+
n,
|
|
39
|
+
weight: round(policy.partWeight(n)),
|
|
40
|
+
};
|
|
25
41
|
}
|
|
26
42
|
//# sourceMappingURL=applicable-coefficient.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const DEFAULT_MIN_TASKS = 1;
|
|
2
|
+
export const DEFAULT_SHRINK = 2;
|
|
3
|
+
/**
|
|
4
|
+
* How calibration weighs a slice (calibration spec): from `calibration.minTasks`
|
|
5
|
+
* tasks a slice has the weight n / (n + k) with k = `calibration.shrink` and is a
|
|
6
|
+
* level of the coefficient; each level is shrunk towards the one above by the
|
|
7
|
+
* weight of its own tasks (`partWeight`).
|
|
8
|
+
*/
|
|
9
|
+
export class CalibrationPolicy {
|
|
10
|
+
minTasks;
|
|
11
|
+
shrink;
|
|
12
|
+
constructor(minTasks, shrink) {
|
|
13
|
+
this.minTasks = minTasks;
|
|
14
|
+
this.shrink = shrink;
|
|
15
|
+
}
|
|
16
|
+
static DEFAULT = new CalibrationPolicy(DEFAULT_MIN_TASKS, DEFAULT_SHRINK);
|
|
17
|
+
/**
|
|
18
|
+
* The settings of `config.yaml`; an invalid value counts as not given. A
|
|
19
|
+
* threshold chosen without `shrink` means no shrinking: the user who picked
|
|
20
|
+
* the sample a coefficient needs keeps the coefficient they had.
|
|
21
|
+
*/
|
|
22
|
+
static fromConfig(given) {
|
|
23
|
+
const minTasks = given.minTasks !== undefined && Number.isInteger(given.minTasks) && given.minTasks >= 1 ? given.minTasks : undefined;
|
|
24
|
+
const shrink = given.shrink !== undefined && Number.isFinite(given.shrink) && given.shrink >= 0 ? given.shrink : undefined;
|
|
25
|
+
return new CalibrationPolicy(minTasks ?? DEFAULT_MIN_TASKS, shrink ?? (minTasks === undefined ? DEFAULT_SHRINK : 0));
|
|
26
|
+
}
|
|
27
|
+
/** The weight of the observations of a slice of n tasks: 0 below `minTasks`. */
|
|
28
|
+
weight(n) {
|
|
29
|
+
return n < this.minTasks ? 0 : this.partWeight(n);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The weight of the own tasks of a level in the chain, n / (n + k), without
|
|
33
|
+
* the threshold: `minTasks` is checked on the whole slice. 0 without tasks.
|
|
34
|
+
*/
|
|
35
|
+
partWeight(n) {
|
|
36
|
+
return n === 0 ? 0 : n / (n + this.shrink);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=calibration-policy.js.map
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { stackLabels } from '../estimate/stack-labels.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ratioSampling } from './ratio-samples.js';
|
|
3
3
|
import { EXTRA_CATEGORIES } from '../measurement/extra.js';
|
|
4
4
|
import { isRevised, linesPerHour, partsByKind, volumeAccuracy, } from './code-and-parts.js';
|
|
5
5
|
import { median, round } from './statistics.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const
|
|
6
|
+
import { CalibrationPolicy } from './calibration-policy.js';
|
|
7
|
+
/** 3: the weight of a slice instead of `applicable`, and `shrink` (dynamic-calibration); readers check the version. */
|
|
8
|
+
export const CALIBRATION_SCHEMA_VERSION = 3;
|
|
9
9
|
const UNCERTAINTY_LIMIT = 0.05;
|
|
10
10
|
/** Calibration from the cards of closed tasks, by author (design §10, calibration spec). */
|
|
11
11
|
export function calibrate(all, options = {}) {
|
|
12
|
-
const
|
|
12
|
+
const policy = options.policy ?? CalibrationPolicy.DEFAULT;
|
|
13
13
|
const cards = normalized(all, options.aliases);
|
|
14
14
|
const authors = {};
|
|
15
15
|
const byId = new Map(cards.map((card) => [card.task.id, card]));
|
|
16
16
|
for (const author of [...new Set(cards.map((card) => card.author))].sort()) {
|
|
17
|
-
authors[author] = forAuthor(cards.filter((card) => card.author === author), byId,
|
|
17
|
+
authors[author] = forAuthor(cards.filter((card) => card.author === author), byId, policy);
|
|
18
18
|
}
|
|
19
|
-
return { schemaVersion: CALIBRATION_SCHEMA_VERSION, minTasks, authors };
|
|
19
|
+
return { schemaVersion: CALIBRATION_SCHEMA_VERSION, minTasks: policy.minTasks, shrink: policy.shrink, authors };
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Cards as calibration compares them: a card of an alias is the author's
|
|
@@ -29,20 +29,23 @@ export function normalized(cards, aliases = new Map()) {
|
|
|
29
29
|
task: { ...card.task, stack: stackLabels(card.task.stack) },
|
|
30
30
|
}));
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
/** The cards of one author as calibration compares them (`normalized`): the cards of their aliases included. */
|
|
33
|
+
export function authorCards(cards, author, aliases) {
|
|
34
|
+
return normalized(cards, aliases).filter((card) => card.author === author);
|
|
35
|
+
}
|
|
36
|
+
function forAuthor(cards, byId, policy) {
|
|
33
37
|
const estimated = cards.filter((card) => card.estimate !== null);
|
|
34
|
-
const main =
|
|
35
|
-
const
|
|
36
|
-
const later = sampled(revisedCards, revisedExclusion, revisedRatioOf);
|
|
38
|
+
const main = ratioSampling(cards, false);
|
|
39
|
+
const later = ratioSampling(cards, true);
|
|
37
40
|
const kept = main.samples.map((sample) => sample.card);
|
|
38
41
|
// Rolled back work leaves lines that say nothing about the volume of the task.
|
|
39
42
|
const volumeCards = kept.filter((card) => !hasExclude(card) && !(card.convertedFrom === 1 && card.revised));
|
|
40
43
|
const volumeExcluded = kept.length - volumeCards.length;
|
|
41
44
|
return {
|
|
42
45
|
tasks: cards.length,
|
|
43
|
-
ratio: slices(main, (
|
|
44
|
-
revised: slices(later, (
|
|
45
|
-
...ratioStats(samples, reasons,
|
|
46
|
+
ratio: slices(main, (samples, reasons) => ratioStats(samples, reasons, policy)),
|
|
47
|
+
revised: slices(later, (samples, reasons) => ({
|
|
48
|
+
...ratioStats(samples, reasons, policy, (card) => card.fact.counted.uncertaintyShare),
|
|
46
49
|
countedAtShare: median(samples.flatMap(({ card }) => {
|
|
47
50
|
const at = card.revisions.at(-1)?.countedAtMinutes;
|
|
48
51
|
return at === undefined || card.fact.counted.totalMinutes === 0 ? [] : [at / card.fact.counted.totalMinutes];
|
|
@@ -63,29 +66,11 @@ function forAuthor(cards, byId, minTasks) {
|
|
|
63
66
|
function hasExclude(card) {
|
|
64
67
|
return card.revisions.some((revision) => revision.spent === 'exclude');
|
|
65
68
|
}
|
|
66
|
-
function sampled(cards, exclude, ratio) {
|
|
67
|
-
const samples = [];
|
|
68
|
-
const excluded = [];
|
|
69
|
-
for (const card of cards) {
|
|
70
|
-
const reason = exclude(card);
|
|
71
|
-
if (reason !== undefined) {
|
|
72
|
-
excluded.push({ card, reason });
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const value = ratio(card);
|
|
76
|
-
if (value === undefined) {
|
|
77
|
-
excluded.push({ card, reason: 'renegotiated-without-groups' });
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
samples.push({ card, ratio: value });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return { samples, excluded };
|
|
84
|
-
}
|
|
85
69
|
/** Overall, by type and by each technology of the stack. */
|
|
86
|
-
function slices(sampled,
|
|
70
|
+
function slices(sampled, stats) {
|
|
87
71
|
const all = [...sampled.samples.map((s) => s.card), ...sampled.excluded.map((e) => e.card)];
|
|
88
72
|
const slice = (keep) => stats(sampled.samples.filter((sample) => keep(sample.card)), sampled.excluded.filter((item) => keep(item.card)).map((item) => item.reason));
|
|
73
|
+
const typeOf = sampled.typeOf;
|
|
89
74
|
const types = [...new Set(all.flatMap((card) => typeOf(card) ?? []))].sort();
|
|
90
75
|
const stacks = [...new Set(all.flatMap((card) => card.task.stack))].sort();
|
|
91
76
|
return {
|
|
@@ -129,7 +114,7 @@ function revisionStats(cards) {
|
|
|
129
114
|
}
|
|
130
115
|
return { byType, excluded: fromV1 === 0 ? {} : { 'card-v1': fromV1 } };
|
|
131
116
|
}
|
|
132
|
-
function ratioStats(samples, reasons,
|
|
117
|
+
function ratioStats(samples, reasons, policy, uncertaintyOf = (card) => card.fact.uncertaintyShare) {
|
|
133
118
|
const ratios = samples.map((sample) => sample.ratio);
|
|
134
119
|
const excluded = {};
|
|
135
120
|
for (const reason of reasons) {
|
|
@@ -139,7 +124,7 @@ function ratioStats(samples, reasons, minTasks, uncertaintyOf = (card) => card.f
|
|
|
139
124
|
n: ratios.length,
|
|
140
125
|
median: median(ratios),
|
|
141
126
|
mean: ratios.length === 0 ? null : round(ratios.reduce((a, b) => a + b, 0) / ratios.length),
|
|
142
|
-
|
|
127
|
+
weight: round(policy.weight(ratios.length)),
|
|
143
128
|
excluded,
|
|
144
129
|
uncertain: samples.filter((sample) => (uncertaintyOf(sample.card) ?? 0) > UNCERTAINTY_LIMIT).length,
|
|
145
130
|
backgroundAgents: samples.filter((sample) => sample.card.backgroundAgents).length,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The levels of the coefficient, from overall to the deepest, each with the
|
|
3
|
+
* tasks it alone counts (calibration-query spec). A level counts when its whole
|
|
4
|
+
* slice has a weight above 0; the overall slice, the technology of the query
|
|
5
|
+
* with the most tasks (the first alphabetically on a tie), the type of the
|
|
6
|
+
* query. The deepest level takes all of its tasks, each level above only those
|
|
7
|
+
* no deeper level holds: every task counts once. Without a weight in the
|
|
8
|
+
* overall slice there are no levels.
|
|
9
|
+
*/
|
|
10
|
+
export function levelParts(sampling, query, policy) {
|
|
11
|
+
const levels = levelsOf(sampling, query, policy);
|
|
12
|
+
const deeper = new Set();
|
|
13
|
+
const parts = [];
|
|
14
|
+
for (const level of [...levels].reverse()) {
|
|
15
|
+
const own = level.samples.filter((sample) => !deeper.has(sample.card));
|
|
16
|
+
own.forEach((sample) => deeper.add(sample.card));
|
|
17
|
+
parts.unshift({ slice: level.slice, ratios: own.map((sample) => sample.ratio) });
|
|
18
|
+
}
|
|
19
|
+
return parts;
|
|
20
|
+
}
|
|
21
|
+
function levelsOf(sampling, query, policy) {
|
|
22
|
+
const level = (slice, keep) => {
|
|
23
|
+
const samples = sampling.samples.filter((sample) => keep(sample.card));
|
|
24
|
+
return policy.weight(samples.length) > 0 ? [{ slice, samples }] : [];
|
|
25
|
+
};
|
|
26
|
+
const overall = level({ kind: 'overall' }, () => true);
|
|
27
|
+
if (overall.length === 0) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const technology = query.stack.values
|
|
31
|
+
.flatMap((key) => level({ kind: 'stack', key }, (card) => card.task.stack.includes(key)))
|
|
32
|
+
.sort((a, b) => b.samples.length - a.samples.length || keyOf(a.slice).localeCompare(keyOf(b.slice)))
|
|
33
|
+
.slice(0, 1);
|
|
34
|
+
const type = query.type?.value;
|
|
35
|
+
const byType = type === undefined ? [] : level({ kind: 'type', key: type }, (card) => sampling.typeOf(card) === type);
|
|
36
|
+
return [...overall, ...technology, ...byType];
|
|
37
|
+
}
|
|
38
|
+
function keyOf(slice) {
|
|
39
|
+
return slice.kind === 'overall' ? '' : slice.key;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=level-parts.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isRevised } from './code-and-parts.js';
|
|
2
|
+
import { exclusion, ratioOf, revisedExclusion, revisedRatioOf } from './task-ratio.js';
|
|
3
|
+
/**
|
|
4
|
+
* Which cards a ratio counts and with what value (calibration spec): the main
|
|
5
|
+
* ratio — whole fact over the first estimate; `revised` — counted fact over the
|
|
6
|
+
* current estimate of revised tasks. Calibration slices and the applicable
|
|
7
|
+
* coefficient both take it from here.
|
|
8
|
+
*/
|
|
9
|
+
export function ratioSampling(cards, revised) {
|
|
10
|
+
const estimated = cards.filter((card) => card.estimate !== null);
|
|
11
|
+
return revised
|
|
12
|
+
? { ...sampled(estimated.filter(isRevised), revisedExclusion, revisedRatioOf), typeOf: (card) => card.currentEstimate?.type }
|
|
13
|
+
: { ...sampled(estimated, exclusion, ratioOf), typeOf: (card) => card.estimate?.type };
|
|
14
|
+
}
|
|
15
|
+
function sampled(cards, exclude, ratio) {
|
|
16
|
+
const samples = [];
|
|
17
|
+
const excluded = [];
|
|
18
|
+
for (const card of cards) {
|
|
19
|
+
const reason = exclude(card);
|
|
20
|
+
if (reason !== undefined) {
|
|
21
|
+
excluded.push({ card, reason });
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const value = ratio(card);
|
|
25
|
+
if (value === undefined) {
|
|
26
|
+
excluded.push({ card, reason: 'renegotiated-without-groups' });
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
samples.push({ card, ratio: value });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { samples, excluded };
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=ratio-samples.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export const CODE_CLASSES = ['generated', 'tests', 'docs', 'config', 'production'];
|
|
6
6
|
const GENERATED_FILES = /(^|\/)(package-lock\.json|pnpm-lock\.yaml|go\.sum)$|\.lock$|\.lockb$|\.g\.dart$|\.freezed\.dart$|\.pb\.go$|_pb2\.py$|\.min\.js$|\.map$|\.snap$/;
|
|
7
|
-
const GENERATED_DIRS = /(^|\/)(node_modules|__snapshots__|generated)\/|^\.(estimetry|claude)\//;
|
|
7
|
+
const GENERATED_DIRS = /(^|\/)(node_modules|__snapshots__|generated)\/|^\.(estimetry|claude|codex|agents)\//;
|
|
8
8
|
const GENERATED_ROOT_DIRS = /^(dist|build)\//;
|
|
9
9
|
const TEST_DIRS = /(^|\/)(test|tests|__tests__|spec|integration_test)\/|(^|\/)src\/test\//;
|
|
10
10
|
const TEST_FILES = /\.(test|spec)\.[^/]+$|_test\.[^/]+$|(^|\/)test_[^/]*\.py$/;
|
|
@@ -19,9 +19,12 @@ export class Estimate {
|
|
|
19
19
|
basedOn;
|
|
20
20
|
calibrated;
|
|
21
21
|
coefficient;
|
|
22
|
+
pessimisticCoefficient;
|
|
22
23
|
constructor(parts, type, stack, codeVolume, rationale, basedOn, calibrated,
|
|
23
|
-
/** What calibration multiplied the
|
|
24
|
-
coefficient
|
|
24
|
+
/** What calibration multiplied the optimistic and likely hours by; undefined when it was not applied. */
|
|
25
|
+
coefficient,
|
|
26
|
+
/** What calibration multiplied the pessimistic hours by; not part of the base of the estimate. */
|
|
27
|
+
pessimisticCoefficient) {
|
|
25
28
|
this.parts = parts;
|
|
26
29
|
this.type = type;
|
|
27
30
|
this.stack = stack;
|
|
@@ -30,13 +33,23 @@ export class Estimate {
|
|
|
30
33
|
this.basedOn = basedOn;
|
|
31
34
|
this.calibrated = calibrated;
|
|
32
35
|
this.coefficient = coefficient;
|
|
36
|
+
this.pessimisticCoefficient = pessimisticCoefficient;
|
|
33
37
|
}
|
|
34
38
|
/** @throws InvalidEstimate when there are no parts or part ids repeat. */
|
|
35
39
|
static of(input) {
|
|
36
40
|
const issues = [];
|
|
37
|
-
|
|
41
|
+
const positive = (value) => Number.isFinite(value) && value > 0;
|
|
42
|
+
if (input.coefficient === undefined ? input.pessimisticCoefficient !== undefined : !positive(input.coefficient)) {
|
|
38
43
|
issues.push({ path: 'calibration.coefficient', message: 'expected a number greater than 0' });
|
|
39
44
|
}
|
|
45
|
+
const pessimistic = input.pessimisticCoefficient;
|
|
46
|
+
if (pessimistic !== undefined && !positive(pessimistic)) {
|
|
47
|
+
issues.push({ path: 'calibration.pessimistic', message: 'expected a number greater than 0' });
|
|
48
|
+
}
|
|
49
|
+
else if (pessimistic !== undefined && input.coefficient !== undefined && pessimistic < input.coefficient) {
|
|
50
|
+
// `emt calibrate` never gives one below the other: the two are swapped.
|
|
51
|
+
issues.push({ path: 'calibration.pessimistic', message: 'expected no less than calibration.coefficient' });
|
|
52
|
+
}
|
|
40
53
|
if (input.parts.length === 0) {
|
|
41
54
|
issues.push({ path: 'parts', message: 'the estimate needs at least one part' });
|
|
42
55
|
}
|
|
@@ -54,7 +67,7 @@ export class Estimate {
|
|
|
54
67
|
throw new InvalidEstimate(issues);
|
|
55
68
|
}
|
|
56
69
|
const rationale = input.rationale?.trim() || undefined;
|
|
57
|
-
return new Estimate([...input.parts], input.type?.trim() || undefined, stackLabels(input.stack ?? []), input.codeVolume, rationale, [...(input.basedOn ?? [])], input.calibrated ?? false, input.coefficient);
|
|
70
|
+
return new Estimate([...input.parts], input.type?.trim() || undefined, stackLabels(input.stack ?? []), input.codeVolume, rationale, [...(input.basedOn ?? [])], input.calibrated ?? false, input.coefficient, input.pessimisticCoefficient);
|
|
58
71
|
}
|
|
59
72
|
static fromData(data) {
|
|
60
73
|
return Estimate.of({
|
|
@@ -66,6 +79,7 @@ export class Estimate {
|
|
|
66
79
|
...(data.basedOn === undefined ? {} : { basedOn: data.basedOn }),
|
|
67
80
|
calibrated: data.calibrated,
|
|
68
81
|
...(data.calibration === undefined ? {} : { coefficient: data.calibration.coefficient }),
|
|
82
|
+
...(data.calibration?.pessimistic === undefined ? {} : { pessimisticCoefficient: data.calibration.pessimistic }),
|
|
69
83
|
});
|
|
70
84
|
}
|
|
71
85
|
/**
|
|
@@ -92,6 +106,9 @@ export class Estimate {
|
|
|
92
106
|
get groups() {
|
|
93
107
|
return groupsOf(this.parts);
|
|
94
108
|
}
|
|
109
|
+
calibrationData(coefficient) {
|
|
110
|
+
return this.pessimisticCoefficient === undefined ? { coefficient } : { coefficient, pessimistic: this.pessimisticCoefficient };
|
|
111
|
+
}
|
|
95
112
|
toData() {
|
|
96
113
|
return {
|
|
97
114
|
schemaVersion: ESTIMATE_SCHEMA_VERSION,
|
|
@@ -102,7 +119,7 @@ export class Estimate {
|
|
|
102
119
|
...(this.rationale === undefined ? {} : { rationale: this.rationale }),
|
|
103
120
|
...(this.basedOn.length === 0 ? {} : { basedOn: [...this.basedOn] }),
|
|
104
121
|
calibrated: this.calibrated,
|
|
105
|
-
...(this.coefficient === undefined ? {} : { calibration:
|
|
122
|
+
...(this.coefficient === undefined ? {} : { calibration: this.calibrationData(this.coefficient) }),
|
|
106
123
|
};
|
|
107
124
|
}
|
|
108
125
|
}
|
|
@@ -156,6 +156,9 @@ function logSession(data) {
|
|
|
156
156
|
});
|
|
157
157
|
buckets(agent['tokens'], `data.agents[${i}].tokens`);
|
|
158
158
|
});
|
|
159
|
+
if (data['costReported'] !== undefined && typeof data['costReported'] !== 'boolean') {
|
|
160
|
+
throw new InvalidProgressRecord('data.costReported', 'must be true or false');
|
|
161
|
+
}
|
|
159
162
|
list(data['cost'], 'data.cost').forEach((item, i) => {
|
|
160
163
|
const total = object(item, `data.cost[${i}]`);
|
|
161
164
|
moment(total, 'startTime', `data.cost[${i}].`);
|
|
@@ -175,6 +178,9 @@ function buckets(value, path) {
|
|
|
175
178
|
for (const key of ['input', 'output', 'cacheRead', 'cacheWrite5m', 'cacheWrite1h']) {
|
|
176
179
|
count(bucket, key, `${path}[${i}].`);
|
|
177
180
|
}
|
|
181
|
+
if (bucket['cacheWrite'] !== undefined) {
|
|
182
|
+
count(bucket, 'cacheWrite', `${path}[${i}].`);
|
|
183
|
+
}
|
|
178
184
|
});
|
|
179
185
|
}
|
|
180
186
|
function moment(record, key, prefix) {
|
|
@@ -22,7 +22,8 @@ export function sessionLogs(records, closed = []) {
|
|
|
22
22
|
continue; // a write cut short: the next import reads the same stretch again
|
|
23
23
|
}
|
|
24
24
|
const { session, from } = first.data;
|
|
25
|
-
const log = merged.get(session) ?? { turns: [], agents: new Map(), cost: new Map() };
|
|
25
|
+
const log = merged.get(session) ?? { turns: [], agents: new Map(), cost: new Map(), reportsCost: false };
|
|
26
|
+
log.reportsCost ||= first.data.costReported !== false;
|
|
26
27
|
log.turns = [...log.turns.filter((turn) => turn.key < from), ...joinedTurns(parts.flatMap((part) => part.data.turns))];
|
|
27
28
|
for (const agent of joinedAgents(parts.flatMap((part) => part.data.agents))) {
|
|
28
29
|
log.agents.set(agent.agent, agent);
|
|
@@ -4,18 +4,26 @@
|
|
|
4
4
|
* session served the task come in as arguments.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
|
-
* Relative weight of a token of each kind, the structure of Claude prices
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Relative weight of a token of each kind (an input token is 1), the structure of Claude prices, the only tool that
|
|
8
|
+
* reports a cost: fitted without residue to the totals of the studied sessions; prices themselves are not in the
|
|
9
|
+
* code. A cache write without a lifetime weighs as the short one. The cost of a session stays exact whatever the
|
|
10
|
+
* weights: they only split it between tasks.
|
|
11
11
|
*/
|
|
12
|
-
export const TOKEN_WEIGHTS = {
|
|
12
|
+
export const TOKEN_WEIGHTS = {
|
|
13
|
+
input: 1,
|
|
14
|
+
output: 5,
|
|
15
|
+
cacheRead: 0.05,
|
|
16
|
+
cacheWrite5m: 1.25,
|
|
17
|
+
cacheWrite1h: 2,
|
|
18
|
+
cacheWrite: 1.25,
|
|
19
|
+
};
|
|
13
20
|
/** Undefined when no session of the task has a log. */
|
|
14
21
|
export function taskUsage(input) {
|
|
15
22
|
const tokens = new Map();
|
|
16
23
|
let cost = 0;
|
|
17
24
|
let approximate = false;
|
|
18
25
|
let withLogs = 0;
|
|
26
|
+
let withCost = 0;
|
|
19
27
|
for (const [session, spans] of input.spans) {
|
|
20
28
|
const log = input.logs.get(session);
|
|
21
29
|
if (log === undefined) {
|
|
@@ -32,6 +40,10 @@ export function taskUsage(input) {
|
|
|
32
40
|
if (own < all) {
|
|
33
41
|
approximate = true;
|
|
34
42
|
}
|
|
43
|
+
if (!log.reportsCost) {
|
|
44
|
+
continue; // its tokens count; its cost is not known to the tool, so it is no part of the cost
|
|
45
|
+
}
|
|
46
|
+
withCost += 1;
|
|
35
47
|
const totals = [...log.cost.values()];
|
|
36
48
|
if (totals.some((total) => total.unknown)) {
|
|
37
49
|
cost = null;
|
|
@@ -43,7 +55,7 @@ export function taskUsage(input) {
|
|
|
43
55
|
if (withLogs === 0) {
|
|
44
56
|
return undefined;
|
|
45
57
|
}
|
|
46
|
-
return { tokens, costUSD: cost, approximate, sessions: input.spans.size, withLogs };
|
|
58
|
+
return { tokens, costUSD: withCost === 0 ? null : cost, approximate, sessions: input.spans.size, withLogs, withCost };
|
|
47
59
|
}
|
|
48
60
|
function weight(buckets) {
|
|
49
61
|
return buckets.reduce((sum, b) => sum +
|
|
@@ -51,7 +63,8 @@ function weight(buckets) {
|
|
|
51
63
|
b.output * TOKEN_WEIGHTS.output +
|
|
52
64
|
b.cacheRead * TOKEN_WEIGHTS.cacheRead +
|
|
53
65
|
b.cacheWrite5m * TOKEN_WEIGHTS.cacheWrite5m +
|
|
54
|
-
b.cacheWrite1h * TOKEN_WEIGHTS.cacheWrite1h
|
|
66
|
+
b.cacheWrite1h * TOKEN_WEIGHTS.cacheWrite1h +
|
|
67
|
+
(b.cacheWrite ?? 0) * TOKEN_WEIGHTS.cacheWrite, 0);
|
|
55
68
|
}
|
|
56
69
|
function add(sum, bucket) {
|
|
57
70
|
return {
|
|
@@ -60,6 +73,9 @@ function add(sum, bucket) {
|
|
|
60
73
|
cacheRead: (sum?.cacheRead ?? 0) + bucket.cacheRead,
|
|
61
74
|
cacheWrite5m: (sum?.cacheWrite5m ?? 0) + bucket.cacheWrite5m,
|
|
62
75
|
cacheWrite1h: (sum?.cacheWrite1h ?? 0) + bucket.cacheWrite1h,
|
|
76
|
+
...(sum?.cacheWrite === undefined && bucket.cacheWrite === undefined
|
|
77
|
+
? {}
|
|
78
|
+
: { cacheWrite: (sum?.cacheWrite ?? 0) + (bucket.cacheWrite ?? 0) }),
|
|
63
79
|
};
|
|
64
80
|
}
|
|
65
81
|
/**
|
|
@@ -81,6 +97,7 @@ export function usageSummary(usage) {
|
|
|
81
97
|
approximate: usage.approximate,
|
|
82
98
|
sessions: usage.sessions,
|
|
83
99
|
withLogs: usage.withLogs,
|
|
100
|
+
withCost: usage.withCost,
|
|
84
101
|
};
|
|
85
102
|
}
|
|
86
103
|
//# sourceMappingURL=task-usage.js.map
|
|
@@ -142,7 +142,7 @@ function isEstimateData(value) {
|
|
|
142
142
|
!optional(value['basedOn'], isStringArray) ||
|
|
143
143
|
!optionalString(value['rationale']) ||
|
|
144
144
|
!optional(value['codeVolume'], isObject) ||
|
|
145
|
-
!optional(value['calibration'], (c) => isObject(c) && typeof c['coefficient'] === 'number')) {
|
|
145
|
+
!optional(value['calibration'], (c) => isObject(c) && typeof c['coefficient'] === 'number' && optional(c['pessimistic'], (p) => typeof p === 'number'))) {
|
|
146
146
|
return false;
|
|
147
147
|
}
|
|
148
148
|
try {
|