@gajae-code/coding-agent 0.22.1 → 0.22.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 +60 -0
- package/dist/types/cli/doctor/probe-types.d.ts +1 -1
- package/dist/types/cli/doctor/session-owners-probe.d.ts +7 -0
- package/dist/types/cli/doctor/session-owners.d.ts +16 -0
- package/dist/types/cli/github-release.d.ts +16 -0
- package/dist/types/cli/session-owners-cli.d.ts +13 -0
- package/dist/types/cli/update-cli.d.ts +2 -0
- package/dist/types/commands/sdk.d.ts +23 -14
- package/dist/types/config/settings-schema.d.ts +6 -0
- package/dist/types/exec/bash-shell-guardian.d.ts +61 -0
- package/dist/types/export/html/html-export-destination.d.ts +16 -0
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +1 -1
- package/dist/types/sdk/host/control/runtime-gate.d.ts +7 -0
- package/dist/types/session/internal/graph-successor-proof.d.ts +33 -0
- package/dist/types/session/internal/managed-session-storage.d.ts +6 -1
- package/dist/types/session/internal/session-claim-set.d.ts +69 -0
- package/dist/types/session/operator-error-message.d.ts +29 -0
- package/dist/types/session/session-manager.d.ts +57 -3
- package/dist/types/session/session-owners-layout.d.ts +24 -0
- package/dist/types/session/session-ownership-mode.d.ts +45 -0
- package/dist/types/session/session-ownership.d.ts +195 -0
- package/dist/types/session/session-storage.d.ts +36 -0
- package/dist/types/slash-commands/helpers/parse.d.ts +1 -0
- package/package.json +12 -8
- package/scripts/verify-gjc-sdk-canonicalization.ts +2 -0
- package/src/cli/doctor/probe-types.ts +1 -1
- package/src/cli/doctor/probe.ts +9 -5
- package/src/cli/doctor/runner.ts +6 -1
- package/src/cli/doctor/session-owners-probe.ts +69 -0
- package/src/cli/doctor/session-owners.ts +106 -0
- package/src/cli/github-release.ts +100 -0
- package/src/cli/session-owners-cli.ts +118 -0
- package/src/cli/stats-cli.ts +19 -1
- package/src/cli/update-cli.ts +50 -3
- package/src/cli-ordinary.ts +1 -1
- package/src/commands/sdk.ts +36 -33
- package/src/commands/session.ts +10 -2
- package/src/config/settings-schema.ts +18 -0
- package/src/config/settings.ts +127 -13
- package/src/exec/bash-shell-guardian.ts +181 -12
- package/src/exec/isolated-shell.ts +13 -3
- package/src/export/html/html-export-destination.ts +47 -2
- package/src/export/html/index.ts +161 -13
- package/src/internal-urls/docs-index.generated.ts +4 -4
- package/src/main.ts +20 -14
- package/src/modes/acp/acp-agent.ts +6 -0
- package/src/modes/action-registry.ts +4 -1
- package/src/modes/controllers/command-controller.ts +12 -5
- package/src/modes/controllers/extension-ui-controller.ts +6 -22
- package/src/modes/controllers/input-controller.ts +3 -2
- package/src/modes/controllers/selector-controller.ts +14 -1
- package/src/modes/interactive-mode.ts +6 -3
- package/src/modes/print-mode.ts +2 -1
- package/src/modes/runtime-init.ts +2 -17
- package/src/modes/utils/ui-helpers.ts +5 -3
- package/src/sdk/bus/index.ts +22 -0
- package/src/sdk/bus/telegram-daemon-contract.ts +1 -1
- package/src/sdk/host/control/dispatch.ts +5 -1
- package/src/sdk/host/control/runtime-gate.ts +22 -0
- package/src/sdk/host/host.ts +4 -1
- package/src/sdk/session-readonly/metadata.ts +24 -18
- package/src/sdk/session.ts +2 -0
- package/src/session/agent-session.ts +101 -22
- package/src/session/internal/graph-successor-proof.ts +108 -0
- package/src/session/internal/managed-session-storage.ts +8 -1
- package/src/session/internal/session-claim-set.ts +242 -0
- package/src/session/operator-error-message.ts +79 -0
- package/src/session/session-manager.ts +524 -108
- package/src/session/session-owners-layout.ts +52 -0
- package/src/session/session-ownership-mode.ts +176 -0
- package/src/session/session-ownership.ts +851 -0
- package/src/session/session-storage.ts +60 -16
- package/src/setup/credential-import.ts +2 -1
- package/src/slash-commands/builtin-registry.ts +2 -0
- package/src/slash-commands/helpers/parse.ts +3 -1
package/src/export/html/index.ts
CHANGED
|
@@ -2,16 +2,32 @@ import * as syncFs from "node:fs";
|
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import type { AgentState } from "@gajae-code/agent-core";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
APP_NAME,
|
|
7
|
+
isCredentialKey,
|
|
8
|
+
isEnoent,
|
|
9
|
+
isFsError,
|
|
10
|
+
logger,
|
|
11
|
+
postmortem,
|
|
12
|
+
redactCrashSecrets,
|
|
13
|
+
} from "@gajae-code/utils";
|
|
6
14
|
import { getResolvedThemeColors, getThemeExportColors } from "../../modes/theme/theme";
|
|
7
15
|
import {
|
|
16
|
+
BOUNDED_RESUME_TRANSCRIPT_MAX_BYTES,
|
|
8
17
|
RESUME_TRANSCRIPT_MAX_BYTES,
|
|
9
18
|
SessionManager,
|
|
19
|
+
SessionSnapshotSourceChangedError,
|
|
20
|
+
SessionTranscriptBoundedOpenError,
|
|
10
21
|
SessionTranscriptOversizedError,
|
|
11
22
|
} from "../../session/session-manager";
|
|
12
23
|
// Pre-generated template (created by scripts/generate-template.ts at publish time)
|
|
13
24
|
import { cssColorOrFallback } from "./css-color";
|
|
14
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
createHtmlExportTempFile,
|
|
27
|
+
openExistingHtmlExportOutput,
|
|
28
|
+
openHtmlExportDestination,
|
|
29
|
+
removeHtmlExportTempFile,
|
|
30
|
+
} from "./html-export-destination";
|
|
15
31
|
import { TEMPLATE } from "./template.generated";
|
|
16
32
|
|
|
17
33
|
export interface ExportOptions {
|
|
@@ -209,6 +225,57 @@ async function openHtmlExportDescriptors(
|
|
|
209
225
|
}
|
|
210
226
|
}
|
|
211
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Like {@link openHtmlExportDescriptors}, but opens a sibling temp file to write instead of the
|
|
230
|
+
* output, which is only opened (never written) to compare its identity with the source.
|
|
231
|
+
*/
|
|
232
|
+
async function openAtomicHtmlExportDescriptors(
|
|
233
|
+
sourcePath: string | undefined,
|
|
234
|
+
outputPath: string,
|
|
235
|
+
): Promise<{ source: number | undefined; temp: { path: string; fd: number } }> {
|
|
236
|
+
let source: number | undefined;
|
|
237
|
+
let existing: number | undefined;
|
|
238
|
+
let temp: { path: string; fd: number } | undefined;
|
|
239
|
+
try {
|
|
240
|
+
if (sourcePath) {
|
|
241
|
+
try {
|
|
242
|
+
source = syncFs.openSync(sourcePath, HTML_EXPORT_SOURCE_OPEN_FLAGS);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (!isEnoent(error)) throw error;
|
|
245
|
+
}
|
|
246
|
+
await assertExportDoesNotAliasSource(sourcePath, outputPath);
|
|
247
|
+
}
|
|
248
|
+
existing = openExistingHtmlExportOutput(outputPath);
|
|
249
|
+
if (source !== undefined && existing !== undefined) {
|
|
250
|
+
const sourceIdentity = syncFs.fstatSync(source, { bigint: true });
|
|
251
|
+
const existingIdentity = syncFs.fstatSync(existing, { bigint: true });
|
|
252
|
+
if (sameFileIdentity(sourceIdentity, existingIdentity))
|
|
253
|
+
throw new Error("HTML export output must not overwrite the source transcript");
|
|
254
|
+
}
|
|
255
|
+
temp = createHtmlExportTempFile(outputPath);
|
|
256
|
+
return { source, temp };
|
|
257
|
+
} catch (error) {
|
|
258
|
+
if (temp !== undefined) {
|
|
259
|
+
syncFs.closeSync(temp.fd);
|
|
260
|
+
removeHtmlExportTempFile(temp.path);
|
|
261
|
+
}
|
|
262
|
+
if (source !== undefined) syncFs.closeSync(source);
|
|
263
|
+
throw error;
|
|
264
|
+
} finally {
|
|
265
|
+
if (existing !== undefined) syncFs.closeSync(existing);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** A regular file, or nothing yet: a temp file renamed over it replaces it without side effects. */
|
|
270
|
+
function isRegularOrMissingOutput(outputPath: string): boolean {
|
|
271
|
+
try {
|
|
272
|
+
return syncFs.lstatSync(outputPath).isFile();
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (isEnoent(error)) return true;
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
212
279
|
async function writeSessionHtml(
|
|
213
280
|
sm: SessionManager,
|
|
214
281
|
state: AgentState | undefined,
|
|
@@ -221,14 +288,12 @@ async function writeSessionHtml(
|
|
|
221
288
|
const markerOffset = themedTemplate.indexOf(marker);
|
|
222
289
|
if (markerOffset < 0) throw new Error("HTML export template is missing the session-data marker");
|
|
223
290
|
const sourcePath = sm.getSessionFile();
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
};
|
|
231
|
-
try {
|
|
291
|
+
const writePayload = (sink: Bun.FileSink): void => {
|
|
292
|
+
const encoder = new Base64StreamEncoder();
|
|
293
|
+
const writeEncoded = (value: string): void => {
|
|
294
|
+
const encoded = encoder.write(value);
|
|
295
|
+
if (encoded) sink.write(encoded);
|
|
296
|
+
};
|
|
232
297
|
sink.write(themedTemplate.slice(0, markerOffset));
|
|
233
298
|
writeEncoded(`{"header":${sessionEmbedJson(sm.getHeader())},"entries":[`);
|
|
234
299
|
let first = true;
|
|
@@ -247,6 +312,18 @@ async function writeSessionHtml(
|
|
|
247
312
|
const final = encoder.finish();
|
|
248
313
|
if (final) sink.write(final);
|
|
249
314
|
sink.write(themedTemplate.slice(markerOffset + marker.length));
|
|
315
|
+
};
|
|
316
|
+
// A bounded snapshot streams its transcript while writing and can fail midway, so it writes a
|
|
317
|
+
// temp file and renames it over a regular (or missing) output, keeping any previous export.
|
|
318
|
+
// Every other export writes the output in place, as before.
|
|
319
|
+
if (sm.isBoundedReadOnlySnapshot() && isRegularOrMissingOutput(outputPath)) {
|
|
320
|
+
await writeSessionHtmlAtomically(sourcePath, outputPath, writePayload);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const descriptors = await openHtmlExportDescriptors(sourcePath, outputPath);
|
|
324
|
+
const sink = Bun.file(descriptors.destination).writer();
|
|
325
|
+
try {
|
|
326
|
+
writePayload(sink);
|
|
250
327
|
await sink.end();
|
|
251
328
|
} catch (error) {
|
|
252
329
|
await sink.end();
|
|
@@ -257,6 +334,52 @@ async function writeSessionHtml(
|
|
|
257
334
|
}
|
|
258
335
|
}
|
|
259
336
|
|
|
337
|
+
async function writeSessionHtmlAtomically(
|
|
338
|
+
sourcePath: string | undefined,
|
|
339
|
+
outputPath: string,
|
|
340
|
+
writePayload: (sink: Bun.FileSink) => void,
|
|
341
|
+
): Promise<void> {
|
|
342
|
+
const descriptors = await openAtomicHtmlExportDescriptors(sourcePath, outputPath);
|
|
343
|
+
const tempPath = descriptors.temp.path;
|
|
344
|
+
const unregisterTempCleanup = postmortem.register("html-export-temp", () => {
|
|
345
|
+
try {
|
|
346
|
+
removeHtmlExportTempFile(tempPath);
|
|
347
|
+
} catch (error) {
|
|
348
|
+
// Shutdown cleanup must not throw; the leftover is an owner-only dot file beside the output.
|
|
349
|
+
logger.warn("Failed to remove an unfinished HTML export temp file", {
|
|
350
|
+
code: isFsError(error) ? error.code : "unknown",
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
let tempOpen = true;
|
|
355
|
+
let published = false;
|
|
356
|
+
const sink = Bun.file(descriptors.temp.fd).writer();
|
|
357
|
+
let sinkEnded = false;
|
|
358
|
+
try {
|
|
359
|
+
writePayload(sink);
|
|
360
|
+
sinkEnded = true;
|
|
361
|
+
await sink.end();
|
|
362
|
+
tempOpen = false;
|
|
363
|
+
syncFs.closeSync(descriptors.temp.fd);
|
|
364
|
+
syncFs.renameSync(tempPath, outputPath);
|
|
365
|
+
published = true;
|
|
366
|
+
} catch (error) {
|
|
367
|
+
if (!sinkEnded) await sink.end();
|
|
368
|
+
throw error;
|
|
369
|
+
} finally {
|
|
370
|
+
if (descriptors.source !== undefined) syncFs.closeSync(descriptors.source);
|
|
371
|
+
if (tempOpen) syncFs.closeSync(descriptors.temp.fd);
|
|
372
|
+
if (!published) {
|
|
373
|
+
try {
|
|
374
|
+
removeHtmlExportTempFile(tempPath);
|
|
375
|
+
} catch {
|
|
376
|
+
// Never mask the export failure; the temp file is an owner-only dot file beside the output.
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
unregisterTempCleanup();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
260
383
|
/**
|
|
261
384
|
* Own `__proto__` stays a data property; a normal object would turn that assignment into the prototype.
|
|
262
385
|
* Credential keys mask every JSON value, and string values are scrubbed directly so JSON escaping
|
|
@@ -362,22 +485,47 @@ export async function exportFromFile(inputPath: string, options?: ExportOptions
|
|
|
362
485
|
await assertExportDoesNotAliasSource(inputPath, outputPath);
|
|
363
486
|
|
|
364
487
|
// Another process may be writing this session: export reads a detached snapshot and
|
|
365
|
-
// never writes to the transcript or its artifact directory.
|
|
488
|
+
// never writes to the transcript or its artifact directory. Transcripts above the
|
|
489
|
+
// eager-load cap stream from sidecars kept in a private cache that close() removes.
|
|
366
490
|
let sm: SessionManager;
|
|
367
491
|
try {
|
|
368
492
|
sm = await SessionManager.openReadOnlySnapshot(inputPath);
|
|
369
493
|
} catch (err) {
|
|
370
494
|
if (isEnoent(err)) throw new Error(`File not found: ${inputPath}`);
|
|
371
|
-
if (err instanceof SessionTranscriptOversizedError)
|
|
495
|
+
if (err instanceof SessionTranscriptOversizedError) {
|
|
496
|
+
// Windows lacks the owner-only private sidecar cache, so the eager cap is its limit.
|
|
497
|
+
const limit = process.platform === "win32" ? RESUME_TRANSCRIPT_MAX_BYTES : BOUNDED_RESUME_TRANSCRIPT_MAX_BYTES;
|
|
372
498
|
throw new Error(
|
|
373
|
-
`Session transcript is too large to export (${err.size} bytes; limit ${
|
|
499
|
+
`Session transcript is too large to export (${err.size} bytes; limit ${limit} bytes): ${inputPath}`,
|
|
374
500
|
);
|
|
501
|
+
}
|
|
502
|
+
if (err instanceof SessionTranscriptBoundedOpenError) {
|
|
503
|
+
// A concurrent writer, not the transcript's shape. An unterminated last line may also be
|
|
504
|
+
// a write a crash cut off, which no retry repairs, so the message names both causes.
|
|
505
|
+
if (err.reason === "bounded_first_open_descriptor_changed")
|
|
506
|
+
throw new Error(
|
|
507
|
+
`Session transcript changed while it was being read (${err.reason}); retry when the session is idle: ${inputPath}`,
|
|
508
|
+
);
|
|
509
|
+
if (err.reason === "bounded_scan_unterminated")
|
|
510
|
+
throw new Error(
|
|
511
|
+
`Session transcript's last line is incomplete (${err.reason}): it is still being written, so retry when the session is idle, or an earlier write was interrupted, which retrying does not fix: ${inputPath}`,
|
|
512
|
+
);
|
|
513
|
+
throw new Error(
|
|
514
|
+
`Session transcript is too large to export in full (${err.size} bytes; limit ${RESUME_TRANSCRIPT_MAX_BYTES} bytes) and cannot be streamed (${err.reason}); only linear, compacted transcripts without patch records can be: ${inputPath}`,
|
|
515
|
+
);
|
|
516
|
+
}
|
|
375
517
|
throw err;
|
|
376
518
|
}
|
|
377
519
|
|
|
378
520
|
try {
|
|
379
521
|
await writeSessionHtml(sm, undefined, outputPath, opts.themeName);
|
|
380
522
|
return outputPath;
|
|
523
|
+
} catch (err) {
|
|
524
|
+
if (err instanceof SessionSnapshotSourceChangedError)
|
|
525
|
+
throw new Error(
|
|
526
|
+
`Session transcript was replaced or truncated while it was being exported; retry when the session is idle: ${inputPath}`,
|
|
527
|
+
);
|
|
528
|
+
throw err;
|
|
381
529
|
} finally {
|
|
382
530
|
await sm.close();
|
|
383
531
|
}
|