@code-yeongyu/senpi 2026.6.10-2 → 2026.6.12-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/cli/startup-ui.d.ts +10 -0
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +72 -1
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +31 -7
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +20 -5
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/settings-manager.d.ts +6 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +17 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +3 -5
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +38 -34
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/tail-window.d.ts +15 -0
- package/dist/core/tools/tail-window.d.ts.map +1 -0
- package/dist/core/tools/tail-window.js +75 -0
- package/dist/core/tools/tail-window.js.map +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +8 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +25 -0
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -0
- package/dist/modes/interactive/components/first-time-setup.js +101 -0
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +6 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +45 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +12 -5
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/settings.md +2 -0
- package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +92 -227
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +140 -247
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js +12 -5
- package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js +11 -2
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts +4 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js +54 -8
- package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +2 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +80 -7
- package/node_modules/@earendil-works/pi-tui/dist/components/editor.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +72 -1
- package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -2,6 +2,7 @@ import { randomBytes } from "node:crypto";
|
|
|
2
2
|
import { createWriteStream } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { TailWindow } from "./tail-window.js";
|
|
5
6
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, truncateTail } from "./truncate.js";
|
|
6
7
|
function defaultTempFilePath(prefix) {
|
|
7
8
|
const id = randomBytes(8).toString("hex");
|
|
@@ -21,9 +22,6 @@ export class OutputAccumulator {
|
|
|
21
22
|
constructor(options = {}) {
|
|
22
23
|
this.decoder = new TextDecoder();
|
|
23
24
|
this.rawChunks = [];
|
|
24
|
-
this.tailText = "";
|
|
25
|
-
this.tailBytes = 0;
|
|
26
|
-
this.tailStartsAtLineBoundary = true;
|
|
27
25
|
this.totalRawBytes = 0;
|
|
28
26
|
this.totalDecodedBytes = 0;
|
|
29
27
|
this.completedLines = 0;
|
|
@@ -33,15 +31,16 @@ export class OutputAccumulator {
|
|
|
33
31
|
this.finished = false;
|
|
34
32
|
this.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
35
33
|
this.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
36
|
-
this.maxRollingBytes = Math.max(this.maxBytes * 2, 1);
|
|
37
34
|
this.tempFilePrefix = options.tempFilePrefix ?? "pi-output";
|
|
35
|
+
this.tail = new TailWindow(Math.max(this.maxBytes * 2, 1));
|
|
38
36
|
}
|
|
39
37
|
append(data) {
|
|
40
38
|
if (this.finished) {
|
|
41
39
|
throw new Error("Cannot append to a finished output accumulator");
|
|
42
40
|
}
|
|
41
|
+
const text = this.decoder.decode(data, { stream: true });
|
|
43
42
|
this.totalRawBytes += data.length;
|
|
44
|
-
this.appendDecodedText(
|
|
43
|
+
this.appendDecodedText(text, byteLength(text));
|
|
45
44
|
if (this.tempFileStream || this.shouldUseTempFile()) {
|
|
46
45
|
this.ensureTempFile();
|
|
47
46
|
this.tempFileStream?.write(data);
|
|
@@ -50,12 +49,31 @@ export class OutputAccumulator {
|
|
|
50
49
|
this.rawChunks.push(data);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
52
|
+
appendText(text) {
|
|
53
|
+
if (this.finished) {
|
|
54
|
+
throw new Error("Cannot append to a finished output accumulator");
|
|
55
|
+
}
|
|
56
|
+
if (text.length === 0) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const bytes = byteLength(text);
|
|
60
|
+
this.totalRawBytes += bytes;
|
|
61
|
+
this.appendDecodedText(text, bytes);
|
|
62
|
+
if (this.tempFileStream || this.shouldUseTempFile()) {
|
|
63
|
+
this.ensureTempFile();
|
|
64
|
+
this.tempFileStream?.write(text);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.rawChunks.push(text);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
53
70
|
finish() {
|
|
54
71
|
if (this.finished) {
|
|
55
72
|
return;
|
|
56
73
|
}
|
|
57
74
|
this.finished = true;
|
|
58
|
-
this.
|
|
75
|
+
const finalText = this.decoder.decode();
|
|
76
|
+
this.appendDecodedText(finalText, byteLength(finalText));
|
|
59
77
|
if (this.shouldUseTempFile()) {
|
|
60
78
|
this.ensureTempFile();
|
|
61
79
|
}
|
|
@@ -88,11 +106,10 @@ export class OutputAccumulator {
|
|
|
88
106
|
};
|
|
89
107
|
}
|
|
90
108
|
async closeTempFile() {
|
|
91
|
-
|
|
109
|
+
const stream = this.takeTempFileStream();
|
|
110
|
+
if (!stream) {
|
|
92
111
|
return;
|
|
93
112
|
}
|
|
94
|
-
const stream = this.tempFileStream;
|
|
95
|
-
this.tempFileStream = undefined;
|
|
96
113
|
await new Promise((resolve, reject) => {
|
|
97
114
|
const onError = (error) => {
|
|
98
115
|
stream.off("finish", onFinish);
|
|
@@ -110,17 +127,12 @@ export class OutputAccumulator {
|
|
|
110
127
|
getLastLineBytes() {
|
|
111
128
|
return this.currentLineBytes;
|
|
112
129
|
}
|
|
113
|
-
appendDecodedText(text) {
|
|
130
|
+
appendDecodedText(text, bytes) {
|
|
114
131
|
if (text.length === 0) {
|
|
115
132
|
return;
|
|
116
133
|
}
|
|
117
|
-
const bytes = byteLength(text);
|
|
118
134
|
this.totalDecodedBytes += bytes;
|
|
119
|
-
this.
|
|
120
|
-
this.tailBytes += bytes;
|
|
121
|
-
if (this.tailBytes > this.maxRollingBytes * 2) {
|
|
122
|
-
this.trimTail();
|
|
123
|
-
}
|
|
135
|
+
this.tail.append(text, bytes, !this.hasOpenLine);
|
|
124
136
|
let newlines = 0;
|
|
125
137
|
let lastNewline = -1;
|
|
126
138
|
for (let i = text.indexOf("\n"); i !== -1; i = text.indexOf("\n", i + 1)) {
|
|
@@ -139,26 +151,13 @@ export class OutputAccumulator {
|
|
|
139
151
|
}
|
|
140
152
|
this.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);
|
|
141
153
|
}
|
|
142
|
-
trimTail() {
|
|
143
|
-
const buffer = Buffer.from(this.tailText, "utf-8");
|
|
144
|
-
if (buffer.length <= this.maxRollingBytes) {
|
|
145
|
-
this.tailBytes = buffer.length;
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
let start = buffer.length - this.maxRollingBytes;
|
|
149
|
-
while (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {
|
|
150
|
-
start++;
|
|
151
|
-
}
|
|
152
|
-
this.tailStartsAtLineBoundary = start === 0 ? this.tailStartsAtLineBoundary : buffer[start - 1] === 0x0a;
|
|
153
|
-
this.tailText = buffer.subarray(start).toString("utf-8");
|
|
154
|
-
this.tailBytes = byteLength(this.tailText);
|
|
155
|
-
}
|
|
156
154
|
getSnapshotText() {
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
const text = this.tail.text();
|
|
156
|
+
if (this.tail.startsAtLineBoundary) {
|
|
157
|
+
return text;
|
|
159
158
|
}
|
|
160
|
-
const firstNewline =
|
|
161
|
-
return firstNewline === -1 ?
|
|
159
|
+
const firstNewline = text.indexOf("\n");
|
|
160
|
+
return firstNewline === -1 ? text : text.slice(firstNewline + 1);
|
|
162
161
|
}
|
|
163
162
|
shouldUseTempFile() {
|
|
164
163
|
return (this.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines);
|
|
@@ -174,5 +173,10 @@ export class OutputAccumulator {
|
|
|
174
173
|
}
|
|
175
174
|
this.rawChunks = [];
|
|
176
175
|
}
|
|
176
|
+
takeTempFileStream() {
|
|
177
|
+
const stream = this.tempFileStream;
|
|
178
|
+
this.tempFileStream = undefined;
|
|
179
|
+
return stream;
|
|
180
|
+
}
|
|
177
181
|
}
|
|
178
182
|
//# sourceMappingURL=output-accumulator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EA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AAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAEO,eAAe;QACtB,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,QAAQ,CAAC;QACtB,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjD,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACpF,CAAC;IAEO,iBAAiB;QACxB,OAAO,CACN,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAC/G,CAAC;IACH,CAAC;IAEO,cAAc;QACrB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,OAAO;QACR,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,mBAAmB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACrB,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nfunction defaultTempFilePath(prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `${prefix}-${id}.log`);\n}\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded\n * tail for display snapshots, and opens a temp file when the full output needs\n * to be preserved.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly maxRollingBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly decoder = new TextDecoder();\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate tailText = \"\";\n\tprivate tailBytes = 0;\n\tprivate tailStartsAtLineBoundary = true;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate currentLineBytes = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileStream: WriteStream | undefined;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.maxRollingBytes = Math.max(this.maxBytes * 2, 1);\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(data);\n\t\t} else if (data.length > 0) {\n\t\t\tthis.rawChunks.push(data);\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tconst tailTruncation = truncateTail(this.getSnapshotText(), {\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t});\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tconst truncatedBy = truncated\n\t\t\t? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\"))\n\t\t\t: null;\n\t\tconst truncation: TruncationResult = {\n\t\t\t...tailTruncation,\n\t\t\ttruncated,\n\t\t\ttruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t};\n\n\t\tif (options.persistIfTruncated && truncation.truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.tempFilePath,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tif (!this.tempFileStream) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst stream = this.tempFileStream;\n\t\tthis.tempFileStream = undefined;\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst onError = (error: Error) => {\n\t\t\t\tstream.off(\"finish\", onFinish);\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tconst onFinish = () => {\n\t\t\t\tstream.off(\"error\", onError);\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tstream.once(\"error\", onError);\n\t\t\tstream.once(\"finish\", onFinish);\n\t\t\tstream.end();\n\t\t});\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.currentLineBytes;\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bytes = byteLength(text);\n\t\tthis.totalDecodedBytes += bytes;\n\t\tthis.tailText += text;\n\t\tthis.tailBytes += bytes;\n\t\tif (this.tailBytes > this.maxRollingBytes * 2) {\n\t\t\tthis.trimTail();\n\t\t}\n\n\t\tlet newlines = 0;\n\t\tlet lastNewline = -1;\n\t\tfor (let i = text.indexOf(\"\\n\"); i !== -1; i = text.indexOf(\"\\n\", i + 1)) {\n\t\t\tnewlines++;\n\t\t\tlastNewline = i;\n\t\t}\n\t\tif (newlines === 0) {\n\t\t\tthis.currentLineBytes += bytes;\n\t\t\tthis.hasOpenLine = true;\n\t\t} else {\n\t\t\tthis.completedLines += newlines;\n\t\t\tconst tail = text.slice(lastNewline + 1);\n\t\t\tthis.currentLineBytes = byteLength(tail);\n\t\t\tthis.hasOpenLine = tail.length > 0;\n\t\t}\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate trimTail(): void {\n\t\tconst buffer = Buffer.from(this.tailText, \"utf-8\");\n\t\tif (buffer.length <= this.maxRollingBytes) {\n\t\t\tthis.tailBytes = buffer.length;\n\t\t\treturn;\n\t\t}\n\n\t\tlet start = buffer.length - this.maxRollingBytes;\n\t\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\t\tstart++;\n\t\t}\n\n\t\tthis.tailStartsAtLineBoundary = start === 0 ? this.tailStartsAtLineBoundary : buffer[start - 1] === 0x0a;\n\t\tthis.tailText = buffer.subarray(start).toString(\"utf-8\");\n\t\tthis.tailBytes = byteLength(this.tailText);\n\t}\n\n\tprivate getSnapshotText(): string {\n\t\tif (this.tailStartsAtLineBoundary) {\n\t\t\treturn this.tailText;\n\t\t}\n\n\t\tconst firstNewline = this.tailText.indexOf(\"\\n\");\n\t\treturn firstNewline === -1 ? this.tailText : this.tailText.slice(firstNewline + 1);\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate ensureTempFile(): void {\n\t\tif (this.tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFilePath = defaultTempFilePath(this.tempFilePrefix);\n\t\tthis.tempFileStream = createWriteStream(this.tempFilePath);\n\t\tfor (const chunk of this.rawChunks) {\n\t\t\tthis.tempFileStream.write(chunk);\n\t\t}\n\t\tthis.rawChunks = [];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAC;AAc1G,SAAS,mBAAmB,CAAC,MAAc;IAC1C,MAAM,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,MAA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,EAAE,CAAC;YACvB,OAAO;QACR,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,mBAAmB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACrB,CAAC;IAEO,kBAAkB;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;QACnC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,OAAO,MAAM,CAAC;IACf,CAAC;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { TailWindow } from \"./tail-window.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nfunction defaultTempFilePath(prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `${prefix}-${id}.log`);\n}\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded\n * tail for display snapshots, and opens a temp file when the full output needs\n * to be preserved.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly decoder = new TextDecoder();\n\tprivate readonly tail: TailWindow;\n\n\tprivate rawChunks: Array<Buffer | string> = [];\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate currentLineBytes = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileStream: WriteStream | undefined;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tail = new TailWindow(Math.max(this.maxBytes * 2, 1));\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tconst text = this.decoder.decode(data, { stream: true });\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(text, byteLength(text));\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(data);\n\t\t} else if (data.length > 0) {\n\t\t\tthis.rawChunks.push(data);\n\t\t}\n\t}\n\n\tappendText(text: string): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bytes = byteLength(text);\n\t\tthis.totalRawBytes += bytes;\n\t\tthis.appendDecodedText(text, bytes);\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(text);\n\t\t} else {\n\t\t\tthis.rawChunks.push(text);\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tconst finalText = this.decoder.decode();\n\t\tthis.appendDecodedText(finalText, byteLength(finalText));\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tconst tailTruncation = truncateTail(this.getSnapshotText(), {\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t});\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tconst truncatedBy = truncated\n\t\t\t? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\"))\n\t\t\t: null;\n\t\tconst truncation: TruncationResult = {\n\t\t\t...tailTruncation,\n\t\t\ttruncated,\n\t\t\ttruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t};\n\n\t\tif (options.persistIfTruncated && truncation.truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.tempFilePath,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst stream = this.takeTempFileStream();\n\t\tif (!stream) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst onError = (error: Error) => {\n\t\t\t\tstream.off(\"finish\", onFinish);\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tconst onFinish = () => {\n\t\t\t\tstream.off(\"error\", onError);\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tstream.once(\"error\", onError);\n\t\t\tstream.once(\"finish\", onFinish);\n\t\t\tstream.end();\n\t\t});\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.currentLineBytes;\n\t}\n\n\tprivate appendDecodedText(text: string, bytes: number): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += bytes;\n\t\tthis.tail.append(text, bytes, !this.hasOpenLine);\n\n\t\tlet newlines = 0;\n\t\tlet lastNewline = -1;\n\t\tfor (let i = text.indexOf(\"\\n\"); i !== -1; i = text.indexOf(\"\\n\", i + 1)) {\n\t\t\tnewlines++;\n\t\t\tlastNewline = i;\n\t\t}\n\t\tif (newlines === 0) {\n\t\t\tthis.currentLineBytes += bytes;\n\t\t\tthis.hasOpenLine = true;\n\t\t} else {\n\t\t\tthis.completedLines += newlines;\n\t\t\tconst tail = text.slice(lastNewline + 1);\n\t\t\tthis.currentLineBytes = byteLength(tail);\n\t\t\tthis.hasOpenLine = tail.length > 0;\n\t\t}\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate getSnapshotText(): string {\n\t\tconst text = this.tail.text();\n\t\tif (this.tail.startsAtLineBoundary) {\n\t\t\treturn text;\n\t\t}\n\n\t\tconst firstNewline = text.indexOf(\"\\n\");\n\t\treturn firstNewline === -1 ? text : text.slice(firstNewline + 1);\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate ensureTempFile(): void {\n\t\tif (this.tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFilePath = defaultTempFilePath(this.tempFilePrefix);\n\t\tthis.tempFileStream = createWriteStream(this.tempFilePath);\n\t\tfor (const chunk of this.rawChunks) {\n\t\t\tthis.tempFileStream.write(chunk);\n\t\t}\n\t\tthis.rawChunks = [];\n\t}\n\n\tprivate takeTempFileStream(): WriteStream | undefined {\n\t\tconst stream = this.tempFileStream;\n\t\tthis.tempFileStream = undefined;\n\t\treturn stream;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class TailWindow {
|
|
2
|
+
private readonly maxBytes;
|
|
3
|
+
private chunks;
|
|
4
|
+
private bytes;
|
|
5
|
+
private startsAtBoundary;
|
|
6
|
+
constructor(maxBytes: number);
|
|
7
|
+
append(text: string, bytes: number, startsAtLineBoundary: boolean): void;
|
|
8
|
+
text(): string;
|
|
9
|
+
get startsAtLineBoundary(): boolean;
|
|
10
|
+
private replaceWithTail;
|
|
11
|
+
private joined;
|
|
12
|
+
private compact;
|
|
13
|
+
private trimToMax;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=tail-window.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tail-window.d.ts","sourceRoot":"","sources":["../../../src/core/tools/tail-window.ts"],"names":[],"mappings":"AAMA,qBAAa,UAAU;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,gBAAgB,CAAQ;IAEhC,YAAY,QAAQ,EAAE,MAAM,EAE3B;IAED,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,GAAG,IAAI,CAiBvE;IAED,IAAI,IAAI,MAAM,CAGb;IAED,IAAI,oBAAoB,IAAI,OAAO,CAElC;IAED,OAAO,CAAC,eAAe;IAavB,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,SAAS;CAgBjB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const MAX_PENDING_TAIL_CHUNKS = 10;
|
|
2
|
+
function byteLength(text) {
|
|
3
|
+
return Buffer.byteLength(text, "utf-8");
|
|
4
|
+
}
|
|
5
|
+
export class TailWindow {
|
|
6
|
+
constructor(maxBytes) {
|
|
7
|
+
this.chunks = [];
|
|
8
|
+
this.bytes = 0;
|
|
9
|
+
this.startsAtBoundary = true;
|
|
10
|
+
this.maxBytes = maxBytes;
|
|
11
|
+
}
|
|
12
|
+
append(text, bytes, startsAtLineBoundary) {
|
|
13
|
+
if (bytes === 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (bytes >= this.maxBytes) {
|
|
17
|
+
this.replaceWithTail(text, startsAtLineBoundary);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.chunks.push(text);
|
|
21
|
+
this.bytes += bytes;
|
|
22
|
+
if (this.chunks.length > MAX_PENDING_TAIL_CHUNKS) {
|
|
23
|
+
this.compact();
|
|
24
|
+
}
|
|
25
|
+
if (this.bytes > this.maxBytes * 2) {
|
|
26
|
+
this.trimToMax();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
text() {
|
|
30
|
+
this.trimToMax();
|
|
31
|
+
return this.joined();
|
|
32
|
+
}
|
|
33
|
+
get startsAtLineBoundary() {
|
|
34
|
+
return this.startsAtBoundary;
|
|
35
|
+
}
|
|
36
|
+
replaceWithTail(text, startsAtLineBoundary) {
|
|
37
|
+
const buffer = Buffer.from(text, "utf-8");
|
|
38
|
+
let start = Math.max(0, buffer.length - this.maxBytes);
|
|
39
|
+
while (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {
|
|
40
|
+
start++;
|
|
41
|
+
}
|
|
42
|
+
this.startsAtBoundary = start === 0 ? startsAtLineBoundary : buffer[start - 1] === 0x0a;
|
|
43
|
+
const tail = buffer.subarray(start).toString("utf-8");
|
|
44
|
+
this.chunks = tail.length > 0 ? [tail] : [];
|
|
45
|
+
this.bytes = byteLength(tail);
|
|
46
|
+
}
|
|
47
|
+
joined() {
|
|
48
|
+
if (this.chunks.length === 0) {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
if (this.chunks.length > 1) {
|
|
52
|
+
this.compact();
|
|
53
|
+
}
|
|
54
|
+
return this.chunks[0] ?? "";
|
|
55
|
+
}
|
|
56
|
+
compact() {
|
|
57
|
+
const joined = this.chunks.join("");
|
|
58
|
+
this.chunks = joined.length > 0 ? [joined] : [];
|
|
59
|
+
}
|
|
60
|
+
trimToMax() {
|
|
61
|
+
if (this.bytes <= this.maxBytes) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const buffer = Buffer.from(this.joined(), "utf-8");
|
|
65
|
+
let start = Math.max(0, buffer.length - this.maxBytes);
|
|
66
|
+
while (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {
|
|
67
|
+
start++;
|
|
68
|
+
}
|
|
69
|
+
this.startsAtBoundary = start === 0 ? this.startsAtBoundary : buffer[start - 1] === 0x0a;
|
|
70
|
+
const tail = buffer.subarray(start).toString("utf-8");
|
|
71
|
+
this.chunks = tail.length > 0 ? [tail] : [];
|
|
72
|
+
this.bytes = byteLength(tail);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=tail-window.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tail-window.js","sourceRoot":"","sources":["../../../src/core/tools/tail-window.ts"],"names":[],"mappings":"AAAA,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,SAAS,UAAU,CAAC,IAAY;IAC/B,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,OAAO,UAAU;IAMtB,YAAY,QAAgB;QAJpB,WAAM,GAAa,EAAE,CAAC;QACtB,UAAK,GAAG,CAAC,CAAC;QACV,qBAAgB,GAAG,IAAI,CAAC;QAG/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,IAAY,EAAE,KAAa,EAAE,oBAA6B;QAChE,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACjB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5B,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gB,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC;QACzF,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACD","sourcesContent":["const MAX_PENDING_TAIL_CHUNKS = 10;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nexport class TailWindow {\n\tprivate readonly maxBytes: number;\n\tprivate chunks: string[] = [];\n\tprivate bytes = 0;\n\tprivate startsAtBoundary = true;\n\n\tconstructor(maxBytes: number) {\n\t\tthis.maxBytes = maxBytes;\n\t}\n\n\tappend(text: string, bytes: number, startsAtLineBoundary: boolean): void {\n\t\tif (bytes === 0) {\n\t\t\treturn;\n\t\t}\n\t\tif (bytes >= this.maxBytes) {\n\t\t\tthis.replaceWithTail(text, startsAtLineBoundary);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.chunks.push(text);\n\t\tthis.bytes += bytes;\n\t\tif (this.chunks.length > MAX_PENDING_TAIL_CHUNKS) {\n\t\t\tthis.compact();\n\t\t}\n\t\tif (this.bytes > this.maxBytes * 2) {\n\t\t\tthis.trimToMax();\n\t\t}\n\t}\n\n\ttext(): string {\n\t\tthis.trimToMax();\n\t\treturn this.joined();\n\t}\n\n\tget startsAtLineBoundary(): boolean {\n\t\treturn this.startsAtBoundary;\n\t}\n\n\tprivate replaceWithTail(text: string, startsAtLineBoundary: boolean): void {\n\t\tconst buffer = Buffer.from(text, \"utf-8\");\n\t\tlet start = Math.max(0, buffer.length - this.maxBytes);\n\t\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\t\tstart++;\n\t\t}\n\n\t\tthis.startsAtBoundary = start === 0 ? startsAtLineBoundary : buffer[start - 1] === 0x0a;\n\t\tconst tail = buffer.subarray(start).toString(\"utf-8\");\n\t\tthis.chunks = tail.length > 0 ? [tail] : [];\n\t\tthis.bytes = byteLength(tail);\n\t}\n\n\tprivate joined(): string {\n\t\tif (this.chunks.length === 0) {\n\t\t\treturn \"\";\n\t\t}\n\t\tif (this.chunks.length > 1) {\n\t\t\tthis.compact();\n\t\t}\n\t\treturn this.chunks[0] ?? \"\";\n\t}\n\n\tprivate compact(): void {\n\t\tconst joined = this.chunks.join(\"\");\n\t\tthis.chunks = joined.length > 0 ? [joined] : [];\n\t}\n\n\tprivate trimToMax(): void {\n\t\tif (this.bytes <= this.maxBytes) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst buffer = Buffer.from(this.joined(), \"utf-8\");\n\t\tlet start = Math.max(0, buffer.length - this.maxBytes);\n\t\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\t\tstart++;\n\t\t}\n\n\t\tthis.startsAtBoundary = start === 0 ? this.startsAtBoundary : buffer[start - 1] === 0x0a;\n\t\tconst tail = buffer.subarray(start).toString(\"utf-8\");\n\t\tthis.chunks = tail.length > 0 ? [tail] : [];\n\t\tthis.bytes = byteLength(tail);\n\t}\n}\n"]}
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsBH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsBH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AA8anE,MAAM,WAAW,WAAW;IAC3B,kBAAkB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACxC;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,iBAkY/D"}
|
package/dist/main.js
CHANGED
|
@@ -13,7 +13,7 @@ import { buildInitialMessage } from "./cli/initial-message.js";
|
|
|
13
13
|
import { listModels } from "./cli/list-models.js";
|
|
14
14
|
import { createProjectTrustContext } from "./cli/project-trust.js";
|
|
15
15
|
import { selectSession } from "./cli/session-picker.js";
|
|
16
|
-
import { showStartupSelector } from "./cli/startup-ui.js";
|
|
16
|
+
import { shouldRunFirstTimeSetup, showFirstTimeSetup, showStartupSelector } from "./cli/startup-ui.js";
|
|
17
17
|
import { ENV_SESSION_DIR, expandTildePath, getAgentDir, getPackageDir, VERSION } from "./config.js";
|
|
18
18
|
import { createAgentSessionRuntime } from "./core/agent-session-runtime.js";
|
|
19
19
|
import { createAgentSessionFromServices, createAgentSessionServices, } from "./core/agent-session-services.js";
|
|
@@ -271,6 +271,7 @@ function buildSessionOptions(parsed, scopedModels, hasExistingSession, modelRegi
|
|
|
271
271
|
const resolved = resolveCliModel({
|
|
272
272
|
cliProvider: parsed.provider,
|
|
273
273
|
cliModel: parsed.model,
|
|
274
|
+
cliThinking: parsed.thinking,
|
|
274
275
|
modelRegistry,
|
|
275
276
|
});
|
|
276
277
|
if (resolved.warning) {
|
|
@@ -445,6 +446,12 @@ export async function main(args, options) {
|
|
|
445
446
|
await listModels(services.modelRegistry, searchPattern);
|
|
446
447
|
process.exit(0);
|
|
447
448
|
}
|
|
449
|
+
// Experimental first-time setup: theme choice and analytics opt-in.
|
|
450
|
+
// Runs before any runtime services are created so the chosen settings apply everywhere.
|
|
451
|
+
if (appMode === "interactive" && !parsed.help && parsed.listModels === undefined && shouldRunFirstTimeSetup()) {
|
|
452
|
+
await showFirstTimeSetup(startupSettingsManager);
|
|
453
|
+
time("firstTimeSetup");
|
|
454
|
+
}
|
|
448
455
|
// Decide the final runtime cwd before creating cwd-bound runtime services.
|
|
449
456
|
// --session and --resume may select a session from another project, so project-local
|
|
450
457
|
// settings, resources, provider registrations, and models must be resolved only after
|