jg-agent-hq 13.3.2 → 13.4.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 +5 -0
- package/README.md +1 -1
- package/api/README.md +3 -1
- package/dist/runtime/runtime.d.ts +2 -1
- package/dist/runtime/runtime.js +3 -1
- package/dist/runtime/types.d.ts +1 -0
- package/dist/runtime/types.js +7 -0
- package/docs/recovery.md +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 13.4.0
|
|
4
|
+
|
|
5
|
+
- Add the optional trusted Node `initializeHostStorage` startup callback for host schema preparation under exclusive ownership, before providers, native rejoin or request admission start. Callback errors retain their identity through startup cleanup; hosts own their SQL transaction and connection.
|
|
6
|
+
- Preserve running Codex turns, native schema 12.0.1, action keys and the existing active-execution refusal for live storage maintenance. No input is replayed by initialization.
|
|
7
|
+
|
|
3
8
|
## 13.3.2
|
|
4
9
|
|
|
5
10
|
- Keep Claude's model-setting and local-command user replays from starting phantom turns. Only the exact pending input replay acknowledges an HQ turn; autonomous turns start on model output. Settings notices remain available in saved native history.
|
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ The controller owns its SQLite worker and native connections independently of cl
|
|
|
55
55
|
|
|
56
56
|
Use `session-evidence` for newest-first historical evidence. It fits within 65,536 serialized bytes, retains exact native identities and content hashes, and continues large bodies in UTF-8 chunks. Select an item, turn or item kinds with filters. Provenance distinguishes native evidence from exact host submissions; historical text and quoted feedback never grant approval. See [bounded session evidence](api/README.md#bounded-session-evidence).
|
|
57
57
|
|
|
58
|
-
Trusted Node hosts can open the database described by `hq.storage` with `openHostDatabase(hq.storage)`, which applies the required connection settings, and keep application tables under their own prefix; the connection can't change the runtime's tables. jg-agent-hq reserves `agent_hq_`, validates its current schema stamp on startup, and leaves application schema ownership and `user_version` with the host.
|
|
58
|
+
Trusted Node hosts can open the database described by `hq.storage` with `openHostDatabase(hq.storage)`, which applies the required connection settings, and keep application tables under their own prefix; the connection can't change the runtime's tables. jg-agent-hq reserves `agent_hq_`, validates its current schema stamp on startup, and leaves application schema ownership and `user_version` with the host. Pass `initializeHostStorage` to `createAgentHq` for host schema preparation under exclusive runtime ownership, before native providers reconnect or requests are admitted. For later host schema changes, use `hq.withStorageMaintenance(callback)`, which drains admitted work and rejects active native execution. Both callbacks own their connections and transactional rollback. The stamp records the package version that wrote the database, and startup refuses any other schema with an error naming that version; jg-agent-hq never migrates storage. See the [shared storage contract](api/README.md#shared-storage).
|
|
59
59
|
|
|
60
60
|
`hq.createSnapshot(destination)` captures local state through SQLite's backup API while agents keep working, including host tables and action.key, under the state root's `snapshot` lock; the host keeps its own connections from writing host tables until it resolves. It leaves out the index of Claude transcripts, which a restored runtime rebuilds from the transcripts on its first Claude history read, as a fresh one does. `restoreHqSnapshot({ snapshotDirectory, destination })` verifies the complete snapshot and stages it into a new private recovery workspace. `packHqSnapshot(snapshotDirectory, archivePath, key)` encrypts a snapshot into one AES-256-GCM file for off-machine copies, and `unpackHqSnapshot(archivePath, destination, key)` verifies and writes it back as a snapshot directory. Snapshots from another schema are refused by the package version that wrote them. Restored native ownership needs reconciliation and allowed roots must be selected explicitly. Hosts own the key and remote backups; a failed disk can lose changes since the last successful off-machine backup. See [snapshot and restore](api/README.md#snapshot-and-restore) and [recovery](docs/recovery.md).
|
|
61
61
|
|
package/api/README.md
CHANGED
|
@@ -42,6 +42,8 @@ A holder whose process is gone is never taken over automatically, because the pr
|
|
|
42
42
|
|
|
43
43
|
## Shared storage
|
|
44
44
|
|
|
45
|
+
Trusted Node hosts may pass `initializeHostStorage: IStorageMaintenanceOperation<void>` to `createAgentHq`. Startup awaits this optional callback exactly once after acquiring exclusive runtime ownership and opening the validated SQLite worker, before constructing providers, observing Claude, creating action controllers, admitting IPC or reconnecting native sessions. It receives an independent storage descriptor. A retained Codex turn may keep running in its independent daemon during this phase; the new runtime has no native connection or event writer yet. The host must coordinate its other writers, use its own transaction and close its connection before returning. It must not start native work or call runtime APIs. Callback errors propagate unchanged after startup closes its store and releases ownership; SQL rollback remains the host's responsibility. A failed callback never starts providers or IPC. This option is absent from CLI, IPC and browser contracts. It does not change the live maintenance guard below or migrate native storage.
|
|
46
|
+
|
|
45
47
|
`hq.storage` returns an independent `IStorageDescriptor` containing the canonical `databasePath`, `schemaHash`, `reservedPrefix` (`agent_hq_`), and required `connectionSettings`: `foreignKeys` true, `busyTimeoutMs` 5000, `journalMode` wal, `synchronous` full, and `journalSizeLimitBytes` 16,777,216. Exported Node types are `IStorageDescriptor` and `IStorageMaintenanceOperation<T>`. No database handle, storage callback, raw SQL command or storage path is exposed by browser contracts or IPC.
|
|
46
48
|
|
|
47
49
|
`openHostDatabase(storage)` opens a node:sqlite `DatabaseSync` connection to `storage.databasePath` with every setting the descriptor names: foreign keys, the 5,000 ms busy timeout, FULL synchronization and the 16 MiB `journal_size_limit`, which SQLite applies only on the connection whose write starts the WAL over. The host owns the connection and closes it. The connection reads the runtime's tables but can't change them: SQLite refuses with its `not authorized` error a statement that writes rows of a table under the reserved prefix, or creates, alters or drops a table, index, trigger or view under it or on such a table. It fails with JG_AGENT_HQ_STORE_FAILED when the database can't be opened. Keep WAL mode; do not change database-wide settings while the runtime is running. Hosts own their table prefix, definitions, connection lifetime and user_version. The runtime's tables and indexes are reserved. A nonempty database requires the current singleton agent_hq_schema stamp, which records the schema hash, the SHA-256 fingerprint of action.key and the package version that wrote the database. Startup rejects any other schema with JG_AGENT_HQ_STORAGE_INVALID before opening a writer; its message names that package version, or reports another jg-agent-hq version when the stamp records none. Rejected storage remains unchanged. A different valid-length key fails with JG_AGENT_HQ_ACTION_KEY_UNAVAILABLE before a writer opens. Fresh initialization is transactional.
|
|
@@ -87,7 +89,7 @@ Native snapshot qualification on 2026-10-23 used Codex 0.164.0 (gpt-6.1-sol) and
|
|
|
87
89
|
|
|
88
90
|
`createAgentHq({ stateRoot, allowedRoots })` starts one controller and returns `IAgentHq`: its canonical `stateRoot`, its `runtimeEpoch`, which `status` also reports and every action envelope names, a `closed` lifetime promise, `request(command)`, idempotent `close()`, a trusted Node-only `storage` descriptor, `withStorageMaintenance(callback)` and `createSnapshot(destination)`. `request` resolves to the response of its command's kind, typed as `IHqResponseOf<kind>` from `jg-agent-hq/contracts`, so `request({ kind: 'threads', ... })` resolves to `{ kind: 'threads', result: IThreadsPage }` without a cast. Paths must be absolute. Allowed roots must exist and are canonicalized at startup. A client-selected workspace must resolve inside an allowed root. State is a real directory owned by the current OS user with no group/other access. The controller creates it privately when absent.
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
After optional `initializeHostStorage` completes, the runtime connects both native CLIs in the background, without waiting for their readiness or failing startup when they are unavailable: it connects to Codex's daemon, which also starts observing the sessions Codex runs, and brings Claude's history index up to date for the allowed roots and the folders the index already holds, at most 128 of them by latest activity, one folder at a time. A CLI that is missing or fails reports `unavailable` in `status`, as its first request would have made it; `status` reports a CLI that is still starting `idle`. Indexing waits while host maintenance holds the store, and closing the runtime stops the warm-up, including a CLI start that never answers.
|
|
91
93
|
|
|
92
94
|
The controller holds the state root's `runtime` lock for its lifetime, as [lock lifecycle](#lock-lifecycle) describes. A live, dead, incomplete or unverifiable existing holder prevents another controller from starting, apart from a dead holder the host's `isPreviousRuntimeStopped` check proves stopped. Before deliberate recovery, establish that the inspected host, its worker and native process group have stopped. Runtime shutdown sends interruption requests across the bounded Claude session cohort concurrently, then closes IPC connections, SQLite and owned native processes before releasing the `runtime` lock. Failed cleanup keeps the lock held. A new runtime receives a new epoch.
|
|
93
95
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type IAgentHq, type IAgentHqOptions } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Starts one local controller with private IPC, a SQLite worker and native providers, which it
|
|
4
|
-
* connects in the background without waiting for them.
|
|
4
|
+
* connects in the background without waiting for them. Optional host storage initialization
|
|
5
|
+
* finishes before providers or admission start; its errors propagate unchanged after cleanup.
|
|
5
6
|
* @returns The owned runtime. Client disconnects do not close it.
|
|
6
7
|
* @throws
|
|
7
8
|
* - JG_AGENT_HQ_REQUEST_INVALID: The HQ request is invalid
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -22,7 +22,8 @@ import { createAsyncInputs } from './async-inputs/index.js';
|
|
|
22
22
|
import { AgentHqOptionsSchema } from './types.js';
|
|
23
23
|
/**
|
|
24
24
|
* Starts one local controller with private IPC, a SQLite worker and native providers, which it
|
|
25
|
-
* connects in the background without waiting for them.
|
|
25
|
+
* connects in the background without waiting for them. Optional host storage initialization
|
|
26
|
+
* finishes before providers or admission start; its errors propagate unchanged after cleanup.
|
|
26
27
|
* @returns The owned runtime. Client disconnects do not close it.
|
|
27
28
|
* @throws
|
|
28
29
|
* - JG_AGENT_HQ_REQUEST_INVALID: The HQ request is invalid
|
|
@@ -72,6 +73,7 @@ export const createAgentHq = async (options) => {
|
|
|
72
73
|
const databasePath = await prepareDatabase(stateRoot);
|
|
73
74
|
actionKey = await prepareActionKey(stateRoot, databasePath);
|
|
74
75
|
store = await createStore(databasePath, ownership.epoch, actionKey);
|
|
76
|
+
await parsed.data.initializeHostStorage?.(structuredClone(store.storage));
|
|
75
77
|
registry = createProviderRegistry([
|
|
76
78
|
createCodexProviderFactory(codexExtraSkillRoots, parsed.data.codexDaemonLauncher ?? []),
|
|
77
79
|
createClaudeProviderFactory(store, claudeAdditionalDirectories),
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const AgentHqOptionsSchema: z.ZodObject<{
|
|
|
9
9
|
codexExtraSkillRoots: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
10
10
|
codexDaemonLauncher: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
11
|
claudeAdditionalDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
12
|
+
initializeHostStorage: z.ZodOptional<z.ZodCustom<IStorageMaintenanceOperation<void>, IStorageMaintenanceOperation<void>>>;
|
|
12
13
|
isPreviousRuntimeStopped: z.ZodOptional<z.ZodCustom<IPreviousRuntimeCheck, IPreviousRuntimeCheck>>;
|
|
13
14
|
}, z.core.$strict>;
|
|
14
15
|
export type IAgentHqOptions = z.infer<typeof AgentHqOptionsSchema>;
|
package/dist/runtime/types.js
CHANGED
|
@@ -8,6 +8,13 @@ export const AgentHqOptionsSchema = z.strictObject({
|
|
|
8
8
|
// a command and its arguments run before `codex app-server daemon start`, such as a new scope
|
|
9
9
|
codexDaemonLauncher: z.array(z.string().min(1)).min(1).max(16).optional(),
|
|
10
10
|
claudeAdditionalDirectories: z.array(z.string().min(1).refine(isAbsolute)).max(128).optional(),
|
|
11
|
+
/*
|
|
12
|
+
* Runs under exclusive runtime ownership after storage opens, before providers or IPC start.
|
|
13
|
+
* The host owns its connection and rollback; errors propagate unchanged through startup cleanup.
|
|
14
|
+
*/
|
|
15
|
+
initializeHostStorage: z
|
|
16
|
+
.custom((input) => typeof input === 'function')
|
|
17
|
+
.optional(),
|
|
11
18
|
/*
|
|
12
19
|
* Proves no process of a runtime that stopped without releasing the state root remains, which
|
|
13
20
|
* lets startup take its runtime lock over and clear the snapshot lock and socket it left.
|
package/docs/recovery.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Snapshot recovery
|
|
2
2
|
|
|
3
|
+
Hosts can prepare their own supported schema through `initializeHostStorage` before native rejoin, including when a retained Codex turn still runs. This startup phase does not alter native schema compatibility, authorize snapshot rollback, or permit changing reserved runtime tables. A rejected host initialization closes startup resources; the host must roll back its SQL transaction and close its connection. Existing live maintenance still refuses active native execution.
|
|
4
|
+
|
|
3
5
|
The runtime supplies local capture, encrypted packing and offline restore primitives, each of which inspects the complete snapshot. The Node signatures and inventory contract live in [the API reference](../api/README.md#snapshot-and-restore).
|
|
4
6
|
|
|
5
7
|
## Capture
|
package/package.json
CHANGED