@afaik-lab/weigh 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +49 -0
- package/LICENSE +373 -0
- package/README.md +102 -2
- package/dist/agent.d.ts +83 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +204 -0
- package/dist/agent.js.map +1 -0
- package/dist/ceilings.d.ts +32 -0
- package/dist/ceilings.d.ts.map +1 -0
- package/dist/ceilings.js +61 -0
- package/dist/ceilings.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +530 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-cli.d.ts +15 -0
- package/dist/config-cli.d.ts.map +1 -0
- package/dist/config-cli.js +132 -0
- package/dist/config-cli.js.map +1 -0
- package/dist/config.d.ts +198 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +373 -0
- package/dist/config.js.map +1 -0
- package/dist/context-cli.d.ts +35 -0
- package/dist/context-cli.d.ts.map +1 -0
- package/dist/context-cli.js +251 -0
- package/dist/context-cli.js.map +1 -0
- package/dist/context.d.ts +118 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +159 -0
- package/dist/context.js.map +1 -0
- package/dist/corrections/correction-set.d.ts +67 -0
- package/dist/corrections/correction-set.d.ts.map +1 -0
- package/dist/corrections/correction-set.js +104 -0
- package/dist/corrections/correction-set.js.map +1 -0
- package/dist/corrections/correction.d.ts +74 -0
- package/dist/corrections/correction.d.ts.map +1 -0
- package/dist/corrections/correction.js +154 -0
- package/dist/corrections/correction.js.map +1 -0
- package/dist/corrections/follow-up.d.ts +69 -0
- package/dist/corrections/follow-up.d.ts.map +1 -0
- package/dist/corrections/follow-up.js +217 -0
- package/dist/corrections/follow-up.js.map +1 -0
- package/dist/corrections/index.d.ts +31 -0
- package/dist/corrections/index.d.ts.map +1 -0
- package/dist/corrections/index.js +31 -0
- package/dist/corrections/index.js.map +1 -0
- package/dist/corrections/ledger.d.ts +78 -0
- package/dist/corrections/ledger.d.ts.map +1 -0
- package/dist/corrections/ledger.js +117 -0
- package/dist/corrections/ledger.js.map +1 -0
- package/dist/corrections/promotion.d.ts +119 -0
- package/dist/corrections/promotion.d.ts.map +1 -0
- package/dist/corrections/promotion.js +221 -0
- package/dist/corrections/promotion.js.map +1 -0
- package/dist/corrections/schema.d.ts +125 -0
- package/dist/corrections/schema.d.ts.map +1 -0
- package/dist/corrections/schema.js +100 -0
- package/dist/corrections/schema.js.map +1 -0
- package/dist/corrections-cli.d.ts +28 -0
- package/dist/corrections-cli.d.ts.map +1 -0
- package/dist/corrections-cli.js +157 -0
- package/dist/corrections-cli.js.map +1 -0
- package/dist/diff.d.ts +105 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +202 -0
- package/dist/diff.js.map +1 -0
- package/dist/doctor.d.ts +38 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +197 -0
- package/dist/doctor.js.map +1 -0
- package/dist/events.d.ts +21 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +5 -0
- package/dist/events.js.map +1 -0
- package/dist/findings.d.ts +510 -0
- package/dist/findings.d.ts.map +1 -0
- package/dist/findings.js +645 -0
- package/dist/findings.js.map +1 -0
- package/dist/follow-up-cli.d.ts +88 -0
- package/dist/follow-up-cli.d.ts.map +1 -0
- package/dist/follow-up-cli.js +208 -0
- package/dist/follow-up-cli.js.map +1 -0
- package/dist/harness.d.ts +64 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +71 -0
- package/dist/harness.js.map +1 -0
- package/dist/help/command-help.d.ts +9 -0
- package/dist/help/command-help.d.ts.map +1 -0
- package/dist/help/command-help.js +21 -0
- package/dist/help/command-help.js.map +1 -0
- package/dist/help/commands/answer.d.ts +3 -0
- package/dist/help/commands/answer.d.ts.map +1 -0
- package/dist/help/commands/answer.js +39 -0
- package/dist/help/commands/answer.js.map +1 -0
- package/dist/help/commands/config.d.ts +3 -0
- package/dist/help/commands/config.d.ts.map +1 -0
- package/dist/help/commands/config.js +25 -0
- package/dist/help/commands/config.js.map +1 -0
- package/dist/help/commands/context.d.ts +3 -0
- package/dist/help/commands/context.d.ts.map +1 -0
- package/dist/help/commands/context.js +44 -0
- package/dist/help/commands/context.js.map +1 -0
- package/dist/help/commands/corrections.d.ts +3 -0
- package/dist/help/commands/corrections.d.ts.map +1 -0
- package/dist/help/commands/corrections.js +30 -0
- package/dist/help/commands/corrections.js.map +1 -0
- package/dist/help/commands/doctor.d.ts +3 -0
- package/dist/help/commands/doctor.d.ts.map +1 -0
- package/dist/help/commands/doctor.js +12 -0
- package/dist/help/commands/doctor.js.map +1 -0
- package/dist/help/commands/index.d.ts +4 -0
- package/dist/help/commands/index.d.ts.map +1 -0
- package/dist/help/commands/index.js +27 -0
- package/dist/help/commands/index.js.map +1 -0
- package/dist/help/commands/memory.d.ts +3 -0
- package/dist/help/commands/memory.d.ts.map +1 -0
- package/dist/help/commands/memory.js +33 -0
- package/dist/help/commands/memory.js.map +1 -0
- package/dist/help/commands/models.d.ts +3 -0
- package/dist/help/commands/models.d.ts.map +1 -0
- package/dist/help/commands/models.js +17 -0
- package/dist/help/commands/models.js.map +1 -0
- package/dist/help/commands/options.d.ts +4 -0
- package/dist/help/commands/options.d.ts.map +1 -0
- package/dist/help/commands/options.js +13 -0
- package/dist/help/commands/options.js.map +1 -0
- package/dist/help/commands/review.d.ts +3 -0
- package/dist/help/commands/review.d.ts.map +1 -0
- package/dist/help/commands/review.js +50 -0
- package/dist/help/commands/review.js.map +1 -0
- package/dist/help/commands/sessions.d.ts +3 -0
- package/dist/help/commands/sessions.d.ts.map +1 -0
- package/dist/help/commands/sessions.js +23 -0
- package/dist/help/commands/sessions.js.map +1 -0
- package/dist/help/commands/show.d.ts +3 -0
- package/dist/help/commands/show.d.ts.map +1 -0
- package/dist/help/commands/show.js +18 -0
- package/dist/help/commands/show.js.map +1 -0
- package/dist/help/help.d.ts +16 -0
- package/dist/help/help.d.ts.map +1 -0
- package/dist/help/help.js +68 -0
- package/dist/help/help.js.map +1 -0
- package/dist/help/index.d.ts +4 -0
- package/dist/help/index.d.ts.map +1 -0
- package/dist/help/index.js +7 -0
- package/dist/help/index.js.map +1 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/block.d.ts +65 -0
- package/dist/knowledge/block.d.ts.map +1 -0
- package/dist/knowledge/block.js +89 -0
- package/dist/knowledge/block.js.map +1 -0
- package/dist/knowledge/claim.d.ts +143 -0
- package/dist/knowledge/claim.d.ts.map +1 -0
- package/dist/knowledge/claim.js +297 -0
- package/dist/knowledge/claim.js.map +1 -0
- package/dist/knowledge/index.d.ts +32 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +29 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/novelty.d.ts +65 -0
- package/dist/knowledge/novelty.d.ts.map +1 -0
- package/dist/knowledge/novelty.js +94 -0
- package/dist/knowledge/novelty.js.map +1 -0
- package/dist/knowledge/recall.d.ts +134 -0
- package/dist/knowledge/recall.d.ts.map +1 -0
- package/dist/knowledge/recall.js +229 -0
- package/dist/knowledge/recall.js.map +1 -0
- package/dist/knowledge/recalled-claim.d.ts +35 -0
- package/dist/knowledge/recalled-claim.d.ts.map +1 -0
- package/dist/knowledge/recalled-claim.js +67 -0
- package/dist/knowledge/recalled-claim.js.map +1 -0
- package/dist/knowledge/recalled.d.ts +70 -0
- package/dist/knowledge/recalled.d.ts.map +1 -0
- package/dist/knowledge/recalled.js +149 -0
- package/dist/knowledge/recalled.js.map +1 -0
- package/dist/knowledge/schema.d.ts +83 -0
- package/dist/knowledge/schema.d.ts.map +1 -0
- package/dist/knowledge/schema.js +96 -0
- package/dist/knowledge/schema.js.map +1 -0
- package/dist/knowledge/staleness.d.ts +48 -0
- package/dist/knowledge/staleness.d.ts.map +1 -0
- package/dist/knowledge/staleness.js +85 -0
- package/dist/knowledge/staleness.js.map +1 -0
- package/dist/knowledge/store.d.ts +100 -0
- package/dist/knowledge/store.d.ts.map +1 -0
- package/dist/knowledge/store.js +184 -0
- package/dist/knowledge/store.js.map +1 -0
- package/dist/memory/compose-file.d.ts +14 -0
- package/dist/memory/compose-file.d.ts.map +1 -0
- package/dist/memory/compose-file.js +25 -0
- package/dist/memory/compose-file.js.map +1 -0
- package/dist/memory/index.d.ts +43 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +119 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/oss.d.ts +62 -0
- package/dist/memory/oss.d.ts.map +1 -0
- package/dist/memory/oss.js +230 -0
- package/dist/memory/oss.js.map +1 -0
- package/dist/memory/platform.d.ts +37 -0
- package/dist/memory/platform.d.ts.map +1 -0
- package/dist/memory/platform.js +131 -0
- package/dist/memory/platform.js.map +1 -0
- package/dist/memory/scope.d.ts +49 -0
- package/dist/memory/scope.d.ts.map +1 -0
- package/dist/memory/scope.js +70 -0
- package/dist/memory/scope.js.map +1 -0
- package/dist/memory/types.d.ts +113 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +18 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/memory-cli.d.ts +17 -0
- package/dist/memory-cli.d.ts.map +1 -0
- package/dist/memory-cli.js +107 -0
- package/dist/memory-cli.js.map +1 -0
- package/dist/models-cli.d.ts +12 -0
- package/dist/models-cli.d.ts.map +1 -0
- package/dist/models-cli.js +54 -0
- package/dist/models-cli.js.map +1 -0
- package/dist/models.d.ts +111 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +227 -0
- package/dist/models.js.map +1 -0
- package/dist/paths.d.ts +35 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +65 -0
- package/dist/paths.js.map +1 -0
- package/dist/profile.d.ts +28 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +154 -0
- package/dist/profile.js.map +1 -0
- package/dist/progress.d.ts +70 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +132 -0
- package/dist/progress.js.map +1 -0
- package/dist/quiet.d.ts +2 -0
- package/dist/quiet.d.ts.map +1 -0
- package/dist/quiet.js +21 -0
- package/dist/quiet.js.map +1 -0
- package/dist/reconcile/continuation.d.ts +132 -0
- package/dist/reconcile/continuation.d.ts.map +1 -0
- package/dist/reconcile/continuation.js +306 -0
- package/dist/reconcile/continuation.js.map +1 -0
- package/dist/reconcile/index.d.ts +26 -0
- package/dist/reconcile/index.d.ts.map +1 -0
- package/dist/reconcile/index.js +28 -0
- package/dist/reconcile/index.js.map +1 -0
- package/dist/reconcile/outcome-set.d.ts +53 -0
- package/dist/reconcile/outcome-set.d.ts.map +1 -0
- package/dist/reconcile/outcome-set.js +124 -0
- package/dist/reconcile/outcome-set.js.map +1 -0
- package/dist/reconcile/outcome.d.ts +56 -0
- package/dist/reconcile/outcome.d.ts.map +1 -0
- package/dist/reconcile/outcome.js +60 -0
- package/dist/reconcile/outcome.js.map +1 -0
- package/dist/reconcile/reconciliation.d.ts +49 -0
- package/dist/reconcile/reconciliation.d.ts.map +1 -0
- package/dist/reconcile/reconciliation.js +88 -0
- package/dist/reconcile/reconciliation.js.map +1 -0
- package/dist/reconcile/schema.d.ts +157 -0
- package/dist/reconcile/schema.d.ts.map +1 -0
- package/dist/reconcile/schema.js +97 -0
- package/dist/reconcile/schema.js.map +1 -0
- package/dist/record/index.d.ts +23 -0
- package/dist/record/index.d.ts.map +1 -0
- package/dist/record/index.js +25 -0
- package/dist/record/index.js.map +1 -0
- package/dist/record/review-record.d.ts +28 -0
- package/dist/record/review-record.d.ts.map +1 -0
- package/dist/record/review-record.js +78 -0
- package/dist/record/review-record.js.map +1 -0
- package/dist/record/schema.d.ts +153 -0
- package/dist/record/schema.d.ts.map +1 -0
- package/dist/record/schema.js +87 -0
- package/dist/record/schema.js.map +1 -0
- package/dist/record/store.d.ts +83 -0
- package/dist/record/store.d.ts.map +1 -0
- package/dist/record/store.js +162 -0
- package/dist/record/store.js.map +1 -0
- package/dist/record/stored-review.d.ts +36 -0
- package/dist/record/stored-review.d.ts.map +1 -0
- package/dist/record/stored-review.js +90 -0
- package/dist/record/stored-review.js.map +1 -0
- package/dist/refute.d.ts +318 -0
- package/dist/refute.d.ts.map +1 -0
- package/dist/refute.js +513 -0
- package/dist/refute.js.map +1 -0
- package/dist/render.d.ts +212 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +544 -0
- package/dist/render.js.map +1 -0
- package/dist/review-cli.d.ts +181 -0
- package/dist/review-cli.d.ts.map +1 -0
- package/dist/review-cli.js +598 -0
- package/dist/review-cli.js.map +1 -0
- package/dist/reviewer.d.ts +297 -0
- package/dist/reviewer.d.ts.map +1 -0
- package/dist/reviewer.js +580 -0
- package/dist/reviewer.js.map +1 -0
- package/dist/session-cli.d.ts +17 -0
- package/dist/session-cli.d.ts.map +1 -0
- package/dist/session-cli.js +62 -0
- package/dist/session-cli.js.map +1 -0
- package/dist/session.d.ts +36 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +105 -0
- package/dist/session.js.map +1 -0
- package/dist/settings.d.ts +68 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +175 -0
- package/dist/settings.js.map +1 -0
- package/dist/show-cli.d.ts +39 -0
- package/dist/show-cli.d.ts.map +1 -0
- package/dist/show-cli.js +56 -0
- package/dist/show-cli.js.map +1 -0
- package/dist/stdout.d.ts +28 -0
- package/dist/stdout.d.ts.map +1 -0
- package/dist/stdout.js +44 -0
- package/dist/stdout.js.map +1 -0
- package/dist/target.d.ts +58 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +96 -0
- package/dist/target.js.map +1 -0
- package/dist/tools/index.d.ts +93 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +146 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/root.d.ts +62 -0
- package/dist/tools/root.d.ts.map +1 -0
- package/dist/tools/root.js +51 -0
- package/dist/tools/root.js.map +1 -0
- package/dist/usage.d.ts +75 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +100 -0
- package/dist/usage.js.map +1 -0
- package/dist/version.d.ts +14 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +26 -0
- package/dist/version.js.map +1 -0
- package/dist/workspace.d.ts +48 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +126 -0
- package/dist/workspace.js.map +1 -0
- package/docker-compose.yml +61 -0
- package/package.json +70 -4
package/dist/models.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
7
|
+
import { ensureDir, paths } from './paths.js';
|
|
8
|
+
/**
|
|
9
|
+
* The fallback, used only until the binary has been asked once.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately short. Every entry here is a claim that ages, so the list holds
|
|
12
|
+
* the names worth guessing at offline and leaves the rest to the catalogue.
|
|
13
|
+
*/
|
|
14
|
+
export const MODELS = [
|
|
15
|
+
{ id: 'claude-opus-5', aliases: ['opus', 'opus-5'],
|
|
16
|
+
describe: 'Deepest reading, for changes where missing something is expensive.' },
|
|
17
|
+
{ id: 'claude-sonnet-5', aliases: ['sonnet', 'sonnet-5'],
|
|
18
|
+
describe: 'The default. Investigates properly and finishes in about a minute.' },
|
|
19
|
+
{ id: 'claude-haiku-4-5', aliases: ['haiku', 'haiku-4-5'],
|
|
20
|
+
describe: 'Cheapest, and measured returning empty reviews at full coverage.' },
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* The bare names that float.
|
|
24
|
+
*
|
|
25
|
+
* `opus-5` asks for a version and should keep meaning that one forever.
|
|
26
|
+
* `opus` asks for "the Opus you have", which is a different question, and is
|
|
27
|
+
* the one the catalogue answers better than this file can.
|
|
28
|
+
*/
|
|
29
|
+
export const FLOATING = MODELS.map((m) => m.aliases[0]);
|
|
30
|
+
/** Lowercased and stripped of separators, so `Opus 5` and `opus-5` agree. */
|
|
31
|
+
function normalise(name) {
|
|
32
|
+
return name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A row's name without its variant suffix: `opus[1m]` is the `opus` row.
|
|
36
|
+
*
|
|
37
|
+
* Someone typing `opus` means "the Opus you have", and the row carrying that
|
|
38
|
+
* is the one to hand them — including whichever context variant it names.
|
|
39
|
+
*/
|
|
40
|
+
function baseName(value) {
|
|
41
|
+
return value.replace(/\[.*$/, '');
|
|
42
|
+
}
|
|
43
|
+
const STATIC_BY_NAME = new Map();
|
|
44
|
+
for (const model of MODELS) {
|
|
45
|
+
for (const name of [model.id, ...model.aliases])
|
|
46
|
+
STATIC_BY_NAME.set(normalise(name), model.id);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Anything that names a Claude model, however a provider spells it.
|
|
50
|
+
*
|
|
51
|
+
* `claude-opus-5` on the first-party API, `anthropic.claude-opus-5` on
|
|
52
|
+
* Bedrock, `claude-opus-4-5@20251101` on Vertex. An earlier version of this
|
|
53
|
+
* checked `startsWith('claude-')`, which refused every Bedrock id and made
|
|
54
|
+
* Weigh unusable there — the point is to tell a deliberate id from a typo,
|
|
55
|
+
* and a prefix test was answering a different question.
|
|
56
|
+
*/
|
|
57
|
+
function looksLikeModelId(name) {
|
|
58
|
+
return /claude[-.]/i.test(name);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* What the Claude Code binary says this account can reach, cached on disk.
|
|
62
|
+
*
|
|
63
|
+
* Cached because asking costs a subprocess — measured at 845ms — and resolving
|
|
64
|
+
* a model name happens on every config load. The cache is refreshed in the
|
|
65
|
+
* background by runs that were spawning a subprocess anyway, so it tracks new
|
|
66
|
+
* releases without anyone having to ask it to.
|
|
67
|
+
*/
|
|
68
|
+
export class ModelCatalogue {
|
|
69
|
+
rows;
|
|
70
|
+
fetchedAt;
|
|
71
|
+
constructor(rows, fetchedAt) {
|
|
72
|
+
this.rows = rows;
|
|
73
|
+
this.fetchedAt = fetchedAt;
|
|
74
|
+
}
|
|
75
|
+
static _memo;
|
|
76
|
+
static file() {
|
|
77
|
+
return join(paths.cache(), 'models.json');
|
|
78
|
+
}
|
|
79
|
+
/** The cache, or an empty catalogue. Memoised: this is on the config path. */
|
|
80
|
+
static load() {
|
|
81
|
+
if (ModelCatalogue._memo)
|
|
82
|
+
return ModelCatalogue._memo;
|
|
83
|
+
try {
|
|
84
|
+
const raw = JSON.parse(readFileSync(ModelCatalogue.file(), 'utf-8'));
|
|
85
|
+
ModelCatalogue._memo = new ModelCatalogue(raw.rows ?? [], raw.fetchedAt);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// No cache, or one written by a version that shaped it differently.
|
|
89
|
+
// Either way the static table carries the run.
|
|
90
|
+
ModelCatalogue._memo = new ModelCatalogue([], undefined);
|
|
91
|
+
}
|
|
92
|
+
return ModelCatalogue._memo;
|
|
93
|
+
}
|
|
94
|
+
static empty() {
|
|
95
|
+
return new ModelCatalogue([], undefined);
|
|
96
|
+
}
|
|
97
|
+
static of(rows, fetchedAt) {
|
|
98
|
+
return new ModelCatalogue(rows, fetchedAt);
|
|
99
|
+
}
|
|
100
|
+
/** Asks the binary. Spawns a subprocess, so never on the config path. */
|
|
101
|
+
static async fetch() {
|
|
102
|
+
const q = query({
|
|
103
|
+
prompt: 'unused',
|
|
104
|
+
options: { settingSources: [], disallowedTools: ['*'], permissionMode: 'dontAsk', maxTurns: 1 },
|
|
105
|
+
});
|
|
106
|
+
try {
|
|
107
|
+
// Answered before the stream is consumed, so no turn is ever run and
|
|
108
|
+
// nothing is spent.
|
|
109
|
+
return (await q.supportedModels());
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
await q.interrupt?.().catch(() => { });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
save() {
|
|
116
|
+
ensureDir(paths.cache());
|
|
117
|
+
writeFileSync(ModelCatalogue.file(), JSON.stringify({ fetchedAt: this.fetchedAt, rows: this.rows }, null, 2));
|
|
118
|
+
ModelCatalogue._memo = this;
|
|
119
|
+
}
|
|
120
|
+
get empty() {
|
|
121
|
+
return this.rows.length === 0;
|
|
122
|
+
}
|
|
123
|
+
/** Milliseconds since it was fetched, or undefined if it never was. */
|
|
124
|
+
ageMs(now = Date.now()) {
|
|
125
|
+
return this.fetchedAt === undefined ? undefined : now - this.fetchedAt;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The id to run, for a name the catalogue recognises.
|
|
129
|
+
*
|
|
130
|
+
* Three passes, in falling order of how exactly the name was given. Each
|
|
131
|
+
* completes across every row before the next begins, so a loose match never
|
|
132
|
+
* beats an exact one further down the list.
|
|
133
|
+
*/
|
|
134
|
+
resolve(name) {
|
|
135
|
+
const wanted = normalise(name);
|
|
136
|
+
// A row named outright. `value` is what the SDK documents as the thing to
|
|
137
|
+
// pass, so it is handed back verbatim rather than swapped for the
|
|
138
|
+
// canonical id — the variant in `opus[1m]` is part of the ask.
|
|
139
|
+
for (const row of this.rows) {
|
|
140
|
+
if (normalise(row.value) === wanted)
|
|
141
|
+
return row.value;
|
|
142
|
+
}
|
|
143
|
+
// A canonical id, handed back as given. Not swapped for the row's `value`,
|
|
144
|
+
// because several rows can name the same model — `default` and `opus[1m]`
|
|
145
|
+
// both resolve to the same Opus — and picking between them would turn an
|
|
146
|
+
// exact request into a guess. `default` in particular names a preference
|
|
147
|
+
// rather than a model, and could move underneath the caller.
|
|
148
|
+
for (const row of this.rows) {
|
|
149
|
+
if (row.resolvedModel && normalise(row.resolvedModel) === wanted)
|
|
150
|
+
return name;
|
|
151
|
+
}
|
|
152
|
+
// A row's name without its variant suffix: `opus` reaches `opus[1m]`.
|
|
153
|
+
for (const row of this.rows) {
|
|
154
|
+
if (normalise(baseName(row.value)) === wanted)
|
|
155
|
+
return row.value;
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
/** The effort levels a model accepts, when the catalogue knows. */
|
|
160
|
+
effortLevels(model) {
|
|
161
|
+
const wanted = normalise(model);
|
|
162
|
+
const row = this.rows.find((r) => normalise(r.value) === wanted || (r.resolvedModel && normalise(r.resolvedModel) === wanted));
|
|
163
|
+
return row?.supportedEffortLevels;
|
|
164
|
+
}
|
|
165
|
+
/** One line per option, for `weigh models`, `--help` and the error below. */
|
|
166
|
+
describe() {
|
|
167
|
+
if (this.empty) {
|
|
168
|
+
const width = Math.max(...MODELS.map((m) => m.id.length));
|
|
169
|
+
return MODELS.map((m) => ` ${m.id.padEnd(width)} (${m.aliases[0]})`).join('\n');
|
|
170
|
+
}
|
|
171
|
+
const width = Math.max(...this.rows.map((r) => r.value.length));
|
|
172
|
+
return this.rows.map((r) => ` ${r.value.padEnd(width)} ${r.displayName}`).join('\n');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** Convenience for callers that only want the list as text. */
|
|
176
|
+
export function describeModels(catalogue = ModelCatalogue.load()) {
|
|
177
|
+
return catalogue.describe();
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The id to run, for whatever the user typed.
|
|
181
|
+
*
|
|
182
|
+
* The catalogue first, so a short name means whatever the binary currently
|
|
183
|
+
* says it means — that is what stops `opus` pinning itself to the Opus that
|
|
184
|
+
* existed when this file was written. The static table second, for a machine
|
|
185
|
+
* that has never fetched one. And anything that reads as a Claude model id is
|
|
186
|
+
* passed through untouched, because the catalogue is a picker rather than a
|
|
187
|
+
* whitelist and refusing what it omits would refuse ids that work.
|
|
188
|
+
*/
|
|
189
|
+
export function resolveModel(name, catalogue = ModelCatalogue.load()) {
|
|
190
|
+
const live = catalogue.resolve(name);
|
|
191
|
+
if (live)
|
|
192
|
+
return live;
|
|
193
|
+
const known = STATIC_BY_NAME.get(normalise(name));
|
|
194
|
+
if (known)
|
|
195
|
+
return known;
|
|
196
|
+
if (looksLikeModelId(name))
|
|
197
|
+
return name;
|
|
198
|
+
throw new Error(`Unknown model: ${name}\n\nAvailable models:\n${catalogue.describe()}\n\n` +
|
|
199
|
+
'Any Claude model id is accepted in full, including provider-prefixed ones.\n' +
|
|
200
|
+
'Run `weigh models` to refresh this list from your Claude Code install.');
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Brings the cache up to date off a run that was already happening.
|
|
204
|
+
*
|
|
205
|
+
* Fire and forget, and deliberately unawaited: `supportedModels()` answers
|
|
206
|
+
* before the stream is consumed, so asking costs nothing on a subprocess that
|
|
207
|
+
* exists anyway. This is what keeps a short name pointing at the current
|
|
208
|
+
* model without anyone running a command to make it so.
|
|
209
|
+
*/
|
|
210
|
+
export function refreshCatalogue(q, now = Date.now()) {
|
|
211
|
+
const age = ModelCatalogue.load().ageMs(now);
|
|
212
|
+
if (age !== undefined && age < STALE_AFTER_MS)
|
|
213
|
+
return;
|
|
214
|
+
void q
|
|
215
|
+
.supportedModels()
|
|
216
|
+
.then((rows) => ModelCatalogue.of(rows, now).save())
|
|
217
|
+
// A catalogue that will not refresh is not a reason to fail a review.
|
|
218
|
+
.catch(() => { });
|
|
219
|
+
}
|
|
220
|
+
/** A day. Long enough to cost nothing, short enough to catch a release. */
|
|
221
|
+
export const STALE_AFTER_MS = 24 * 60 * 60 * 1000;
|
|
222
|
+
/** Whether the cache is old enough to be worth refreshing. */
|
|
223
|
+
export function isStale(catalogue = ModelCatalogue.load(), now = Date.now()) {
|
|
224
|
+
const age = catalogue.ageMs(now);
|
|
225
|
+
return age === undefined || age >= STALE_AFTER_MS;
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=models.js.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2
|
+
export declare function weighCache(): string;
|
|
3
|
+
export declare const paths: {
|
|
4
|
+
home: typeof weighHome;
|
|
5
|
+
cache: typeof weighCache;
|
|
6
|
+
/** Global settings. Repo-level overrides live in `<repo>/.weigh.json`. */
|
|
7
|
+
config: () => string;
|
|
8
|
+
/** Credentials. Authoritative for the variables Weigh owns. */
|
|
9
|
+
envFile: () => string;
|
|
10
|
+
/** JSONL transcripts, one per invocation. */
|
|
11
|
+
sessions: () => string;
|
|
12
|
+
/**
|
|
13
|
+
* Stored reviews, as JSON, one directory per repository.
|
|
14
|
+
*
|
|
15
|
+
* Here and not under the cache. A worktree or a clone can be deleted and
|
|
16
|
+
* rebuilt from the repository; a review is the only copy of what a run found,
|
|
17
|
+
* and corrections are keyed to the findings in it.
|
|
18
|
+
*/
|
|
19
|
+
reviews: () => string;
|
|
20
|
+
/**
|
|
21
|
+
* Human rulings on findings, one JSON-lines file per repository.
|
|
22
|
+
*
|
|
23
|
+
* Beside the reviews they are keyed to, and for the same reason: this is the
|
|
24
|
+
* only record that a person said a finding was wrong, deliberate or not
|
|
25
|
+
* worth fixing, and nothing can rebuild it. It is also the one input that
|
|
26
|
+
* works with no memory backend configured.
|
|
27
|
+
*/
|
|
28
|
+
corrections: () => string;
|
|
29
|
+
/** Disposable checkouts of the code under review. */
|
|
30
|
+
workspaces: () => string;
|
|
31
|
+
/** Clones of repositories we have no local copy of. */
|
|
32
|
+
repos: () => string;
|
|
33
|
+
};
|
|
34
|
+
export declare function ensureDir(dir: string): string;
|
|
35
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AA0BA,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED,eAAO,MAAM,KAAK;IAChB,IAAI;IACJ,KAAK;IACL,0EAA0E;IAC1E,MAAM;IACN,+DAA+D;IAC/D,OAAO;IACP,6CAA6C;IAC7C,QAAQ;IACR;;;;;;OAMG;IACH,OAAO;IACP;;;;;;;OAOG;IACH,WAAW;IACX,qDAAqD;IACrD,UAAU;IACV,uDAAuD;IACvD,KAAK;CACN,CAAC;AAEF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG7C"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { join, isAbsolute } from 'path';
|
|
6
|
+
import { mkdirSync } from 'fs';
|
|
7
|
+
/**
|
|
8
|
+
* Everything Weigh owns lives here — never inside the repository under review.
|
|
9
|
+
*
|
|
10
|
+
* Config and credentials are separated from the cache because they have
|
|
11
|
+
* different lifetimes: `~/.weigh` is yours to keep, while worktrees and repo
|
|
12
|
+
* clones can reach gigabytes and must be safe to delete, and worth caching in
|
|
13
|
+
* CI. `WEIGH_CACHE_DIR` moves the heavy half somewhere disposable.
|
|
14
|
+
*
|
|
15
|
+
* Functions rather than constants: the environment changes between calls, and
|
|
16
|
+
* resolving once at import time would freeze whatever the first importer saw.
|
|
17
|
+
* A relative override is ignored — honouring one would reintroduce exactly the
|
|
18
|
+
* write-into-someone-else's-repo bug this module exists to prevent.
|
|
19
|
+
*/
|
|
20
|
+
function absoluteEnv(name) {
|
|
21
|
+
const value = process.env[name];
|
|
22
|
+
return value && isAbsolute(value) ? value : null;
|
|
23
|
+
}
|
|
24
|
+
export function weighHome() {
|
|
25
|
+
return absoluteEnv('WEIGH_HOME') ?? join(homedir(), '.weigh');
|
|
26
|
+
}
|
|
27
|
+
export function weighCache() {
|
|
28
|
+
return absoluteEnv('WEIGH_CACHE_DIR') ?? join(weighHome(), 'cache');
|
|
29
|
+
}
|
|
30
|
+
export const paths = {
|
|
31
|
+
home: weighHome,
|
|
32
|
+
cache: weighCache,
|
|
33
|
+
/** Global settings. Repo-level overrides live in `<repo>/.weigh.json`. */
|
|
34
|
+
config: () => join(weighHome(), 'config.json'),
|
|
35
|
+
/** Credentials. Authoritative for the variables Weigh owns. */
|
|
36
|
+
envFile: () => join(weighHome(), '.env'),
|
|
37
|
+
/** JSONL transcripts, one per invocation. */
|
|
38
|
+
sessions: () => join(weighHome(), 'sessions'),
|
|
39
|
+
/**
|
|
40
|
+
* Stored reviews, as JSON, one directory per repository.
|
|
41
|
+
*
|
|
42
|
+
* Here and not under the cache. A worktree or a clone can be deleted and
|
|
43
|
+
* rebuilt from the repository; a review is the only copy of what a run found,
|
|
44
|
+
* and corrections are keyed to the findings in it.
|
|
45
|
+
*/
|
|
46
|
+
reviews: () => join(weighHome(), 'reviews'),
|
|
47
|
+
/**
|
|
48
|
+
* Human rulings on findings, one JSON-lines file per repository.
|
|
49
|
+
*
|
|
50
|
+
* Beside the reviews they are keyed to, and for the same reason: this is the
|
|
51
|
+
* only record that a person said a finding was wrong, deliberate or not
|
|
52
|
+
* worth fixing, and nothing can rebuild it. It is also the one input that
|
|
53
|
+
* works with no memory backend configured.
|
|
54
|
+
*/
|
|
55
|
+
corrections: () => join(weighHome(), 'corrections'),
|
|
56
|
+
/** Disposable checkouts of the code under review. */
|
|
57
|
+
workspaces: () => join(weighCache(), 'workspaces'),
|
|
58
|
+
/** Clones of repositories we have no local copy of. */
|
|
59
|
+
repos: () => join(weighCache(), 'repos'),
|
|
60
|
+
};
|
|
61
|
+
export function ensureDir(dir) {
|
|
62
|
+
mkdirSync(dir, { recursive: true });
|
|
63
|
+
return dir;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAA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,qDAAqD;IACrD,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,YAAY,CAAC;IAClD,uDAAuD;IACvD,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC;CACzC,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What kind of repository this is, read from the files already on disk.
|
|
3
|
+
*
|
|
4
|
+
* Standing context for the review, so the model is not rediscovering "this is
|
|
5
|
+
* a Bun project that uses Zod and Biome" from first principles on every run.
|
|
6
|
+
* Deterministic and free — no model call, a handful of file reads.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately shallow. Anything that needs judgement belongs to the review
|
|
9
|
+
* itself, and anything that needs a scan of the whole tree costs more than the
|
|
10
|
+
* fact is worth.
|
|
11
|
+
*/
|
|
12
|
+
export interface RepoProfile {
|
|
13
|
+
/** Languages inferred from manifests and config, most likely first. */
|
|
14
|
+
languages: string[];
|
|
15
|
+
packageManager: string | null;
|
|
16
|
+
/** Test runner, when a manifest names one. */
|
|
17
|
+
testFramework: string | null;
|
|
18
|
+
/** How this repository names its tests, e.g. `*.test.ts`. */
|
|
19
|
+
testConvention: string | null;
|
|
20
|
+
/** Commands the repository defines for itself, filtered to the useful ones. */
|
|
21
|
+
scripts: Record<string, string>;
|
|
22
|
+
/** Tooling and settings a reviewer should hold the code to. */
|
|
23
|
+
conventions: string[];
|
|
24
|
+
/** Manifests and config found at the root, in the order they were read. */
|
|
25
|
+
sources: string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function readProfile(root: string): RepoProfile;
|
|
28
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,8CAA8C;IAC9C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,6DAA6D;IAC7D,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,+EAA+E;IAC/E,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,+DAA+D;IAC/D,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,2EAA2E;IAC3E,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAmGD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAwDrD"}
|
package/dist/profile.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
import { existsSync, readFileSync, readdirSync } from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
const LOCKFILES = {
|
|
7
|
+
'bun.lock': 'bun',
|
|
8
|
+
'bun.lockb': 'bun',
|
|
9
|
+
'pnpm-lock.yaml': 'pnpm',
|
|
10
|
+
'yarn.lock': 'yarn',
|
|
11
|
+
'package-lock.json': 'npm',
|
|
12
|
+
'poetry.lock': 'poetry',
|
|
13
|
+
'uv.lock': 'uv',
|
|
14
|
+
'Cargo.lock': 'cargo',
|
|
15
|
+
'go.sum': 'go',
|
|
16
|
+
'Gemfile.lock': 'bundler',
|
|
17
|
+
'composer.lock': 'composer',
|
|
18
|
+
};
|
|
19
|
+
const MANIFESTS = {
|
|
20
|
+
'package.json': 'javascript',
|
|
21
|
+
'tsconfig.json': 'typescript',
|
|
22
|
+
'pyproject.toml': 'python',
|
|
23
|
+
'setup.py': 'python',
|
|
24
|
+
'Cargo.toml': 'rust',
|
|
25
|
+
'go.mod': 'go',
|
|
26
|
+
Gemfile: 'ruby',
|
|
27
|
+
'composer.json': 'php',
|
|
28
|
+
'pom.xml': 'java',
|
|
29
|
+
'build.gradle': 'java',
|
|
30
|
+
'build.gradle.kts': 'kotlin',
|
|
31
|
+
};
|
|
32
|
+
/** Test runners, checked against declared dependencies in manifest order. */
|
|
33
|
+
const TEST_FRAMEWORKS = ['vitest', 'jest', 'mocha', 'ava', 'jasmine', 'playwright', 'cypress', 'pytest'];
|
|
34
|
+
const CONVENTION_FILES = {
|
|
35
|
+
'biome.json': 'Biome for lint and format',
|
|
36
|
+
'.eslintrc.json': 'ESLint',
|
|
37
|
+
'.eslintrc.cjs': 'ESLint',
|
|
38
|
+
'eslint.config.js': 'ESLint',
|
|
39
|
+
'eslint.config.mjs': 'ESLint',
|
|
40
|
+
'.prettierrc': 'Prettier',
|
|
41
|
+
'prettier.config.js': 'Prettier',
|
|
42
|
+
'ruff.toml': 'Ruff',
|
|
43
|
+
'.editorconfig': 'EditorConfig',
|
|
44
|
+
'CONTRIBUTING.md': 'CONTRIBUTING.md — house rules worth honouring',
|
|
45
|
+
'CLAUDE.md': 'CLAUDE.md — instructions written for an agent working here',
|
|
46
|
+
'.golangci.yml': 'golangci-lint',
|
|
47
|
+
'rustfmt.toml': 'rustfmt',
|
|
48
|
+
};
|
|
49
|
+
function readJson(path) {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Guesses how tests are named, from the tests that exist.
|
|
59
|
+
*
|
|
60
|
+
* A convention read off the repository beats one asserted by a config file:
|
|
61
|
+
* this is what tells a review whether a changed file has a test beside it.
|
|
62
|
+
*/
|
|
63
|
+
function testConvention(root) {
|
|
64
|
+
const patterns = [
|
|
65
|
+
[/\.test\.[jt]sx?$/, '*.test.*'],
|
|
66
|
+
[/\.spec\.[jt]sx?$/, '*.spec.*'],
|
|
67
|
+
[/_test\.go$/, '*_test.go'],
|
|
68
|
+
[/^test_.*\.py$/, 'test_*.py'],
|
|
69
|
+
[/_test\.py$/, '*_test.py'],
|
|
70
|
+
[/_spec\.rb$/, '*_spec.rb'],
|
|
71
|
+
];
|
|
72
|
+
const counts = new Map();
|
|
73
|
+
const walk = (dir, depth) => {
|
|
74
|
+
if (depth > 3)
|
|
75
|
+
return;
|
|
76
|
+
let entries;
|
|
77
|
+
try {
|
|
78
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const entry of entries) {
|
|
84
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'vendor')
|
|
85
|
+
continue;
|
|
86
|
+
if (entry.isDirectory()) {
|
|
87
|
+
walk(join(dir, entry.name), depth + 1);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
for (const [re, label] of patterns) {
|
|
91
|
+
if (re.test(entry.name))
|
|
92
|
+
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
walk(root, 0);
|
|
97
|
+
const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1]);
|
|
98
|
+
return ranked[0]?.[0] ?? null;
|
|
99
|
+
}
|
|
100
|
+
export function readProfile(root) {
|
|
101
|
+
const sources = [];
|
|
102
|
+
const languages = [];
|
|
103
|
+
const conventions = [];
|
|
104
|
+
let packageManager = null;
|
|
105
|
+
let testFramework = null;
|
|
106
|
+
let scripts = {};
|
|
107
|
+
for (const [file, language] of Object.entries(MANIFESTS)) {
|
|
108
|
+
if (!existsSync(join(root, file)))
|
|
109
|
+
continue;
|
|
110
|
+
sources.push(file);
|
|
111
|
+
if (!languages.includes(language))
|
|
112
|
+
languages.push(language);
|
|
113
|
+
}
|
|
114
|
+
for (const [file, manager] of Object.entries(LOCKFILES)) {
|
|
115
|
+
if (!existsSync(join(root, file)))
|
|
116
|
+
continue;
|
|
117
|
+
sources.push(file);
|
|
118
|
+
packageManager ??= manager;
|
|
119
|
+
}
|
|
120
|
+
const pkg = readJson(join(root, 'package.json'));
|
|
121
|
+
if (pkg) {
|
|
122
|
+
const deps = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
|
|
123
|
+
testFramework = TEST_FRAMEWORKS.find((f) => f in deps) ?? null;
|
|
124
|
+
// Bun and node ship test runners, so an absent framework is not an absent
|
|
125
|
+
// test suite — fall back to what the repository says `test` means.
|
|
126
|
+
if (!testFramework && typeof pkg.scripts?.test === 'string') {
|
|
127
|
+
testFramework = pkg.scripts.test.includes('bun test') ? 'bun test' : null;
|
|
128
|
+
}
|
|
129
|
+
scripts = Object.fromEntries(Object.entries(pkg.scripts ?? {}).filter(([name]) => ['test', 'lint', 'typecheck', 'build', 'format', 'check'].includes(name)));
|
|
130
|
+
if (pkg.type === 'module')
|
|
131
|
+
conventions.push('ES modules ("type": "module")');
|
|
132
|
+
if (pkg.engines?.node)
|
|
133
|
+
conventions.push(`node ${pkg.engines.node}`);
|
|
134
|
+
}
|
|
135
|
+
const tsconfig = readJson(join(root, 'tsconfig.json'));
|
|
136
|
+
if (tsconfig?.compilerOptions?.strict)
|
|
137
|
+
conventions.push('TypeScript strict mode');
|
|
138
|
+
for (const [file, note] of Object.entries(CONVENTION_FILES)) {
|
|
139
|
+
if (!existsSync(join(root, file)))
|
|
140
|
+
continue;
|
|
141
|
+
sources.push(file);
|
|
142
|
+
conventions.push(note);
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
languages,
|
|
146
|
+
packageManager,
|
|
147
|
+
testFramework,
|
|
148
|
+
testConvention: testConvention(root),
|
|
149
|
+
scripts,
|
|
150
|
+
conventions,
|
|
151
|
+
sources,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AA6B5B,MAAM,SAAS,GAA2B;IACxC,UAAU,EAAE,KAAK;IACjB,WAAW,EAAE,KAAK;IAClB,gBAAgB,EAAE,MAAM;IACxB,WAAW,EAAE,MAAM;IACnB,mBAAmB,EAAE,KAAK;IAC1B,aAAa,EAAE,QAAQ;IACvB,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,OAAO;IACrB,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,SAAS;IACzB,eAAe,EAAE,UAAU;CAC5B,CAAC;AAEF,MAAM,SAAS,GAA2B;IACxC,cAAc,EAAE,YAAY;IAC5B,eAAe,EAAE,YAAY;IAC7B,gBAAgB,EAAE,QAAQ;IAC1B,UAAU,EAAE,QAAQ;IACpB,YAAY,EAAE,MAAM;IACpB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,MAAM;IACf,eAAe,EAAE,KAAK;IACtB,SAAS,EAAE,MAAM;IACjB,cAAc,EAAE,MAAM;IACtB,kBAAkB,EAAE,QAAQ;CAC7B,CAAC;AAEF,6EAA6E;AAC7E,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAEzG,MAAM,gBAAgB,GAA2B;IAC/C,YAAY,EAAE,2B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
|
|
2
|
+
export interface ProgressOptions {
|
|
3
|
+
/** Where the lines go. Defaults to stderr. */
|
|
4
|
+
stream?: NodeJS.WriteStream;
|
|
5
|
+
/** Clock injection, so tests are not timing-dependent. */
|
|
6
|
+
now?: () => number;
|
|
7
|
+
}
|
|
8
|
+
export declare class ProgressReporter {
|
|
9
|
+
private readonly _stream;
|
|
10
|
+
private readonly _palette;
|
|
11
|
+
private readonly _now;
|
|
12
|
+
private readonly _startedAt;
|
|
13
|
+
constructor(options?: ProgressOptions);
|
|
14
|
+
/**
|
|
15
|
+
* A reporter, unless the user asked for silence.
|
|
16
|
+
*
|
|
17
|
+
* `--quiet` promises no output at all, so it implies this. `--json` does
|
|
18
|
+
* not: progress is on stderr and the JSON is on stdout, and the two do not
|
|
19
|
+
* collide.
|
|
20
|
+
*/
|
|
21
|
+
static for(options: {
|
|
22
|
+
quiet?: boolean;
|
|
23
|
+
noProgress?: boolean;
|
|
24
|
+
}, opts?: ProgressOptions): ProgressReporter | undefined;
|
|
25
|
+
/** `[0:04]`, so a long run shows where the time went. */
|
|
26
|
+
private _elapsed;
|
|
27
|
+
/**
|
|
28
|
+
* The same call, again.
|
|
29
|
+
*
|
|
30
|
+
* Counted because a repeat is the one thing a reader cannot interpret. Four
|
|
31
|
+
* identical `report` lines are the SDK re-asking for schema-valid output —
|
|
32
|
+
* measured on Haiku 4.5 — and they look exactly like a run that has stopped
|
|
33
|
+
* making progress. Saying "retry 2" is the difference between a loop you
|
|
34
|
+
* can diagnose and one you can only worry about.
|
|
35
|
+
*/
|
|
36
|
+
private _last;
|
|
37
|
+
private _repeats;
|
|
38
|
+
private _write;
|
|
39
|
+
/** Announced before the model call, because assembly itself takes a moment. */
|
|
40
|
+
start(detail: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Announced before a prompt run, which has no diff to describe.
|
|
43
|
+
*
|
|
44
|
+
* The same job as `start` above with a different verb, because the two are
|
|
45
|
+
* different runs: one is handed a change to judge, the other a question to
|
|
46
|
+
* answer, and a line that said `review` over a question would be wrong about
|
|
47
|
+
* which of them is happening.
|
|
48
|
+
*/
|
|
49
|
+
asking(detail: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* A blank line, for when the answer starts arriving on stdout.
|
|
52
|
+
*
|
|
53
|
+
* The run is no longer searching, it is answering, and a progress line
|
|
54
|
+
* landing mid-paragraph would splice itself into the output the user is
|
|
55
|
+
* reading. `done` writes this for a review; a prompt run has no findings to
|
|
56
|
+
* count, so it just needs the separation.
|
|
57
|
+
*/
|
|
58
|
+
settled(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Announced before the second model call, for the same reason as the first.
|
|
61
|
+
*
|
|
62
|
+
* A refute pass reads files and takes minutes, and without a heading its
|
|
63
|
+
* tool calls appear under the review's as though the review had gone back
|
|
64
|
+
* for more. The caller holds back the review's `done` when a pass follows,
|
|
65
|
+
* so this is not printed after the line that closes the run.
|
|
66
|
+
*/
|
|
67
|
+
refuting(detail: string): void;
|
|
68
|
+
handle(event: ReviewEvent): void;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAU/C,MAAM,WAAW,eAAe;IAC9B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC;IAC5B,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAe;IACpC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC,YAAY,OAAO,GAAE,eAAoB,EAKxC;IAED;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