jg-agent-hq 10.9.2 → 11.0.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 +12 -0
- package/README.md +1 -1
- package/api/README.md +27 -26
- package/dist/actions/actions.d.ts +1 -1
- package/dist/actions/actions.js +58 -1
- package/dist/actions/live/live.d.ts +7 -0
- package/dist/actions/live/live.js +15 -0
- package/dist/cli/cli.js +1 -0
- package/dist/contracts/types.d.ts +6 -2
- package/dist/contracts/types.js +4 -1
- package/dist/providers/claude/adapter.js +4 -2
- package/dist/providers/claude/claude.d.ts +16 -2
- package/dist/providers/claude/claude.js +22 -3
- package/dist/providers/claude/control/index.d.ts +1 -0
- package/dist/providers/claude/control/index.js +2 -0
- package/dist/providers/claude/rpc.d.ts +7 -2
- package/dist/providers/claude/rpc.js +6 -4
- package/dist/providers/codex/adapter.js +1 -1
- package/dist/providers/registry/registry.js +2 -2
- package/dist/providers/types.d.ts +5 -2
- package/dist/runtime/runtime.js +14 -2
- package/dist/skills/skills.d.ts +7 -4
- package/dist/skills/skills.js +44 -23
- package/dist/store/types.d.ts +6 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 11.0.0
|
|
4
|
+
|
|
5
|
+
- Read the skill catalog of a folder without a session. `skills` now takes `provider` and `workspaceRoot`, with `threadId` optional: with it, the request reads that controlled session's catalog as before, and refuses a session of another provider or folder with JG_AGENT_HQ_REQUEST_INVALID; without it, the request reads the catalog a session started in the folder would have. Codex lists the folder, and Claude reads the initialization command list of a session-less read process started there, without a user prompt or model turn. A skill has the same ID in both catalogs, so a folder's catalog can pick a skill for a session's first input.
|
|
6
|
+
- Breaking: a `skills` request must name `provider` and `workspaceRoot`; one with only `threadId` is invalid. The CLI's `skills` takes `--workspace-root`, with `--provider` defaulting to `codex` and `--thread-id` optional.
|
|
7
|
+
- Breaking: `IAgentProvider.readSkills` takes `(workspaceRoot, nativeId, call)`, with `nativeId` undefined for a folder's inventory, in the order `readConfiguration` uses.
|
|
8
|
+
- Start every folder-scoped Claude read process, configuration reads included, with the trusted additional directories sessions get, so a folder read sees the commands a session there sees.
|
|
9
|
+
- Store nothing new: the schema and existing databases are unchanged.
|
|
10
|
+
|
|
11
|
+
## 10.9.3
|
|
12
|
+
|
|
13
|
+
- Clear a finished turn's saved items from the live window without waiting on a client's history read. A saved item used to stay `awaiting-flush` until some `items` read happened to cover it, so a session nobody read while it worked kept its items, and a client that read only its newest pages later showed them after the newest items. When a turn ends, the runtime now reads that turn's history itself, newest first and at most 8 pages of 128, until none of its finished items remain, and once more 2 seconds later when some do, since Codex's saved state can trail its turn's end. A failed read leaves them to the next history read, as before.
|
|
14
|
+
|
|
3
15
|
## 10.9.2
|
|
4
16
|
|
|
5
17
|
- Read a Claude transcript whose compaction names a record the transcript doesn't hold before the boundary. Such a transcript was refused whole, its history unavailable and its `thread` read failing: a chat Claude Code moved into a new session, whose boundary names the old session's record, and a transcript whose boundary named a record written after it. The chain now starts at that boundary. Every Claude history is indexed again once, so the transcripts refused before are read.
|
package/README.md
CHANGED
|
@@ -85,7 +85,7 @@ Text and skill inputs can attach up to 8 workspace files by path and media type,
|
|
|
85
85
|
|
|
86
86
|
Use `suggest-thread-name --topic "Build usage" --state-root <directory>` for an editable label and `managed-thread-name --name build-usage --state-root <directory>` to resolve it. Creation adds a short ordinal suffix when a name is occupied. Actions and relationships retain immutable IDs.
|
|
87
87
|
|
|
88
|
-
Use `skills --
|
|
88
|
+
Use `skills --workspace-root <directory> --state-root <directory>` to browse the native skill catalog a session started in that folder would have, with `--provider` (default `codex`), and add `--thread-id <id>` for a controlled session's own catalog. `skill-preview --thread-id <id> --skill-id <id> --arguments "auto exact-plan" --state-root <directory>` shows the exact invocation without sending it. Missing native metadata is explicitly unavailable. The CLI loads all skill content and retains its permissions and invocation rules.
|
|
89
89
|
|
|
90
90
|
Use `jg-agent-hq request --state-root <directory>` with a closed HQ command on stdin for action and control reads. The [API reference](api/README.md) describes action envelopes, receipts and reconnect reads.
|
|
91
91
|
|
package/api/README.md
CHANGED
|
@@ -129,28 +129,29 @@ Third-party adapter failures use JG_AGENT_HQ_PROVIDER_FAILED, retaining safe dia
|
|
|
129
129
|
|
|
130
130
|
Import `HqRequestSchema`, `HqResponseSchema` and their inferred types from `jg-agent-hq/contracts`. Requests are closed contracts. Responses tolerate additive fields. Provider fields use `ProviderIdSchema`, a bounded lowercase identifier. `codex` and `claude` are built in; trusted Node factories can add providers. Status returns a bounded `providers` array of `{ provider, state, version }`, where state is `idle`, `ready` or `unavailable`. Reading status does not start a provider. The diagnostic version/user-agent string may be null and never decides compatibility.
|
|
131
131
|
|
|
132
|
-
| Command | Required fields | Result
|
|
133
|
-
| ----------------------------- | -------------------------------------------------------- |
|
|
134
|
-
| `status` | None | Runtime epoch, host PID, start time, worker availability and native transport availability
|
|
135
|
-
| `capabilities` | `provider`; optional managed `threadId` | Provider/session-scoped support, input/configuration schemas and unavailable reasons
|
|
136
|
-
| `models` | `provider` | Paged native model identities, effort choices, fast support and defaults when observed
|
|
137
|
-
| `configuration` | `provider`, `workspaceRoot`; optional managed `threadId` | Known effective native settings and paged agent/profile choices
|
|
138
|
-
| `
|
|
139
|
-
| `
|
|
140
|
-
| `
|
|
141
|
-
| `
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
144
|
-
| `
|
|
145
|
-
| `item-
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `mcp-
|
|
150
|
-
| `
|
|
151
|
-
| `
|
|
152
|
-
| `
|
|
153
|
-
| `
|
|
132
|
+
| Command | Required fields | Result |
|
|
133
|
+
| ----------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
134
|
+
| `status` | None | Runtime epoch, host PID, start time, worker availability and native transport availability |
|
|
135
|
+
| `capabilities` | `provider`; optional managed `threadId` | Provider/session-scoped support, input/configuration schemas and unavailable reasons |
|
|
136
|
+
| `models` | `provider` | Paged native model identities, effort choices, fast support and defaults when observed |
|
|
137
|
+
| `configuration` | `provider`, `workspaceRoot`; optional managed `threadId` | Known effective native settings and paged agent/profile choices |
|
|
138
|
+
| `skills` | `provider`, `workspaceRoot`; optional managed `threadId` | The paged native skill catalog of the session, or of the folder; see [Native skill catalog](#native-skill-catalog) |
|
|
139
|
+
| `stop` | None | Accepted shutdown and runtime epoch |
|
|
140
|
+
| `threads` | `provider`, `workspaceRoot` | Paged native discovery; optional `search` |
|
|
141
|
+
| `sessions` | `provider`, `workspaceRoot` | Byte-bounded discovery with exact IDs; optional `search` |
|
|
142
|
+
| `thread` | `provider`, `workspaceRoot`, `nativeId` | One native thread's metadata |
|
|
143
|
+
| `turns` | Same target fields | Paged native turn metadata without hydrating items |
|
|
144
|
+
| `items` | Same target fields | Newest-first persisted native items; optional `turnId`, `textLimit` and `nativeItemId` |
|
|
145
|
+
| `item-detail` | Same target fields, `turnId`, `nativeItemId` | One item with its command, tool call, file diffs and images, or null |
|
|
146
|
+
| `item-image` | Same target fields, `turnId`, `nativeItemId`, `index` | One image of an item as `{ mediaType, data }`, its bytes in base64 |
|
|
147
|
+
| `session-evidence` | Same target fields | Newest-first bounded evidence, exact references and full normalized text continuation |
|
|
148
|
+
| `account` | `provider` | Safe native account metadata with explicit unavailable observations |
|
|
149
|
+
| `mcp-servers` | Managed `threadId` | Paged configured native MCP server identity, connection and auth metadata |
|
|
150
|
+
| `mcp-tools` / `mcp-resources` | Managed `threadId`, `serverName` | Paged native descriptions; no resource content is fetched |
|
|
151
|
+
| `provider-actions` | `provider` | Paged global action metadata, including authentication receipts |
|
|
152
|
+
| `login` | `actionId` | Live authentication presentation or known terminal state |
|
|
153
|
+
| `usage` | `provider` | Actual subscription observations |
|
|
154
|
+
| `locks` | None | The machine's jg-locks locks and their holders; see [machine locks](#machine-locks) |
|
|
154
155
|
|
|
155
156
|
Paged commands accept `limit` (default 32, maximum 128) and an opaque `cursor`. Continue with exactly the same command, target, filters and limit. The cursor binds those fields to the provider continuation. Codex requests threads by last activity (`updated_at`), descending, with descending turns and descending items. Claude orders discovery by last activity, the later of a transcript's modification time and its newest record, then native UUID, descending, turns by native chain position ascending and items by native chain position descending. Workspace authorization is rechecked for each request, independently of cursor validation, before selected-thread items are fetched.
|
|
156
157
|
|
|
@@ -311,15 +312,15 @@ Partial text uses temporary live identities until the final native message UUID
|
|
|
311
312
|
|
|
312
313
|
## Native skill catalog
|
|
313
314
|
|
|
314
|
-
`skills` accepts `threadId`, optional `search`, `limit` (default 32, maximum 128) and `cursor`.
|
|
315
|
+
`skills` accepts `provider`, `workspaceRoot`, an optional managed `threadId`, optional `search`, `limit` (default 32, maximum 128) and `cursor`. The folder must be inside the allowed roots. With `threadId` it reads that controlled session's catalog, and the session must run for that provider in that folder, or the request fails with JG_AGENT_HQ_REQUEST_INVALID; it never adopts or resumes an external session. Without `threadId` it reads the catalog a session started in the folder would have, with no session: Codex lists the folder, and Claude starts a session-less read process there with the trusted additional directories, reads its initialization command list and closes it, without a user prompt or model turn. A skill's ID is derived from its provider, name and path, so a folder's catalog and a session started there give the same skill the same ID while the skills don't change, and an ID from the folder's catalog can name a skill for that session's input. Codex uses native `skills/list` for the workspace, plus the skills in the operator's Codex extra roots; Claude uses the native initialization command list, which includes explicit-only skills. Its refresh endpoint omits those skills, so HQ does not use it. Close and explicitly resume the session to refresh Claude's catalog. Inactive or unsupported sessions report `unavailable`, with no successful-empty fallback. Native discovery errors produce `partial` and an `unavailableCount`. `observedAt` records when the native inventory was observed; it stays fixed for a Claude session and is null when unavailable. `invocationPrefix` is the text that starts a skill invocation in the provider's native input, `/` for Claude and `$` for Codex, and is null when unavailable; a provider adapter supplies it with its inventory in `IProviderSkills`, from `readSkills(workspaceRoot, nativeId, call)`, which reads the folder's inventory when `nativeId` is undefined.
|
|
315
316
|
|
|
316
317
|
Rows contain an opaque `id`, native `name`, `description`, nullable `argumentHint`, `kind`, `path`, `scope`, `prerequisites` and `requiresExplicitInvocation`, plus native availability as `isEnabled`. Codex supplies skill identity, source/scope, enabled state and declared tool prerequisites. Claude supplies native command names, descriptions, argument hints and a built-in marker when available. Missing fields are null or `kind: 'unavailable'`; HQ does not inspect skill files to infer them. The one exception is Codex extra roots, which native discovery does not list: HQ reads each skill's single-line `name` and `description` frontmatter from `<root>/<directory>/SKILL.md`, reports it with scope `host`, skips linked directories and files, and counts unreadable entries in `unavailableCount`. A native skill with the same name takes precedence. Declared prerequisites are metadata, not proof that an integration is connected. Invocation rules remain with the CLI, including explicit-only skills.
|
|
317
318
|
|
|
318
|
-
Both native inventory interfaces are unpaged. HQ accepts at most 4,096 native rows and 1 MiB of normalized catalog metadata per read, then provides stable ID seek pages guarded by the complete inventory revision and query. A changed inventory invalidates continuation. Only metadata is read, never skill bodies or complete conversation histories. Concurrent reads
|
|
319
|
+
Both native inventory interfaces are unpaged. HQ accepts at most 4,096 native rows and 1 MiB of normalized catalog metadata per read, then provides stable ID seek pages guarded by the complete inventory revision and query. A changed inventory invalidates continuation. Only metadata is read, never skill bodies or complete conversation histories. Concurrent reads of the same session, or of the same provider's folder, share their in-flight native request; Codex results are not retained as an HQ cache. Claude's native initialization metadata remains attached to its owned connection until that session closes. Native refresh and discovery caches remain provider-owned.
|
|
319
320
|
|
|
320
321
|
`skill-preview` accepts `threadId`, `skillId` and `arguments`. Its result is `ready`, `missing`, `disabled` or `unavailable`, with the selected metadata and exact text only when ready. Codex previews `$name arguments` and receives an explicit native skill selection containing its native name/path alongside that text. Claude previews `/name arguments` and performs native slash-command loading. Native same-name precedence applies. Preview never sends user input. Explicit message and queue actions share the established action ledger, ownership checks and delivery/uncertainty rules. They grant no tool permissions and do not expand the invoked workflow's authority.
|
|
321
322
|
|
|
322
|
-
Trusted runtime construction also accepts `codexExtraSkillRoots?: string[]` and `claudeAdditionalDirectories?: string[]`. Paths must resolve to existing absolute directories. Codex receives them as capability roots of each thread HQ starts, so other sessions on the shared daemon, including terminal sessions, never see them. Forks inherit them. A session Codex later reloads from disk loses native discovery of those skills, while explicit invocation through the HQ catalog still works, because it names the skill file. Claude
|
|
323
|
+
Trusted runtime construction also accepts `codexExtraSkillRoots?: string[]` and `claudeAdditionalDirectories?: string[]`. Paths must resolve to existing absolute directories. Codex receives them as capability roots of each thread HQ starts, so other sessions on the shared daemon, including terminal sessions, never see them. Forks inherit them. A session Codex later reloads from disk loses native discovery of those skills, while explicit invocation through the HQ catalog still works, because it names the skill file. Claude sessions and every folder-scoped read process receive native `--add-dir` arguments, which also grant native file access to those directories. These inputs belong to the operator and cannot be changed through IPC commands. The installed `serve` command exposes repeated `--codex-extra-skill-root` and `--claude-additional-directory` flags. No global skill installation or coding-instruction change is performed.
|
|
323
324
|
|
|
324
325
|
`codexDaemonLauncher?: string[]`, also trusted, names a command and its arguments that run `codex app-server daemon start`, such as `['systemd-run', '--user', '--scope', '--quiet', '--collect']`. HQ runs the start through it, while the proxy still runs directly. Codex's daemon detaches into its own session, but on Linux it stays in the cgroup of whatever started it, so a host that runs as a systemd service and starts the daemon itself would take the daemon, and the work of every terminal session on it, down whenever the service stops. A new scope gives the daemon a lifetime of its own. The installed `serve` command doesn't expose it.
|
|
325
326
|
|
|
@@ -346,7 +347,7 @@ The installed CLI exposes `managed-thread-name --name <name>` and `suggest-threa
|
|
|
346
347
|
|
|
347
348
|
Control pages default to 32 and cap at 128. Seek cursors are bound to their complete query and ordering. Reads recheck allowed workspaces. Rejected controls retain their known thread association, and native availability failures appear in each affected thread's replay. Lifecycle replay contains metadata, not token or tool output. Each provider has a bounded native lifecycle backlog; overflow stops that source and marks its state uncertain rather than losing events silently. Other providers retain their independent connection and admission state.
|
|
348
349
|
|
|
349
|
-
Live item presentation is bounded to 128 items per cached thread, 32 windows and 4 MiB of serialized presentation across the runtime, including escaped text and identifiers. This leaves room inside the IPC response limit. Display text uses the same truncation contract as native history. Eviction, an unavailable window or missing chunks sets `hasGap`. Completed items remain `awaiting-flush` after thread closure until a native history page holds the same item, with exactly matching normalized content or, for an item with an outcome, the same final outcome, or the bounded cache evicts them. The outcome is enough because Codex shortens long command output when it saves it. An item still streaming when its turn ended, such as a message an interrupt or a Codex steer cut, stays `awaiting-flush` until a native history page holds an item of that turn, since the provider may never save it; the history then shows what was saved of it. Read persisted history and the live window together after reconnect; a process restart cannot reconstruct unflushed in-memory content.
|
|
350
|
+
Live item presentation is bounded to 128 items per cached thread, 32 windows and 4 MiB of serialized presentation across the runtime, including escaped text and identifiers. This leaves room inside the IPC response limit. Display text uses the same truncation contract as native history. Eviction, an unavailable window or missing chunks sets `hasGap`. Completed items remain `awaiting-flush` after thread closure until a native history page holds the same item, with exactly matching normalized content or, for an item with an outcome, the same final outcome, or the bounded cache evicts them. The outcome is enough because Codex shortens long command output when it saves it. An item still streaming when its turn ended, such as a message an interrupt or a Codex steer cut, stays `awaiting-flush` until a native history page holds an item of that turn, since the provider may never save it; the history then shows what was saved of it. A client's `items` read is one such page, and when a turn ends the runtime reads that turn's own history too, newest first and at most 8 pages of 128, until none of its finished items remain, so the window doesn't wait on a client that never reads them. Codex's saved state can trail its turn's end, so a turn whose items remain is read once more 2 seconds later; a failed read leaves them to the next history read. A client that shows live items should therefore expect them to leave the window before its own history read holds them. Read persisted history and the live window together after reconnect; a process restart cannot reconstruct unflushed in-memory content.
|
|
350
351
|
|
|
351
352
|
Items expose only normalized presentation fields, and one mapping per provider presents `items`, live items and `session-evidence` alike, as the provider's CLI shows them. Kinds are `user-message`, `agent-message`, `command`, `tool`, `file-change`, `notice` and `unsupported`. `callId` pairs a tool call with its result, or is null. `outcome` is `succeeded`, `failed`, or null when unknown or still running. `files` lists each file a file change touched, at most 128, with its added and removed lines, and is empty on other items. `outcome` and `files` come from the full native record, so `textLimit` never changes them. Unknown native kinds report `unsupported` without copying arbitrary payloads. Display text is bounded to 65,536 UTF-16 code units without splitting a surrogate pair; `isTruncated` reports omissions. An unsupported or oversized native transport frame fails explicitly. `createdAt` is the item's time in Unix milliseconds, or null when the provider records none. A Claude item takes its record's `timestamp`, and a live one the time its frame arrived. A Codex item takes its turn's times, which Codex records across all of its history: an operator message takes its turn's start and every other item its turn's end, or its start while the turn runs. A Codex history page reads the turns of its items newest first, 128 at a time and at most 8 times, so a recent page takes one read and an item whose turn lies further back has no time. A live Codex item takes its running turn's start.
|
|
352
353
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IActionEnvelope, type IActionReceipt, type INativeApproval, type INativeApprovalSummary, type ILoginObservation, type ISessionTerminal } from '../contracts/index.js';
|
|
2
2
|
import { type createProviderRegistry } from '../providers/registry/index.js';
|
|
3
3
|
import type { createSkills } from '../skills/index.js';
|
|
4
4
|
import type { IStore } from '../store/index.js';
|
package/dist/actions/actions.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHmac, randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { Exception, extractMessage, isException } from 'jg-exception';
|
|
3
3
|
import { delay } from 'jg-utilities';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
+
import { MAX_ITEM_TEXT_LENGTH, MAX_PAGE_SIZE, } from '../contracts/index.js';
|
|
5
6
|
import { getErrorKind } from '../errors/index.js';
|
|
6
7
|
import { retainNativeLineage, readInputFiles } from '../providers/index.js';
|
|
7
8
|
import { capabilityUnavailable } from '../providers/registry/index.js';
|
|
@@ -14,6 +15,8 @@ const ITEM_OBSERVATIONS = new Set([
|
|
|
14
15
|
'item-started',
|
|
15
16
|
'item-completed',
|
|
16
17
|
]);
|
|
18
|
+
// the most history pages of 128 items a finished turn's own read takes, as a Codex page reads turns
|
|
19
|
+
const TURN_FLUSH_PAGES = 8;
|
|
17
20
|
const NativeRejectionSchema = z.union([
|
|
18
21
|
z.object({ nativeCode: z.number() }),
|
|
19
22
|
z.object({ nativeRejection: z.literal(true) }),
|
|
@@ -458,9 +461,63 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
458
461
|
: { kind: 'uncertain', actionId: receipt.id, requestId: receipt.nativeRequestId });
|
|
459
462
|
}
|
|
460
463
|
};
|
|
464
|
+
// finished turns whose own history is being read, so a turn is read by one task at a time
|
|
465
|
+
const flushing = new Set();
|
|
466
|
+
/*
|
|
467
|
+
* A saved item leaves the live window only once a native history page holds it, and a client may
|
|
468
|
+
* never read the pages that do, so a finished turn's own history is read here, newest first,
|
|
469
|
+
* until none of its saved items remain. Codex's saved state can trail its turn's end, so a turn
|
|
470
|
+
* whose items remain is read once more after the re-check wait. An aborted wait or a failed read
|
|
471
|
+
* leaves them to the next history read, as before, and never fails the session's events.
|
|
472
|
+
*/
|
|
473
|
+
const flushTurn = (provider, nativeId, workspaceRoot, turnId) => {
|
|
474
|
+
const liveKey = key(provider, nativeId);
|
|
475
|
+
const flushKey = JSON.stringify([liveKey, turnId]);
|
|
476
|
+
if (flushing.has(flushKey))
|
|
477
|
+
return;
|
|
478
|
+
flushing.add(flushKey);
|
|
479
|
+
runOwned(async () => {
|
|
480
|
+
try {
|
|
481
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
482
|
+
if (attempt > 0)
|
|
483
|
+
await delay(RESYNC_REREAD_DELAY_SECONDS, { signal: resyncLifetime.signal });
|
|
484
|
+
const control = await registry.get(provider);
|
|
485
|
+
let cursor;
|
|
486
|
+
for (let page = 0; page < TURN_FLUSH_PAGES; page += 1) {
|
|
487
|
+
if (closing || !live.awaitsFlush(liveKey, turnId))
|
|
488
|
+
return;
|
|
489
|
+
const response = await control.readHistory({
|
|
490
|
+
kind: 'items',
|
|
491
|
+
provider,
|
|
492
|
+
workspaceRoot,
|
|
493
|
+
nativeId,
|
|
494
|
+
turnId,
|
|
495
|
+
limit: MAX_PAGE_SIZE,
|
|
496
|
+
cursor,
|
|
497
|
+
textLimit: MAX_ITEM_TEXT_LENGTH,
|
|
498
|
+
});
|
|
499
|
+
if (response.kind !== 'items')
|
|
500
|
+
return;
|
|
501
|
+
live.reconcile(liveKey, response.result.data);
|
|
502
|
+
if (response.result.nextCursor === null)
|
|
503
|
+
break;
|
|
504
|
+
cursor = response.result.nextCursor;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
catch {
|
|
509
|
+
// the items wait for the next history read
|
|
510
|
+
}
|
|
511
|
+
finally {
|
|
512
|
+
flushing.delete(flushKey);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
};
|
|
461
516
|
const observe = async (observation) => {
|
|
462
517
|
const result = await recordObservation(observation);
|
|
463
518
|
if (observation.kind === 'turn-completed') {
|
|
519
|
+
if (result.thread && controlled.has(key(observation.provider, observation.nativeThreadId)))
|
|
520
|
+
flushTurn(observation.provider, observation.nativeThreadId, result.thread.workspaceRoot, observation.nativeTurnId);
|
|
464
521
|
watched.delete(key(observation.provider, observation.nativeThreadId));
|
|
465
522
|
for (const [id, prompt] of prompts)
|
|
466
523
|
if (prompt.native.provider === observation.provider &&
|
|
@@ -487,7 +544,7 @@ export const createActions = (registry, store, roots, epoch, actionKey, skills,
|
|
|
487
544
|
live.completeTurn(key(provider, observation.nativeThreadId), observation.nativeTurnId);
|
|
488
545
|
enqueue(provider, () => observe(observation));
|
|
489
546
|
};
|
|
490
|
-
// ends the waits of delayed re-checks when the runtime closes
|
|
547
|
+
// ends the waits of delayed re-checks and turn reads when the runtime closes
|
|
491
548
|
const resyncLifetime = new AbortController();
|
|
492
549
|
/*
|
|
493
550
|
* Sessions a re-check after an unidentified loss left running, or skipped while an action was in
|
|
@@ -46,6 +46,13 @@ export declare class LiveItems {
|
|
|
46
46
|
* finished goes once persisted history holds that turn, which then shows what was saved of it.
|
|
47
47
|
*/
|
|
48
48
|
reconcile(nativeId: string, persisted: IHistoryItem[]): void;
|
|
49
|
+
/**
|
|
50
|
+
* Says whether a turn's window still holds a finished item no native history page has held.
|
|
51
|
+
* @param nativeId The session's key.
|
|
52
|
+
* @param turnId The native turn.
|
|
53
|
+
* @returns Whether such an item remains.
|
|
54
|
+
*/
|
|
55
|
+
awaitsFlush(nativeId: string, turnId: string): boolean;
|
|
49
56
|
/** Keeps a turn's partial items available until native history holds the turn. */
|
|
50
57
|
completeTurn(nativeId: string, turnId: string): void;
|
|
51
58
|
/** Releases one cached window when the bounded window collection must evict it. */
|
|
@@ -172,6 +172,21 @@ export class LiveItems {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Says whether a turn's window still holds a finished item no native history page has held.
|
|
177
|
+
* @param nativeId The session's key.
|
|
178
|
+
* @param turnId The native turn.
|
|
179
|
+
* @returns Whether such an item remains.
|
|
180
|
+
*/
|
|
181
|
+
awaitsFlush(nativeId, turnId) {
|
|
182
|
+
const thread = this.__threads.get(nativeId);
|
|
183
|
+
if (!thread)
|
|
184
|
+
return false;
|
|
185
|
+
for (const entry of thread.items.values())
|
|
186
|
+
if (entry.isComplete && entry.item.turnId === turnId)
|
|
187
|
+
return true;
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
175
190
|
/** Keeps a turn's partial items available until native history holds the turn. */
|
|
176
191
|
completeTurn(nativeId, turnId) {
|
|
177
192
|
const thread = this.__threads.get(nativeId);
|
package/dist/cli/cli.js
CHANGED
|
@@ -115,7 +115,9 @@ export declare const HqRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
115
115
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
116
116
|
cursor: z.ZodOptional<z.ZodString>;
|
|
117
117
|
kind: z.ZodLiteral<"skills">;
|
|
118
|
-
|
|
118
|
+
provider: z.ZodString;
|
|
119
|
+
workspaceRoot: z.ZodString;
|
|
120
|
+
threadId: z.ZodOptional<z.ZodUUID>;
|
|
119
121
|
search: z.ZodOptional<z.ZodString>;
|
|
120
122
|
}, z.core.$strict>, z.ZodObject<{
|
|
121
123
|
kind: z.ZodLiteral<"skill-preview">;
|
|
@@ -3322,7 +3324,9 @@ export declare const IpcRequestSchema: z.ZodObject<{
|
|
|
3322
3324
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
3323
3325
|
cursor: z.ZodOptional<z.ZodString>;
|
|
3324
3326
|
kind: z.ZodLiteral<"skills">;
|
|
3325
|
-
|
|
3327
|
+
provider: z.ZodString;
|
|
3328
|
+
workspaceRoot: z.ZodString;
|
|
3329
|
+
threadId: z.ZodOptional<z.ZodUUID>;
|
|
3326
3330
|
search: z.ZodOptional<z.ZodString>;
|
|
3327
3331
|
}, z.core.$strict>, z.ZodObject<{
|
|
3328
3332
|
kind: z.ZodLiteral<"skill-preview">;
|
package/dist/contracts/types.js
CHANGED
|
@@ -77,9 +77,12 @@ export const HqRequestSchema = z.discriminatedUnion('kind', [
|
|
|
77
77
|
.max(MAX_ITEM_IMAGES - 1),
|
|
78
78
|
}),
|
|
79
79
|
z.strictObject({ kind: z.literal('usage'), provider: TargetFields.provider }),
|
|
80
|
+
// a managed session's catalog with threadId, else the one a session started in the folder gets
|
|
80
81
|
z.strictObject({
|
|
81
82
|
kind: z.literal('skills'),
|
|
82
|
-
|
|
83
|
+
provider: TargetFields.provider,
|
|
84
|
+
workspaceRoot: TargetFields.workspaceRoot,
|
|
85
|
+
threadId: z.uuid().optional(),
|
|
83
86
|
search: z.string().max(1024).optional(),
|
|
84
87
|
...PageFields,
|
|
85
88
|
}),
|
|
@@ -14,7 +14,7 @@ import { createClaudeControl } from './control/index.js';
|
|
|
14
14
|
export const createClaudeProviderFactory = (store, additionalDirectories) => ({
|
|
15
15
|
id: 'claude',
|
|
16
16
|
async create(context) {
|
|
17
|
-
const reader = createClaudeProvider(store);
|
|
17
|
+
const reader = createClaudeProvider(store, additionalDirectories);
|
|
18
18
|
const authentication = createClaudeAuthentication();
|
|
19
19
|
const control = createClaudeControl(additionalDirectories);
|
|
20
20
|
control.setEvents(context.events);
|
|
@@ -241,7 +241,9 @@ export const createClaudeProviderFactory = (store, additionalDirectories) => ({
|
|
|
241
241
|
readMcpServers: (nativeId, limit, cursor) => control.readMcpServers(nativeId, limit, cursor),
|
|
242
242
|
readMcpTools: (nativeId, serverName) => control.readMcpTools(nativeId, serverName),
|
|
243
243
|
readMcpResources: (nativeId) => control.readMcpResources(nativeId),
|
|
244
|
-
readSkills: (nativeId) =>
|
|
244
|
+
readSkills: (workspaceRoot, nativeId, call) => nativeId === undefined
|
|
245
|
+
? reader.readWorkspaceSkills(workspaceRoot, call.signal)
|
|
246
|
+
: control.readSkills(nativeId),
|
|
245
247
|
formatSkill: (skill, argumentsText) => `/${skill.name}${argumentsText ? ` ${argumentsText}` : ''}`,
|
|
246
248
|
async startThread(requestId, workspaceRoot, settings, call) {
|
|
247
249
|
const result = await control.startThread(requestId, workspaceRoot, settings, call.signal);
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { IHqResponse, IUsageSnapshot, IProviderModelsRequest, IProviderModelPage, IConfigurationRequest } from '../../contracts/index.js';
|
|
2
2
|
import type { IStore } from '../../store/index.js';
|
|
3
3
|
import type { IHistoryRequest } from '../../sessions/index.js';
|
|
4
|
+
import type { IProviderSkills } from '../types.js';
|
|
4
5
|
/**
|
|
5
|
-
* Lazily connects read-only Claude capabilities; Codex needs no Claude installation.
|
|
6
|
+
* Lazily connects read-only Claude capabilities; Codex needs no Claude installation. A read in a
|
|
7
|
+
* folder starts with the additional directories sessions get.
|
|
8
|
+
* @param store The store transcript reads use.
|
|
9
|
+
* @param additionalDirectories The directories every session and folder read adds.
|
|
6
10
|
* @returns The read adapter with independent usage and transcript availability.
|
|
7
11
|
*/
|
|
8
|
-
export declare const createClaudeProvider: (store: IStore) => {
|
|
12
|
+
export declare const createClaudeProvider: (store: IStore, additionalDirectories: string[]) => {
|
|
9
13
|
/**
|
|
10
14
|
* Drops account-derived observations and the read connection after native sign-out.
|
|
11
15
|
* @returns Confirmation that subsequent observations use a fresh native connection.
|
|
@@ -70,6 +74,16 @@ export declare const createClaudeProvider: (store: IStore) => {
|
|
|
70
74
|
observedAt: number;
|
|
71
75
|
source: "native";
|
|
72
76
|
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Reads the commands a session started in the folder would list, explicit-only skills
|
|
79
|
+
* included, from a read lane with no user prompt or model turn.
|
|
80
|
+
* @returns The native inventory with unavailable fields left explicit; the lane is closed
|
|
81
|
+
* before returning.
|
|
82
|
+
* @throws
|
|
83
|
+
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
84
|
+
* - JG_AGENT_HQ_TRANSPORT_FAILED: The HQ transport failed
|
|
85
|
+
*/
|
|
86
|
+
readWorkspaceSkills(workspaceRoot: string, signal?: AbortSignal): Promise<IProviderSkills>;
|
|
73
87
|
/**
|
|
74
88
|
* Reads fresh native account metadata in a disposable read lane.
|
|
75
89
|
* @returns Safe account metadata after confirmed read-lane cleanup.
|
|
@@ -8,15 +8,19 @@ import { toClaudeUsageSnapshot } from './transformers.js';
|
|
|
8
8
|
import { readClaudeModels } from './models/index.js';
|
|
9
9
|
import { toClaudeConfiguration } from './configuration/index.js';
|
|
10
10
|
import { toClaudeAccount } from './accounts/index.js';
|
|
11
|
+
import { toClaudeSkills } from './control/index.js';
|
|
11
12
|
// the session-less read process closes after this long without a read, and reopens on the next one
|
|
12
13
|
const METADATA_IDLE_SECONDS = 300;
|
|
13
14
|
// a usage result read this recently answers the next read without asking Claude again
|
|
14
15
|
const USAGE_KEPT_MS = 60_000;
|
|
15
16
|
/**
|
|
16
|
-
* Lazily connects read-only Claude capabilities; Codex needs no Claude installation.
|
|
17
|
+
* Lazily connects read-only Claude capabilities; Codex needs no Claude installation. A read in a
|
|
18
|
+
* folder starts with the additional directories sessions get.
|
|
19
|
+
* @param store The store transcript reads use.
|
|
20
|
+
* @param additionalDirectories The directories every session and folder read adds.
|
|
17
21
|
* @returns The read adapter with independent usage and transcript availability.
|
|
18
22
|
*/
|
|
19
|
-
export const createClaudeProvider = (store) => {
|
|
23
|
+
export const createClaudeProvider = (store, additionalDirectories) => {
|
|
20
24
|
let connection;
|
|
21
25
|
let opening;
|
|
22
26
|
const metadataReads = new Set();
|
|
@@ -131,7 +135,7 @@ export const createClaudeProvider = (store) => {
|
|
|
131
135
|
code: 'JG_AGENT_HQ_CLAUDE_FAILED',
|
|
132
136
|
data: { kind: 'agent-unavailable' },
|
|
133
137
|
});
|
|
134
|
-
const starting = createClaudeRpc(() => { }, undefined, workspaceRoot, signal);
|
|
138
|
+
const starting = createClaudeRpc(() => { }, undefined, workspaceRoot === undefined ? undefined : { workspaceRoot, additionalDirectories }, signal);
|
|
135
139
|
metadataReads.add(starting);
|
|
136
140
|
let native;
|
|
137
141
|
let hasUnconfirmedStartup = false;
|
|
@@ -212,6 +216,21 @@ export const createClaudeProvider = (store) => {
|
|
|
212
216
|
async readConfiguration(command, signal) {
|
|
213
217
|
return withReadConnection(command.workspaceRoot, signal, async (native) => toClaudeConfiguration(await native.requestControl({ subtype: 'get_settings' }), native.initialization.agents, native.initialization.current_permission_mode, undefined, false, undefined, {}, command));
|
|
214
218
|
},
|
|
219
|
+
/**
|
|
220
|
+
* Reads the commands a session started in the folder would list, explicit-only skills
|
|
221
|
+
* included, from a read lane with no user prompt or model turn.
|
|
222
|
+
* @returns The native inventory with unavailable fields left explicit; the lane is closed
|
|
223
|
+
* before returning.
|
|
224
|
+
* @throws
|
|
225
|
+
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
226
|
+
* - JG_AGENT_HQ_TRANSPORT_FAILED: The HQ transport failed
|
|
227
|
+
*/
|
|
228
|
+
async readWorkspaceSkills(workspaceRoot, signal) {
|
|
229
|
+
return withReadConnection(workspaceRoot, signal, async (native) => ({
|
|
230
|
+
...toClaudeSkills({ skills: native.initialization.commands }),
|
|
231
|
+
observedAt: native.initializedAt,
|
|
232
|
+
}));
|
|
233
|
+
},
|
|
215
234
|
/**
|
|
216
235
|
* Reads fresh native account metadata in a disposable read lane.
|
|
217
236
|
* @returns Safe account metadata after confirmed read-lane cleanup.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ISessionSettings } from '../../contracts/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Opens an idle native structured lane without a user prompt or inference
|
|
3
|
+
* Opens an idle native structured lane without a user prompt or inference: a session's, or a
|
|
4
|
+
* session-less read lane, which a folder-scoped read starts in its folder with the additional
|
|
5
|
+
* directories sessions get, so it sees the commands a session started there would.
|
|
4
6
|
* @returns An owned control connection; normal CLI configuration remains enabled.
|
|
5
7
|
* @throws
|
|
6
8
|
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
@@ -15,7 +17,10 @@ export declare const createClaudeRpc: (invalidate: (reason: "account" | "limits"
|
|
|
15
17
|
settings?: ISessionSettings;
|
|
16
18
|
receive(message: unknown): void;
|
|
17
19
|
lateResponse(id: string, result: unknown, error: unknown): void;
|
|
18
|
-
},
|
|
20
|
+
}, lane?: {
|
|
21
|
+
workspaceRoot: string;
|
|
22
|
+
additionalDirectories: string[];
|
|
23
|
+
}, signal?: AbortSignal) => Promise<{
|
|
19
24
|
version: string | null;
|
|
20
25
|
initialization: {
|
|
21
26
|
claude_code_version?: string | null | undefined;
|
|
@@ -16,13 +16,15 @@ const EnvelopeSchema = z.object({
|
|
|
16
16
|
request_id: z.string().optional(),
|
|
17
17
|
});
|
|
18
18
|
/**
|
|
19
|
-
* Opens an idle native structured lane without a user prompt or inference
|
|
19
|
+
* Opens an idle native structured lane without a user prompt or inference: a session's, or a
|
|
20
|
+
* session-less read lane, which a folder-scoped read starts in its folder with the additional
|
|
21
|
+
* directories sessions get, so it sees the commands a session started there would.
|
|
20
22
|
* @returns An owned control connection; normal CLI configuration remains enabled.
|
|
21
23
|
* @throws
|
|
22
24
|
* - JG_AGENT_HQ_CLAUDE_FAILED: The Claude integration failed
|
|
23
25
|
* - JG_AGENT_HQ_CAPABILITY_UNAVAILABLE: The HQ capability is unavailable
|
|
24
26
|
*/
|
|
25
|
-
export const createClaudeRpc = async (invalidate, control,
|
|
27
|
+
export const createClaudeRpc = async (invalidate, control, lane, signal) => {
|
|
26
28
|
let sequence = 0;
|
|
27
29
|
const late = new Set();
|
|
28
30
|
const pending = new Map();
|
|
@@ -62,7 +64,7 @@ export const createClaudeRpc = async (invalidate, control, workspaceRoot, signal
|
|
|
62
64
|
...control.additionalDirectories.flatMap((directory) => ['--add-dir', directory]),
|
|
63
65
|
...toClaudeSessionFlags(control.settings ?? {}),
|
|
64
66
|
]
|
|
65
|
-
: []),
|
|
67
|
+
: (lane?.additionalDirectories.flatMap((directory) => ['--add-dir', directory]) ?? [])),
|
|
66
68
|
], (message) => {
|
|
67
69
|
const parsed = EnvelopeSchema.safeParse(message);
|
|
68
70
|
if (!parsed.success)
|
|
@@ -119,7 +121,7 @@ export const createClaudeRpc = async (invalidate, control, workspaceRoot, signal
|
|
|
119
121
|
invalidate('account');
|
|
120
122
|
else if (envelope.type === 'rate_limit_event')
|
|
121
123
|
invalidate('limits');
|
|
122
|
-
}, fail, control?.workspaceRoot ?? workspaceRoot);
|
|
124
|
+
}, fail, control?.workspaceRoot ?? lane?.workspaceRoot);
|
|
123
125
|
/**
|
|
124
126
|
* Matches one native control acknowledgement and retains bounded late-response identity.
|
|
125
127
|
* @returns The native success payload, which may be absent for acknowledgement-only controls.
|
|
@@ -354,7 +354,7 @@ export const createCodexProviderFactory = (extraSkillRoots, daemonLauncher) => (
|
|
|
354
354
|
readMcpServers: (nativeId, limit, cursor) => native.readMcpServers(nativeId, limit, cursor),
|
|
355
355
|
readMcpTools: (nativeId, serverName) => native.readMcpTools(nativeId, serverName),
|
|
356
356
|
readMcpResources: (nativeId, serverName) => native.readMcpResources(nativeId, serverName),
|
|
357
|
-
readSkills: (
|
|
357
|
+
readSkills: (workspaceRoot) => native.readSkills(workspaceRoot),
|
|
358
358
|
formatSkill: (skill, argumentsText) => `$${skill.name}${argumentsText ? ` ${argumentsText}` : ''}`,
|
|
359
359
|
startThread: async (requestId, workspaceRoot, settings) => toProviderThread(await native.startThread(requestId, workspaceRoot, settings)),
|
|
360
360
|
resumeThread: async (requestId, nativeId, _workspaceRoot, _name, settings, call) => toProviderThread(await native.resumeThread(requestId, nativeId, settings, call.signal)),
|
|
@@ -415,8 +415,8 @@ export const createProviderRegistry = (registrations, allowedRoots, runtimeEpoch
|
|
|
415
415
|
rejectProviderResponse();
|
|
416
416
|
return result;
|
|
417
417
|
}),
|
|
418
|
-
readSkills: (
|
|
419
|
-
const result = await adapter.readSkills(
|
|
418
|
+
readSkills: (workspaceRoot, nativeId) => invoke(async (call) => {
|
|
419
|
+
const result = await adapter.readSkills(workspaceRoot, nativeId, call);
|
|
420
420
|
if (Buffer.byteLength(JSON.stringify(result)) > 1_048_576)
|
|
421
421
|
capabilityUnavailable();
|
|
422
422
|
return ProviderSkillsSchema.parse(result);
|
|
@@ -200,8 +200,11 @@ export type IAgentProvider = {
|
|
|
200
200
|
readMcpTools(nativeId: string, serverName: string, call: IProviderCall): Promise<IProviderMcpTools>;
|
|
201
201
|
/** @returns Bounded native resource metadata, or an explicit unsupported state. */
|
|
202
202
|
readMcpResources(nativeId: string, serverName: string, call: IProviderCall): Promise<IProviderMcpResources>;
|
|
203
|
-
/**
|
|
204
|
-
|
|
203
|
+
/**
|
|
204
|
+
* @returns The bounded native skill inventory of the selected session, or without one the
|
|
205
|
+
* inventory a session started in the folder gets.
|
|
206
|
+
*/
|
|
207
|
+
readSkills(workspaceRoot: string, nativeId: string | undefined, call: IProviderCall): Promise<IProviderSkills>;
|
|
205
208
|
/** @returns The exact native invocation spelling from validated inventory metadata. */
|
|
206
209
|
formatSkill(skill: ISkill, argumentsText: string): string;
|
|
207
210
|
/** @returns The exact created native session identity and workspace. */
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -242,8 +242,20 @@ export const createAgentHq = async (options) => {
|
|
|
242
242
|
result: await (await providers.get(command.provider)).readConfiguration({ ...command, workspaceRoot }, thread?.nativeId ?? undefined),
|
|
243
243
|
};
|
|
244
244
|
}
|
|
245
|
-
case 'skills':
|
|
246
|
-
|
|
245
|
+
case 'skills': {
|
|
246
|
+
const workspaceRoot = await resolveWorkspaceTarget(command.workspaceRoot, allowedRoots);
|
|
247
|
+
// a session's catalog answers only for the provider and folder the session runs in
|
|
248
|
+
const thread = command.threadId ? await projection.getThread(command.threadId) : null;
|
|
249
|
+
if (command.threadId &&
|
|
250
|
+
(!thread ||
|
|
251
|
+
thread.provider !== command.provider ||
|
|
252
|
+
thread.workspaceRoot !== workspaceRoot))
|
|
253
|
+
throw new Exception('The HQ request is invalid', {
|
|
254
|
+
code: 'JG_AGENT_HQ_REQUEST_INVALID',
|
|
255
|
+
data: { kind: 'invalid-request' },
|
|
256
|
+
});
|
|
257
|
+
return { kind: command.kind, result: await skills.list({ ...command, workspaceRoot }) };
|
|
258
|
+
}
|
|
247
259
|
case 'skill-preview':
|
|
248
260
|
return {
|
|
249
261
|
kind: command.kind,
|
package/dist/skills/skills.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type IMessageInput, type INativeSkillInput, type ISkillPage, type ISkillPreview } from '../contracts/index.js';
|
|
1
|
+
import { type IMessageInput, type INativeSkillInput, type ISkillPage, type ISkillPreview, type IProviderId } from '../contracts/index.js';
|
|
2
2
|
import type { createProviderRegistry } from '../providers/registry/index.js';
|
|
3
3
|
import type { IStore } from '../store/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Reads bounded native inventories without interpreting skill files or installing workflows.
|
|
6
|
-
* @returns
|
|
6
|
+
* @returns Session and folder discovery, exact previews and explicit input preparation.
|
|
7
7
|
*/
|
|
8
8
|
export declare const createSkills: (registry: ReturnType<typeof createProviderRegistry>, store: IStore, roots: string[]) => {
|
|
9
9
|
/** Stops new reads joining an observation started before a native change. */
|
|
@@ -18,7 +18,8 @@ export declare const createSkills: (registry: ReturnType<typeof createProviderRe
|
|
|
18
18
|
*/
|
|
19
19
|
previewName(threadId: string, name: string, skillArguments: string): Promise<ISkillPreview>;
|
|
20
20
|
/**
|
|
21
|
-
* Pages
|
|
21
|
+
* Pages a managed session's native inventory, or with no session the one a session started in
|
|
22
|
+
* the folder gets, with a content revision guard; an inventory change invalidates continuation.
|
|
22
23
|
* @returns One bounded page, or explicit unavailable state without a successful empty fallback.
|
|
23
24
|
* @throws
|
|
24
25
|
* - JG_AGENT_HQ_TARGET_FORBIDDEN: The HQ target is outside the allowed workspaces
|
|
@@ -26,7 +27,9 @@ export declare const createSkills: (registry: ReturnType<typeof createProviderRe
|
|
|
26
27
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
27
28
|
*/
|
|
28
29
|
list(command: {
|
|
29
|
-
|
|
30
|
+
provider: IProviderId;
|
|
31
|
+
workspaceRoot: string;
|
|
32
|
+
threadId?: string;
|
|
30
33
|
limit: number;
|
|
31
34
|
cursor?: string;
|
|
32
35
|
search?: string;
|
package/dist/skills/skills.js
CHANGED
|
@@ -23,40 +23,58 @@ const toSkillPreview = (formatSkill, skill, skillArguments) => {
|
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Reads bounded native inventories without interpreting skill files or installing workflows.
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns Session and folder discovery, exact previews and explicit input preparation.
|
|
27
27
|
*/
|
|
28
28
|
export const createSkills = (registry, store, roots) => {
|
|
29
29
|
const pending = new Map();
|
|
30
30
|
/**
|
|
31
|
-
* Coalesces a native metadata read and enforces the catalog budget before paging.
|
|
31
|
+
* Coalesces a native metadata read and enforces the catalog budget before paging. A session's
|
|
32
|
+
* catalog needs a managed session that isn't inactive; a folder's needs no session.
|
|
32
33
|
* @returns Current metadata, or null when the native inventory cannot be used.
|
|
33
34
|
* @throws
|
|
34
35
|
* - JG_AGENT_HQ_TARGET_FORBIDDEN: The HQ target is outside the allowed workspaces
|
|
35
36
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
36
37
|
*/
|
|
37
|
-
const scan = async (
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
const scan = async (target) => {
|
|
39
|
+
let source;
|
|
40
|
+
if ('threadId' in target) {
|
|
41
|
+
const thread = await store.getThread(target.threadId);
|
|
42
|
+
if (!thread)
|
|
43
|
+
return null;
|
|
44
|
+
await resolveWorkspaceTarget(thread.workspaceRoot, roots);
|
|
45
|
+
if (thread.ownership !== 'managed' ||
|
|
46
|
+
!thread.runtimeEpoch ||
|
|
47
|
+
!thread.nativeId ||
|
|
48
|
+
thread.state === 'inactive')
|
|
49
|
+
return null;
|
|
50
|
+
source = {
|
|
51
|
+
key: `thread:${target.threadId}`,
|
|
52
|
+
provider: thread.provider,
|
|
53
|
+
workspaceRoot: thread.workspaceRoot,
|
|
54
|
+
nativeId: thread.nativeId,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const workspaceRoot = await resolveWorkspaceTarget(target.workspaceRoot, roots);
|
|
59
|
+
source = {
|
|
60
|
+
key: `workspace:${target.provider}:${workspaceRoot}`,
|
|
61
|
+
provider: target.provider,
|
|
62
|
+
workspaceRoot,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
let operation = pending.get(source.key);
|
|
48
66
|
if (!operation) {
|
|
49
67
|
if (pending.size >= 32)
|
|
50
68
|
return null;
|
|
51
69
|
operation = (async () => {
|
|
52
|
-
const adapter = await registry.get(
|
|
70
|
+
const adapter = await registry.get(source.provider);
|
|
53
71
|
return {
|
|
54
|
-
provider:
|
|
55
|
-
inventory: await adapter.readSkills(
|
|
72
|
+
provider: source.provider,
|
|
73
|
+
inventory: await adapter.readSkills(source.workspaceRoot, source.nativeId),
|
|
56
74
|
formatSkill: adapter.formatSkill,
|
|
57
75
|
};
|
|
58
76
|
})();
|
|
59
|
-
pending.set(
|
|
77
|
+
pending.set(source.key, operation);
|
|
60
78
|
}
|
|
61
79
|
try {
|
|
62
80
|
const { provider, inventory, formatSkill } = await operation;
|
|
@@ -78,8 +96,8 @@ export const createSkills = (registry, store, roots) => {
|
|
|
78
96
|
return null;
|
|
79
97
|
}
|
|
80
98
|
finally {
|
|
81
|
-
if (pending.get(
|
|
82
|
-
pending.delete(
|
|
99
|
+
if (pending.get(source.key) === operation)
|
|
100
|
+
pending.delete(source.key);
|
|
83
101
|
}
|
|
84
102
|
};
|
|
85
103
|
return {
|
|
@@ -96,7 +114,7 @@ export const createSkills = (registry, store, roots) => {
|
|
|
96
114
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
97
115
|
*/
|
|
98
116
|
async previewName(threadId, name, skillArguments) {
|
|
99
|
-
const result = await scan(threadId);
|
|
117
|
+
const result = await scan({ threadId });
|
|
100
118
|
if (!result)
|
|
101
119
|
return { state: 'unavailable', skill: null, text: null };
|
|
102
120
|
const matches = result.skills.filter((skill) => skill.name === name);
|
|
@@ -105,7 +123,8 @@ export const createSkills = (registry, store, roots) => {
|
|
|
105
123
|
return toSkillPreview(result.formatSkill, matches[0], skillArguments);
|
|
106
124
|
},
|
|
107
125
|
/**
|
|
108
|
-
* Pages
|
|
126
|
+
* Pages a managed session's native inventory, or with no session the one a session started in
|
|
127
|
+
* the folder gets, with a content revision guard; an inventory change invalidates continuation.
|
|
109
128
|
* @returns One bounded page, or explicit unavailable state without a successful empty fallback.
|
|
110
129
|
* @throws
|
|
111
130
|
* - JG_AGENT_HQ_TARGET_FORBIDDEN: The HQ target is outside the allowed workspaces
|
|
@@ -128,7 +147,9 @@ export const createSkills = (registry, store, roots) => {
|
|
|
128
147
|
});
|
|
129
148
|
}
|
|
130
149
|
}
|
|
131
|
-
const result = await scan(command.threadId
|
|
150
|
+
const result = await scan(command.threadId
|
|
151
|
+
? { threadId: command.threadId }
|
|
152
|
+
: { provider: command.provider, workspaceRoot: command.workspaceRoot });
|
|
132
153
|
if (!result)
|
|
133
154
|
return {
|
|
134
155
|
state: 'unavailable',
|
|
@@ -174,7 +195,7 @@ export const createSkills = (registry, store, roots) => {
|
|
|
174
195
|
* - JG_AGENT_HQ_STORE_FAILED: The HQ store failed
|
|
175
196
|
*/
|
|
176
197
|
async preview(threadId, skillId, skillArguments) {
|
|
177
|
-
const result = await scan(threadId);
|
|
198
|
+
const result = await scan({ threadId });
|
|
178
199
|
if (!result)
|
|
179
200
|
return { state: 'unavailable', skill: null, text: null };
|
|
180
201
|
const skill = result.skills.find((skill) => skill.id === skillId);
|
package/dist/store/types.d.ts
CHANGED
|
@@ -418,7 +418,9 @@ export declare const StoreCommandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
418
418
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
419
419
|
cursor: z.ZodOptional<z.ZodString>;
|
|
420
420
|
kind: z.ZodLiteral<"skills">;
|
|
421
|
-
|
|
421
|
+
provider: z.ZodString;
|
|
422
|
+
workspaceRoot: z.ZodString;
|
|
423
|
+
threadId: z.ZodOptional<z.ZodUUID>;
|
|
422
424
|
search: z.ZodOptional<z.ZodString>;
|
|
423
425
|
}, z.core.$strict>, z.ZodObject<{
|
|
424
426
|
kind: z.ZodLiteral<"skill-preview">;
|
|
@@ -1820,7 +1822,9 @@ export declare const StoreRequestSchema: z.ZodObject<{
|
|
|
1820
1822
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
1821
1823
|
cursor: z.ZodOptional<z.ZodString>;
|
|
1822
1824
|
kind: z.ZodLiteral<"skills">;
|
|
1823
|
-
|
|
1825
|
+
provider: z.ZodString;
|
|
1826
|
+
workspaceRoot: z.ZodString;
|
|
1827
|
+
threadId: z.ZodOptional<z.ZodUUID>;
|
|
1824
1828
|
search: z.ZodOptional<z.ZodString>;
|
|
1825
1829
|
}, z.core.$strict>, z.ZodObject<{
|
|
1826
1830
|
kind: z.ZodLiteral<"skill-preview">;
|
package/package.json
CHANGED