@gajae-code/coding-agent 0.22.2-nightly.20261124082924.45420261659.g79e2acc07056 → 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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,66 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.22.2] - 2026-11-25
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Each ChatGPT workspace of one OpenAI Codex login is stored as its own account, labeled `email (workspace name)`, and can be chosen with `org:<workspace id or name>` in `--credential`, `/credential`, `gjc accounts pin`, and `gjc accounts prefer openai-codex`, so the workspaces can be ordered with quota fallback (for example `gjc accounts prefer openai-codex 'org:Acme Team' org:Personal`). A row whose name lookup failed is chosen by `org:<workspace-id>`. Importing a Codex CLI `auth.json` is also scoped to its workspace.
|
|
10
|
+
|
|
11
|
+
- `gjc session owners` lists which processes hold sessions open for writing: claims held by this process or the gjc it runs under, every other held session with its surface, pid and how long it has been held, and the owners directory's sidecar count and size on disk. `--json` gives the same report as JSON. It only reads: it never takes, breaks or rewrites a lock or record, and creates nothing on a machine where no session was ever claimed. Session ownership is still off by default, so the list stays empty until it is turned on.
|
|
12
|
+
- `gjc doctor` checks session ownership: it warns when a held session's record names a process that no longer exists, and when the owners directory holds more than 10,000 sidecars.
|
|
13
|
+
|
|
14
|
+
- With session ownership turned on (`session.ownership.mode` set to `observe` or `enforce`), each gjc process adds its ownership counts to the local stats database when it exits: claims taken, released and refused, fail-open claims, locks still held at exit, writes without a claim, and the claim-set signals. `gjc stats --summary` and `gjc stats --json` show the all-time totals, the dates they span, and the same per gjc version with the number of processes that reported. `gjc stats` now also waits for a moment when another gjc process is writing the stats database, instead of failing with "database is locked". The counts stay on this machine. With the default `off`, nothing is counted or written, and `gjc stats` output is unchanged.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- The release validation step in the GitHub Actions release workflow now outputs diagnostic information when git fetch fails, so issues with tag provenance validation are visible instead of failing silently.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- `gjc --export` can export transcripts larger than 128 MiB again, up to the 2 GiB session-memory limit, without writing anything to the source (not on Windows, which still refuses transcripts above 128 MiB). Their session-memory sidecars are built in a private cache directory under the agent dir, which is removed when the export finishes, fails or is interrupted. Before, export built these sidecars in the session's artifact directory (in the managed store for default-store sessions) and left them there, so only the first export succeeded. Export reflects the transcript as it was when the export started: lines appended during the export are left out, and a transcript replaced or truncated mid-export is refused. A failed export of one of these transcripts leaves any existing output file in place, because the page is written to a temp file and renamed over the output only when complete. As before, only linear, compacted transcripts without patch records can be exported at this size. Any other transcript is refused with an error that names the reason, and a session that was being written while the export read it gets a "retry when the session is idle" error.
|
|
23
|
+
|
|
24
|
+
- On macOS, a bash tool command (including a `monitor` job) that happened to start the shared SDK broker no longer SIGKILLs it when the command finishes or is cancelled. Before, the bash shell guardian tracked the detached broker as one of the command's descendants, so every session host bound to it died, either at once with `SIGHUP` or 10 minutes later through the broker-absence exit. The guardian now leaves alone a process whose pid and kernel incarnation match the published broker discovery. Its session hosts are left alone only when the broker's process lineage can be read at cleanup: if the lineage is unavailable, only the broker survives, and if the lookup fails or takes longer than one second, nothing is spared and cleanup kills everything as before. A reused pid, or a broker-shaped process that is not the published broker, is still killed. When the broker is spared, each remaining process is signalled on its own, right after its recorded incarnation is re-checked. Linux and Windows behavior is unchanged ([#7998](https://github.com/Yeachan-Heo/gajae-code/issues/7998)).
|
|
25
|
+
|
|
26
|
+
- An SDK session host no longer shuts itself down 10 minutes after the broker that launched it dies while a replacement broker is running. Brokers route through the agent directory's shared session index, so the replacement reaches the host, and any live broker publication now resets the host's broker-absence window. The host also no longer exits on broker absence while a turn is in flight: if the absence bound passes during the turn, the host exits within one poll after the turn ends. An idle host under a replacement broker is still bounded by the existing detached-idle windows ([#7998](https://github.com/Yeachan-Heo/gajae-code/issues/7998)).
|
|
27
|
+
|
|
28
|
+
- Fixed regression where `/resume` of a shared managed session with stale OpenAI Responses replay metadata would throw "Shared session mutation requires transaction admission" error. The admission check for replay metadata sanitization is now only performed when actually persisting patches (non-managed destinations), not during in-memory sanitization.
|
|
29
|
+
|
|
30
|
+
- Fixed `/resume` copying the transcripts it scans for header patches. The scan reads backward until it finds the header fields it needs, which for most transcripts means reading to the start of the file. It joined each 64 KiB chunk to the carried partial line and searched both the joined bytes and the raw chunk for the marker. It now searches the chunk and the partial line separately and joins them for parsing only when the marker text appears in them. Partial lines at chunk edges, including lines longer than a chunk, are still copied so they can be completed. Scanning 655 transcripts (1.29 GB) took about 1.9 s before and about 1.1 s after. Listing 772 sessions went from about 11.2 s to 10.5 s, and from about 6.6 s to 5.9 s with #7973 applied. The same header patches are found.
|
|
31
|
+
|
|
32
|
+
- A session that shuts down while its SDK host is still starting now sends `session_closed` once per release. Before, the shutdown, the abandoned startup and a deferred re-stop each ran the terminal release at the same time, so clients could get up to three `session_closed` frames. A retry after a failed release still publishes `session_closed` again.
|
|
33
|
+
|
|
34
|
+
- `/fork` works again in an interactive session after messages were sent, including after `--resume` and in sessions with OpenAI Responses or Codex replies. Since v0.21.0 it failed with "Shared session mutation requires transaction admission: prepare branched session" even with no other process open. The fork is built from the session's saved transcript and leaves the source session file untouched. A fork made this way records its source by session id; other fork paths are unchanged.
|
|
35
|
+
- When `/fork` still cannot run, it says why (for example, "another gjc process has written to this session" or "this session is too large to fork safely"). In the common case it refuses before it disconnects the agent, settles `/btw` or runs `session_before_branch` hooks. A save that starts in the short window after that check can still refuse later, as before. Sessions whose transcript has been moved to the session-memory sidecar (over 128 MiB, or `sessionMemory.mode: enabled`) still cannot fork from an interactive session; they refuse before any effect.
|
|
36
|
+
- `/move` and the `move_session` tool refuse before they start the directory transition when the session cannot be moved.
|
|
37
|
+
|
|
38
|
+
- A session holder record's `claimedAt` is shown only when it is a plain UTC timestamp, so a malformed record can no longer put arbitrary text into ownership output.
|
|
39
|
+
|
|
40
|
+
- When another process changes a session's transcript, the interactive TUI and startup prompts now show the session's operator message instead of the raw `managed_append_identity_mismatch` code, SDK clients get it instead of an opaque "Control operation failed.", and ACP errors carry it in `data.operatorMessage`. SDK and ACP machine codes, and ACP `details`, are unchanged.
|
|
41
|
+
- `/resume`, `/new` and `/fork` work again in a session whose transcript another process changed. Previously the predecessor flush rethrew the identity mismatch, so every way out of the session failed until the process was restarted.
|
|
42
|
+
- Once a session is known to be stuck because another process changed its transcript, it refuses new prompts, skills, hidden custom-message turns, `--continue`, steering and follow-ups up front, before admission, hooks, tools or model calls. Extension and custom slash commands that start no turn still run, so status commands and commands that open another session keep working; one that turns into a prompt is refused after its handler runs. The TUI `input` extension hook also still runs first. The message names the recovery: reopen with `/resume` (or `gjc --resume`), or fork with `/fork` (or `gjc --fork`). The first prompt after the other process writes is only refused at its first transcript write, after skill resolution, command dispatch and title invalidation but before any model call. A hidden custom-message turn used to resolve as if it had succeeded, leaving unsaved entries in memory.
|
|
43
|
+
- Quitting the TUI from a session whose transcript another process changed no longer crashes with an unhandled `managed_append_identity_mismatch` rejection.
|
|
44
|
+
- After any other transcript write failure, those turns are also refused up front with the original error, so a hidden custom-message turn no longer resolves with unsaved entries.
|
|
45
|
+
- `/compact` and `/handoff` on a session already known to be stuck are refused before any compaction hook or model call, and their failure text in the TUI and in headless/ACP slash commands shows the operator message.
|
|
46
|
+
- Keybinding actions that fail with a session refusal, such as the queue/follow-up shortcut on a stuck session, show the operator message instead of the raw code.
|
|
47
|
+
- A context clear on a stuck session is refused before it resets the conversation, and `/move` failures show the operator message.
|
|
48
|
+
- A resume rejected during startup, before anything ran in the session, keeps the accurate "this resume did not run" message.
|
|
49
|
+
- Turns started without a typed prompt on a stuck session are refused before the system prompt build, recall or `before_agent_start` hooks: the auto-continue prompt, hidden next-turn deliveries, `cancelAndSubmit`, and extension `sendMessage(…, { triggerTurn: true })`. The extension send now reports the failure instead of resolving as a success.
|
|
50
|
+
- Extension command failures on a stuck session show the operator message. An error that wraps a session refusal but reports its own failure (for example a failed rollback) keeps that failure in front of the operator message instead of hiding it.
|
|
51
|
+
- SDK and ACP error text only ever carries the fixed operator message. A wrapper's own failure message, which can include local paths, stays on local surfaces (TUI, print mode, CLI stderr).
|
|
52
|
+
- Extension `sendMessage` and `sendUserMessage` failures in the TUI show the operator message on a stuck session.
|
|
53
|
+
|
|
54
|
+
- A project file or runtime override that sets the parent of a protected setting to `null`, a scalar or an array (for example `plan: null` or `hindsight: null`) no longer resets the user's value for that setting. This covers global-only settings such as `plan.enabled` and `hindsight.apiUrl`, and, for project files, project-denied settings such as `task.agentModelOverrides`. `get`, `gjc config list` and the resolution snapshot now report the user value. Other keys under that parent are still replaced as before.
|
|
55
|
+
|
|
56
|
+
- Settings migrations now properly tolerate non-object values in legacy settings sections instead of throwing. When a project settings file contains a non-object value where a migration expects an object (e.g., `retry: "off"` instead of `retry: { ... }`), the malformed section is now skipped gracefully and other valid keys are preserved. (#8034)
|
|
57
|
+
- Settings layer loading failures are now logged with a warning instead of being silently swallowed, improving visibility into why project settings might be dropped. (#8034)
|
|
58
|
+
|
|
59
|
+
- Fixed shared root TUI sessions running an emergency compaction before every prompt once their transcript passed 48 MiB. Shared compaction only appends a summary and never rewrites the transcript, so this floor could not shrink the file there: each prompt paid for an extra summary call and added a compaction entry (about 190 KB on average in the reported session), which brought the session to the 128 MiB managed limit sooner (#8006). Shared sessions now ignore the transcript-size floor; the other emergency floors and the floor for non-shared sessions are unchanged.
|
|
60
|
+
|
|
61
|
+
- `gjc stats` counted two gjc processes that recorded session ownership counts in the same millisecond as one process report. Each process's counts now carry their own report id. Counts recorded before this fix are still read, and are counted by write time as before.
|
|
62
|
+
|
|
63
|
+
- `gjc update` now skips stable releases that don't have the binary asset for the current platform (e.g., when a release is published without all platform binaries yet), and falls back to the newest release that has the asset. Users see a clear message like "release v0.22.1 has no asset for gjc-linux-x64 yet" instead of a 404 download failure.
|
|
64
|
+
|
|
5
65
|
## [0.22.1] - 2026-11-24
|
|
6
66
|
|
|
7
67
|
### Added
|
|
@@ -8,7 +8,7 @@ export declare const PROBE_OUTPUT_LIMIT_BYTES: number;
|
|
|
8
8
|
* and transport framing.
|
|
9
9
|
*/
|
|
10
10
|
export declare const PROJECTION_RECEIPT_BUDGET_BYTES: number;
|
|
11
|
-
export type DoctorProbeKind = "native" | "projection";
|
|
11
|
+
export type DoctorProbeKind = "native" | "projection" | "session-owners";
|
|
12
12
|
export interface DoctorProbeReceipt {
|
|
13
13
|
readonly schemaVersion: 1;
|
|
14
14
|
readonly kind: DoctorProbeKind;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DoctorProbeReceipt } from "./probe-types";
|
|
2
|
+
/**
|
|
3
|
+
* Held sidecars whose record names a process that no longer exists: impossible under a kernel lock,
|
|
4
|
+
* so a bug signal. A suspect is flagged only if a second look, at the suspects alone, finds its lock
|
|
5
|
+
* still held and the same dead pid still named. The sidecar count is the collector's, from `readdir`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function collectSessionOwnersProbe(recheckMs?: number): Promise<DoctorProbeReceipt>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SessionOwnerEntryCounts } from "../../session/session-owners-layout";
|
|
2
|
+
import { type DoctorCollector } from "./checks";
|
|
3
|
+
import { type DoctorProbeResult } from "./probe-client";
|
|
4
|
+
import type { DoctorCheck } from "./types";
|
|
5
|
+
/** Above this many sidecars, gc pruning is not keeping up (design §2.9). */
|
|
6
|
+
export declare const SESSION_OWNER_SIDECAR_LIMIT = 10000;
|
|
7
|
+
/** Both checks for a present owners directory; exported for tests of the probe-failure paths. */
|
|
8
|
+
export declare function sessionOwnersChecks(targetId: string, counts: SessionOwnerEntryCounts | {
|
|
9
|
+
readonly errno?: string;
|
|
10
|
+
}, probe: DoctorProbeResult): DoctorCheck[];
|
|
11
|
+
/**
|
|
12
|
+
* Session ownership (design §2.9). A home with no owners directory has nothing to check, so no
|
|
13
|
+
* probe runs. Otherwise the sidecar count comes from `readdir` here, and a probe child does the
|
|
14
|
+
* lock work, as native code may fail to load.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SESSION_COLLECTOR: DoctorCollector;
|
|
@@ -25,6 +25,10 @@ export interface GithubReleaseLookupOptions {
|
|
|
25
25
|
webOrigin?: string;
|
|
26
26
|
timeoutMs?: number;
|
|
27
27
|
useAmbientToken?: boolean;
|
|
28
|
+
/** Skip releases that don't have this binary asset. */
|
|
29
|
+
requiredBinaryAsset?: string;
|
|
30
|
+
/** Callback to log when a release is skipped due to missing asset. */
|
|
31
|
+
onSkippedRelease?: (tag: string, version: string) => void;
|
|
28
32
|
}
|
|
29
33
|
/** A GitHub REST response that failed, carrying the status the caller must branch on. */
|
|
30
34
|
export declare class GithubApiStatusError extends Error {
|
|
@@ -34,7 +38,18 @@ export declare class GithubApiStatusError extends Error {
|
|
|
34
38
|
/** 403/429 is how api.github.com reports an exhausted unauthenticated budget. */
|
|
35
39
|
get isRateLimited(): boolean;
|
|
36
40
|
}
|
|
41
|
+
interface GithubReleaseJson {
|
|
42
|
+
tag_name?: unknown;
|
|
43
|
+
draft?: unknown;
|
|
44
|
+
prerelease?: unknown;
|
|
45
|
+
html_url?: unknown;
|
|
46
|
+
assets?: unknown[];
|
|
47
|
+
}
|
|
37
48
|
export declare function isSafeReleaseTag(tag: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check if a release has a binary asset matching the given name.
|
|
51
|
+
*/
|
|
52
|
+
export declare function releaseHasBinaryAsset(release: GithubReleaseJson, assetName: string): boolean;
|
|
38
53
|
export declare function versionFromTag(tag: string): string;
|
|
39
54
|
export declare function githubReleaseHeaders(token: string | undefined): Record<string, string>;
|
|
40
55
|
/**
|
|
@@ -62,3 +77,4 @@ export declare function verifyDownloadedBinaryChecksum(options: {
|
|
|
62
77
|
lookupEnv?: (name: string) => string | undefined;
|
|
63
78
|
downloadOrigin?: string;
|
|
64
79
|
}): Promise<"verified">;
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type SessionOwnerSidecar, type SessionOwnersInventory } from "../session/session-ownership";
|
|
2
|
+
export interface SessionOwnerRow extends SessionOwnerSidecar {
|
|
3
|
+
/** Held by this process or one of its ancestors (a gjc whose shell ran this command). */
|
|
4
|
+
readonly processTree: boolean;
|
|
5
|
+
readonly ageMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SessionOwnersReport extends Omit<SessionOwnersInventory, "held"> {
|
|
8
|
+
readonly owners: readonly SessionOwnerRow[];
|
|
9
|
+
}
|
|
10
|
+
export declare function collectSessionOwnersReport(now?: number): Promise<SessionOwnersReport>;
|
|
11
|
+
export declare function renderSessionOwnersText(report: SessionOwnersReport): string[];
|
|
12
|
+
/** `gjc session owners [--json]`. A refused or unreadable directory exits 1 with its code. */
|
|
13
|
+
export declare function runSessionOwnersCommand(json: boolean): Promise<void>;
|
|
@@ -113,6 +113,8 @@ export declare function defaultUserBinaryPathForTest(platform?: NodeJS.Platform,
|
|
|
113
113
|
/** Lookup options for the GitHub release check. */
|
|
114
114
|
export interface LatestReleaseLookupOptions extends GithubReleaseLookupOptions {
|
|
115
115
|
channel?: UpdateChannel;
|
|
116
|
+
/** When true for stable releases, checks that the release has the binary asset for the current platform. */
|
|
117
|
+
forBinaryUpdate?: boolean;
|
|
116
118
|
}
|
|
117
119
|
export declare function getLatestReleaseForTest(options: LatestReleaseLookupOptions): Promise<ReleaseInfo>;
|
|
118
120
|
export declare function compareVersionsForTest(a: string, b: string): number;
|
|
@@ -12,31 +12,40 @@ export declare function lifecycleArgs(request: SessionLifecycleLaunchRequest, cw
|
|
|
12
12
|
* How long a session host tolerates losing the broker it was launched under
|
|
13
13
|
* before treating itself as orphaned.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* a restart-shaped gap, because a broker that is merely slow to
|
|
20
|
-
* never cost a live host
|
|
21
|
-
*
|
|
15
|
+
* Brokers route through the agent directory's session index and the host's
|
|
16
|
+
* endpoint file, not through per-broker state, so a replacement broker for the
|
|
17
|
+
* same agent directory reaches a host its predecessor launched. The window
|
|
18
|
+
* therefore only runs while no live broker is published at all. It still has to
|
|
19
|
+
* outlast a restart-shaped gap, because a broker that is merely slow to
|
|
20
|
+
* republish must never cost a live host, but it must stay finite for an idle
|
|
21
|
+
* host, or every broker that is gone for good leaks a detached
|
|
22
|
+
* multi-hundred-megabyte host. A host holding its session-work lease is the one
|
|
23
|
+
* exception: it never exits on broker absence, so a turn that never settles keeps
|
|
24
|
+
* the host alive until it is closed or signalled.
|
|
22
25
|
*/
|
|
23
26
|
export declare const SESSION_HOST_BROKER_ABSENCE_GRACE_MS: number;
|
|
24
27
|
/**
|
|
25
|
-
* Resolves only once
|
|
26
|
-
*
|
|
28
|
+
* Resolves only once no live broker has been published for the agent directory
|
|
29
|
+
* for the full grace window, and the host is not doing session work.
|
|
27
30
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* so it accrues against the bound instead of resetting it. Only the pinned
|
|
32
|
-
* broker reappearing resets the window. An unreadable or unidentifiable
|
|
31
|
+
* Any identifiable publication resets the window, including one from a
|
|
32
|
+
* replacement incarnation: the replacement routes through the shared session
|
|
33
|
+
* index, so it can still reach this host. An unreadable or unidentifiable
|
|
33
34
|
* publication is not proof of orphanhood but accrues against the same bound.
|
|
35
|
+
*
|
|
36
|
+
* `readWorkLease` reports whether the host's session-work lease is held. It
|
|
37
|
+
* defaults to the lease the host's SDK runtime publishes (the AgentSession's
|
|
38
|
+
* `sessionWorkLease`, registered by the notifications bus at host startup). A
|
|
39
|
+
* turn in flight is never cut short by broker absence: the window keeps
|
|
40
|
+
* accruing, but the host only exits once the lease is released. If the bound was
|
|
41
|
+
* crossed during the turn, the host exits on the first poll after the turn ends.
|
|
34
42
|
*/
|
|
35
43
|
export declare function watchSessionHostBrokerLiveness(deps: {
|
|
36
44
|
agentDir: string;
|
|
37
45
|
now?: () => number;
|
|
38
46
|
sleep?: (ms: number) => Promise<void>;
|
|
39
47
|
readDiscovery?: (agentDir: string) => Promise<unknown>;
|
|
48
|
+
readWorkLease?: () => boolean;
|
|
40
49
|
graceMs?: number;
|
|
41
50
|
pollMs?: number;
|
|
42
51
|
}): Promise<void>;
|
|
@@ -223,6 +223,12 @@ export declare const SETTINGS_SCHEMA: {
|
|
|
223
223
|
readonly values: readonly ["copy-retain", "disabled"];
|
|
224
224
|
readonly default: "copy-retain";
|
|
225
225
|
};
|
|
226
|
+
readonly "session.ownership.mode": {
|
|
227
|
+
readonly type: "enum";
|
|
228
|
+
readonly values: readonly ["off", "observe", "enforce"];
|
|
229
|
+
readonly default: "off";
|
|
230
|
+
readonly description: "Not yet active; reserved for single-owner session claims.";
|
|
231
|
+
};
|
|
226
232
|
readonly "workspaceTree.mode": {
|
|
227
233
|
readonly type: "enum";
|
|
228
234
|
readonly values: readonly ["eager", "lazy"];
|
|
@@ -21,6 +21,12 @@ export type DarwinAncestryTracker = {
|
|
|
21
21
|
track(processRef: NativeProcess, uniqueId?: bigint): boolean;
|
|
22
22
|
trackGuardian(processRef: NativeProcess, uniqueId?: bigint): boolean;
|
|
23
23
|
poll(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Pids currently descended from `rootPid` by unique-id ancestry, including
|
|
26
|
+
* `rootPid` itself. Reparenting does not break the chain. Returns undefined
|
|
27
|
+
* when the root or the process table cannot be read.
|
|
28
|
+
*/
|
|
29
|
+
lineage(rootPid: number): Set<number> | undefined;
|
|
24
30
|
close(): void;
|
|
25
31
|
};
|
|
26
32
|
export type DarwinIdentity = {
|
|
@@ -37,5 +43,60 @@ export type DarwinAncestryTrackerDeps = {
|
|
|
37
43
|
};
|
|
38
44
|
};
|
|
39
45
|
export declare function createDarwinAncestryTracker(owned: Map<string, NativeProcess>, deps?: DarwinAncestryTrackerDeps): DarwinAncestryTracker | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Agent dir of a shared SDK broker launch argv (`... sdk broker-internal --agent-dir <dir>`),
|
|
48
|
+
* the only shape `ensure.ts` spawns. The argv only says where to look; the published
|
|
49
|
+
* discovery record decides whether the process is that broker.
|
|
50
|
+
*/
|
|
51
|
+
export declare function sdkBrokerAgentDirFromArgs(args: readonly string[]): string | undefined;
|
|
52
|
+
export type SparedSdkBrokerDeps = {
|
|
53
|
+
/** Published broker identity for an agent dir, read fresh; null when none is published. */
|
|
54
|
+
readDiscovery: (agentDir: string) => Promise<{
|
|
55
|
+
pid: number;
|
|
56
|
+
incarnation: string;
|
|
57
|
+
} | null>;
|
|
58
|
+
/** Pids descended from a pid by unique-id ancestry, including the pid itself. */
|
|
59
|
+
lineage: (pid: number) => Set<number> | undefined;
|
|
60
|
+
/** Current kernel incarnation of a pid, or undefined when it is gone or unreadable. */
|
|
61
|
+
incarnationOf: (pid: number) => string | undefined;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Pids cleanup must not kill: every owned process that is the published shared SDK
|
|
65
|
+
* broker for its agent dir (same pid and incarnation as the discovery record), plus
|
|
66
|
+
* the broker's descendants (its session hosts). The broker is a machine-wide daemon
|
|
67
|
+
* that a guarded command may only have happened to start. A reused pid has a
|
|
68
|
+
* different incarnation, so it does not match and is still killed.
|
|
69
|
+
*/
|
|
70
|
+
export declare function findSparedSdkBrokerPids(owned: Iterable<Pick<NativeProcess, "pid" | "incarnation" | "args">>, deps: SparedSdkBrokerDeps): Promise<Set<number>>;
|
|
71
|
+
/** Upper bound on the broker lookup so a stalled discovery read cannot stall cleanup. */
|
|
72
|
+
export declare const SPARED_SDK_BROKER_LOOKUP_TIMEOUT_MS = 1000;
|
|
73
|
+
/**
|
|
74
|
+
* {@link findSparedSdkBrokerPids} that cannot weaken cleanup: any throw, or a lookup
|
|
75
|
+
* that outlives `timeoutMs`, spares nothing, so every owned process is killed as before.
|
|
76
|
+
*/
|
|
77
|
+
export declare function findSparedSdkBrokerPidsBounded(owned: Iterable<Pick<NativeProcess, "pid" | "incarnation" | "args">>, deps: SparedSdkBrokerDeps, timeoutMs?: number): Promise<Set<number>>;
|
|
78
|
+
/** Process operations {@link signalOwnedProcessAlone} needs, injectable for tests. */
|
|
79
|
+
export type SignalOwnedProcessDeps = {
|
|
80
|
+
/** Current kernel incarnation of a pid, or undefined when it is gone or unreadable. */
|
|
81
|
+
incarnationOf: (pid: number) => string | undefined;
|
|
82
|
+
/** Raw signal by pid; throws when delivery fails. */
|
|
83
|
+
killPid: (pid: number, signal: NodeJS.Signals) => void;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* SIGKILL one owned process without touching its descendants, and only while `pid`
|
|
87
|
+
* still names the incarnation that was recorded as owned.
|
|
88
|
+
*
|
|
89
|
+
* The only caller is darwin cleanup when a broker is spared. Darwin has no atomic
|
|
90
|
+
* "signal iff start time matches" primitive, so `signalRoot` fails closed there
|
|
91
|
+
* today; it is tried first so this picks up an identity-bound signal if the platform
|
|
92
|
+
* ever gains one. The fallback re-reads the incarnation right before a raw `kill(2)`.
|
|
93
|
+
* That is the same check-then-kill race the native `killTree` accepts per node on
|
|
94
|
+
* darwin (slightly wider here because of the JS and napi hop), and narrower than
|
|
95
|
+
* `killTree`'s unchecked process-group signal, which this path replaces. The
|
|
96
|
+
* `signalRoot` rule against raw-pid fallback covers broker retirement, where failing
|
|
97
|
+
* closed just spares the broker; here failing closed would leak an owned process.
|
|
98
|
+
* Returns whether a signal was delivered.
|
|
99
|
+
*/
|
|
100
|
+
export declare function signalOwnedProcessAlone(owned: Pick<NativeProcess, "pid" | "incarnation" | "signalRoot">, deps: SignalOwnedProcessDeps): boolean;
|
|
40
101
|
export declare function runBashShellGuardian(): Promise<void>;
|
|
41
102
|
export {};
|
|
@@ -1,2 +1,18 @@
|
|
|
1
1
|
/** Owner-only HTML export. A replaced file is locked down on the opened descriptor. */
|
|
2
2
|
export declare function openHtmlExportDestination(outputPath: string): number;
|
|
3
|
+
/**
|
|
4
|
+
* Owner-only sibling of `outputPath` that an export is written to and then renamed over the
|
|
5
|
+
* output, so a failed or interrupted export never leaves a partial file at the output path.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createHtmlExportTempFile(outputPath: string): {
|
|
8
|
+
path: string;
|
|
9
|
+
fd: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Opens an existing output only to compare its identity with the source; never writes it.
|
|
13
|
+
* Returns undefined when there is no output yet, or it cannot be opened for reading (the path
|
|
14
|
+
* preflight already compared its identity).
|
|
15
|
+
*/
|
|
16
|
+
export declare function openExistingHtmlExportOutput(outputPath: string): number | undefined;
|
|
17
|
+
/** Removes an export temp file; a missing file is fine. */
|
|
18
|
+
export declare function removeHtmlExportTempFile(tempPath: string): void;
|
|
@@ -319,7 +319,7 @@ export declare const SDK_LIFECYCLE_ROUTER_PROTOCOL_VERSION = 1;
|
|
|
319
319
|
* Generation 230 composes that ownership policy with retained replay and
|
|
320
320
|
* SDK notification-authority bindings.
|
|
321
321
|
*/
|
|
322
|
-
export declare const DAEMON_GENERATION =
|
|
322
|
+
export declare const DAEMON_GENERATION = 237;
|
|
323
323
|
/**
|
|
324
324
|
* Serving-compatibility boundary for daemon lifecycle requests. Epoch 7
|
|
325
325
|
* requires durable publication receipts and acknowledged attachment dispatch,
|
|
@@ -9,6 +9,13 @@ import type { SdkFrame } from "../types";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const BROKER_RUNTIME_REVISE_CAPABILITY_FIELD = "__gjcBrokerReviseCapability";
|
|
11
11
|
export declare function hasBrokerRuntimeReviseCapability(input: unknown): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Session lifecycle operations that only the Broker lifecycle service may run. A
|
|
14
|
+
* session's own control surfaces (extension runtime and the interactive extension
|
|
15
|
+
* UI) refuse them with {@link prohibitBrokerLifecycleOperation}.
|
|
16
|
+
*/
|
|
17
|
+
export declare const BROKER_LIFECYCLE_OPERATIONS: ReadonlySet<string>;
|
|
18
|
+
export declare function prohibitBrokerLifecycleOperation(operation: string): never;
|
|
12
19
|
export declare const BROKER_RUNTIME_CLOSE_CAPABILITY_FIELD = "__gjcBrokerCloseCapability";
|
|
13
20
|
/** Private field carried only on the Broker-authorized terminal-abort request. */
|
|
14
21
|
export declare const BROKER_RUNTIME_ABORT_CAPABILITY_FIELD = "__gjcBrokerAbortCapability";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { FileEntry, SessionEntry } from "../session-manager";
|
|
2
|
+
/** Why a fork or branch of a shared session cannot be built from its committed transcript. */
|
|
3
|
+
export type GraphSuccessorRefusal = "publication-in-flight" | "not-admitted" | "unknown-entry" | "large-session" | "old-format" | "unreadable" | "foreign-entry" | "uncommitted" | "content-mismatch" | "changed" | "busy";
|
|
4
|
+
/** The user-facing refusal message for `reason`. */
|
|
5
|
+
export declare function graphSuccessorRefusalMessage(reason: GraphSuccessorRefusal): string;
|
|
6
|
+
/** The load-time projection applied to every entry read back from a transcript. */
|
|
7
|
+
export declare function sanitizeLoadedSessionEntryReplayMetadata(entry: SessionEntry): SessionEntry;
|
|
8
|
+
/**
|
|
9
|
+
* Whether a committed transcript entry and the legacy serialisation of a resident entry
|
|
10
|
+
* are the same entry for a successor: JSON-equal as they stand, or equal once both have
|
|
11
|
+
* had the load-time projection applied. Resume strips OpenAI Responses replay metadata
|
|
12
|
+
* in memory without rewriting a managed transcript; a live session keeps it on both sides.
|
|
13
|
+
*/
|
|
14
|
+
export declare function committedEntryMatchesResident(committed: FileEntry, serializedResident: FileEntry): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Prove the committed transcript is this opener's own graph and each source entry is
|
|
17
|
+
* committed as this opener holds it. Requires this session at the current version; no
|
|
18
|
+
* entry id outside `ownIds` (a peer's sibling is foreign; id-less patch lines are
|
|
19
|
+
* applied, not counted); every source entry committed and matching
|
|
20
|
+
* ({@link committedEntryMatchesResident}). Returns the successor's source lines (the
|
|
21
|
+
* legacy serialisation) and the digest of the bytes proven, or the refusal.
|
|
22
|
+
*/
|
|
23
|
+
export declare function proveOwnCommittedGraph(input: {
|
|
24
|
+
bytes: Uint8Array;
|
|
25
|
+
sessionId: string;
|
|
26
|
+
ownIds: ReadonlySet<string>;
|
|
27
|
+
sourceEntries: readonly SessionEntry[];
|
|
28
|
+
serialize: (entry: SessionEntry) => FileEntry;
|
|
29
|
+
onMismatch?: (entryId: string) => void;
|
|
30
|
+
}): {
|
|
31
|
+
lines: string[];
|
|
32
|
+
digest: string;
|
|
33
|
+
} | GraphSuccessorRefusal;
|
|
@@ -3,11 +3,16 @@ import { type ManagedFileIdentity, type ManagedFileSnapshot } from "../../sdk/se
|
|
|
3
3
|
import type { SessionStorageRangeSnapshot, SessionStorageStat } from "../../sdk/session-readonly/storage";
|
|
4
4
|
import { type NativePublishOutcome } from "./native-publish-outcome";
|
|
5
5
|
export declare const MANAGED_ARTIFACT_COPY_BATCH_SIZE = 256;
|
|
6
|
+
/**
|
|
7
|
+
* Operator text for a fence rejection during startup, before this process ran anything
|
|
8
|
+
* in the session: the resume itself did not happen, so there is nothing to recover.
|
|
9
|
+
*/
|
|
10
|
+
export declare const RESUME_REJECTED_OPERATOR_MESSAGE = "Session was resumed by another process; this resume did not run. Retry, or resume a different session.";
|
|
6
11
|
/** A pre-mutation append fence rejection: no bytes from this append were written. */
|
|
7
12
|
export declare class ManagedAppendIdentityMismatchError extends Error {
|
|
8
13
|
readonly code = "managed_append_identity_mismatch";
|
|
9
14
|
readonly relativePath: string;
|
|
10
|
-
readonly operatorMessage = "
|
|
15
|
+
readonly operatorMessage = "Another process changed this session's transcript, so this process stopped saving to it. To continue, reopen the session with /resume (or gjc --resume), or fork it with /fork (or gjc --fork).";
|
|
11
16
|
constructor(relativePath: string);
|
|
12
17
|
}
|
|
13
18
|
export declare class ManagedPublishError extends Error {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { SessionManager } from "../session-manager";
|
|
2
|
+
import { type SessionOwnerClaim } from "../session-ownership";
|
|
3
|
+
/** How long a deferred owner shutdown may keep its predecessor's claim (design §2.5). */
|
|
4
|
+
export declare const DEFERRED_RELEASE_CAP_MS = 60000;
|
|
5
|
+
/** Thrown only under the strict test seam, for a write the detector flags. */
|
|
6
|
+
export declare class SessionWriteWithoutClaimError extends Error {
|
|
7
|
+
readonly code = "session_write_without_claim";
|
|
8
|
+
readonly site: string;
|
|
9
|
+
constructor(site: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class SessionClaimSet {
|
|
12
|
+
#private;
|
|
13
|
+
constructor();
|
|
14
|
+
/** The session id the manager's identity helper last bound. */
|
|
15
|
+
get currentSessionId(): string | undefined;
|
|
16
|
+
get sessionIds(): readonly string[];
|
|
17
|
+
has(sessionId: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The identity helper's record of the manager's id. It never claims and never releases. A change
|
|
20
|
+
* of id outside any transition is counted (when ownership is on): nothing settles after it.
|
|
21
|
+
*/
|
|
22
|
+
bind(sessionId: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* The write-path detector (design §2.5), called before a transcript write. When ownership is on
|
|
25
|
+
* and this set holds no claim for `sessionId` (the current id unless a successor is named), it
|
|
26
|
+
* logs `session_write_without_claim` with the call site and counts it. It never claims, and it
|
|
27
|
+
* throws only under the strict test seam. In `off` it returns at once.
|
|
28
|
+
*/
|
|
29
|
+
checkWrite(site: string, sessionId?: string | undefined): void;
|
|
30
|
+
/**
|
|
31
|
+
* Take ownership of a claim: a factory's, or a transition's target claimed before the rotation.
|
|
32
|
+
* The key is the id, so a second claim of an id already here is released at once (one claim per id).
|
|
33
|
+
*/
|
|
34
|
+
add(claim: SessionOwnerClaim): void;
|
|
35
|
+
/**
|
|
36
|
+
* Open a transition: no claim is released until the outermost transition ends. Disposing settles,
|
|
37
|
+
* so the claims kept are exactly those for the id current at the end (rotation committed: the
|
|
38
|
+
* predecessor goes; rolled back or cancelled: the target goes).
|
|
39
|
+
*/
|
|
40
|
+
transition(): Disposable;
|
|
41
|
+
/**
|
|
42
|
+
* Release every claim whose id is not current and not held for a deferred shutdown. Runs when the
|
|
43
|
+
* outermost transition ends, so a target added outside any transition stays until the next one
|
|
44
|
+
* settles; stage targets inside the transition that rotates to them.
|
|
45
|
+
*/
|
|
46
|
+
settle(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Deferred owner shutdown: keep `sessionId` while `finalization` runs, at most `capMs`. A hold that
|
|
49
|
+
* reaches the cap releases anyway and counts `release_after_deferred_timeout`.
|
|
50
|
+
*/
|
|
51
|
+
holdUntil(sessionId: string, finalization: Promise<unknown>, capMs?: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* Cold-sidecar manager swap: every claim and hold moves to `target`, and this set is emptied
|
|
54
|
+
* without unlocking anything. The target then settles: a claim for its current id and any held
|
|
55
|
+
* claim survive, everything else is released (a fork's predecessor, once the swap commits).
|
|
56
|
+
* Open transitions are not carried across: a caller that swaps inside a transition must call
|
|
57
|
+
* this after that transition ends, or open one on the target.
|
|
58
|
+
*/
|
|
59
|
+
moveTo(target: SessionClaimSet): void;
|
|
60
|
+
/**
|
|
61
|
+
* `close()`: release every claim. A claim under a deferred hold is released when its hold ends,
|
|
62
|
+
* at most the cap later; nothing can be added afterwards.
|
|
63
|
+
*/
|
|
64
|
+
releaseAll(): void;
|
|
65
|
+
}
|
|
66
|
+
/** Opaque capability for a manager's claim set. Excluded from package exports with `internal/`. */
|
|
67
|
+
export declare const sessionClaimSetCapability: unique symbol;
|
|
68
|
+
/** The claim set of a SessionManager, for factories, transitions and tests in this package. */
|
|
69
|
+
export declare function sessionClaimSetOf(manager: SessionManager): SessionClaimSet;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator-facing text for errors raised by session operations.
|
|
3
|
+
*
|
|
4
|
+
* Session persistence errors keep a stable machine code in `message` (for example
|
|
5
|
+
* `managed_append_identity_mismatch`) and carry the human explanation, including the
|
|
6
|
+
* recovery, in `operatorMessage`. Every surface that shows such an error to a person
|
|
7
|
+
* must show the operator text; machine fields (`code`) stay as they are.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Boundary-safe operator text for SDK, ACP and other protocol surfaces: the fixed,
|
|
11
|
+
* path-free `operatorMessage` of `error` or of the refusal it purely re-raises. A wrapper
|
|
12
|
+
* that reports its own failure yields `undefined`, because its message may carry local
|
|
13
|
+
* paths or other detail those surfaces keep opaque.
|
|
14
|
+
*/
|
|
15
|
+
export declare function findOperatorMessage(error: unknown): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Operator text for a person reading a local surface (TUI, print mode, CLI stderr). A
|
|
18
|
+
* wrapper with its own failure, such as a failed rollback or an invariant failure raised
|
|
19
|
+
* while handling the refusal, keeps that message first so the operator text cannot hide
|
|
20
|
+
* the real failure.
|
|
21
|
+
*/
|
|
22
|
+
export declare function composeOperatorMessage(error: unknown): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Text to show a person on a local surface for `error`: its operator message (composed
|
|
25
|
+
* with a wrapper's own failure, see {@link composeOperatorMessage}) when one exists, otherwise
|
|
26
|
+
* `error.message`. A non-Error value renders as `fallback`, so each call site keeps its
|
|
27
|
+
* existing rendering for thrown non-errors.
|
|
28
|
+
*/
|
|
29
|
+
export declare function operatorErrorMessage(error: unknown, fallback?: string): string;
|