@smeltjs/core 0.2.0 → 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/README.md +3 -3
- package/dist/apply.d.ts.map +1 -1
- package/dist/apply.js.map +1 -1
- package/dist/cache/prefix.d.ts.map +1 -1
- package/dist/cache/prefix.js.map +1 -1
- package/dist/cli/args.d.ts +16 -70
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +18 -338
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/bin.d.ts.map +1 -1
- package/dist/cli/bin.js.map +1 -1
- package/dist/cli/config.d.ts +40 -0
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +55 -1
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/hooks.d.ts +33 -38
- package/dist/cli/hooks.d.ts.map +1 -1
- package/dist/cli/hooks.js +140 -485
- package/dist/cli/hooks.js.map +1 -1
- package/dist/cli/init.d.ts +30 -15
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +167 -38
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/report.d.ts.map +1 -1
- package/dist/cli/report.js +2 -2
- package/dist/cli/report.js.map +1 -1
- package/dist/cli/run.d.ts +25 -88
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +32 -341
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/shell.d.ts +106 -0
- package/dist/cli/shell.d.ts.map +1 -0
- package/dist/cli/shell.js +100 -0
- package/dist/cli/shell.js.map +1 -0
- package/dist/cli/subcommands/flags.d.ts +141 -0
- package/dist/cli/subcommands/flags.d.ts.map +1 -0
- package/dist/cli/subcommands/flags.js +208 -0
- package/dist/cli/subcommands/flags.js.map +1 -0
- package/dist/cli/subcommands/hooks.d.ts +18 -0
- package/dist/cli/subcommands/hooks.d.ts.map +1 -0
- package/dist/cli/subcommands/hooks.js +64 -0
- package/dist/cli/subcommands/hooks.js.map +1 -0
- package/dist/cli/subcommands/init.d.ts +19 -0
- package/dist/cli/subcommands/init.d.ts.map +1 -0
- package/dist/cli/subcommands/init.js +44 -0
- package/dist/cli/subcommands/init.js.map +1 -0
- package/dist/cli/subcommands/map.d.ts +75 -0
- package/dist/cli/subcommands/map.d.ts.map +1 -0
- package/dist/cli/subcommands/map.js +132 -0
- package/dist/cli/subcommands/map.js.map +1 -0
- package/dist/cli/subcommands/registry.d.ts +80 -0
- package/dist/cli/subcommands/registry.d.ts.map +1 -0
- package/dist/cli/subcommands/registry.js +138 -0
- package/dist/cli/subcommands/registry.js.map +1 -0
- package/dist/cli/subcommands/retrieve.d.ts +74 -0
- package/dist/cli/subcommands/retrieve.d.ts.map +1 -0
- package/dist/cli/subcommands/retrieve.js +84 -0
- package/dist/cli/subcommands/retrieve.js.map +1 -0
- package/dist/cli/subcommands/smelt.d.ts +107 -0
- package/dist/cli/subcommands/smelt.d.ts.map +1 -0
- package/dist/cli/subcommands/smelt.js +304 -0
- package/dist/cli/subcommands/smelt.js.map +1 -0
- package/dist/cli/subcommands/stats.d.ts +43 -0
- package/dist/cli/subcommands/stats.d.ts.map +1 -0
- package/dist/cli/subcommands/stats.js +62 -0
- package/dist/cli/subcommands/stats.js.map +1 -0
- package/dist/cli/subcommands/subcommand.d.ts +113 -0
- package/dist/cli/subcommands/subcommand.d.ts.map +1 -0
- package/dist/cli/subcommands/subcommand.js +3 -0
- package/dist/cli/subcommands/subcommand.js.map +1 -0
- package/dist/cli/usage.d.ts +3 -0
- package/dist/cli/usage.d.ts.map +1 -0
- package/dist/cli/usage.js +95 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/detect.d.ts.map +1 -1
- package/dist/detect.js.map +1 -1
- package/dist/errors.d.ts +21 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +33 -1
- package/dist/errors.js.map +1 -1
- package/dist/harness/aider.d.ts +10 -0
- package/dist/harness/aider.d.ts.map +1 -0
- package/dist/harness/aider.js +21 -0
- package/dist/harness/aider.js.map +1 -0
- package/dist/harness/claude-code.d.ts +3 -0
- package/dist/harness/claude-code.d.ts.map +1 -0
- package/dist/harness/claude-code.js +68 -0
- package/dist/harness/claude-code.js.map +1 -0
- package/dist/harness/cline.d.ts +3 -0
- package/dist/harness/cline.d.ts.map +1 -0
- package/dist/harness/cline.js +54 -0
- package/dist/harness/cline.js.map +1 -0
- package/dist/harness/codex.d.ts +3 -0
- package/dist/harness/codex.d.ts.map +1 -0
- package/dist/harness/codex.js +91 -0
- package/dist/harness/codex.js.map +1 -0
- package/dist/harness/cursor.d.ts +3 -0
- package/dist/harness/cursor.d.ts.map +1 -0
- package/dist/harness/cursor.js +54 -0
- package/dist/harness/cursor.js.map +1 -0
- package/dist/harness/gemini.d.ts +3 -0
- package/dist/harness/gemini.d.ts.map +1 -0
- package/dist/harness/gemini.js +59 -0
- package/dist/harness/gemini.js.map +1 -0
- package/dist/harness/grok.d.ts +3 -0
- package/dist/harness/grok.d.ts.map +1 -0
- package/dist/harness/grok.js +46 -0
- package/dist/harness/grok.js.map +1 -0
- package/dist/harness/hermes.d.ts +3 -0
- package/dist/harness/hermes.d.ts.map +1 -0
- package/dist/harness/hermes.js +71 -0
- package/dist/harness/hermes.js.map +1 -0
- package/dist/harness/kilocode.d.ts +3 -0
- package/dist/harness/kilocode.d.ts.map +1 -0
- package/dist/harness/kilocode.js +35 -0
- package/dist/harness/kilocode.js.map +1 -0
- package/dist/harness/opencode.d.ts +3 -0
- package/dist/harness/opencode.d.ts.map +1 -0
- package/dist/harness/opencode.js +97 -0
- package/dist/harness/opencode.js.map +1 -0
- package/dist/harness/paths.d.ts +17 -0
- package/dist/harness/paths.d.ts.map +1 -0
- package/dist/harness/paths.js +45 -0
- package/dist/harness/paths.js.map +1 -0
- package/dist/harness/profile.d.ts +184 -0
- package/dist/harness/profile.d.ts.map +1 -0
- package/dist/harness/profile.js +26 -0
- package/dist/harness/profile.js.map +1 -0
- package/dist/harness/registry.d.ts +51 -0
- package/dist/harness/registry.d.ts.map +1 -0
- package/dist/harness/registry.js +87 -0
- package/dist/harness/registry.js.map +1 -0
- package/dist/harness/snippet.d.ts +19 -0
- package/dist/harness/snippet.d.ts.map +1 -0
- package/dist/harness/snippet.js +41 -0
- package/dist/harness/snippet.js.map +1 -0
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js.map +1 -1
- package/dist/hooks/guard-core.d.ts +14 -14
- package/dist/hooks/guard-core.d.ts.map +1 -1
- package/dist/hooks/guard-core.js +15 -37
- package/dist/hooks/guard-core.js.map +1 -1
- package/dist/hooks/shim.d.ts +95 -4
- package/dist/hooks/shim.d.ts.map +1 -1
- package/dist/hooks/shim.js +87 -2
- package/dist/hooks/shim.js.map +1 -1
- package/dist/hooks/shims/claude-code.d.ts +5 -18
- package/dist/hooks/shims/claude-code.d.ts.map +1 -1
- package/dist/hooks/shims/claude-code.js +9 -56
- package/dist/hooks/shims/claude-code.js.map +1 -1
- package/dist/hooks/shims/cline.d.ts +5 -12
- package/dist/hooks/shims/cline.d.ts.map +1 -1
- package/dist/hooks/shims/cline.js +9 -34
- package/dist/hooks/shims/cline.js.map +1 -1
- package/dist/hooks/shims/codex.d.ts +5 -18
- package/dist/hooks/shims/codex.d.ts.map +1 -1
- package/dist/hooks/shims/codex.js +9 -51
- package/dist/hooks/shims/codex.js.map +1 -1
- package/dist/hooks/shims/cursor.d.ts +5 -14
- package/dist/hooks/shims/cursor.d.ts.map +1 -1
- package/dist/hooks/shims/cursor.js +9 -42
- package/dist/hooks/shims/cursor.js.map +1 -1
- package/dist/hooks/shims/gemini.d.ts +5 -18
- package/dist/hooks/shims/gemini.d.ts.map +1 -1
- package/dist/hooks/shims/gemini.js +9 -48
- package/dist/hooks/shims/gemini.js.map +1 -1
- package/dist/hooks/shims/grok.d.ts +5 -13
- package/dist/hooks/shims/grok.d.ts.map +1 -1
- package/dist/hooks/shims/grok.js +9 -32
- package/dist/hooks/shims/grok.js.map +1 -1
- package/dist/hooks/shims/hermes.d.ts +5 -17
- package/dist/hooks/shims/hermes.d.ts.map +1 -1
- package/dist/hooks/shims/hermes.js +9 -45
- package/dist/hooks/shims/hermes.js.map +1 -1
- package/dist/index.d.ts +33 -76
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -67
- package/dist/index.js.map +1 -1
- package/dist/lang/bash.d.ts.map +1 -1
- package/dist/lang/bash.js.map +1 -1
- package/dist/lang/c.d.ts.map +1 -1
- package/dist/lang/c.js.map +1 -1
- package/dist/lang/c_sharp.d.ts.map +1 -1
- package/dist/lang/c_sharp.js.map +1 -1
- package/dist/lang/cpp.d.ts.map +1 -1
- package/dist/lang/cpp.js.map +1 -1
- package/dist/lang/go.d.ts.map +1 -1
- package/dist/lang/go.js.map +1 -1
- package/dist/lang/java.d.ts.map +1 -1
- package/dist/lang/java.js.map +1 -1
- package/dist/lang/javascript.d.ts.map +1 -1
- package/dist/lang/javascript.js.map +1 -1
- package/dist/lang/kotlin.d.ts.map +1 -1
- package/dist/lang/kotlin.js.map +1 -1
- package/dist/lang/php.d.ts.map +1 -1
- package/dist/lang/php.js.map +1 -1
- package/dist/lang/profile.d.ts.map +1 -1
- package/dist/lang/profile.js.map +1 -1
- package/dist/lang/python.d.ts.map +1 -1
- package/dist/lang/python.js.map +1 -1
- package/dist/lang/registry.d.ts.map +1 -1
- package/dist/lang/registry.js.map +1 -1
- package/dist/lang/ruby.d.ts.map +1 -1
- package/dist/lang/ruby.js.map +1 -1
- package/dist/lang/rust.d.ts.map +1 -1
- package/dist/lang/rust.js.map +1 -1
- package/dist/lang/swift.d.ts.map +1 -1
- package/dist/lang/swift.js.map +1 -1
- package/dist/lang/tsx.d.ts.map +1 -1
- package/dist/lang/tsx.js.map +1 -1
- package/dist/lang/typescript.d.ts.map +1 -1
- package/dist/lang/typescript.js.map +1 -1
- package/dist/net/policy.d.ts +18 -1
- package/dist/net/policy.d.ts.map +1 -1
- package/dist/net/policy.js +6 -4
- package/dist/net/policy.js.map +1 -1
- package/dist/ops/index.d.ts +39 -0
- package/dist/ops/index.d.ts.map +1 -0
- package/dist/ops/index.js +37 -0
- package/dist/ops/index.js.map +1 -0
- package/dist/ops/inputs.d.ts +170 -0
- package/dist/ops/inputs.d.ts.map +1 -0
- package/dist/ops/inputs.js +142 -0
- package/dist/ops/inputs.js.map +1 -0
- package/dist/ops/verbs.d.ts +136 -0
- package/dist/ops/verbs.d.ts.map +1 -0
- package/dist/ops/verbs.js +76 -0
- package/dist/ops/verbs.js.map +1 -0
- package/dist/plan/auto.d.ts +69 -0
- package/dist/plan/auto.d.ts.map +1 -0
- package/dist/plan/auto.js +70 -0
- package/dist/plan/auto.js.map +1 -0
- package/dist/plan/budget.d.ts +21 -0
- package/dist/plan/budget.d.ts.map +1 -0
- package/dist/plan/budget.js +26 -0
- package/dist/plan/budget.js.map +1 -0
- package/dist/plan/grammar.d.ts +14 -0
- package/dist/plan/grammar.d.ts.map +1 -1
- package/dist/plan/grammar.js +47 -6
- package/dist/plan/grammar.js.map +1 -1
- package/dist/plan/lexical.d.ts.map +1 -1
- package/dist/plan/lexical.js +1 -7
- package/dist/plan/lexical.js.map +1 -1
- package/dist/plan/planners.d.ts +35 -2
- package/dist/plan/planners.d.ts.map +1 -1
- package/dist/plan/planners.js +35 -2
- package/dist/plan/planners.js.map +1 -1
- package/dist/plan/structural.d.ts +19 -5
- package/dist/plan/structural.d.ts.map +1 -1
- package/dist/plan/structural.js +180 -33
- package/dist/plan/structural.js.map +1 -1
- package/dist/repomap/cache.d.ts +48 -0
- package/dist/repomap/cache.d.ts.map +1 -1
- package/dist/repomap/cache.js +112 -13
- package/dist/repomap/cache.js.map +1 -1
- package/dist/repomap/io.d.ts +24 -0
- package/dist/repomap/io.d.ts.map +1 -0
- package/dist/repomap/io.js +34 -0
- package/dist/repomap/io.js.map +1 -0
- package/dist/repomap/map.d.ts +69 -6
- package/dist/repomap/map.d.ts.map +1 -1
- package/dist/repomap/map.js +104 -22
- package/dist/repomap/map.js.map +1 -1
- package/dist/repomap/rank.d.ts +26 -2
- package/dist/repomap/rank.d.ts.map +1 -1
- package/dist/repomap/rank.js +20 -0
- package/dist/repomap/rank.js.map +1 -1
- package/dist/repomap/reader.d.ts +73 -0
- package/dist/repomap/reader.d.ts.map +1 -0
- package/dist/repomap/reader.js +30 -0
- package/dist/repomap/reader.js.map +1 -0
- package/dist/repomap/tags.d.ts.map +1 -1
- package/dist/repomap/tags.js.map +1 -1
- package/dist/retrieve.d.ts +8 -0
- package/dist/retrieve.d.ts.map +1 -1
- package/dist/retrieve.js +12 -1
- package/dist/retrieve.js.map +1 -1
- package/dist/smelter.d.ts +79 -0
- package/dist/smelter.d.ts.map +1 -0
- package/dist/smelter.js +65 -0
- package/dist/smelter.js.map +1 -0
- package/dist/stages.d.ts.map +1 -1
- package/dist/stages.js +2 -2
- package/dist/stages.js.map +1 -1
- package/dist/stats.d.ts +2 -1
- package/dist/stats.d.ts.map +1 -1
- package/dist/stats.js +2 -1
- package/dist/stats.js.map +1 -1
- package/dist/store-dir.d.ts +43 -4
- package/dist/store-dir.d.ts.map +1 -1
- package/dist/store-dir.js +48 -5
- package/dist/store-dir.js.map +1 -1
- package/dist/store.d.ts +6 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +6 -0
- package/dist/store.js.map +1 -1
- package/dist/types.d.ts +35 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/grammars/tree-sitter-bash.wasm +0 -0
- package/grammars/tree-sitter-c.wasm +0 -0
- package/grammars/tree-sitter-c_sharp.wasm +0 -0
- package/grammars/tree-sitter-cpp.wasm +0 -0
- package/grammars/tree-sitter-go.wasm +0 -0
- package/grammars/tree-sitter-java.wasm +0 -0
- package/grammars/tree-sitter-javascript.wasm +0 -0
- package/grammars/tree-sitter-kotlin.wasm +0 -0
- package/grammars/tree-sitter-php.wasm +0 -0
- package/grammars/tree-sitter-python.wasm +0 -0
- package/grammars/tree-sitter-ruby.wasm +0 -0
- package/grammars/tree-sitter-rust.wasm +0 -0
- package/grammars/tree-sitter-swift.wasm +0 -0
- package/grammars/tree-sitter-tsx.wasm +0 -0
- package/grammars/tree-sitter-typescript.wasm +0 -0
- package/package.json +11 -11
- package/dist/cli/resolve.d.ts +0 -103
- package/dist/cli/resolve.d.ts.map +0 -1
- package/dist/cli/resolve.js +0 -106
- package/dist/cli/resolve.js.map +0 -1
package/dist/cli/run.d.ts
CHANGED
|
@@ -1,99 +1,36 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
1
|
+
import type { CliIo } from './shell.ts';
|
|
2
|
+
export { CLI_NAME, EXIT } from './shell.ts';
|
|
3
|
+
export type { AnswerStream, CliIo } from './shell.ts';
|
|
4
|
+
export { cliUsage } from './usage.ts';
|
|
5
|
+
export { parseSmeltArgs } from './args.ts';
|
|
6
|
+
export type { CliInvocation, HooksInvocation, InitInvocation, MapInvocation, RetrieveInvocation, SmeltInvocation, StatsInvocation, } from './args.ts';
|
|
5
7
|
export { formatMapReport, formatReport } from './report.ts';
|
|
6
8
|
export type { MapReportInput, ReportInput } from './report.ts';
|
|
7
|
-
export {
|
|
8
|
-
export type {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* not an error — smelt refused to cut the regions the caller asked to keep, which is
|
|
16
|
-
* correct — but it is also not success, and a script must be able to see the
|
|
17
|
-
* difference without parsing prose.
|
|
18
|
-
*/
|
|
19
|
-
export declare const EXIT: {
|
|
20
|
-
readonly ok: 0;
|
|
21
|
-
readonly overBudget: 1;
|
|
22
|
-
readonly usage: 2;
|
|
23
|
-
readonly refused: 3;
|
|
24
|
-
readonly unexpected: 4;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* The `--json` envelope format, versioned like the marker for the same reason: this is
|
|
28
|
-
* a surface other programs parse, so a change to it has to be identifiable rather than
|
|
29
|
-
* silent.
|
|
30
|
-
*/
|
|
31
|
-
export declare const CLI_JSON_FORMAT = "smelt-cli/v1";
|
|
32
|
-
/**
|
|
33
|
-
* The `smelt map --json` envelope format. Its own version line, because the two
|
|
34
|
-
* envelopes carry different structures and must be able to move independently —
|
|
35
|
-
* a map envelope has no elided bytes to carry, since a map elides nothing.
|
|
36
|
-
*/
|
|
37
|
-
export declare const CLI_MAP_JSON_FORMAT = "smelt-map-cli/v1";
|
|
38
|
-
/**
|
|
39
|
-
* The `smelt stats --json` envelope format. Its own version line for the same reason
|
|
40
|
-
* `smelt map` has one: the two envelopes carry different structures and must move
|
|
41
|
-
* independently.
|
|
42
|
-
*/
|
|
43
|
-
export declare const CLI_STATS_JSON_FORMAT = "smelt-stats-cli/v1";
|
|
44
|
-
/** What `smelt stats --json` prints: the {@link RetrieveStats} verbatim, versioned. */
|
|
45
|
-
export interface CliStatsJsonEnvelope {
|
|
46
|
-
readonly format: string;
|
|
47
|
-
/** The {@link RetrieveStats} exactly as the store's `stats()` returned them. */
|
|
48
|
-
readonly stats: RetrieveStats;
|
|
49
|
-
}
|
|
50
|
-
/** What `smelt map --json` prints: the {@link RepoMap} verbatim, versioned. */
|
|
51
|
-
export interface CliMapJsonEnvelope {
|
|
52
|
-
readonly format: string;
|
|
53
|
-
/** The {@link RepoMap} exactly as `buildRepoMap` returned it. */
|
|
54
|
-
readonly map: RepoMap;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* What `--json` prints, and what `--reconstruct` reads back.
|
|
58
|
-
*
|
|
59
|
-
* `result` is the {@link SmeltResult} **verbatim** — nothing renamed, nothing dropped —
|
|
60
|
-
* so it can be diffed in a test. `elided` is the other half, and it is here because a
|
|
61
|
-
* result on its own is *not* reconstructible: Law 3 is a property of the result plus
|
|
62
|
-
* the store that holds its bytes, and a file claiming to prove the round trip while
|
|
63
|
-
* carrying only half of it would prove nothing.
|
|
64
|
-
*/
|
|
65
|
-
export interface CliJsonEnvelope {
|
|
66
|
-
readonly format: string;
|
|
67
|
-
readonly result: SmeltResult;
|
|
68
|
-
/** hash → the exact elided bytes. Keys match `result.elisions[].hash`. */
|
|
69
|
-
readonly elided: Readonly<Record<string, string>>;
|
|
70
|
-
}
|
|
71
|
-
/** Where the CLI's bytes come from and go. Injected so `runCli` is testable in-process. */
|
|
72
|
-
export interface CliIo {
|
|
73
|
-
readonly stdout: (text: string) => void;
|
|
74
|
-
readonly stderr: (text: string) => void;
|
|
75
|
-
/** All of stdin, as UTF-8. @throws {CliUsageError} when nothing is piped. */
|
|
76
|
-
readonly stdin: () => string;
|
|
77
|
-
/** The package version, for `--version`. */
|
|
78
|
-
readonly version: string;
|
|
79
|
-
/**
|
|
80
|
-
* Where `smelt.config.json` discovery starts, and where `init` writes. Defaults to
|
|
81
|
-
* the process working directory; tests pass a temp directory to stay hermetic.
|
|
82
|
-
*/
|
|
83
|
-
readonly cwd?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Interactive input for `smelt init` — the wizard reads answers line by line, which
|
|
86
|
-
* the one-shot `stdin()` above cannot provide. `bin.ts` passes the real stdin
|
|
87
|
-
* stream; tests pass a scripted one. Absent means `init` is a usage error.
|
|
88
|
-
*/
|
|
89
|
-
readonly initInput?: NodeJS.ReadableStream;
|
|
90
|
-
}
|
|
9
|
+
export { CLI_JSON_FORMAT, resolveRun } from './subcommands/smelt.ts';
|
|
10
|
+
export type { CliJsonEnvelope, ResolvedRun } from './subcommands/smelt.ts';
|
|
11
|
+
export { CLI_MAP_JSON_FORMAT, resolveMapRun } from './subcommands/map.ts';
|
|
12
|
+
export type { CliMapJsonEnvelope, ResolvedMapRun } from './subcommands/map.ts';
|
|
13
|
+
export { resolveStoreRun } from './subcommands/retrieve.ts';
|
|
14
|
+
export type { ResolvedStoreRun } from './subcommands/retrieve.ts';
|
|
15
|
+
export { CLI_STATS_JSON_FORMAT } from './subcommands/stats.ts';
|
|
16
|
+
export type { CliStatsJsonEnvelope } from './subcommands/stats.ts';
|
|
91
17
|
/**
|
|
92
18
|
* The whole CLI, as a function that returns an exit code instead of calling `exit`.
|
|
93
19
|
*
|
|
94
20
|
* Smelted text goes to stdout and the report goes to stderr, so `smelt big.log
|
|
95
21
|
* --budget 4000 > small.log` leaves the human-readable part on the terminal and the
|
|
96
22
|
* payload in the file.
|
|
23
|
+
*
|
|
24
|
+
* It is a lookup and a dispatch, and nothing else: this function used to hold a
|
|
25
|
+
* `switch` over seven modes and seven `run*` functions beneath it, so adding a verb
|
|
26
|
+
* meant editing it. Now the verb that parsed an invocation is the verb that resolves
|
|
27
|
+
* and runs it — `SUBCOMMANDS` in `subcommands/registry.ts` — and the only decisions
|
|
28
|
+
* left here are the two global flags and the mapping from a thrown error to an exit
|
|
29
|
+
* code.
|
|
30
|
+
*
|
|
31
|
+
* The config is passed as a thunk, not a value: `init` and `hooks` read
|
|
32
|
+
* `smelt.config.json` themselves with their own tolerance, and loading it eagerly here
|
|
33
|
+
* would make a wizard you run to *fix* a malformed config refuse to start.
|
|
97
34
|
*/
|
|
98
35
|
export declare function runCli(argv: readonly string[], io: CliIo): Promise<number>;
|
|
99
36
|
//# sourceMappingURL=run.d.ts.map
|
package/dist/cli/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAMxC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EACV,aAAa,EACb,eAAe,EACf,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,eAAe,GAChB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACrE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1E,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BhF","sourcesContent":["import process from 'node:process';\n\nimport { CliUsageError, SmeltError } from '../errors.ts';\n\nimport { loadNearestConfig } from './config.ts';\nimport { EXIT } from './shell.ts';\nimport type { CliIo } from './shell.ts';\nimport { commandFor } from './subcommands/registry.ts';\nimport { cliUsage } from './usage.ts';\n\nimport { parseSmeltArgs } from './args.ts';\n\nexport { CLI_NAME, EXIT } from './shell.ts';\nexport type { AnswerStream, CliIo } from './shell.ts';\nexport { cliUsage } from './usage.ts';\nexport { parseSmeltArgs } from './args.ts';\nexport type {\n CliInvocation,\n HooksInvocation,\n InitInvocation,\n MapInvocation,\n RetrieveInvocation,\n SmeltInvocation,\n StatsInvocation,\n} from './args.ts';\nexport { formatMapReport, formatReport } from './report.ts';\nexport type { MapReportInput, ReportInput } from './report.ts';\nexport { CLI_JSON_FORMAT, resolveRun } from './subcommands/smelt.ts';\nexport type { CliJsonEnvelope, ResolvedRun } from './subcommands/smelt.ts';\nexport { CLI_MAP_JSON_FORMAT, resolveMapRun } from './subcommands/map.ts';\nexport type { CliMapJsonEnvelope, ResolvedMapRun } from './subcommands/map.ts';\nexport { resolveStoreRun } from './subcommands/retrieve.ts';\nexport type { ResolvedStoreRun } from './subcommands/retrieve.ts';\nexport { CLI_STATS_JSON_FORMAT } from './subcommands/stats.ts';\nexport type { CliStatsJsonEnvelope } from './subcommands/stats.ts';\n\n/**\n * The whole CLI, as a function that returns an exit code instead of calling `exit`.\n *\n * Smelted text goes to stdout and the report goes to stderr, so `smelt big.log\n * --budget 4000 > small.log` leaves the human-readable part on the terminal and the\n * payload in the file.\n *\n * It is a lookup and a dispatch, and nothing else: this function used to hold a\n * `switch` over seven modes and seven `run*` functions beneath it, so adding a verb\n * meant editing it. Now the verb that parsed an invocation is the verb that resolves\n * and runs it — `SUBCOMMANDS` in `subcommands/registry.ts` — and the only decisions\n * left here are the two global flags and the mapping from a thrown error to an exit\n * code.\n *\n * The config is passed as a thunk, not a value: `init` and `hooks` read\n * `smelt.config.json` themselves with their own tolerance, and loading it eagerly here\n * would make a wizard you run to *fix* a malformed config refuse to start.\n */\nexport async function runCli(argv: readonly string[], io: CliIo): Promise<number> {\n try {\n const invocation = parseSmeltArgs(argv);\n\n if (invocation.mode === 'help') {\n io.stdout(cliUsage());\n return EXIT.ok;\n }\n if (invocation.mode === 'version') {\n io.stdout(`${io.version}\\n`);\n return EXIT.ok;\n }\n\n const command = commandFor(invocation.mode);\n const config = () => loadNearestConfig(io.cwd ?? process.cwd());\n return await command.run(command.resolve(invocation, config), io);\n } catch (error) {\n if (error instanceof CliUsageError) {\n io.stderr(`${error.message}\\n`);\n return EXIT.usage;\n }\n if (error instanceof SmeltError) {\n io.stderr(`${error.name}: ${error.message}\\n`);\n return EXIT.refused;\n }\n throw error;\n }\n}\n"]}
|
package/dist/cli/run.js
CHANGED
|
@@ -1,96 +1,50 @@
|
|
|
1
|
-
import { readFileSync, statSync } from 'node:fs';
|
|
2
1
|
import process from 'node:process';
|
|
3
|
-
import { reconstruct } from '../apply.js';
|
|
4
2
|
import { CliUsageError, SmeltError } from '../errors.js';
|
|
5
|
-
import { createSmelter } from '../index.js';
|
|
6
|
-
import { buildRepoMap } from '../repomap/map.js';
|
|
7
|
-
import { MemoryElisionStore } from '../store.js';
|
|
8
|
-
import { DirectoryElisionStore } from '../store-dir.js';
|
|
9
|
-
import { CLI_NAME, cliUsage, parseSmeltArgs } from './args.js';
|
|
10
3
|
import { loadNearestConfig } from './config.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
export { CLI_NAME,
|
|
4
|
+
import { EXIT } from './shell.js';
|
|
5
|
+
import { commandFor } from './subcommands/registry.js';
|
|
6
|
+
import { cliUsage } from './usage.js';
|
|
7
|
+
import { parseSmeltArgs } from './args.js';
|
|
8
|
+
export { CLI_NAME, EXIT } from './shell.js';
|
|
9
|
+
export { cliUsage } from './usage.js';
|
|
10
|
+
export { parseSmeltArgs } from './args.js';
|
|
16
11
|
export { formatMapReport, formatReport } from './report.js';
|
|
17
|
-
export {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* A CLI that returns 0 whatever happens is the shell-level version of a stub that
|
|
22
|
-
* returns `[]`: the caller cannot tell success from failure, so a pipeline built on it
|
|
23
|
-
* fails silently. **`overBudget` is the load-bearing one.** A plan that did not fit is
|
|
24
|
-
* not an error — smelt refused to cut the regions the caller asked to keep, which is
|
|
25
|
-
* correct — but it is also not success, and a script must be able to see the
|
|
26
|
-
* difference without parsing prose.
|
|
27
|
-
*/
|
|
28
|
-
export const EXIT = {
|
|
29
|
-
ok: 0,
|
|
30
|
-
overBudget: 1,
|
|
31
|
-
usage: 2,
|
|
32
|
-
refused: 3,
|
|
33
|
-
unexpected: 4,
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* The `--json` envelope format, versioned like the marker for the same reason: this is
|
|
37
|
-
* a surface other programs parse, so a change to it has to be identifiable rather than
|
|
38
|
-
* silent.
|
|
39
|
-
*/
|
|
40
|
-
export const CLI_JSON_FORMAT = 'smelt-cli/v1';
|
|
41
|
-
/**
|
|
42
|
-
* The `smelt map --json` envelope format. Its own version line, because the two
|
|
43
|
-
* envelopes carry different structures and must be able to move independently —
|
|
44
|
-
* a map envelope has no elided bytes to carry, since a map elides nothing.
|
|
45
|
-
*/
|
|
46
|
-
export const CLI_MAP_JSON_FORMAT = 'smelt-map-cli/v1';
|
|
47
|
-
/**
|
|
48
|
-
* The `smelt stats --json` envelope format. Its own version line for the same reason
|
|
49
|
-
* `smelt map` has one: the two envelopes carry different structures and must move
|
|
50
|
-
* independently.
|
|
51
|
-
*/
|
|
52
|
-
export const CLI_STATS_JSON_FORMAT = 'smelt-stats-cli/v1';
|
|
12
|
+
export { CLI_JSON_FORMAT, resolveRun } from './subcommands/smelt.js';
|
|
13
|
+
export { CLI_MAP_JSON_FORMAT, resolveMapRun } from './subcommands/map.js';
|
|
14
|
+
export { resolveStoreRun } from './subcommands/retrieve.js';
|
|
15
|
+
export { CLI_STATS_JSON_FORMAT } from './subcommands/stats.js';
|
|
53
16
|
/**
|
|
54
17
|
* The whole CLI, as a function that returns an exit code instead of calling `exit`.
|
|
55
18
|
*
|
|
56
19
|
* Smelted text goes to stdout and the report goes to stderr, so `smelt big.log
|
|
57
20
|
* --budget 4000 > small.log` leaves the human-readable part on the terminal and the
|
|
58
21
|
* payload in the file.
|
|
22
|
+
*
|
|
23
|
+
* It is a lookup and a dispatch, and nothing else: this function used to hold a
|
|
24
|
+
* `switch` over seven modes and seven `run*` functions beneath it, so adding a verb
|
|
25
|
+
* meant editing it. Now the verb that parsed an invocation is the verb that resolves
|
|
26
|
+
* and runs it — `SUBCOMMANDS` in `subcommands/registry.ts` — and the only decisions
|
|
27
|
+
* left here are the two global flags and the mapping from a thrown error to an exit
|
|
28
|
+
* code.
|
|
29
|
+
*
|
|
30
|
+
* The config is passed as a thunk, not a value: `init` and `hooks` read
|
|
31
|
+
* `smelt.config.json` themselves with their own tolerance, and loading it eagerly here
|
|
32
|
+
* would make a wizard you run to *fix* a malformed config refuse to start.
|
|
59
33
|
*/
|
|
60
34
|
export async function runCli(argv, io) {
|
|
61
35
|
try {
|
|
62
36
|
const invocation = parseSmeltArgs(argv);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
case 'reconstruct':
|
|
71
|
-
return runReconstruct(readInput(invocation.file, io), io);
|
|
72
|
-
case 'init': {
|
|
73
|
-
if (io.initInput === undefined) {
|
|
74
|
-
throw new CliUsageError(`${CLI_NAME}: init is interactive, and this invocation has no interactive ` +
|
|
75
|
-
`input stream. Run \`${CLI_NAME} init\` from a terminal.`);
|
|
76
|
-
}
|
|
77
|
-
return await runInit({
|
|
78
|
-
input: io.initInput,
|
|
79
|
-
output: io.stdout,
|
|
80
|
-
cwd: io.cwd ?? process.cwd(),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
case 'smelt':
|
|
84
|
-
return await runSmelt(invocation, io);
|
|
85
|
-
case 'map':
|
|
86
|
-
return await runMap(invocation, io);
|
|
87
|
-
case 'retrieve':
|
|
88
|
-
return runRetrieve(invocation, io);
|
|
89
|
-
case 'stats':
|
|
90
|
-
return runStats(invocation, io);
|
|
91
|
-
case 'hooks':
|
|
92
|
-
return await runHooksMode(invocation, io);
|
|
37
|
+
if (invocation.mode === 'help') {
|
|
38
|
+
io.stdout(cliUsage());
|
|
39
|
+
return EXIT.ok;
|
|
40
|
+
}
|
|
41
|
+
if (invocation.mode === 'version') {
|
|
42
|
+
io.stdout(`${io.version}\n`);
|
|
43
|
+
return EXIT.ok;
|
|
93
44
|
}
|
|
45
|
+
const command = commandFor(invocation.mode);
|
|
46
|
+
const config = () => loadNearestConfig(io.cwd ?? process.cwd());
|
|
47
|
+
return await command.run(command.resolve(invocation, config), io);
|
|
94
48
|
}
|
|
95
49
|
catch (error) {
|
|
96
50
|
if (error instanceof CliUsageError) {
|
|
@@ -104,267 +58,4 @@ export async function runCli(argv, io) {
|
|
|
104
58
|
throw error;
|
|
105
59
|
}
|
|
106
60
|
}
|
|
107
|
-
/**
|
|
108
|
-
* `smelt hooks <install|remove>` — interactive like `init`, so it needs the same
|
|
109
|
-
* line-by-line input stream, and refuses to run without one for the same reason.
|
|
110
|
-
*/
|
|
111
|
-
async function runHooksMode(invocation, io) {
|
|
112
|
-
if (io.initInput === undefined) {
|
|
113
|
-
throw new CliUsageError(`${CLI_NAME}: hooks ${invocation.action} is interactive, and this invocation has ` +
|
|
114
|
-
`no interactive input stream. Run \`${CLI_NAME} hooks ${invocation.action}\` ` +
|
|
115
|
-
`from a terminal.`);
|
|
116
|
-
}
|
|
117
|
-
return await runHooks(invocation.action, invocation.harness, {
|
|
118
|
-
input: io.initInput,
|
|
119
|
-
output: io.stdout,
|
|
120
|
-
cwd: io.cwd ?? process.cwd(),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* One smelt run, executed straight-line over a {@link ResolvedRun}.
|
|
125
|
-
*
|
|
126
|
-
* All merging — flags versus `smelt.config.json` versus built-ins, including the
|
|
127
|
-
* budget-required refusal — happens in {@link resolveRun}, which is the only place
|
|
128
|
-
* precedence lives. This function reads the resolved object and never consults a flag
|
|
129
|
-
* or a config field directly.
|
|
130
|
-
*/
|
|
131
|
-
async function runSmelt(invocation, io) {
|
|
132
|
-
const run = resolveRun(invocation, loadNearestConfig(io.cwd ?? process.cwd()));
|
|
133
|
-
const inputText = readInput(run.file, io);
|
|
134
|
-
const source = run.file ?? '<stdin>';
|
|
135
|
-
const store = storeFor(run);
|
|
136
|
-
const smelter = createSmelter({
|
|
137
|
-
strategy: run.strategy,
|
|
138
|
-
...(store === undefined ? {} : { store }),
|
|
139
|
-
});
|
|
140
|
-
const options = {
|
|
141
|
-
budgetBytes: run.budgetBytes,
|
|
142
|
-
...(run.file === undefined ? {} : { path: run.file }),
|
|
143
|
-
...(run.language === undefined ? {} : { language: run.language }),
|
|
144
|
-
...(run.focus.length === 0 ? {} : { focus: run.focus }),
|
|
145
|
-
};
|
|
146
|
-
const result = await smelter.smelt(inputText, options);
|
|
147
|
-
if (run.json) {
|
|
148
|
-
io.stdout(`${JSON.stringify(envelope(result, smelter.store), null, 2)}\n`);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
io.stdout(result.text);
|
|
152
|
-
}
|
|
153
|
-
io.stderr(formatReport({ result, source, budgetBytes: run.budgetBytes, inputText }));
|
|
154
|
-
return result.outputBytes > run.budgetBytes ? EXIT.overBudget : EXIT.ok;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* One `smelt map` run, executed straight-line over a {@link ResolvedMapRun} the same
|
|
158
|
-
* way {@link runSmelt} executes its {@link ResolvedRun} — the merge, including the
|
|
159
|
-
* budget-required refusal, lives in {@link resolveMapRun}.
|
|
160
|
-
*
|
|
161
|
-
* The map is deliberately **not** served through a planner strategy: `buildRepoMap`
|
|
162
|
-
* returns a {@link RepoMap}, not an `ElisionPlan` — nothing is elided, stored, or
|
|
163
|
-
* reversible — so it gets its own subcommand and its own envelope instead of a
|
|
164
|
-
* `--strategy` name that would lie about what comes back. And the exit code is
|
|
165
|
-
* {@link EXIT.ok} on every successful build: `EXIT.overBudget` exists because a smelt
|
|
166
|
-
* plan may refuse to cut kept regions and come back too big, while the map fits
|
|
167
|
-
* itself to the budget by construction — an over-budget map cannot happen, so no
|
|
168
|
-
* exit code pretends it can.
|
|
169
|
-
*/
|
|
170
|
-
async function runMap(invocation, io) {
|
|
171
|
-
const run = resolveMapRun(invocation, loadNearestConfig(io.cwd ?? process.cwd()));
|
|
172
|
-
assertDirectory(run.dir);
|
|
173
|
-
const map = await buildRepoMap({
|
|
174
|
-
root: run.dir,
|
|
175
|
-
budgetBytes: run.budgetBytes,
|
|
176
|
-
...(run.focus.length === 0 ? {} : { focus: run.focus }),
|
|
177
|
-
...(run.ignore === undefined ? {} : { ignore: run.ignore }),
|
|
178
|
-
...(run.cacheDir === undefined ? {} : { cacheDir: run.cacheDir }),
|
|
179
|
-
});
|
|
180
|
-
if (run.json) {
|
|
181
|
-
const mapEnvelope = { format: CLI_MAP_JSON_FORMAT, map };
|
|
182
|
-
io.stdout(`${JSON.stringify(mapEnvelope, null, 2)}\n`);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
io.stdout(map.text);
|
|
186
|
-
}
|
|
187
|
-
io.stderr(formatMapReport({ map, source: run.dir, budgetSource: run.budgetSource }));
|
|
188
|
-
return EXIT.ok;
|
|
189
|
-
}
|
|
190
|
-
/** A directory the walk can start from, or a usage error naming what is wrong. */
|
|
191
|
-
function assertDirectory(dir) {
|
|
192
|
-
let isDirectory;
|
|
193
|
-
try {
|
|
194
|
-
isDirectory = statSync(dir).isDirectory();
|
|
195
|
-
}
|
|
196
|
-
catch (cause) {
|
|
197
|
-
throw new CliUsageError(`${CLI_NAME}: cannot read directory "${dir}": ` +
|
|
198
|
-
`${cause instanceof Error ? cause.message : String(cause)}`);
|
|
199
|
-
}
|
|
200
|
-
if (!isDirectory) {
|
|
201
|
-
throw new CliUsageError(`${CLI_NAME}: "${dir}" is not a directory. map reads a whole tree; for one ` +
|
|
202
|
-
`file, use \`${CLI_NAME} <file>\`.`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Construct the store a {@link ResolvedRun} decided on, or `undefined` for the
|
|
207
|
-
* library's own default (a fresh in-memory store). Pure construction — the decision,
|
|
208
|
-
* including path resolution, was already made in {@link resolveRun}.
|
|
209
|
-
*/
|
|
210
|
-
function storeFor(run) {
|
|
211
|
-
if (run.store.kind === 'memory')
|
|
212
|
-
return undefined;
|
|
213
|
-
return new DirectoryElisionStore(run.store.path);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* `smelt retrieve <hash>` — the marker's `retrieve("hash")`, as a real command.
|
|
217
|
-
*
|
|
218
|
-
* The exact original bytes go to stdout and **nothing else does**: no report, no
|
|
219
|
-
* trailing newline the store did not hold, no re-encoding. Trailing-newline fidelity
|
|
220
|
-
* is not pedantry — the retrieved bytes get spliced back into reasoning about the
|
|
221
|
-
* original, and an almost-right blob is the silent wrong answer this project refuses.
|
|
222
|
-
*
|
|
223
|
-
* The retrieval IS counted — that is the point. `store.retrieve()` journals the hit,
|
|
224
|
-
* so an agent working from pure shell moves the same `expansionRate` a tool-calling
|
|
225
|
-
* consumer moves, and over-pruning stays visible whichever loop is in use. Errors are
|
|
226
|
-
* the store's own, verbatim: `UnknownHashError` for a hash never elided,
|
|
227
|
-
* `StoreCorruptionError` for bytes that no longer hash to their name — distinct
|
|
228
|
-
* texts, both exiting {@link EXIT.refused}.
|
|
229
|
-
*/
|
|
230
|
-
function runRetrieve(invocation, io) {
|
|
231
|
-
const run = resolveStoreRun('retrieve', loadNearestConfig(io.cwd ?? process.cwd()));
|
|
232
|
-
const store = new DirectoryElisionStore(run.storePath);
|
|
233
|
-
const content = store.retrieve(invocation.hash);
|
|
234
|
-
io.stdout(content);
|
|
235
|
-
return EXIT.ok;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* `smelt stats` — the store's counters, without touching them.
|
|
239
|
-
*
|
|
240
|
-
* Reading stats does NOT count as a retrieval: `stats()` folds the journal and scans
|
|
241
|
-
* the blobs, journaling nothing, so watching the expansion rate can never move it —
|
|
242
|
-
* an observer that inflated its own metric would make the honest signal dishonest.
|
|
243
|
-
*
|
|
244
|
-
* The plain form is one `name value` per line, greppable and stable; `--json` emits
|
|
245
|
-
* the {@link RetrieveStats} verbatim in its own versioned envelope
|
|
246
|
-
* ({@link CLI_STATS_JSON_FORMAT}), like every other machine-read surface here.
|
|
247
|
-
*/
|
|
248
|
-
function runStats(invocation, io) {
|
|
249
|
-
const run = resolveStoreRun('stats', loadNearestConfig(io.cwd ?? process.cwd()));
|
|
250
|
-
const stats = new DirectoryElisionStore(run.storePath).stats();
|
|
251
|
-
if (invocation.json) {
|
|
252
|
-
const statsEnvelope = { format: CLI_STATS_JSON_FORMAT, stats };
|
|
253
|
-
io.stdout(`${JSON.stringify(statsEnvelope, null, 2)}\n`);
|
|
254
|
-
return EXIT.ok;
|
|
255
|
-
}
|
|
256
|
-
io.stdout([
|
|
257
|
-
`elisionsStored ${String(stats.elisionsStored)}`,
|
|
258
|
-
`bytesStored ${String(stats.bytesStored)}`,
|
|
259
|
-
`retrieveCalls ${String(stats.retrieveCalls)}`,
|
|
260
|
-
`uniqueRetrieved ${String(stats.uniqueRetrieved)}`,
|
|
261
|
-
`expansionRate ${String(stats.expansionRate)}`,
|
|
262
|
-
`allElisionsRetrieved ${String(stats.allElisionsRetrieved)}`,
|
|
263
|
-
'',
|
|
264
|
-
].join('\n'));
|
|
265
|
-
return EXIT.ok;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Law 3, from a shell.
|
|
269
|
-
*
|
|
270
|
-
* This is deliberately not "print the text and hope": it rebuilds the store from the
|
|
271
|
-
* envelope, checks every hash against the bytes it claims to key, and checks the
|
|
272
|
-
* reconstructed length against the `inputBytes` the result recorded at the time of the
|
|
273
|
-
* cut. A round trip that quietly returns almost-right text is the failure this whole
|
|
274
|
-
* repository is arranged against.
|
|
275
|
-
*/
|
|
276
|
-
function runReconstruct(text, io) {
|
|
277
|
-
const { result, elided } = parseEnvelope(text);
|
|
278
|
-
const store = new MemoryElisionStore();
|
|
279
|
-
for (const [hash, content] of Object.entries(elided)) {
|
|
280
|
-
const actual = store.put(content);
|
|
281
|
-
if (actual !== hash) {
|
|
282
|
-
throw new CliUsageError(`${CLI_NAME}: envelope is not self-consistent — it stores bytes under ` +
|
|
283
|
-
`"${hash}" that actually hash to "${actual}". Refusing to reconstruct from it.`);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
for (const elision of result.elisions) {
|
|
287
|
-
if (!store.has(elision.hash)) {
|
|
288
|
-
throw new CliUsageError(`${CLI_NAME}: envelope is missing the bytes for "${elision.hash}". A result ` +
|
|
289
|
-
`without its elided bytes cannot be reconstructed; re-run with --json.`);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
const original = reconstruct(result, store);
|
|
293
|
-
const bytes = Buffer.byteLength(original, 'utf8');
|
|
294
|
-
if (bytes !== result.inputBytes) {
|
|
295
|
-
throw new SmeltError(`${CLI_NAME}: reconstruction produced ${String(bytes)} bytes but the result ` +
|
|
296
|
-
`recorded ${String(result.inputBytes)}. The round trip did not close.`);
|
|
297
|
-
}
|
|
298
|
-
io.stdout(original);
|
|
299
|
-
io.stderr(`${CLI_NAME} reconstructed ${String(result.inputBytes)} B from ` +
|
|
300
|
-
`${String(result.elisions.length)} elisions — byte for byte\n`);
|
|
301
|
-
return EXIT.ok;
|
|
302
|
-
}
|
|
303
|
-
/** `peek`, not `retrieve`: writing a file is not the model asking for anything back. */
|
|
304
|
-
function envelope(result, store) {
|
|
305
|
-
const elided = {};
|
|
306
|
-
for (const elision of result.elisions) {
|
|
307
|
-
const content = store.peek(elision.hash);
|
|
308
|
-
if (content === undefined) {
|
|
309
|
-
throw new SmeltError(`${CLI_NAME}: the store does not hold "${elision.hash}", which its own result ` +
|
|
310
|
-
`says it elided. Refusing to write an envelope that cannot round-trip.`);
|
|
311
|
-
}
|
|
312
|
-
elided[elision.hash] = content;
|
|
313
|
-
}
|
|
314
|
-
return { format: CLI_JSON_FORMAT, result, elided };
|
|
315
|
-
}
|
|
316
|
-
function parseEnvelope(text) {
|
|
317
|
-
let value;
|
|
318
|
-
try {
|
|
319
|
-
value = JSON.parse(text);
|
|
320
|
-
}
|
|
321
|
-
catch (cause) {
|
|
322
|
-
throw new CliUsageError(`${CLI_NAME}: --reconstruct expected a --json envelope, and this is not JSON: ` +
|
|
323
|
-
`${cause instanceof Error ? cause.message : String(cause)}`);
|
|
324
|
-
}
|
|
325
|
-
if (typeof value !== 'object' || value === null) {
|
|
326
|
-
throw new CliUsageError(`${CLI_NAME}: --reconstruct expected a JSON object.`);
|
|
327
|
-
}
|
|
328
|
-
const fields = value;
|
|
329
|
-
if (fields['format'] !== CLI_JSON_FORMAT) {
|
|
330
|
-
throw new CliUsageError(`${CLI_NAME}: this envelope says format "${String(fields['format'])}"; this build ` +
|
|
331
|
-
`reads "${CLI_JSON_FORMAT}". Formats are versioned so a mismatch is visible ` +
|
|
332
|
-
`instead of being half-understood.`);
|
|
333
|
-
}
|
|
334
|
-
const result = fields['result'];
|
|
335
|
-
if (typeof result !== 'object' || result === null) {
|
|
336
|
-
throw new CliUsageError(`${CLI_NAME}: envelope has no \`result\` object.`);
|
|
337
|
-
}
|
|
338
|
-
const resultFields = result;
|
|
339
|
-
if (typeof resultFields['text'] !== 'string' ||
|
|
340
|
-
typeof resultFields['inputBytes'] !== 'number' ||
|
|
341
|
-
!Array.isArray(resultFields['elisions'])) {
|
|
342
|
-
throw new CliUsageError(`${CLI_NAME}: envelope's \`result\` is missing text, inputBytes or elisions.`);
|
|
343
|
-
}
|
|
344
|
-
const elided = fields['elided'];
|
|
345
|
-
if (typeof elided !== 'object' || elided === null) {
|
|
346
|
-
throw new CliUsageError(`${CLI_NAME}: envelope has no \`elided\` map.`);
|
|
347
|
-
}
|
|
348
|
-
for (const [hash, content] of Object.entries(elided)) {
|
|
349
|
-
if (typeof content !== 'string') {
|
|
350
|
-
throw new CliUsageError(`${CLI_NAME}: envelope's \`elided["${hash}"]\` is not a string.`);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return {
|
|
354
|
-
format: CLI_JSON_FORMAT,
|
|
355
|
-
result: result,
|
|
356
|
-
elided: elided,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
function readInput(file, io) {
|
|
360
|
-
if (file === undefined)
|
|
361
|
-
return io.stdin();
|
|
362
|
-
try {
|
|
363
|
-
return readFileSync(file, 'utf8');
|
|
364
|
-
}
|
|
365
|
-
catch (cause) {
|
|
366
|
-
throw new CliUsageError(`${CLI_NAME}: cannot read "${file}": ` +
|
|
367
|
-
`${cause instanceof Error ? cause.message : String(cause)}`);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
61
|
//# sourceMappingURL=run.js.map
|
package/dist/cli/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAQ/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAS/D,OAAO,EAAE,eAAe,EAAE,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CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;YACtB,OAAO,IAAI,CAAC,EAAE,CAAC;QACjB,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAClC,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,IAAI,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC,EAAE,CAAC;QACjB,CAAC;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAChE,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;YACnC,EAAE,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;YAChC,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QACD,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;YAChC,EAAE,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;YAC/C,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import process from 'node:process';\n\nimport { CliUsageError, SmeltError } from '../errors.ts';\n\nimport { loadNearestConfig } from './config.ts';\nimport { EXIT } from './shell.ts';\nimport type { CliIo } from './shell.ts';\nimport { commandFor } from './subcommands/registry.ts';\nimport { cliUsage } from './usage.ts';\n\nimport { parseSmeltArgs } from './args.ts';\n\nexport { CLI_NAME, EXIT } from './shell.ts';\nexport type { AnswerStream, CliIo } from './shell.ts';\nexport { cliUsage } from './usage.ts';\nexport { parseSmeltArgs } from './args.ts';\nexport type {\n CliInvocation,\n HooksInvocation,\n InitInvocation,\n MapInvocation,\n RetrieveInvocation,\n SmeltInvocation,\n StatsInvocation,\n} from './args.ts';\nexport { formatMapReport, formatReport } from './report.ts';\nexport type { MapReportInput, ReportInput } from './report.ts';\nexport { CLI_JSON_FORMAT, resolveRun } from './subcommands/smelt.ts';\nexport type { CliJsonEnvelope, ResolvedRun } from './subcommands/smelt.ts';\nexport { CLI_MAP_JSON_FORMAT, resolveMapRun } from './subcommands/map.ts';\nexport type { CliMapJsonEnvelope, ResolvedMapRun } from './subcommands/map.ts';\nexport { resolveStoreRun } from './subcommands/retrieve.ts';\nexport type { ResolvedStoreRun } from './subcommands/retrieve.ts';\nexport { CLI_STATS_JSON_FORMAT } from './subcommands/stats.ts';\nexport type { CliStatsJsonEnvelope } from './subcommands/stats.ts';\n\n/**\n * The whole CLI, as a function that returns an exit code instead of calling `exit`.\n *\n * Smelted text goes to stdout and the report goes to stderr, so `smelt big.log\n * --budget 4000 > small.log` leaves the human-readable part on the terminal and the\n * payload in the file.\n *\n * It is a lookup and a dispatch, and nothing else: this function used to hold a\n * `switch` over seven modes and seven `run*` functions beneath it, so adding a verb\n * meant editing it. Now the verb that parsed an invocation is the verb that resolves\n * and runs it — `SUBCOMMANDS` in `subcommands/registry.ts` — and the only decisions\n * left here are the two global flags and the mapping from a thrown error to an exit\n * code.\n *\n * The config is passed as a thunk, not a value: `init` and `hooks` read\n * `smelt.config.json` themselves with their own tolerance, and loading it eagerly here\n * would make a wizard you run to *fix* a malformed config refuse to start.\n */\nexport async function runCli(argv: readonly string[], io: CliIo): Promise<number> {\n try {\n const invocation = parseSmeltArgs(argv);\n\n if (invocation.mode === 'help') {\n io.stdout(cliUsage());\n return EXIT.ok;\n }\n if (invocation.mode === 'version') {\n io.stdout(`${io.version}\\n`);\n return EXIT.ok;\n }\n\n const command = commandFor(invocation.mode);\n const config = () => loadNearestConfig(io.cwd ?? process.cwd());\n return await command.run(command.resolve(invocation, config), io);\n } catch (error) {\n if (error instanceof CliUsageError) {\n io.stderr(`${error.message}\\n`);\n return EXIT.usage;\n }\n if (error instanceof SmeltError) {\n io.stderr(`${error.name}: ${error.message}\\n`);\n return EXIT.refused;\n }\n throw error;\n }\n}\n"]}
|