@gajae-code/coding-agent 0.12.21 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -2
- package/dist/types/cli/args.d.ts +5 -2
- package/dist/types/cli/root-flags.d.ts +246 -0
- package/dist/types/cli.d.ts +11 -19
- package/dist/types/commands/daemon.d.ts +0 -30
- package/dist/types/commands/launch.d.ts +11 -19
- package/dist/types/commands/quick-lane.d.ts +32 -0
- package/dist/types/commands/sdk.d.ts +21 -15
- package/dist/types/config/file-lock-gc.d.ts +2 -0
- package/dist/types/config/model-equivalence.d.ts +20 -0
- package/dist/types/config/model-profile-activation.d.ts +62 -17
- package/dist/types/config/model-profiles.d.ts +10 -0
- package/dist/types/config/model-registry.d.ts +68 -1
- package/dist/types/config/model-resolver.d.ts +15 -4
- package/dist/types/config/models-config-schema.d.ts +7 -2
- package/dist/types/config/provider-selection-policy.d.ts +62 -0
- package/dist/types/config/settings-schema.d.ts +36 -78
- package/dist/types/config/settings.d.ts +2 -0
- package/dist/types/edit/renderer.d.ts +5 -2
- package/dist/types/edit/streaming.d.ts +13 -0
- package/dist/types/extensibility/custom-tools/types.d.ts +2 -0
- package/dist/types/extensibility/extensions/compact-handler.d.ts +2 -1
- package/dist/types/extensibility/extensions/types.d.ts +3 -0
- package/dist/types/gjc-runtime/gc-runtime.d.ts +19 -5
- package/dist/types/internal-urls/local-protocol.d.ts +1 -0
- package/dist/types/modes/components/model-selector.d.ts +0 -2
- package/dist/types/modes/components/provider-order-context.d.ts +45 -0
- package/dist/types/modes/components/provider-order-editor.d.ts +24 -0
- package/dist/types/modes/components/settings-defs.d.ts +5 -1
- package/dist/types/modes/components/settings-selector.d.ts +2 -0
- package/dist/types/quick-lane/classify.d.ts +40 -0
- package/dist/types/runtime/stt-settings-setup.d.ts +18 -0
- package/dist/types/sdk/broker/broker.d.ts +56 -2
- package/dist/types/sdk/broker/operation-receipt-ledger.d.ts +25 -0
- package/dist/types/sdk/broker/session-index.d.ts +83 -2
- package/dist/types/sdk/broker/state-version.d.ts +1 -1
- package/dist/types/sdk/bus/notification-service.d.ts +6 -0
- package/dist/types/sdk/bus/prompt-reconciliation.d.ts +8 -1
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +4 -1
- package/dist/types/sdk/bus/telegram-daemon.d.ts +26 -0
- package/dist/types/sdk/cli/rows.d.ts +98 -0
- package/dist/types/sdk/cli/session-cli.d.ts +35 -3
- package/dist/types/sdk/elevation/allowlist.d.ts +20 -0
- package/dist/types/sdk/elevation/audit.d.ts +93 -0
- package/dist/types/sdk/elevation/capability.d.ts +3 -0
- package/dist/types/sdk/elevation/digest.d.ts +72 -0
- package/dist/types/sdk/elevation/dispatch-receipt.d.ts +85 -0
- package/dist/types/sdk/elevation/grant-ledger.d.ts +163 -0
- package/dist/types/sdk/elevation/owner.d.ts +48 -0
- package/dist/types/sdk/guides/cache.d.ts +98 -0
- package/dist/types/sdk/guides/catalog.d.ts +156 -0
- package/dist/types/sdk/guides/cli.d.ts +39 -0
- package/dist/types/sdk/guides/manifest.d.ts +66 -0
- package/dist/types/sdk/guides/verify.d.ts +66 -0
- package/dist/types/sdk/host/control/dispatch.d.ts +8 -0
- package/dist/types/sdk/host/control/index.d.ts +1 -1
- package/dist/types/sdk/host/control/operations.d.ts +3 -2
- package/dist/types/sdk/host/query/cursor.d.ts +10 -0
- package/dist/types/sdk/host/query/handlers.d.ts +21 -0
- package/dist/types/sdk/host/session-runtime.d.ts +9 -0
- package/dist/types/sdk/mcp/server.d.ts +2 -2
- package/dist/types/sdk/prompt-status.d.ts +11 -0
- package/dist/types/sdk/session.d.ts +4 -0
- package/dist/types/sdk/transport/index.d.ts +1 -0
- package/dist/types/sdk/transport/relay.d.ts +1 -0
- package/dist/types/sdk/transport/serve-cli.d.ts +20 -1
- package/dist/types/session/agent-session.d.ts +32 -18
- package/dist/types/session/blob-store.d.ts +13 -7
- package/dist/types/session/fallback-chain-controller.d.ts +15 -0
- package/dist/types/session/internal/managed-session-storage.d.ts +25 -1
- package/dist/types/session/internal/session-memory-sidecar.d.ts +5 -5
- package/dist/types/session/session-manager.d.ts +139 -10
- package/dist/types/session/session-storage.d.ts +48 -0
- package/dist/types/setup/provider-onboarding.d.ts +7 -1
- package/dist/types/slash-commands/builtin-registry.d.ts +14 -0
- package/dist/types/stt/setup.d.ts +2 -0
- package/dist/types/task/executor.d.ts +10 -2
- package/dist/types/tools/browser/runtime-diagnostics.d.ts +65 -0
- package/dist/types/tools/browser/tab-protocol.d.ts +4 -0
- package/dist/types/tools/browser/tab-supervisor.d.ts +2 -0
- package/dist/types/tools/browser/tab-worker.d.ts +2 -0
- package/dist/types/tools/browser.d.ts +2 -0
- package/dist/types/tools/image-gen.d.ts +14 -18
- package/dist/types/tools/index.d.ts +2 -0
- package/dist/types/tools/resource-gc.d.ts +2 -0
- package/dist/types/utils/pasted-image-path.d.ts +6 -0
- package/package.json +9 -9
- package/scripts/generate-sdk-operation-inventory.ts +8 -0
- package/scripts/run-test-manifest.ts +61 -21
- package/scripts/verify-gjc-sdk-canonicalization.ts +9 -4
- package/src/cli/args.ts +62 -9
- package/src/cli/completion-cli.ts +1 -0
- package/src/cli/fast-help.ts +1 -0
- package/src/cli/root-flags.ts +100 -0
- package/src/cli/setup-cli.ts +6 -2
- package/src/cli.ts +42 -65
- package/src/commands/acp.ts +1 -1
- package/src/commands/daemon.ts +2 -31
- package/src/commands/gc.ts +1 -1
- package/src/commands/launch.ts +8 -129
- package/src/commands/quick-lane.ts +51 -0
- package/src/commands/sdk.ts +200 -26
- package/src/commands/setup.ts +4 -2
- package/src/config/file-lock-gc.ts +4 -1
- package/src/config/model-equivalence.ts +76 -7
- package/src/config/model-profile-activation.ts +1115 -265
- package/src/config/model-profiles.ts +134 -2
- package/src/config/model-registry.ts +352 -50
- package/src/config/model-resolver.ts +289 -38
- package/src/config/models-config-schema.ts +11 -4
- package/src/config/provider-selection-policy.ts +146 -0
- package/src/config/settings-schema.ts +50 -77
- package/src/config/settings.ts +40 -0
- package/src/coordinator-mcp/server.ts +32 -2
- package/src/edit/renderer.ts +175 -223
- package/src/edit/streaming.ts +108 -1
- package/src/export/html/index.ts +57 -7
- package/src/extensibility/custom-tools/types.ts +2 -0
- package/src/extensibility/extensions/compact-handler.ts +3 -2
- package/src/extensibility/extensions/runner.ts +6 -0
- package/src/extensibility/extensions/types.ts +3 -0
- package/src/gjc-runtime/gc-runtime.ts +379 -20
- package/src/gjc-runtime/launch-worktree.ts +5 -1
- package/src/gjc-runtime/team-runtime.ts +59 -2
- package/src/gjc-runtime/tmux-owner-isolation.ts +19 -0
- package/src/gjc-runtime/ultragoal-receipt-freshness.ts +16 -1
- package/src/internal-urls/docs-index.generated.ts +17 -13
- package/src/internal-urls/local-protocol.ts +1 -0
- package/src/main.ts +40 -3
- package/src/memories/index.ts +4 -2
- package/src/modes/acp/acp-agent.ts +235 -91
- package/src/modes/components/model-selector.ts +206 -42
- package/src/modes/components/provider-order-context.ts +197 -0
- package/src/modes/components/provider-order-editor.ts +441 -0
- package/src/modes/components/settings-defs.ts +21 -1
- package/src/modes/components/settings-selector.ts +45 -2
- package/src/modes/components/tool-execution.ts +47 -15
- package/src/modes/controllers/command-controller.ts +6 -3
- package/src/modes/controllers/extension-ui-controller.ts +2 -0
- package/src/modes/controllers/input-controller.ts +73 -2
- package/src/modes/controllers/selector-controller.ts +260 -153
- package/src/modes/prompt-suggestion-controller.ts +1 -1
- package/src/modes/runtime-init.ts +1 -0
- package/src/modes/utils/ui-helpers.ts +18 -0
- package/src/prompts/tools/browser.md +1 -0
- package/src/quick-lane/classify.ts +257 -0
- package/src/rlm/index.ts +1 -1
- package/src/runtime/stt-settings-setup.ts +57 -0
- package/src/sdk/acp/adapter.ts +2 -1
- package/src/sdk/broker/broker.ts +780 -12
- package/src/sdk/broker/lifecycle.ts +70 -29
- package/src/sdk/broker/operation-receipt-ledger.ts +144 -0
- package/src/sdk/broker/session-index.ts +463 -48
- package/src/sdk/broker/state-version.ts +13 -9
- package/src/sdk/broker/transport.ts +14 -1
- package/src/sdk/bus/index.ts +34 -13
- package/src/sdk/bus/kind-aware-reconciliation.ts +21 -2
- package/src/sdk/bus/notification-service.ts +47 -1
- package/src/sdk/bus/prompt-reconciliation.ts +22 -3
- package/src/sdk/bus/telegram-daemon-contract.ts +4 -1
- package/src/sdk/bus/telegram-daemon.ts +54 -3
- package/src/sdk/cli/rows.ts +247 -0
- package/src/sdk/cli/session-cli.ts +930 -79
- package/src/sdk/elevation/allowlist.ts +54 -0
- package/src/sdk/elevation/audit.ts +208 -0
- package/src/sdk/elevation/capability.ts +41 -0
- package/src/sdk/elevation/digest.ts +129 -0
- package/src/sdk/elevation/dispatch-receipt.ts +184 -0
- package/src/sdk/elevation/grant-ledger.ts +1142 -0
- package/src/sdk/elevation/owner.ts +109 -0
- package/src/sdk/guides/cache.ts +363 -0
- package/src/sdk/guides/catalog.ts +554 -0
- package/src/sdk/guides/cli.ts +235 -0
- package/src/sdk/guides/manifest.ts +152 -0
- package/src/sdk/guides/verify.ts +178 -0
- package/src/sdk/host/control/dispatch.ts +49 -1
- package/src/sdk/host/control/index.ts +1 -0
- package/src/sdk/host/control/operations.ts +8 -1
- package/src/sdk/host/query/cursor.ts +47 -3
- package/src/sdk/host/query/handlers.ts +155 -2
- package/src/sdk/host/sdk-surface-parity.test.ts +1 -0
- package/src/sdk/host/session-runtime.test.ts +391 -1
- package/src/sdk/host/session-runtime.ts +308 -73
- package/src/sdk/host/surface-policy.ts +3 -0
- package/src/sdk/host/websocket-transport.ts +7 -1
- package/src/sdk/mcp/server.ts +88 -15
- package/src/sdk/prompt-status.ts +8 -0
- package/src/sdk/protocol/operation-inventory.generated.json +62 -0
- package/src/sdk/protocol/operation-registry.ts +3 -2
- package/src/sdk/session.ts +87 -39
- package/src/sdk/transport/index.ts +1 -0
- package/src/sdk/transport/relay.ts +3 -0
- package/src/sdk/transport/serve-cli.ts +111 -24
- package/src/secrets/obfuscator.ts +92 -12
- package/src/session/agent-session.ts +322 -93
- package/src/session/blob-store.ts +60 -8
- package/src/session/fallback-chain-controller.ts +35 -0
- package/src/session/internal/managed-session-scope.ts +25 -3
- package/src/session/internal/managed-session-storage.ts +574 -73
- package/src/session/internal/session-memory-sidecar.ts +19 -29
- package/src/session/session-manager.ts +2166 -743
- package/src/session/session-storage.ts +715 -48
- package/src/setup/provider-onboarding.ts +19 -3
- package/src/setup/provider-presets.json +3 -1
- package/src/slash-commands/builtin-registry.ts +85 -3
- package/src/stt/downloader.ts +2 -3
- package/src/stt/setup.ts +29 -4
- package/src/task/executor.ts +22 -18
- package/src/task/index.ts +24 -1
- package/src/tools/archive-reader.ts +11 -2
- package/src/tools/browser/runtime-diagnostics.ts +249 -0
- package/src/tools/browser/tab-protocol.ts +4 -0
- package/src/tools/browser/tab-supervisor.ts +5 -0
- package/src/tools/browser/tab-worker.ts +36 -1
- package/src/tools/browser.ts +7 -0
- package/src/tools/image-gen.ts +110 -166
- package/src/tools/index.ts +2 -0
- package/src/tools/read.ts +1 -1
- package/src/tools/resource-gc.ts +6 -1
- package/src/tools/tool-catalog.generated.ts +5 -1
- package/src/utils/pasted-image-path.ts +93 -0
- package/src/web/search/index.ts +3 -3
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned DTO rows for `gjc sdk session` semantic verbs (row DTO v1, DR-12).
|
|
3
|
+
*
|
|
4
|
+
* Every semantic verb renders its output through these rows so machine
|
|
5
|
+
* consumers get one deterministic, versioned envelope per verb. Credentials
|
|
6
|
+
* are never part of the row schema: broker `session.list` rows carry no
|
|
7
|
+
* credentials, offline inspect rows are projected from endpoint discovery
|
|
8
|
+
* records with secret-shaped fields stripped before they can reach a row, and
|
|
9
|
+
* pass-through host payloads are redacted recursively before rendering.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const SESSION_ROWS_VERSION = 1;
|
|
13
|
+
|
|
14
|
+
export type SdkSessionActivityState = "active" | "idle";
|
|
15
|
+
|
|
16
|
+
export interface SdkSessionActivityV1 {
|
|
17
|
+
state: SdkSessionActivityState;
|
|
18
|
+
at: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface SdkSessionRowV1 {
|
|
22
|
+
sessionId: string;
|
|
23
|
+
locator: { repo: string; stateRoot: string };
|
|
24
|
+
endpointGeneration: number;
|
|
25
|
+
/** Process-bound incarnation of the hosting process (C1); absent for legacy-provenance rows. */
|
|
26
|
+
hostIncarnation?: string;
|
|
27
|
+
pid: number;
|
|
28
|
+
live: boolean;
|
|
29
|
+
/** Tombstone flag (C4): deleted sessions are excluded from list/endpoint/resumable surfaces. */
|
|
30
|
+
deleted: boolean;
|
|
31
|
+
indexSeq: number;
|
|
32
|
+
terminalUncertain?: boolean;
|
|
33
|
+
lifecycleRequestId?: string;
|
|
34
|
+
endpointMtimeMs?: number;
|
|
35
|
+
/** Coalesced broker-owned heartbeat checkpoint (C2). */
|
|
36
|
+
activity?: SdkSessionActivityV1;
|
|
37
|
+
/** Wall-clock timestamp of the latest admitted heartbeat, when one exists. */
|
|
38
|
+
lastHeartbeatAt?: number;
|
|
39
|
+
/** "legacy" for v1/v2-era rows that predate process-incarnation identity. */
|
|
40
|
+
identityProvenance?: "composite" | "legacy";
|
|
41
|
+
/** True when the same sessionId maps to more than one stateRoot (cross-repo duplicate). */
|
|
42
|
+
ambiguous?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SdkCheckpointRecordV1 {
|
|
46
|
+
revision: number;
|
|
47
|
+
generation: number;
|
|
48
|
+
seq: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface SdkRetentionGapV1 {
|
|
52
|
+
code: "retention_gap";
|
|
53
|
+
missing?: { from: number; to: number };
|
|
54
|
+
resync?: SdkCheckpointRecordV1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** One tail item: a retained transcript entry or a live event-ring event. */
|
|
58
|
+
export interface SdkTailItemV1 {
|
|
59
|
+
/** "transcript" for retained transcript entries, otherwise the event-ring kind. */
|
|
60
|
+
kind: string;
|
|
61
|
+
id?: string;
|
|
62
|
+
generation?: number;
|
|
63
|
+
seq?: number;
|
|
64
|
+
payload: unknown;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface SdkTailEnvelopeV1 {
|
|
68
|
+
version: typeof SESSION_ROWS_VERSION;
|
|
69
|
+
source: "session" | "offline";
|
|
70
|
+
session: SdkSessionRowV1;
|
|
71
|
+
checkpoint?: SdkCheckpointRecordV1;
|
|
72
|
+
gap?: SdkRetentionGapV1;
|
|
73
|
+
items: SdkTailItemV1[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const SECRET_FIELD = /(?:secret|token|password|credential|authorization|api[_-]?key)/i;
|
|
77
|
+
|
|
78
|
+
/** Recursively removes secret-shaped fields (defense in depth for DTO output). */
|
|
79
|
+
export function stripSecretFields(value: unknown): unknown {
|
|
80
|
+
if (Array.isArray(value)) return value.map(stripSecretFields);
|
|
81
|
+
if (!value || typeof value !== "object") return value;
|
|
82
|
+
const out: Record<string, unknown> = {};
|
|
83
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
84
|
+
if (SECRET_FIELD.test(key)) continue;
|
|
85
|
+
out[key] = stripSecretFields(nested);
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
91
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function optionalString(value: unknown): string | undefined {
|
|
95
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function optionalFiniteNumber(value: unknown): number | undefined {
|
|
99
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function locatorOf(row: Record<string, unknown>): { repo: string; stateRoot: string } {
|
|
103
|
+
const locator = isRecord(row.locator) ? row.locator : {};
|
|
104
|
+
return {
|
|
105
|
+
repo: optionalString(locator.repo) ?? "unknown",
|
|
106
|
+
stateRoot: optionalString(locator.stateRoot) ?? "unknown",
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function activityOf(row: Record<string, unknown>): SdkSessionActivityV1 | undefined {
|
|
111
|
+
if (!isRecord(row.activity)) return undefined;
|
|
112
|
+
const state = row.activity.state;
|
|
113
|
+
const at = row.activity.at;
|
|
114
|
+
if ((state !== "active" && state !== "idle") || typeof at !== "number" || !Number.isFinite(at)) return undefined;
|
|
115
|
+
return { state, at };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Projects one broker `session.list` row into the credential-free v1 row DTO.
|
|
120
|
+
* The row is a superset-tolerant projection: identity fields introduced by
|
|
121
|
+
* later index versions (hostIncarnation, activity, deleted) pass through when
|
|
122
|
+
* present and are omitted otherwise, so the same mapper serves both v2 and v3
|
|
123
|
+
* index shapes.
|
|
124
|
+
*/
|
|
125
|
+
export function toSessionRowV1(value: unknown): SdkSessionRowV1 {
|
|
126
|
+
if (!isRecord(value)) throw new Error("session row is not a record");
|
|
127
|
+
const sessionId = optionalString(value.sessionId);
|
|
128
|
+
if (!sessionId) throw new Error("session row is missing sessionId");
|
|
129
|
+
const pid = typeof value.pid === "number" && Number.isSafeInteger(value.pid) ? value.pid : 0;
|
|
130
|
+
const endpointGeneration =
|
|
131
|
+
typeof value.endpointGeneration === "number" && Number.isSafeInteger(value.endpointGeneration)
|
|
132
|
+
? value.endpointGeneration
|
|
133
|
+
: 0;
|
|
134
|
+
const indexSeq = typeof value.indexSeq === "number" && Number.isSafeInteger(value.indexSeq) ? value.indexSeq : 0;
|
|
135
|
+
const row: SdkSessionRowV1 = {
|
|
136
|
+
sessionId,
|
|
137
|
+
locator: locatorOf(value),
|
|
138
|
+
endpointGeneration,
|
|
139
|
+
pid,
|
|
140
|
+
live: value.live === true,
|
|
141
|
+
deleted: value.deleted === true,
|
|
142
|
+
indexSeq,
|
|
143
|
+
};
|
|
144
|
+
const hostIncarnation = optionalString(value.hostIncarnation);
|
|
145
|
+
if (hostIncarnation !== undefined) row.hostIncarnation = hostIncarnation;
|
|
146
|
+
if (value.terminalUncertain === true) row.terminalUncertain = true;
|
|
147
|
+
const lifecycleRequestId = optionalString(value.lifecycleRequestId);
|
|
148
|
+
if (lifecycleRequestId !== undefined) row.lifecycleRequestId = lifecycleRequestId;
|
|
149
|
+
const endpointMtimeMs = optionalFiniteNumber(value.endpointMtimeMs);
|
|
150
|
+
if (endpointMtimeMs !== undefined) row.endpointMtimeMs = endpointMtimeMs;
|
|
151
|
+
const activity = activityOf(value);
|
|
152
|
+
if (activity !== undefined) row.activity = activity;
|
|
153
|
+
const lastHeartbeatAt = optionalFiniteNumber(value.lastHeartbeatAt);
|
|
154
|
+
if (lastHeartbeatAt !== undefined) row.lastHeartbeatAt = lastHeartbeatAt;
|
|
155
|
+
if (value.identityProvenance === "composite" || value.identityProvenance === "legacy")
|
|
156
|
+
row.identityProvenance = value.identityProvenance;
|
|
157
|
+
if (value.ambiguous === true) row.ambiguous = true;
|
|
158
|
+
return row;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Offline inspect row projected from a local SDK endpoint discovery record.
|
|
163
|
+
* The discovery record carries the endpoint credential (`url`/`token`); neither
|
|
164
|
+
* is ever projected into the row. `path` is the endpoint file
|
|
165
|
+
* `<stateRoot>/sdk/<sessionId>.json`, so the state root is recovered from the
|
|
166
|
+
* path when the layout matches.
|
|
167
|
+
*/
|
|
168
|
+
export function toOfflineSessionRowV1(value: unknown): SdkSessionRowV1 {
|
|
169
|
+
if (!isRecord(value)) throw new Error("endpoint discovery record is not a record");
|
|
170
|
+
const sessionId = optionalString(value.sessionId);
|
|
171
|
+
if (!sessionId) throw new Error("endpoint discovery record is missing sessionId");
|
|
172
|
+
const pid = typeof value.pid === "number" && Number.isSafeInteger(value.pid) ? value.pid : 0;
|
|
173
|
+
const stale = value.stale === true;
|
|
174
|
+
const rawPath = optionalString(value.path);
|
|
175
|
+
const stateRoot =
|
|
176
|
+
rawPath !== undefined && /[\\/]sdk[\\/][^\\/]+\.json$/.test(rawPath)
|
|
177
|
+
? rawPath.replace(/[\\/]sdk[\\/][^\\/]+\.json$/, "")
|
|
178
|
+
: rawPath !== undefined
|
|
179
|
+
? rawPath.replace(/[\\/][^\\/]+\.json$/, "")
|
|
180
|
+
: "unknown";
|
|
181
|
+
const row: SdkSessionRowV1 = {
|
|
182
|
+
sessionId,
|
|
183
|
+
locator: { repo: "unknown", stateRoot },
|
|
184
|
+
endpointGeneration: 0,
|
|
185
|
+
pid,
|
|
186
|
+
live: !stale,
|
|
187
|
+
deleted: false,
|
|
188
|
+
indexSeq: 0,
|
|
189
|
+
};
|
|
190
|
+
return row;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function toCheckpointRecordV1(value: unknown): SdkCheckpointRecordV1 | undefined {
|
|
194
|
+
if (!isRecord(value)) return undefined;
|
|
195
|
+
const revision = value.revision;
|
|
196
|
+
const generation = value.generation;
|
|
197
|
+
const seq = value.seq;
|
|
198
|
+
if (
|
|
199
|
+
typeof revision !== "number" ||
|
|
200
|
+
!Number.isSafeInteger(revision) ||
|
|
201
|
+
revision < 0 ||
|
|
202
|
+
typeof generation !== "number" ||
|
|
203
|
+
!Number.isSafeInteger(generation) ||
|
|
204
|
+
generation < 0 ||
|
|
205
|
+
typeof seq !== "number" ||
|
|
206
|
+
!Number.isSafeInteger(seq) ||
|
|
207
|
+
seq < 0
|
|
208
|
+
)
|
|
209
|
+
return undefined;
|
|
210
|
+
return { revision, generation, seq };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function toRetentionGapV1(value: unknown): SdkRetentionGapV1 | undefined {
|
|
214
|
+
if (!isRecord(value) || value.code !== "retention_gap") return undefined;
|
|
215
|
+
const gap: SdkRetentionGapV1 = { code: "retention_gap" };
|
|
216
|
+
if (isRecord(value.missing)) {
|
|
217
|
+
const from = value.missing.from;
|
|
218
|
+
const to = value.missing.to;
|
|
219
|
+
if (typeof from === "number" && Number.isSafeInteger(from) && typeof to === "number" && Number.isSafeInteger(to))
|
|
220
|
+
gap.missing = { from, to };
|
|
221
|
+
}
|
|
222
|
+
const resync = toCheckpointRecordV1(value.resync);
|
|
223
|
+
if (resync !== undefined) gap.resync = resync;
|
|
224
|
+
return gap;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Projects a transcript entry or ring event into a tail item with dedupe keys. */
|
|
228
|
+
export function toTailItemV1(
|
|
229
|
+
value: unknown,
|
|
230
|
+
fallback: { kind: string; generation?: number; seq?: number },
|
|
231
|
+
): SdkTailItemV1 {
|
|
232
|
+
if (!isRecord(value)) return { kind: fallback.kind, payload: stripSecretFields(value) };
|
|
233
|
+
const kind = optionalString(value.kind) ?? fallback.kind;
|
|
234
|
+
const id = optionalString(value.id);
|
|
235
|
+
const payload = isRecord(value.payload) ? (value.payload as Record<string, unknown>) : value;
|
|
236
|
+
const payloadId = optionalString(payload.id);
|
|
237
|
+
const item: SdkTailItemV1 = {
|
|
238
|
+
kind,
|
|
239
|
+
...(payloadId !== undefined ? { id: payloadId } : id !== undefined ? { id } : {}),
|
|
240
|
+
...(typeof value.generation === "number" ? { generation: value.generation } : {}),
|
|
241
|
+
...(typeof value.seq === "number" ? { seq: value.seq } : {}),
|
|
242
|
+
payload: stripSecretFields(payload),
|
|
243
|
+
};
|
|
244
|
+
if (fallback.generation !== undefined && item.generation === undefined) item.generation = fallback.generation;
|
|
245
|
+
if (fallback.seq !== undefined && item.seq === undefined) item.seq = fallback.seq;
|
|
246
|
+
return item;
|
|
247
|
+
}
|