@agent-watch-ai/edge 0.4.0 → 0.6.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 +50 -0
- package/README.md +8 -7
- package/SECURITY.md +1 -1
- package/dist/config/config-store.js +1 -1
- package/dist/config/repo-config.js +1 -1
- package/dist/config/schemas/config.schema.d.ts +93 -857
- package/dist/config/schemas/config.schema.js +5 -5
- package/dist/credentials/credentials.js +2 -2
- package/dist/credentials/schemas/device-api.schema.d.ts +4 -51
- package/dist/credentials/schemas/device-state.schema.d.ts +3 -38
- package/dist/events/constants/events.constants.d.ts +5 -2
- package/dist/events/constants/events.constants.js +4 -1
- package/dist/events/index.d.ts +1 -0
- package/dist/events/product-event.d.ts +7 -4
- package/dist/events/types/repo-snapshot.types.d.ts +1 -4
- package/dist/events/types/repo-tree.types.d.ts +24 -0
- package/dist/events/types/repo-tree.types.js +1 -0
- package/dist/git/code-state.d.ts +33 -0
- package/dist/git/code-state.js +44 -0
- package/dist/git/constants/git.constants.d.ts +6 -0
- package/dist/git/constants/git.constants.js +6 -0
- package/dist/git/constants/tree.constants.d.ts +71 -0
- package/dist/git/constants/tree.constants.js +92 -0
- package/dist/git/git-context.d.ts +1 -0
- package/dist/git/git-context.js +3 -2
- package/dist/git/index.d.ts +2 -1
- package/dist/git/index.js +1 -0
- package/dist/git/repo-tree.d.ts +69 -0
- package/dist/git/repo-tree.js +130 -0
- package/dist/git/types/git.types.d.ts +11 -2
- package/dist/git/types/snapshot.types.d.ts +12 -0
- package/dist/pipeline/hook-pipeline.js +40 -24
- package/dist/privacy/command-fingerprint.d.ts +42 -0
- package/dist/privacy/command-fingerprint.js +249 -0
- package/dist/privacy/constants/command-fingerprint.constants.d.ts +34 -0
- package/dist/privacy/constants/command-fingerprint.constants.js +38 -0
- package/dist/privacy/index.d.ts +3 -1
- package/dist/privacy/index.js +2 -0
- package/dist/privacy/product-capture.js +53 -6
- package/dist/privacy/types/privacy.types.d.ts +7 -0
- package/dist/providers/antigravity/antigravity.adapter.js +3 -0
- package/dist/providers/antigravity/schemas/antigravity.schema.d.ts +18 -492
- package/dist/providers/claude/claude.adapter.js +12 -1
- package/dist/providers/claude/constants/claude.constants.d.ts +6 -0
- package/dist/providers/claude/constants/claude.constants.js +6 -0
- package/dist/providers/claude/schemas/claude.schema.d.ts +1 -43
- package/dist/providers/codex/codex.adapter.js +14 -0
- package/dist/providers/codex/schemas/codex.schema.d.ts +1 -41
- package/dist/providers/cursor/cursor.adapter.js +5 -2
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +5 -85
- package/dist/providers/gemini/constants/gemini.constants.d.ts +2 -0
- package/dist/providers/gemini/constants/gemini.constants.js +2 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +10 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +11 -2
- package/dist/providers/gemini/gemini.detect.d.ts +11 -0
- package/dist/providers/gemini/gemini.detect.js +14 -1
- package/dist/providers/gemini/gemini.hooks.d.ts +3 -3
- package/dist/providers/gemini/gemini.hooks.js +5 -5
- package/dist/providers/gemini/gemini.otel.d.ts +6 -6
- package/dist/providers/gemini/gemini.otel.js +392 -121
- package/dist/providers/gemini/schemas/gemini.schema.d.ts +1 -49
- package/dist/providers/shared/event-builder.d.ts +17 -2
- package/dist/providers/shared/event-builder.js +43 -3
- package/dist/providers/shared/install-record.d.ts +2 -0
- package/dist/providers/shared/install-record.js +3 -2
- package/dist/providers/shared/tooling.d.ts +7 -0
- package/dist/providers/shared/tooling.js +10 -1
- package/dist/providers/shared/types/adapter.types.d.ts +18 -0
- package/dist/snapshot/branch-selection.js +3 -1
- package/dist/snapshot/budget.js +2 -2
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +8 -0
- package/dist/snapshot/constants/snapshot-stages.constants.js +8 -0
- package/dist/snapshot/constants/snapshot.constants.d.ts +6 -0
- package/dist/snapshot/constants/snapshot.constants.js +6 -0
- package/dist/snapshot/index.d.ts +5 -0
- package/dist/snapshot/index.js +2 -0
- package/dist/snapshot/snapshot-event.d.ts +7 -0
- package/dist/snapshot/snapshot-event.js +8 -5
- package/dist/snapshot/snapshot-state.js +19 -1
- package/dist/snapshot/tree-event.d.ts +14 -0
- package/dist/snapshot/tree-event.js +91 -0
- package/dist/snapshot/tree-pipeline.d.ts +12 -0
- package/dist/snapshot/tree-pipeline.js +153 -0
- package/dist/snapshot/types/snapshot.types.d.ts +44 -1
- package/dist/storage/schemas/storage.schema.d.ts +11 -175
- package/dist/storage/schemas/storage.schema.js +7 -1
- package/dist/transport/constants/transport.constants.d.ts +5 -0
- package/dist/transport/constants/transport.constants.js +5 -0
- package/dist/transport/queue.js +40 -6
- package/dist/transport/schemas/queue.schema.d.ts +1 -16
- package/dist/transport/schemas/queue.schema.js +1 -1
- package/dist/turns/constants/turns.constants.d.ts +17 -0
- package/dist/turns/constants/turns.constants.js +17 -0
- package/dist/turns/index.d.ts +3 -2
- package/dist/turns/index.js +1 -0
- package/dist/turns/tool-events.d.ts +15 -0
- package/dist/turns/tool-events.js +59 -0
- package/dist/turns/turn-state.js +2 -2
- package/dist/turns/turn-summary.d.ts +1 -1
- package/dist/turns/turn-summary.js +4 -4
- package/dist/turns/turn-tracker.js +138 -7
- package/dist/turns/types/turn-state.types.d.ts +28 -1
- package/dist/turns/types/turn-summary.types.d.ts +33 -5
- package/dist/turns/types/turn-tracker.types.d.ts +10 -0
- package/docs/AUDIT_PROMPT.md +11 -0
- package/docs/DATA_HANDLING.md +132 -33
- package/docs/ENTERPRISE_DEPLOYMENT.md +2 -1
- package/docs/PERFORMANCE.md +17 -0
- package/package.json +9 -8
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { debugLog } from '../core/logger.js';
|
|
2
|
+
import { next, runFlow, step, stop } from '../core/pipe.js';
|
|
3
|
+
import { resolveDefaultBranch } from '../git/repo-snapshot.js';
|
|
4
|
+
import { collectRepoTree, resolveTreeSha } from '../git/repo-tree.js';
|
|
5
|
+
import { sanitizeValue } from '../privacy/sanitizer.js';
|
|
6
|
+
import { budgetedRunner, remainingMs, withinBudget } from './budget.js';
|
|
7
|
+
import { TREE_RETRY_INTERVAL_MS } from './constants/snapshot.constants.js';
|
|
8
|
+
import { STAGE_ENQUEUE, STAGE_SANITIZE, STAGE_TREE_COLLECT, STAGE_TREE_DUE, STAGE_TREE_RESOLVE, STOP_BUDGET_SPENT, STOP_NO_EVENT, STOP_TREE_NOT_DUE, STOP_TREE_NO_TRUNK, STOP_TREE_SENT, STOP_TREE_UNLISTED } from './constants/snapshot-stages.constants.js';
|
|
9
|
+
import { emptyState } from './snapshot-state.js';
|
|
10
|
+
import { buildRepoTree } from './tree-event.js';
|
|
11
|
+
/**
|
|
12
|
+
* The tree flow, as the list of stages it is.
|
|
13
|
+
*
|
|
14
|
+
* Cheapest first: the stored state costs no git at all, and once the tree has
|
|
15
|
+
* been sent it is the only stage that ever runs again.
|
|
16
|
+
*/
|
|
17
|
+
const TREE_STAGES = [
|
|
18
|
+
step(STAGE_TREE_DUE, due),
|
|
19
|
+
step(STAGE_TREE_RESOLVE, resolve),
|
|
20
|
+
step(STAGE_TREE_COLLECT, collect),
|
|
21
|
+
step(STAGE_SANITIZE, sanitize),
|
|
22
|
+
step(STAGE_ENQUEUE, enqueue)
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Send the default branch's source paths and declaration names, once per repository and identity.
|
|
26
|
+
*
|
|
27
|
+
* Shares the snapshot's deadline and never outlives it: an overrun stops
|
|
28
|
+
* without recording anything, so the next turn tries again. Never throws.
|
|
29
|
+
*
|
|
30
|
+
* @param pipeline - The snapshot flow's input, the state cache and the offline queue.
|
|
31
|
+
* @returns The final state and where the flow stopped.
|
|
32
|
+
*/
|
|
33
|
+
export function runTreePipeline(pipeline) {
|
|
34
|
+
const initial = {
|
|
35
|
+
input: pipeline.input,
|
|
36
|
+
store: pipeline.store,
|
|
37
|
+
queue: pipeline.queue,
|
|
38
|
+
run: budgetedRunner(pipeline.input.run, pipeline.input.deadline)
|
|
39
|
+
};
|
|
40
|
+
return runFlow(TREE_STAGES, initial, (trace) => {
|
|
41
|
+
if (trace.outcome === 'next')
|
|
42
|
+
return;
|
|
43
|
+
debugLog(`tree flow ${trace.outcome} at ${trace.step}${trace.reason ? `: ${trace.reason}` : ''}`);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether this repository still owes its one tree.
|
|
48
|
+
*
|
|
49
|
+
* Once per repository per identity: after the first tree is queued nothing
|
|
50
|
+
* here runs again, so an ordinary turn pays one small state read and no git
|
|
51
|
+
* process. The files a session changes arrive in its turn summaries and branch
|
|
52
|
+
* snapshots anyway. A new identity — a re-setup with a new credential, a
|
|
53
|
+
* different account — owes the tree again. An attempt that failed waits out
|
|
54
|
+
* {@link TREE_RETRY_INTERVAL_MS}, so a repository the budget cannot list costs
|
|
55
|
+
* its second once an hour, not on every turn.
|
|
56
|
+
*
|
|
57
|
+
* @param state - Current flow state.
|
|
58
|
+
* @returns The state with what was stored, or a stop when nothing is owed yet.
|
|
59
|
+
*/
|
|
60
|
+
async function due(state) {
|
|
61
|
+
const stored = await state.store.read(state.input.repository);
|
|
62
|
+
const tree = stored.tree;
|
|
63
|
+
if (tree?.sentAt !== undefined && tree.sentFor === state.input.identity)
|
|
64
|
+
return stop({ ...state, stored }, STOP_TREE_SENT);
|
|
65
|
+
if (tree?.triedAt !== undefined && Date.parse(state.input.capturedAt) - tree.triedAt < TREE_RETRY_INTERVAL_MS)
|
|
66
|
+
return stop({ ...state, stored }, STOP_TREE_NOT_DUE);
|
|
67
|
+
return next({ ...state, stored });
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The trunk and its tree oid.
|
|
71
|
+
*
|
|
72
|
+
* @param state - Current flow state.
|
|
73
|
+
* @returns The state with the trunk and the tree, or a stop when there is none.
|
|
74
|
+
*/
|
|
75
|
+
async function resolve(state) {
|
|
76
|
+
const { cwd } = state.input;
|
|
77
|
+
const defaultBranch = await resolveDefaultBranch(cwd, state.run);
|
|
78
|
+
const treeSha = defaultBranch ? await resolveTreeSha(cwd, defaultBranch, state.run) : undefined;
|
|
79
|
+
if (!defaultBranch || !treeSha)
|
|
80
|
+
return stop(await triedNow(state), STOP_TREE_NO_TRUNK);
|
|
81
|
+
return next({ ...state, treeSha });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* List the tree and search it for declaration names.
|
|
85
|
+
*
|
|
86
|
+
* The budget is checked after, not only before: a search the budget cut short
|
|
87
|
+
* returns nothing, which reads exactly like a tree with no declarations, and
|
|
88
|
+
* sending that would record the tree as named when it was not.
|
|
89
|
+
*
|
|
90
|
+
* ponytail: a tree that never fits in what the branch snapshot leaves of one
|
|
91
|
+
* second is never sent (agent-watch-core, 1,704 source files, takes ~200 ms).
|
|
92
|
+
* Upgrade: give the tree its own budget on its hourly attempt, or search it
|
|
93
|
+
* in slices across turns.
|
|
94
|
+
*
|
|
95
|
+
* @param state - Current flow state.
|
|
96
|
+
* @returns The state with the tree, or a stop when it could not be listed in time.
|
|
97
|
+
*/
|
|
98
|
+
async function collect(state) {
|
|
99
|
+
const tree = await collectRepoTree(state.input.cwd, state.treeSha, state.run);
|
|
100
|
+
if (remainingMs(state.input.deadline) === 0)
|
|
101
|
+
return stop(await triedNow(state), STOP_BUDGET_SPENT);
|
|
102
|
+
if (!tree)
|
|
103
|
+
return stop(await triedNow(state), STOP_TREE_UNLISTED);
|
|
104
|
+
return next({ ...state, tree });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Record a failed attempt, so the next one waits out the retry interval.
|
|
108
|
+
*
|
|
109
|
+
* Written whatever is left of the deadline — usually nothing, which is why
|
|
110
|
+
* the attempt failed — because it is one small local file, and skipping it
|
|
111
|
+
* would put the same failing listing on every following turn.
|
|
112
|
+
*
|
|
113
|
+
* @param state - Current flow state.
|
|
114
|
+
* @returns The state, unchanged.
|
|
115
|
+
*/
|
|
116
|
+
async function triedNow(state) {
|
|
117
|
+
const stored = state.stored ?? emptyState();
|
|
118
|
+
await state.store.write(state.input.repository, { ...stored, tree: { ...stored.tree, triedAt: Date.parse(state.input.capturedAt) } }).catch(() => undefined);
|
|
119
|
+
return state;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Build the event and put it through the same scrubber every record gets.
|
|
123
|
+
*
|
|
124
|
+
* @param state - Current flow state.
|
|
125
|
+
* @returns The state carrying the event to send.
|
|
126
|
+
*/
|
|
127
|
+
async function sanitize(state) {
|
|
128
|
+
const event = buildRepoTree({ identity: state.input, tree: state.tree });
|
|
129
|
+
return next({ ...state, event: sanitizeValue(event) });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Queue the event, then record the tree as sent — never the other way round.
|
|
133
|
+
* The tree oid stays in this local marker; it is not sent.
|
|
134
|
+
*
|
|
135
|
+
* Queued is sent: the queue retries until it is delivered. ponytail: a tree
|
|
136
|
+
* the queue gives up on (attempts or age exhausted) is not offered again for
|
|
137
|
+
* this identity; clearing `tree.sentAt` when the queue drops a `repo.tree`
|
|
138
|
+
* is the upgrade if that ever bites.
|
|
139
|
+
*
|
|
140
|
+
* @param state - Current flow state.
|
|
141
|
+
* @returns The state, unchanged.
|
|
142
|
+
*/
|
|
143
|
+
async function enqueue(state) {
|
|
144
|
+
if (!state.event)
|
|
145
|
+
return stop(state, STOP_NO_EVENT);
|
|
146
|
+
const { deadline, repository, capturedAt } = state.input;
|
|
147
|
+
const queued = await withinBudget(state.queue.enqueue([state.event]), deadline);
|
|
148
|
+
if (!queued)
|
|
149
|
+
return stop(await triedNow(state), STOP_BUDGET_SPENT);
|
|
150
|
+
const stored = state.stored ?? emptyState();
|
|
151
|
+
await withinBudget(state.store.write(repository, { ...stored, tree: { sha: state.treeSha, sentAt: Date.parse(capturedAt), sentFor: state.input.identity } }), deadline);
|
|
152
|
+
return next(state);
|
|
153
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RepoSnapshotEvent } from '../../events/types/repo-snapshot.types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RepoTreeEvent } from '../../events/types/repo-tree.types.js';
|
|
3
|
+
import type { BranchRef, RepoTree, SnapshotBranch } from '../../git/types/snapshot.types.js';
|
|
3
4
|
import type { GitRunner } from '../../git/types/git.types.js';
|
|
4
5
|
/** What was last reported about one branch. */
|
|
5
6
|
export interface SnapshotStateEntry {
|
|
@@ -18,6 +19,19 @@ export interface SnapshotState {
|
|
|
18
19
|
*/
|
|
19
20
|
readonly defaultBranch?: string;
|
|
20
21
|
readonly branches: Record<string, SnapshotStateEntry>;
|
|
22
|
+
/** The default-branch tree last sent as `repo.tree`, and when. */
|
|
23
|
+
readonly tree?: SnapshotTreeEntry;
|
|
24
|
+
}
|
|
25
|
+
/** Whether one repository's trunk tree has been sent, and for whom, or when it was last tried. */
|
|
26
|
+
export interface SnapshotTreeEntry {
|
|
27
|
+
/** The tree that was sent; absent when none has been yet. */
|
|
28
|
+
readonly sha?: string;
|
|
29
|
+
/** Epoch milliseconds the tree was queued. */
|
|
30
|
+
readonly sentAt?: number;
|
|
31
|
+
/** The identity fingerprint it was sent as: a different identity owes the tree again. */
|
|
32
|
+
readonly sentFor?: string;
|
|
33
|
+
/** When an attempt last failed, so the next waits out {@link TREE_RETRY_INTERVAL_MS}. */
|
|
34
|
+
readonly triedAt?: number;
|
|
21
35
|
}
|
|
22
36
|
/**
|
|
23
37
|
* Who and where a snapshot is about: everything the event itself carries.
|
|
@@ -41,6 +55,8 @@ export interface SnapshotFlowInput extends SnapshotIdentity {
|
|
|
41
55
|
readonly cwd: string;
|
|
42
56
|
/** Whether the effective capture policy allows file names; when not, no files listing runs. */
|
|
43
57
|
readonly files: boolean;
|
|
58
|
+
/** Fingerprint of the identity events are sent as; the tree is sent once per repository and identity. */
|
|
59
|
+
readonly identity?: string;
|
|
44
60
|
readonly deadline: number;
|
|
45
61
|
readonly run: GitRunner;
|
|
46
62
|
}
|
|
@@ -57,6 +73,29 @@ export interface BuildSnapshotInput {
|
|
|
57
73
|
readonly defaultBranch?: string;
|
|
58
74
|
readonly branches: readonly SnapshotBranch[];
|
|
59
75
|
}
|
|
76
|
+
/** Identity and the tree one `repo.tree` describes. */
|
|
77
|
+
export interface BuildTreeInput {
|
|
78
|
+
readonly identity: SnapshotIdentity;
|
|
79
|
+
readonly tree: RepoTree;
|
|
80
|
+
}
|
|
81
|
+
/** Everything one run of the tree flow needs beyond its own state. */
|
|
82
|
+
export interface TreePipelineInput {
|
|
83
|
+
/** Reuses the snapshot flow's input; its `files` flag must already be on to get here. */
|
|
84
|
+
readonly input: SnapshotFlowInput;
|
|
85
|
+
readonly store: SnapshotStateReader;
|
|
86
|
+
readonly queue: TreeQueue;
|
|
87
|
+
}
|
|
88
|
+
/** State threaded through the tree flow's stages. */
|
|
89
|
+
export interface TreeFlowState {
|
|
90
|
+
readonly input: SnapshotFlowInput;
|
|
91
|
+
readonly store: SnapshotStateReader;
|
|
92
|
+
readonly queue: TreeQueue;
|
|
93
|
+
readonly run: GitRunner;
|
|
94
|
+
readonly stored?: SnapshotState;
|
|
95
|
+
readonly treeSha?: string;
|
|
96
|
+
readonly tree?: RepoTree;
|
|
97
|
+
readonly event?: RepoTreeEvent;
|
|
98
|
+
}
|
|
60
99
|
/** Everything one run of the flow needs beyond its own state. */
|
|
61
100
|
export interface SnapshotPipelineInput {
|
|
62
101
|
readonly input: SnapshotFlowInput;
|
|
@@ -86,3 +125,7 @@ export interface SnapshotStateReader {
|
|
|
86
125
|
export interface SnapshotQueue {
|
|
87
126
|
enqueue(events: readonly RepoSnapshotEvent[]): Promise<void>;
|
|
88
127
|
}
|
|
128
|
+
/** The one thing the tree flow asks of the offline queue. */
|
|
129
|
+
export interface TreeQueue {
|
|
130
|
+
enqueue(events: readonly RepoTreeEvent[]): Promise<void>;
|
|
131
|
+
}
|
|
@@ -9,192 +9,28 @@ import { z } from 'zod';
|
|
|
9
9
|
export declare const agentInstallSchema: z.ZodObject<{
|
|
10
10
|
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
11
11
|
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
12
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString
|
|
12
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
13
13
|
hookCommand: z.ZodOptional<z.ZodString>;
|
|
14
14
|
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
15
15
|
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
16
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString
|
|
17
|
-
/**
|
|
18
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
19
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
20
|
-
* never tightened, or when AgentWatch created it.
|
|
21
|
-
*/
|
|
16
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
22
17
|
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
27
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
28
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
29
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
30
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
31
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
32
|
-
/**
|
|
33
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
34
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
35
|
-
* never tightened, or when AgentWatch created it.
|
|
36
|
-
*/
|
|
37
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
38
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
39
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
40
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
41
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
42
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
43
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
44
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
45
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
46
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
47
|
-
/**
|
|
48
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
49
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
50
|
-
* never tightened, or when AgentWatch created it.
|
|
51
|
-
*/
|
|
52
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
53
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
54
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
18
|
+
otelPriorValues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
19
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
20
|
+
}, z.core.$loose>;
|
|
55
21
|
/** The whole install-state file: one entry per agent. */
|
|
56
22
|
export declare const installStateSchema: z.ZodObject<{
|
|
57
23
|
schemaVersion: z.ZodDefault<z.ZodLiteral<1>>;
|
|
58
24
|
agents: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
59
25
|
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
60
26
|
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
61
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString
|
|
62
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
63
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
64
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
65
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
66
|
-
/**
|
|
67
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
68
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
69
|
-
* never tightened, or when AgentWatch created it.
|
|
70
|
-
*/
|
|
71
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
72
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
73
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
74
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
75
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
76
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
77
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
78
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
79
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
80
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
81
|
-
/**
|
|
82
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
83
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
84
|
-
* never tightened, or when AgentWatch created it.
|
|
85
|
-
*/
|
|
86
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
87
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
88
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
89
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
90
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
91
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
92
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
93
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
94
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
95
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
96
|
-
/**
|
|
97
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
98
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
99
|
-
* never tightened, or when AgentWatch created it.
|
|
100
|
-
*/
|
|
101
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
102
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
103
|
-
}, z.ZodTypeAny, "passthrough">>>>;
|
|
104
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
105
|
-
schemaVersion: z.ZodDefault<z.ZodLiteral<1>>;
|
|
106
|
-
agents: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
107
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
108
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
109
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
110
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
111
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
112
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
113
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
114
|
-
/**
|
|
115
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
116
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
117
|
-
* never tightened, or when AgentWatch created it.
|
|
118
|
-
*/
|
|
119
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
120
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
121
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
122
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
123
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
124
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
125
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
126
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
127
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
128
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
129
|
-
/**
|
|
130
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
131
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
132
|
-
* never tightened, or when AgentWatch created it.
|
|
133
|
-
*/
|
|
134
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
135
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
136
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
137
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
138
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
139
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
140
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
141
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
142
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
143
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
144
|
-
/**
|
|
145
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
146
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
147
|
-
* never tightened, or when AgentWatch created it.
|
|
148
|
-
*/
|
|
149
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
150
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
151
|
-
}, z.ZodTypeAny, "passthrough">>>>;
|
|
152
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
153
|
-
schemaVersion: z.ZodDefault<z.ZodLiteral<1>>;
|
|
154
|
-
agents: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
155
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
156
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
157
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
158
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
159
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
160
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
161
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
162
|
-
/**
|
|
163
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
164
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
165
|
-
* never tightened, or when AgentWatch created it.
|
|
166
|
-
*/
|
|
167
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
168
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
169
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
170
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
171
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
172
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
173
|
-
hookCommand: z.ZodOptional<z.ZodString>;
|
|
174
|
-
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
175
|
-
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
176
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
177
|
-
/**
|
|
178
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
179
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
180
|
-
* never tightened, or when AgentWatch created it.
|
|
181
|
-
*/
|
|
182
|
-
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
183
|
-
notes: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
184
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
185
|
-
hooksInstalledAt: z.ZodOptional<z.ZodString>;
|
|
186
|
-
hookConfigPath: z.ZodOptional<z.ZodString>;
|
|
187
|
-
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
27
|
+
hookEvents: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
188
28
|
hookCommand: z.ZodOptional<z.ZodString>;
|
|
189
29
|
otelConfiguredAt: z.ZodOptional<z.ZodString>;
|
|
190
30
|
otelConfigPath: z.ZodOptional<z.ZodString>;
|
|
191
|
-
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString
|
|
192
|
-
/**
|
|
193
|
-
* Permission bits the agent's own config file carried before AgentWatch
|
|
194
|
-
* tightened it, so uninstall can put them back. Absent when the file was
|
|
195
|
-
* never tightened, or when AgentWatch created it.
|
|
196
|
-
*/
|
|
31
|
+
otelOwnedKeys: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
197
32
|
otelPriorMode: z.ZodOptional<z.ZodNumber>;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}, z.
|
|
33
|
+
otelPriorValues: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
34
|
+
notes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
35
|
+
}, z.core.$loose>>>;
|
|
36
|
+
}, z.core.$loose>;
|
|
@@ -21,6 +21,12 @@ export const agentInstallSchema = z
|
|
|
21
21
|
* never tightened, or when AgentWatch created it.
|
|
22
22
|
*/
|
|
23
23
|
otelPriorMode: z.number().int().optional(),
|
|
24
|
+
/**
|
|
25
|
+
* What each owned key held before AgentWatch set it (the agent's own text
|
|
26
|
+
* for that entry), so uninstall puts the developer's value back instead of
|
|
27
|
+
* deleting it. Keys absent here were not there before.
|
|
28
|
+
*/
|
|
29
|
+
otelPriorValues: z.record(z.string(), z.string()).optional(),
|
|
24
30
|
notes: z.array(z.string()).default([])
|
|
25
31
|
})
|
|
26
32
|
.passthrough();
|
|
@@ -28,6 +34,6 @@ export const agentInstallSchema = z
|
|
|
28
34
|
export const installStateSchema = z
|
|
29
35
|
.object({
|
|
30
36
|
schemaVersion: z.literal(1).default(1),
|
|
31
|
-
agents: z.record(agentInstallSchema).default({})
|
|
37
|
+
agents: z.record(z.string(), agentInstallSchema).default({})
|
|
32
38
|
})
|
|
33
39
|
.passthrough();
|
|
@@ -124,3 +124,8 @@ export declare const DELIVERY_STAGE_NAMES: {
|
|
|
124
124
|
/** In an identity's state directory: its cached access token and its device credential state (AWT-356). */
|
|
125
125
|
export declare const ACCESS_TOKEN_FILE_NAME = "access-token.json";
|
|
126
126
|
export declare const DEVICE_STATE_FILE_NAME = "device.json";
|
|
127
|
+
/**
|
|
128
|
+
* How long a `repo.tree` whose upload the delivery budget cut short waits before the next try.
|
|
129
|
+
* Not an attempt: the tree was fine, the link was slow. A catalog tree is never urgent.
|
|
130
|
+
*/
|
|
131
|
+
export declare const TREE_DEFERRED_RETRY_MS: number;
|
|
@@ -124,3 +124,8 @@ export const DELIVERY_STAGE_NAMES = {
|
|
|
124
124
|
/** In an identity's state directory: its cached access token and its device credential state (AWT-356). */
|
|
125
125
|
export const ACCESS_TOKEN_FILE_NAME = 'access-token.json';
|
|
126
126
|
export const DEVICE_STATE_FILE_NAME = 'device.json';
|
|
127
|
+
/**
|
|
128
|
+
* How long a `repo.tree` whose upload the delivery budget cut short waits before the next try.
|
|
129
|
+
* Not an attempt: the tree was fine, the link was slow. A catalog tree is never urgent.
|
|
130
|
+
*/
|
|
131
|
+
export const TREE_DEFERRED_RETRY_MS = 15 * 60_000;
|
package/dist/transport/queue.js
CHANGED
|
@@ -6,7 +6,7 @@ import { writeFileAtomic } from '../storage/atomic-file.js';
|
|
|
6
6
|
import { acquireLock } from '../storage/lock.js';
|
|
7
7
|
import { claimSweep } from '../storage/sweep-marker.js';
|
|
8
8
|
import { SECRET_FILE_MODE, SWEEP_MARKER_FILE } from '../storage/constants/storage.constants.js';
|
|
9
|
-
import { ANY_DESTINATION, AUTH_REJECTED_STATUSES, BACKOFF_BASE_MS, BACKOFF_JITTER_MIN, BACKOFF_JITTER_RANGE, BACKOFF_MAX_MS, MAX_ISOLATION_SENDS, MS_PER_DAY, QUEUE_DRAIN_LOCK, QUEUE_FILE_SUFFIX, QUEUE_SCAN_CURSOR_FILE, QUEUE_SWEEP_INTERVAL_MS, RE_UNSAFE_QUEUE_NAME } from './constants/transport.constants.js';
|
|
9
|
+
import { ANY_DESTINATION, AUTH_REJECTED_STATUSES, BACKOFF_BASE_MS, BACKOFF_JITTER_MIN, BACKOFF_JITTER_RANGE, BACKOFF_MAX_MS, MAX_ISOLATION_SENDS, MS_PER_DAY, QUEUE_DRAIN_LOCK, QUEUE_FILE_SUFFIX, QUEUE_SCAN_CURSOR_FILE, QUEUE_SWEEP_INTERVAL_MS, RE_UNSAFE_QUEUE_NAME, TREE_DEFERRED_RETRY_MS } from './constants/transport.constants.js';
|
|
10
10
|
import { sendEvents } from './send.js';
|
|
11
11
|
import { queueEntrySchema } from './schemas/queue.schema.js';
|
|
12
12
|
export { ANY_DESTINATION } from './constants/transport.constants.js';
|
|
@@ -103,10 +103,7 @@ export class EventQueue {
|
|
|
103
103
|
const collected = await this.collectDue(transport, nowMs, maxBatch);
|
|
104
104
|
// Oldest first among what was scanned: hash-ordered filenames would
|
|
105
105
|
// otherwise let a large backlog defer the same late-sorting entries.
|
|
106
|
-
const batch = collected.due
|
|
107
|
-
.slice()
|
|
108
|
-
.sort((a, b) => Date.parse(a.entry.firstQueuedAt) - Date.parse(b.entry.firstQueuedAt))
|
|
109
|
-
.slice(0, maxBatch);
|
|
106
|
+
const batch = treesLastAndAlone(collected.due.slice().sort((a, b) => Date.parse(a.entry.firstQueuedAt) - Date.parse(b.entry.firstQueuedAt)), maxBatch);
|
|
110
107
|
const sent = batch.length === 0 ? EMPTY_DELTA : await this.sendBatch(transport, batch, nowMs, authBlock);
|
|
111
108
|
const stats = { ...mergeDeltas(mergeDeltas(swept, collected.delta), sent), skipped: false };
|
|
112
109
|
await report(statsRecorder, stats);
|
|
@@ -323,8 +320,16 @@ export class EventQueue {
|
|
|
323
320
|
await authBlock?.clear();
|
|
324
321
|
return { ...EMPTY_DELTA, sent: batch.length, rejected: reportRejected(result.counters?.rejected, 'the drained batch') };
|
|
325
322
|
}
|
|
326
|
-
if (result.deferred)
|
|
323
|
+
if (result.deferred) {
|
|
324
|
+
// A tree the budget cut short would be cut short again on the next hook,
|
|
325
|
+
// re-uploading megabytes on a slow link every time: postpone it, without
|
|
326
|
+
// spending an attempt, since nothing was wrong with it.
|
|
327
|
+
const [only] = batch;
|
|
328
|
+
if (batch.length === 1 && only && isTreeEntry(only)) {
|
|
329
|
+
await writeFileAtomic(only.file, JSON.stringify({ ...only.entry, nextAttemptAt: new Date(nowMs + TREE_DEFERRED_RETRY_MS).toISOString() }), SECRET_FILE_MODE);
|
|
330
|
+
}
|
|
327
331
|
return { ...EMPTY_DELTA, failed: batch.length };
|
|
332
|
+
}
|
|
328
333
|
debugLog('queue drain failed', result.error ?? `status ${result.status}`);
|
|
329
334
|
if (result.status !== undefined && AUTH_REJECTED_STATUSES.has(result.status)) {
|
|
330
335
|
// The credential was refused, so nothing in this batch is at fault and
|
|
@@ -517,6 +522,35 @@ function mergeDeltas(left, right) {
|
|
|
517
522
|
rejected: left.rejected + right.rejected
|
|
518
523
|
};
|
|
519
524
|
}
|
|
525
|
+
/**
|
|
526
|
+
* The batch one pass sends: everything else first, and a `repo.tree` only
|
|
527
|
+
* alone, when nothing else is due.
|
|
528
|
+
*
|
|
529
|
+
* A tree is up to 4 MiB on its own and the gateway refuses a body over 8 MiB
|
|
530
|
+
* without retry, so two trees, or one beside a backlog, could lose a whole
|
|
531
|
+
* batch. Last, not first: a tree that keeps deferring on a slow link would
|
|
532
|
+
* otherwise sit at the head and starve the spend records behind it, and a
|
|
533
|
+
* catalog tree is never as urgent as a turn.
|
|
534
|
+
*
|
|
535
|
+
* @param ordered - Due entries, oldest first.
|
|
536
|
+
* @param maxBatch - Ceiling on the batch.
|
|
537
|
+
* @returns The entries to send now.
|
|
538
|
+
*/
|
|
539
|
+
function treesLastAndAlone(ordered, maxBatch) {
|
|
540
|
+
const others = ordered.filter((due) => !isTreeEntry(due));
|
|
541
|
+
if (others.length > 0)
|
|
542
|
+
return others.slice(0, maxBatch);
|
|
543
|
+
return ordered.slice(0, 1);
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Whether a queued entry is a `repo.tree`, the one record large enough to be batched on its own.
|
|
547
|
+
*
|
|
548
|
+
* @param due - A due entry.
|
|
549
|
+
* @returns True for a tree.
|
|
550
|
+
*/
|
|
551
|
+
function isTreeEntry(due) {
|
|
552
|
+
return due.entry.event.event?.type === 'repo.tree';
|
|
553
|
+
}
|
|
520
554
|
/**
|
|
521
555
|
* Log events the backend permanently refused inside an accepted batch.
|
|
522
556
|
*
|
|
@@ -11,20 +11,5 @@ export declare const queueEntrySchema: z.ZodObject<{
|
|
|
11
11
|
attempts: z.ZodDefault<z.ZodNumber>;
|
|
12
12
|
firstQueuedAt: z.ZodString;
|
|
13
13
|
nextAttemptAt: z.ZodString;
|
|
14
|
-
/** Events URL this entry was queued for; absent on pre-destination entries. */
|
|
15
14
|
destination: z.ZodOptional<z.ZodString>;
|
|
16
|
-
},
|
|
17
|
-
event: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
18
|
-
attempts: z.ZodDefault<z.ZodNumber>;
|
|
19
|
-
firstQueuedAt: z.ZodString;
|
|
20
|
-
nextAttemptAt: z.ZodString;
|
|
21
|
-
/** Events URL this entry was queued for; absent on pre-destination entries. */
|
|
22
|
-
destination: z.ZodOptional<z.ZodString>;
|
|
23
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
24
|
-
event: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
25
|
-
attempts: z.ZodDefault<z.ZodNumber>;
|
|
26
|
-
firstQueuedAt: z.ZodString;
|
|
27
|
-
nextAttemptAt: z.ZodString;
|
|
28
|
-
/** Events URL this entry was queued for; absent on pre-destination entries. */
|
|
29
|
-
destination: z.ZodOptional<z.ZodString>;
|
|
30
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
15
|
+
}, z.core.$loose>;
|
|
@@ -8,7 +8,7 @@ import { z } from 'zod';
|
|
|
8
8
|
*/
|
|
9
9
|
export const queueEntrySchema = z
|
|
10
10
|
.object({
|
|
11
|
-
event: z.record(z.unknown()),
|
|
11
|
+
event: z.record(z.string(), z.unknown()),
|
|
12
12
|
attempts: z.number().int().nonnegative().default(0),
|
|
13
13
|
firstQueuedAt: z.string(),
|
|
14
14
|
nextAttemptAt: z.string(),
|
|
@@ -142,6 +142,23 @@ export declare const MAX_TURN_FILES = 500;
|
|
|
142
142
|
export declare const MAX_PROMPT_TEXT_LENGTH = 4000;
|
|
143
143
|
export declare const MAX_TOOL_INPUT_LENGTH = 2000;
|
|
144
144
|
export declare const MAX_TURN_TOOL_INPUTS = 50;
|
|
145
|
+
/**
|
|
146
|
+
* Tool calls one summary sends as `tool_events`; core clamps at the same
|
|
147
|
+
* count. A longer turn sends its first calls, and `tool_calls` and
|
|
148
|
+
* `tools_used` still count every one.
|
|
149
|
+
*/
|
|
150
|
+
export declare const MAX_TURN_TOOL_EVENTS = 200;
|
|
151
|
+
/** Core's bound on a tool name and a call id. */
|
|
152
|
+
export declare const MAX_TOOL_EVENT_ID_LENGTH = 200;
|
|
153
|
+
/** The exit codes core accepts. */
|
|
154
|
+
export declare const INT32_MIN = -2147483648;
|
|
155
|
+
export declare const INT32_MAX = 2147483647;
|
|
156
|
+
/** An unkeyed digest as core takes one. */
|
|
157
|
+
export declare const RE_SHA256_HEX: RegExp;
|
|
158
|
+
/** Metadata key of the content-free tool-call block an adapter puts on a tool event. */
|
|
159
|
+
export declare const TOOL_CALL_KEY = "toolCall";
|
|
160
|
+
/** Every turn record kind this release reads back; a file of any other kind is skipped. */
|
|
161
|
+
export declare const TURN_RECORD_KINDS: ReadonlySet<string>;
|
|
145
162
|
/**
|
|
146
163
|
* The longest session title sent, in UTF-16 units — what core cuts at — and
|
|
147
164
|
* never through a code point. Scrubbed whole first, like prompt text.
|
|
@@ -163,6 +163,23 @@ export const MAX_TURN_FILES = 500;
|
|
|
163
163
|
export const MAX_PROMPT_TEXT_LENGTH = 4000;
|
|
164
164
|
export const MAX_TOOL_INPUT_LENGTH = 2000;
|
|
165
165
|
export const MAX_TURN_TOOL_INPUTS = 50;
|
|
166
|
+
/**
|
|
167
|
+
* Tool calls one summary sends as `tool_events`; core clamps at the same
|
|
168
|
+
* count. A longer turn sends its first calls, and `tool_calls` and
|
|
169
|
+
* `tools_used` still count every one.
|
|
170
|
+
*/
|
|
171
|
+
export const MAX_TURN_TOOL_EVENTS = 200;
|
|
172
|
+
/** Core's bound on a tool name and a call id. */
|
|
173
|
+
export const MAX_TOOL_EVENT_ID_LENGTH = 200;
|
|
174
|
+
/** The exit codes core accepts. */
|
|
175
|
+
export const INT32_MIN = -2_147_483_648;
|
|
176
|
+
export const INT32_MAX = 2_147_483_647;
|
|
177
|
+
/** An unkeyed digest as core takes one. */
|
|
178
|
+
export const RE_SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
179
|
+
/** Metadata key of the content-free tool-call block an adapter puts on a tool event. */
|
|
180
|
+
export const TOOL_CALL_KEY = 'toolCall';
|
|
181
|
+
/** Every turn record kind this release reads back; a file of any other kind is skipped. */
|
|
182
|
+
export const TURN_RECORD_KINDS = new Set(['prompt', 'tool', 'tool-start', 'response', 'checkout']);
|
|
166
183
|
/**
|
|
167
184
|
* The longest session title sent, in UTF-16 units — what core cuts at — and
|
|
168
185
|
* never through a code point. Scrubbed whole first, like prompt text.
|
package/dist/turns/index.d.ts
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* closes the turn into one flat summary, and the backend finalizes its usage
|
|
4
4
|
* from the atomic llm.call ledger.
|
|
5
5
|
*/
|
|
6
|
-
export type { AgentUsageSummary, BuildTurnSummaryInput, TouchedFiles, TurnSummaryEvent, TurnUsageStatus } from './types/turn-summary.types.js';
|
|
7
|
-
export type { PromptRecord, ResponseRecord, SessionModelRecord, ToolRecord, TurnRecord, TurnStateEntry } from './types/turn-state.types.js';
|
|
6
|
+
export type { AgentUsageSummary, BuildTurnSummaryInput, ToolEvent, TouchedFiles, TurnSummaryEvent, TurnUsageStatus } from './types/turn-summary.types.js';
|
|
7
|
+
export type { PromptRecord, ResponseRecord, SessionModelRecord, ToolRecord, ToolStartRecord, TurnRecord, TurnStateEntry } from './types/turn-state.types.js';
|
|
8
8
|
export type { ReadTurnUsageRetry, TranscriptReader, TranscriptUsageEntry, TurnUsage } from './types/transcript.types.js';
|
|
9
9
|
export type { TrackTurnOptions, TurnWindow } from './types/turn-tracker.types.js';
|
|
10
10
|
export type { AggregateTurnUsageOptions, UsageTotals } from './types/aggregate-usage.types.js';
|
|
11
11
|
export { PROVIDER_LABELS, TURN_STATE_TTL_MS, USAGE_RETRY } from './constants/turns.constants.js';
|
|
12
|
+
export { buildToolEvents } from './tool-events.js';
|
|
12
13
|
export { buildTurnSummary } from './turn-summary.js';
|
|
13
14
|
export { TurnStateStore } from './turn-state.js';
|
|
14
15
|
export { readTurnUsage } from './claude-transcript.js';
|
package/dist/turns/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { PROVIDER_LABELS, TURN_STATE_TTL_MS, USAGE_RETRY } from './constants/turns.constants.js';
|
|
2
|
+
export { buildToolEvents } from './tool-events.js';
|
|
2
3
|
export { buildTurnSummary } from './turn-summary.js';
|
|
3
4
|
export { TurnStateStore } from './turn-state.js';
|
|
4
5
|
export { readTurnUsage } from './claude-transcript.js';
|