@peer-agent/protocol 0.1.0-rc.5 → 0.1.0-rc.50
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/dist/acceptance-close-gate.d.ts +10 -1
- package/dist/acceptance-close-gate.js +12 -0
- package/dist/agent-supervision.d.ts +81 -0
- package/dist/agent-supervision.js +1 -0
- package/dist/attention.d.ts +44 -0
- package/dist/attention.js +1 -0
- package/dist/bot-access-policy.d.ts +29 -0
- package/dist/bot-access-policy.js +1 -0
- package/dist/bot-conversation-read.d.ts +67 -0
- package/dist/bot-conversation-read.js +9 -0
- package/dist/bot-direct-step.d.ts +11 -0
- package/dist/bot-direct-step.js +1 -0
- package/dist/bot-git.d.ts +55 -0
- package/dist/bot-git.js +1 -0
- package/dist/bot-model-selection.d.ts +13 -0
- package/dist/bot-model-selection.js +1 -0
- package/dist/browser-window.d.ts +48 -0
- package/dist/browser-window.js +23 -0
- package/dist/capability-admission.d.ts +20 -0
- package/dist/capability-admission.js +1 -0
- package/dist/compaction-history-selection.d.ts +15 -0
- package/dist/compaction-history-selection.js +30 -0
- package/dist/compaction.d.ts +5 -0
- package/dist/compaction.js +6 -0
- package/dist/context-accounting.d.ts +3 -0
- package/dist/conversation-execution.d.ts +68 -0
- package/dist/conversation-execution.js +222 -0
- package/dist/delegation-coordination.d.ts +81 -0
- package/dist/delegation-coordination.js +1 -0
- package/dist/delegation.d.ts +260 -7
- package/dist/delegation.js +97 -39
- package/dist/document-reference.d.ts +111 -0
- package/dist/document-reference.js +1 -0
- package/dist/evidence-inspection.d.ts +64 -0
- package/dist/evidence-inspection.js +1 -0
- package/dist/gemini-standard-pricing.json +105 -0
- package/dist/goal.d.ts +50 -2
- package/dist/hook-observation.d.ts +2 -0
- package/dist/hook-observation.js +19 -0
- package/dist/index.d.ts +109 -25
- package/dist/index.js +38 -0
- package/dist/input-prediction.d.ts +86 -0
- package/dist/input-prediction.js +48 -0
- package/dist/intent-coordination.d.ts +201 -0
- package/dist/intent-coordination.js +1 -0
- package/dist/interactive-result.d.ts +363 -0
- package/dist/interactive-result.js +215 -0
- package/dist/interactive-verification.d.ts +41 -0
- package/dist/interactive-verification.js +65 -0
- package/dist/local-git.d.ts +44 -0
- package/dist/local-git.js +3 -0
- package/dist/local-image.d.ts +53 -0
- package/dist/local-image.js +5 -0
- package/dist/local-read.d.ts +9 -0
- package/dist/local-read.js +1 -0
- package/dist/memory.d.ts +71 -11
- package/dist/memory.js +12 -0
- package/dist/model-reasoning.d.ts +16 -0
- package/dist/model-reasoning.js +25 -0
- package/dist/model-routing.d.ts +39 -3
- package/dist/model-routing.js +31 -5
- package/dist/native-process.d.ts +21 -0
- package/dist/native-process.js +51 -0
- package/dist/parent-coordination.d.ts +104 -0
- package/dist/parent-coordination.js +2 -0
- package/dist/project-agent-failure.d.ts +30 -0
- package/dist/project-agent-failure.js +44 -0
- package/dist/project-input-recovery.d.ts +83 -0
- package/dist/project-input-recovery.js +25 -0
- package/dist/project-matter.d.ts +225 -0
- package/dist/project-matter.js +1 -0
- package/dist/project-recovery.d.ts +43 -0
- package/dist/project-recovery.js +1 -0
- package/dist/project.d.ts +136 -0
- package/dist/project.js +130 -5
- package/dist/quiet-reply.d.ts +9 -0
- package/dist/quiet-reply.js +43 -0
- package/dist/remote-access.d.ts +15 -0
- package/dist/remote-access.js +1 -1
- package/dist/reply-delivery.d.ts +28 -0
- package/dist/reply-delivery.js +1 -0
- package/dist/resource-edit-execution.d.ts +68 -0
- package/dist/resource-edit-execution.js +96 -0
- package/dist/resource-edit.d.ts +237 -0
- package/dist/resource-edit.js +134 -0
- package/dist/resource-feedback-transport.d.ts +26 -0
- package/dist/resource-feedback-transport.js +94 -0
- package/dist/resource-feedback.d.ts +98 -0
- package/dist/resource-feedback.js +151 -0
- package/dist/resource-file-replace.d.ts +36 -0
- package/dist/resource-file-replace.js +40 -0
- package/dist/resource-reference-hints.d.ts +3 -0
- package/dist/resource-reference-hints.js +58 -0
- package/dist/resource-window.d.ts +222 -0
- package/dist/resource-window.js +252 -0
- package/dist/runtime-session-facts.d.ts +58 -0
- package/dist/runtime-session-facts.js +57 -0
- package/dist/session-control.d.ts +211 -0
- package/dist/session-control.js +48 -0
- package/dist/session-facts.d.ts +29 -0
- package/dist/session-facts.js +35 -0
- package/dist/skill-marketplace.d.ts +39 -4
- package/dist/spend-budget.d.ts +69 -0
- package/dist/spend-budget.js +1 -0
- package/dist/system-context.d.ts +7 -0
- package/dist/task-overview.d.ts +91 -0
- package/dist/task-overview.js +325 -17
- package/dist/tool-activity-preview.d.ts +4 -0
- package/dist/tool-activity-preview.js +72 -0
- package/dist/updater.d.ts +13 -3
- package/dist/usage-accounting.d.ts +42 -1
- package/dist/user-anchor.d.ts +17 -0
- package/dist/user-anchor.js +1 -0
- package/dist/work-coordination.d.ts +188 -0
- package/dist/work-coordination.js +1 -0
- package/dist/work-hook.d.ts +3 -0
- package/dist/work-hook.js +76 -0
- package/dist/working-plan.d.ts +18 -0
- package/dist/working-plan.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { interactiveToken, normalizeInteractiveReference } from "./interactive-result.js";
|
|
2
|
+
const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
3
|
+
const keys = (value, allowed) => Object.keys(value).every(key => allowed.includes(key));
|
|
4
|
+
const token = (value) => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/.test(value) && !value.includes('..');
|
|
5
|
+
const text = (value, max) => typeof value === 'string' && !!value.trim() && value.length <= max && !/[\u0000-\u001f]/.test(value);
|
|
6
|
+
const point = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 10_000_000;
|
|
7
|
+
function reference(raw) {
|
|
8
|
+
if (!object(raw) || !keys(raw, ['workspaceId', 'path', 'relativeTo', 'task', 'kind', 'expectedObservation', 'revision']) || !token(raw.workspaceId) || !text(raw.path, 8192))
|
|
9
|
+
return;
|
|
10
|
+
if (raw.kind !== undefined && raw.kind !== 'file' && raw.kind !== 'directory' || raw.relativeTo !== undefined && !text(raw.relativeTo, 8192))
|
|
11
|
+
return;
|
|
12
|
+
let task, expectedObservation, revision;
|
|
13
|
+
if (raw.task !== undefined) {
|
|
14
|
+
if (!object(raw.task) || !keys(raw.task, ['sessionId', 'planId']) || !token(raw.task.sessionId) || !token(raw.task.planId))
|
|
15
|
+
return;
|
|
16
|
+
task = { sessionId: raw.task.sessionId, planId: raw.task.planId };
|
|
17
|
+
}
|
|
18
|
+
if (raw.expectedObservation !== undefined) {
|
|
19
|
+
const e = raw.expectedObservation;
|
|
20
|
+
if (!object(e) || !keys(e, ['resourceId', 'contentVersion']) || (typeof e.resourceId !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(e.resourceId))
|
|
21
|
+
|| e.contentVersion !== undefined && (typeof e.contentVersion !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(e.contentVersion)))
|
|
22
|
+
return;
|
|
23
|
+
expectedObservation = { resourceId: e.resourceId, ...(typeof e.contentVersion === 'string' ? { contentVersion: e.contentVersion } : {}) };
|
|
24
|
+
}
|
|
25
|
+
if (raw.revision !== undefined) {
|
|
26
|
+
const r = raw.revision;
|
|
27
|
+
if (!object(r) || !keys(r, ['kind', 'commit', 'repositoryId']) || r.kind !== 'git' || typeof r.commit !== 'string' || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(r.commit)
|
|
28
|
+
|| r.repositoryId !== undefined && !text(r.repositoryId, 1024))
|
|
29
|
+
return;
|
|
30
|
+
revision = { kind: 'git', commit: r.commit, ...(typeof r.repositoryId === 'string' ? { repositoryId: r.repositoryId } : {}) };
|
|
31
|
+
}
|
|
32
|
+
return { workspaceId: raw.workspaceId, path: raw.path, ...(raw.kind ? { kind: raw.kind } : {}),
|
|
33
|
+
...(typeof raw.relativeTo === 'string' ? { relativeTo: raw.relativeTo } : {}), ...(task ? { task } : {}), ...(expectedObservation ? { expectedObservation } : {}), ...(revision ? { revision } : {}) };
|
|
34
|
+
}
|
|
35
|
+
function resource(raw) {
|
|
36
|
+
if (!object(raw))
|
|
37
|
+
return;
|
|
38
|
+
if (raw.kind === 'interactive') {
|
|
39
|
+
if (!keys(raw, ['kind', 'reference']))
|
|
40
|
+
return;
|
|
41
|
+
const fixed = normalizeInteractiveReference(raw.reference);
|
|
42
|
+
return fixed ? { kind: 'interactive', reference: fixed } : undefined;
|
|
43
|
+
}
|
|
44
|
+
const ref = reference(raw.reference);
|
|
45
|
+
if (!ref)
|
|
46
|
+
return;
|
|
47
|
+
if (raw.kind === 'directory') {
|
|
48
|
+
if (!keys(raw, ['kind', 'reference']) || ref.revision || ref.expectedObservation)
|
|
49
|
+
return;
|
|
50
|
+
return { kind: 'directory', reference: { ...ref, kind: 'directory' } };
|
|
51
|
+
}
|
|
52
|
+
if (raw.kind === 'comparison') {
|
|
53
|
+
if (!keys(raw, ['kind', 'reference', 'fromRef', 'toRef', 'comparison']) || ref.revision || ref.expectedObservation || !text(raw.fromRef, 256)
|
|
54
|
+
|| raw.toRef !== undefined && !text(raw.toRef, 256) || raw.comparison !== undefined && (typeof raw.comparison !== 'string' || !['working', 'staged'].includes(raw.comparison)))
|
|
55
|
+
return;
|
|
56
|
+
// A working/index comparison cannot silently discard a supplied immutable endpoint.
|
|
57
|
+
if (raw.comparison && (raw.fromRef !== 'HEAD' || raw.toRef !== undefined))
|
|
58
|
+
return;
|
|
59
|
+
if (!raw.comparison && (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(raw.fromRef)
|
|
60
|
+
|| typeof raw.toRef === 'string' && !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(raw.toRef)))
|
|
61
|
+
return;
|
|
62
|
+
return { kind: 'comparison', reference: { ...ref, kind: 'directory' }, fromRef: raw.fromRef,
|
|
63
|
+
...(typeof raw.toRef === 'string' ? { toRef: raw.toRef } : {}), ...(raw.comparison ? { comparison: raw.comparison } : {}) };
|
|
64
|
+
}
|
|
65
|
+
if (raw.kind !== 'document' || !keys(raw, ['kind', 'reference', 'mode', 'comparison', 'line', 'delivery']) || ref.kind === 'directory'
|
|
66
|
+
|| typeof raw.mode !== 'string' || !['preview', 'source', 'diff'].includes(raw.mode) || ref.revision && raw.mode === 'diff'
|
|
67
|
+
|| raw.mode === 'diff' && raw.comparison === undefined
|
|
68
|
+
|| raw.comparison !== undefined && (raw.mode !== 'diff' || typeof raw.comparison !== 'string' || !['working', 'staged'].includes(raw.comparison))
|
|
69
|
+
|| raw.line !== undefined && (!Number.isSafeInteger(raw.line) || Number(raw.line) < 1 || Number(raw.line) > 1_000_000))
|
|
70
|
+
return;
|
|
71
|
+
let delivery;
|
|
72
|
+
if (raw.delivery !== undefined) {
|
|
73
|
+
const d = raw.delivery;
|
|
74
|
+
if (ref.revision || !object(d) || !keys(d, ['evidenceRef', 'artifactRef']) || !text(d.evidenceRef, 500) || /[\s\\]/.test(d.evidenceRef) || d.evidenceRef.includes('..') || !text(d.artifactRef, 8192))
|
|
75
|
+
return;
|
|
76
|
+
delivery = { evidenceRef: d.evidenceRef, artifactRef: d.artifactRef };
|
|
77
|
+
}
|
|
78
|
+
const common = { kind: 'document', reference: { ...ref, kind: 'file' },
|
|
79
|
+
...(typeof raw.line === 'number' ? { line: raw.line } : {}), ...(delivery ? { delivery } : {}) };
|
|
80
|
+
return raw.mode === 'diff' ? { ...common, mode: 'diff', comparison: raw.comparison }
|
|
81
|
+
: { ...common, mode: raw.mode };
|
|
82
|
+
}
|
|
83
|
+
/** Only bounded hints for this kind of view; never accept a body, permission, browser instance or draft. */
|
|
84
|
+
export function normalizeResourceWindowNavigation(raw, kind) {
|
|
85
|
+
if (!object(raw) || !keys(raw, kind === 'interactive' ? ['top', 'left'] : kind === 'directory' ? ['top', 'left', 'selected', 'expanded', 'filter'] : kind === 'comparison' ? ['top', 'left', 'selected', 'positions'] : ['top', 'left', 'mode', 'positions']) || !point(raw.top) || !point(raw.left))
|
|
86
|
+
return;
|
|
87
|
+
if (raw.selected !== undefined && !text(raw.selected, 8192) || raw.filter !== undefined && (typeof raw.filter !== 'string' || raw.filter.length > 256 || /[\u0000-\u001f]/.test(raw.filter))
|
|
88
|
+
|| raw.expanded !== undefined && (!Array.isArray(raw.expanded) || raw.expanded.length > 64 || !raw.expanded.every(value => text(value, 8192))))
|
|
89
|
+
return;
|
|
90
|
+
if (raw.mode !== undefined && raw.mode !== 'preview' && raw.mode !== 'source')
|
|
91
|
+
return;
|
|
92
|
+
const relative = (value) => text(value, 4096) && (value === '.' || !/^[\\/]/.test(value) && value.split('/').length <= 16 && value.split('/').every(part => part && part !== '.' && part !== '..' && !/[\\:]/.test(part)));
|
|
93
|
+
if (kind === 'directory' && (raw.selected !== undefined && !relative(raw.selected)
|
|
94
|
+
|| Array.isArray(raw.expanded) && !raw.expanded.every(relative)))
|
|
95
|
+
return;
|
|
96
|
+
if (raw.positions !== undefined && (!Array.isArray(raw.positions) || raw.positions.length > 12 || !raw.positions.every(value => object(value) && keys(value, ['key', 'top', 'left']) && text(value.key, 8192) && point(value.top) && point(value.left)
|
|
97
|
+
&& (kind !== 'document' || ['preview', 'source', 'diff'].includes(value.key)))))
|
|
98
|
+
return;
|
|
99
|
+
if (Array.isArray(raw.positions) && new Set(raw.positions.map(value => value.key)).size !== raw.positions.length)
|
|
100
|
+
return;
|
|
101
|
+
return { top: raw.top, left: raw.left, ...(typeof raw.selected === 'string' ? { selected: raw.selected } : {}),
|
|
102
|
+
...(typeof raw.filter === 'string' ? { filter: raw.filter } : {}), ...(Array.isArray(raw.expanded) ? { expanded: [...new Set(raw.expanded)] } : {}),
|
|
103
|
+
...(raw.mode ? { mode: raw.mode } : {}), ...(Array.isArray(raw.positions) ? { positions: raw.positions.map(value => ({ key: value.key, top: value.top, left: value.left })) } : {}) };
|
|
104
|
+
}
|
|
105
|
+
export function normalizeResourceWindowRequest(raw) {
|
|
106
|
+
if (!object(raw) || !keys(raw, ['resource', 'sourceTabId', 'navigation']) || raw.sourceTabId !== undefined && !token(raw.sourceTabId))
|
|
107
|
+
return;
|
|
108
|
+
const target = resource(raw.resource);
|
|
109
|
+
if (!target)
|
|
110
|
+
return;
|
|
111
|
+
const navigation = raw.navigation === undefined ? undefined : normalizeResourceWindowNavigation(raw.navigation, target.kind);
|
|
112
|
+
if (raw.navigation !== undefined && !navigation)
|
|
113
|
+
return;
|
|
114
|
+
return { resource: target, ...(typeof raw.sourceTabId === 'string' ? { sourceTabId: raw.sourceTabId } : {}), ...(navigation ? { navigation } : {}) };
|
|
115
|
+
}
|
|
116
|
+
export function normalizeResourceWindowOwner(raw) {
|
|
117
|
+
if (!object(raw) || !keys(raw, ['workspaceId', 'conversationId', 'task']) || !token(raw.workspaceId) || !token(raw.conversationId))
|
|
118
|
+
return;
|
|
119
|
+
if (raw.task !== undefined && (!object(raw.task) || !keys(raw.task, ['sessionId', 'planId']) || !token(raw.task.sessionId) || !token(raw.task.planId)))
|
|
120
|
+
return;
|
|
121
|
+
return { workspaceId: raw.workspaceId, conversationId: raw.conversationId,
|
|
122
|
+
...(object(raw.task) ? { task: { sessionId: raw.task.sessionId, planId: raw.task.planId } } : {}) };
|
|
123
|
+
}
|
|
124
|
+
export function resourceWindowWorkspaceId(resource) {
|
|
125
|
+
return resource.kind === 'interactive' ? resource.reference.owner.workspaceId : resource.reference.workspaceId;
|
|
126
|
+
}
|
|
127
|
+
export function resourceWindowTask(resource) {
|
|
128
|
+
return resource.kind === 'interactive' ? undefined : resource.reference.task;
|
|
129
|
+
}
|
|
130
|
+
export function interactiveReferenceKey(reference) {
|
|
131
|
+
return JSON.stringify([reference.owner.workspaceId, reference.owner.conversationId, reference.resultId, reference.contentVersion]);
|
|
132
|
+
}
|
|
133
|
+
const titleHint = (value) => typeof value === 'string' && !!value.trim() && value.length <= 160 && !value.includes('\0');
|
|
134
|
+
export function normalizeResourceInteractiveSession(raw) {
|
|
135
|
+
if (!object(raw) || !keys(raw, ['tabs', 'activeTabId']) || !Array.isArray(raw.tabs) || raw.tabs.length > 32
|
|
136
|
+
|| raw.activeTabId !== null && !interactiveToken(raw.activeTabId))
|
|
137
|
+
return;
|
|
138
|
+
const tabs = [];
|
|
139
|
+
const ids = new Set(), references = new Set();
|
|
140
|
+
for (const item of raw.tabs) {
|
|
141
|
+
if (!object(item) || !keys(item, ['id', 'reference', 'title', 'navigation']) || !interactiveToken(item.id) || item.title !== undefined && !titleHint(item.title))
|
|
142
|
+
return;
|
|
143
|
+
const reference = normalizeInteractiveReference(item.reference);
|
|
144
|
+
const navigation = item.navigation === undefined ? undefined : normalizeResourceWindowNavigation(item.navigation, 'interactive');
|
|
145
|
+
if (!reference || item.navigation !== undefined && !navigation || ids.has(item.id) || references.has(interactiveReferenceKey(reference)))
|
|
146
|
+
return;
|
|
147
|
+
ids.add(item.id);
|
|
148
|
+
references.add(interactiveReferenceKey(reference));
|
|
149
|
+
tabs.push({ id: item.id, reference, ...(item.title !== undefined ? { title: item.title } : {}), ...(navigation ? { navigation } : {}) });
|
|
150
|
+
}
|
|
151
|
+
if (raw.activeTabId !== null && !ids.has(raw.activeTabId))
|
|
152
|
+
return;
|
|
153
|
+
return { tabs, activeTabId: raw.activeTabId };
|
|
154
|
+
}
|
|
155
|
+
export function normalizeResourceRecentReference(raw) {
|
|
156
|
+
if (!object(raw))
|
|
157
|
+
return;
|
|
158
|
+
if (raw.kind === 'interactive') {
|
|
159
|
+
if (!keys(raw, ['kind', 'reference', 'title']) || raw.title !== undefined && !titleHint(raw.title))
|
|
160
|
+
return;
|
|
161
|
+
const reference = normalizeInteractiveReference(raw.reference);
|
|
162
|
+
return reference ? { kind: 'interactive', reference, ...(raw.title !== undefined ? { title: raw.title } : {}) } : undefined;
|
|
163
|
+
}
|
|
164
|
+
if (raw.kind === 'browser') {
|
|
165
|
+
if (!keys(raw, ['kind', 'url']) || !text(raw.url, 8192))
|
|
166
|
+
return;
|
|
167
|
+
try {
|
|
168
|
+
const url = new URL(raw.url);
|
|
169
|
+
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password)
|
|
170
|
+
return;
|
|
171
|
+
return { kind: 'browser', url: url.href };
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (!['document', 'comparison', 'directory'].includes(String(raw.kind)) || !keys(raw, raw.kind === 'document' ? ['kind', 'path', 'relativeTo', 'task', 'revision'] : raw.kind === 'directory' ? ['kind', 'path', 'relativeTo', 'task'] : ['kind', 'path', 'relativeTo', 'task', 'comparison']))
|
|
178
|
+
return;
|
|
179
|
+
// A recent descriptor is a hint scoped by its containing owner. It never supplies a workspace or an access grant.
|
|
180
|
+
const ref = { workspaceId: 'presentation', path: raw.path, ...(raw.relativeTo !== undefined ? { relativeTo: raw.relativeTo } : {}),
|
|
181
|
+
...(raw.task !== undefined ? { task: raw.task } : {}), ...(raw.revision !== undefined ? { revision: raw.revision } : {}) };
|
|
182
|
+
if (raw.kind === 'directory') {
|
|
183
|
+
const request = normalizeResourceWindowRequest({ resource: { kind: 'directory', reference: ref } });
|
|
184
|
+
if (request?.resource.kind !== 'directory')
|
|
185
|
+
return;
|
|
186
|
+
const fixed = request.resource.reference;
|
|
187
|
+
return { kind: 'directory', path: fixed.path, ...(fixed.relativeTo ? { relativeTo: fixed.relativeTo } : {}), ...(fixed.task ? { task: fixed.task } : {}) };
|
|
188
|
+
}
|
|
189
|
+
if (raw.kind === 'document') {
|
|
190
|
+
const request = normalizeResourceWindowRequest({ resource: { kind: 'document', reference: ref, mode: 'preview' } });
|
|
191
|
+
if (request?.resource.kind !== 'document')
|
|
192
|
+
return;
|
|
193
|
+
const fixed = request.resource.reference;
|
|
194
|
+
return { kind: 'document', path: fixed.path, ...(fixed.relativeTo ? { relativeTo: fixed.relativeTo } : {}), ...(fixed.task ? { task: fixed.task } : {}), ...(fixed.revision ? { revision: fixed.revision } : {}) };
|
|
195
|
+
}
|
|
196
|
+
if (!object(raw.comparison) || !keys(raw.comparison, ['fromRef', 'toRef', 'comparison']))
|
|
197
|
+
return;
|
|
198
|
+
const request = normalizeResourceWindowRequest({ resource: { kind: 'comparison', reference: ref, ...raw.comparison } });
|
|
199
|
+
if (request?.resource.kind !== 'comparison')
|
|
200
|
+
return;
|
|
201
|
+
const fixed = request.resource;
|
|
202
|
+
return { kind: 'comparison', path: fixed.reference.path, ...(fixed.reference.relativeTo ? { relativeTo: fixed.reference.relativeTo } : {}), ...(fixed.reference.task ? { task: fixed.reference.task } : {}),
|
|
203
|
+
comparison: { fromRef: fixed.fromRef, ...(fixed.toRef ? { toRef: fixed.toRef } : {}), ...(fixed.comparison ? { comparison: fixed.comparison } : {}) } };
|
|
204
|
+
}
|
|
205
|
+
export function normalizeResourceLayout(raw) {
|
|
206
|
+
if (!object(raw) || !keys(raw, ['order', 'recent', 'interactive']))
|
|
207
|
+
return;
|
|
208
|
+
const interactive = normalizeResourceInteractiveSession(raw.interactive);
|
|
209
|
+
if (!interactive)
|
|
210
|
+
return;
|
|
211
|
+
const list = (value, limit) => Array.isArray(value) && value.length <= limit
|
|
212
|
+
&& value.every(key => typeof key === 'string' && key.length <= 8192 && !/[\u0000-\u001f]/.test(key)
|
|
213
|
+
&& (key === 'launcher' || /^(?:document|browser|conversation|interactive|directory):.+$/.test(key) || key === 'comparison:workspace')) && new Set(value).size === value.length;
|
|
214
|
+
if (!list(raw.order, 200) || !Array.isArray(raw.recent) || raw.recent.length > 16 || new TextEncoder().encode(JSON.stringify(raw)).byteLength > 256 * 1024)
|
|
215
|
+
return;
|
|
216
|
+
const mapped = new Set(interactive.tabs.map(tab => `interactive:${tab.id}`));
|
|
217
|
+
if (raw.order.some(key => key.startsWith('interactive:') && !mapped.has(key))
|
|
218
|
+
|| interactive.activeTabId !== null && !raw.order.includes(`interactive:${interactive.activeTabId}`))
|
|
219
|
+
return;
|
|
220
|
+
const recent = [];
|
|
221
|
+
for (const item of raw.recent) {
|
|
222
|
+
if (typeof item !== 'string' || item.length > 8192)
|
|
223
|
+
return;
|
|
224
|
+
if (list([item], 1)) {
|
|
225
|
+
recent.push(item);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
const ref = normalizeResourceRecentReference(JSON.parse(item));
|
|
230
|
+
if (!ref)
|
|
231
|
+
return;
|
|
232
|
+
const descriptor = JSON.stringify(ref);
|
|
233
|
+
if (descriptor.length > 8192)
|
|
234
|
+
return;
|
|
235
|
+
recent.push(descriptor);
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (new Set(recent).size !== recent.length)
|
|
242
|
+
return;
|
|
243
|
+
const layout = { order: [...raw.order], recent, interactive };
|
|
244
|
+
return new TextEncoder().encode(JSON.stringify(layout)).byteLength <= 256 * 1024 ? layout : undefined;
|
|
245
|
+
}
|
|
246
|
+
export function normalizeResourceLayoutSnapshot(raw) {
|
|
247
|
+
if (!object(raw) || !keys(raw, ['formatVersion', 'revision', 'order', 'recent', 'interactive', 'updatedAt']) || raw.formatVersion !== 2
|
|
248
|
+
|| !Number.isSafeInteger(raw.revision) || Number(raw.revision) < 1 || typeof raw.updatedAt !== 'string' || raw.updatedAt.length > 40 || !Number.isFinite(Date.parse(raw.updatedAt)))
|
|
249
|
+
return;
|
|
250
|
+
const layout = normalizeResourceLayout({ order: raw.order, recent: raw.recent, interactive: raw.interactive });
|
|
251
|
+
return layout ? { formatVersion: 2, ...layout, revision: raw.revision, updatedAt: raw.updatedAt } : undefined;
|
|
252
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type WorkSessionStatus } from './delegation.ts';
|
|
2
|
+
import { type ExecutionOwnership, type FollowUpOwner } from './task-overview.ts';
|
|
3
|
+
export type RuntimeHandling = 'model' | 'host' | 'user' | 'none';
|
|
4
|
+
/** A checked view of existing session facts, never a second lifecycle or execution receipt. */
|
|
5
|
+
export interface RuntimeSessionFacts {
|
|
6
|
+
readonly sessionId: string;
|
|
7
|
+
readonly status: WorkSessionStatus | 'unknown';
|
|
8
|
+
readonly valid: boolean;
|
|
9
|
+
readonly executionOwnership: ExecutionOwnership;
|
|
10
|
+
readonly owner: FollowUpOwner;
|
|
11
|
+
readonly reason: string;
|
|
12
|
+
readonly handling: RuntimeHandling;
|
|
13
|
+
readonly pendingManaged: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function runtimeSessionFacts(value: unknown): RuntimeSessionFacts;
|
|
16
|
+
/** Missing/invalid facts remain obligations; a valid public terminal does not invent live ownership. */
|
|
17
|
+
export declare function hasPendingRuntimeSessions(sessions: readonly unknown[], expectedIds?: readonly string[]): boolean;
|
|
18
|
+
export interface RuntimeSessionOwnership {
|
|
19
|
+
readonly repairSessionIds: readonly string[];
|
|
20
|
+
readonly hostSessionIds: readonly string[];
|
|
21
|
+
readonly waitingSessionIds: readonly string[];
|
|
22
|
+
readonly needsUser: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function runtimeSessionOwnership(sessions: readonly unknown[]): RuntimeSessionOwnership;
|
|
25
|
+
export interface ResourceWaitScope {
|
|
26
|
+
readonly workspaceId: string;
|
|
27
|
+
readonly parentConversationId: string;
|
|
28
|
+
readonly workId: string;
|
|
29
|
+
readonly sessionIds: readonly string[];
|
|
30
|
+
readonly executionBindings?: Readonly<Record<string, {
|
|
31
|
+
readonly executionEpoch: string;
|
|
32
|
+
readonly goalRevision: number;
|
|
33
|
+
}>>;
|
|
34
|
+
}
|
|
35
|
+
export interface ResourceWaitReference {
|
|
36
|
+
readonly kind: 'resource';
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly revision: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ResourceWaitFact {
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
readonly wait: ResourceWaitReference;
|
|
43
|
+
readonly reason: string;
|
|
44
|
+
}
|
|
45
|
+
export type ResourceWaitInspection = {
|
|
46
|
+
readonly state: 'waiting';
|
|
47
|
+
readonly current: ResourceWaitFact;
|
|
48
|
+
} | {
|
|
49
|
+
readonly state: 'ready';
|
|
50
|
+
readonly sessionId: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly state: 'stale' | 'unavailable';
|
|
53
|
+
readonly reason: string;
|
|
54
|
+
};
|
|
55
|
+
export interface ResourceWaitPort {
|
|
56
|
+
readonly read: (scope: ResourceWaitScope) => readonly ResourceWaitFact[];
|
|
57
|
+
readonly inspect: (scope: ResourceWaitScope, wait: ResourceWaitReference) => ResourceWaitInspection;
|
|
58
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { WORK_SESSION_STATUSES } from "./delegation.js";
|
|
2
|
+
import { decideFollowUp } from "./task-overview.js";
|
|
3
|
+
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
4
|
+
const text = (value) => typeof value === 'string' ? value : '';
|
|
5
|
+
const statuses = new Set(WORK_SESSION_STATUSES);
|
|
6
|
+
const ownerships = new Set(['live', 'ended', 'unknown']);
|
|
7
|
+
const owners = new Set(['bot', 'user', 'none']);
|
|
8
|
+
const reasons = new Set(['settled', 'superseded', 'stop_confirmed', 'user_withdrawn',
|
|
9
|
+
'stop_unconfirmed', 'human_request', 'awaiting_human_gate', 'technical_block', 'local_persistence_failed', 'awaiting_acceptance_technical',
|
|
10
|
+
'verification_failed', 'execution_failed', 'live_execution', 'paused', 'unknown_facts', 'obligation_indexed']);
|
|
11
|
+
const hostReasons = new Set(['live_execution', 'stop_unconfirmed', 'unknown_facts', 'local_persistence_failed']);
|
|
12
|
+
export function runtimeSessionFacts(value) {
|
|
13
|
+
const row = record(value), origin = record(row.origin), cancellation = record(origin.cancellation);
|
|
14
|
+
const sessionId = text(row.sessionId), rawStatus = text(row.status);
|
|
15
|
+
const status = statuses.has(rawStatus) ? rawStatus : 'unknown';
|
|
16
|
+
const executionOwnership = ownerships.has(row.executionOwnership)
|
|
17
|
+
? row.executionOwnership : 'unknown';
|
|
18
|
+
const declared = row.followUp === undefined ? null : record(row.followUp);
|
|
19
|
+
const valid = Boolean(sessionId) && status !== 'unknown'
|
|
20
|
+
&& (row.executionOwnership === undefined || ownerships.has(row.executionOwnership))
|
|
21
|
+
&& (!declared || owners.has(declared.owner) && reasons.has(declared.reason))
|
|
22
|
+
&& ['resultConfirmationRequired', 'completionReviewRequired'].every(key => row[key] === undefined || typeof row[key] === 'boolean')
|
|
23
|
+
&& (row.needsUser === undefined || typeof row.needsUser === 'boolean' || Array.isArray(row.needsUser));
|
|
24
|
+
const human = row.resultConfirmationRequired === true || row.completionReviewRequired === true
|
|
25
|
+
|| row.needsUser === true || Array.isArray(row.needsUser) && row.needsUser.length > 0;
|
|
26
|
+
const fallback = status === 'unknown' ? null : decideFollowUp({ status }, {
|
|
27
|
+
accepted: status === 'accepted', humanGate: row.resultConfirmationRequired === true,
|
|
28
|
+
...(typeof cancellation.phase === 'string' ? { cancellationPhase: cancellation.phase } : {}),
|
|
29
|
+
...(cancellation.disposition === 'user_withdrawn' ? { cancellationDisposition: 'user_withdrawn' } : {}),
|
|
30
|
+
}, executionOwnership);
|
|
31
|
+
const owner = declared && owners.has(declared.owner) ? declared.owner : fallback?.owner || 'bot';
|
|
32
|
+
const reason = text(declared?.reason) || fallback?.reason || 'unknown_facts';
|
|
33
|
+
const stopping = reason !== 'obligation_indexed' && (['stopping', 'awaiting_outcome'].includes(status)
|
|
34
|
+
|| status === 'cancelled' && owner !== 'none');
|
|
35
|
+
const handling = !valid ? 'host' : human || owner === 'user' ? 'user'
|
|
36
|
+
: executionOwnership === 'live' || stopping || owner === 'bot' && hostReasons.has(reason) ? 'host'
|
|
37
|
+
: owner === 'none' ? 'none' : 'model';
|
|
38
|
+
return { sessionId, status, valid, executionOwnership, owner, reason, handling,
|
|
39
|
+
pendingManaged: reason === 'obligation_indexed' || (reason === 'execution_failed' && handling === 'none')
|
|
40
|
+
? false
|
|
41
|
+
: handling === 'host' || handling === 'user' || !['accepted', 'cancelled'].includes(status) };
|
|
42
|
+
}
|
|
43
|
+
/** Missing/invalid facts remain obligations; a valid public terminal does not invent live ownership. */
|
|
44
|
+
export function hasPendingRuntimeSessions(sessions, expectedIds = []) {
|
|
45
|
+
return sessions.some(session => runtimeSessionFacts(session).pendingManaged)
|
|
46
|
+
|| expectedIds.some(id => !sessions.some(session => record(session).sessionId === id));
|
|
47
|
+
}
|
|
48
|
+
export function runtimeSessionOwnership(sessions) {
|
|
49
|
+
const facts = sessions.map(runtimeSessionFacts);
|
|
50
|
+
return {
|
|
51
|
+
repairSessionIds: facts.filter(row => row.handling === 'model').map(row => row.sessionId),
|
|
52
|
+
hostSessionIds: facts.filter(row => row.handling === 'host').map(row => row.sessionId),
|
|
53
|
+
waitingSessionIds: facts.filter(row => row.handling === 'host'
|
|
54
|
+
&& (row.executionOwnership === 'live' || row.reason === 'live_execution')).map(row => row.sessionId),
|
|
55
|
+
needsUser: facts.some(row => row.handling === 'user'),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/** Host-issued control and resource facts. None of these receipts grants tool permission. */
|
|
2
|
+
/** Dispatch-declared protection scopes (ADR 127 and ADR 145). */
|
|
3
|
+
export type ExecutionResourceScope = {
|
|
4
|
+
readonly kind: 'directory';
|
|
5
|
+
readonly path: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: 'file';
|
|
8
|
+
readonly path: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'git_common_dir';
|
|
11
|
+
readonly path: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: 'git_ref';
|
|
14
|
+
readonly ref: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: 'remote_object';
|
|
17
|
+
readonly ref: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function normalizeExecutionResourceScope(raw: unknown): ExecutionResourceScope | undefined;
|
|
20
|
+
export interface SessionExecutionIdentity {
|
|
21
|
+
readonly planId: string;
|
|
22
|
+
readonly sessionId: string;
|
|
23
|
+
readonly executionEpoch: string;
|
|
24
|
+
readonly goalRevision?: number;
|
|
25
|
+
readonly generation?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Shape only; a host must still compare it with the current canonical plan. */
|
|
28
|
+
export declare function normalizeSessionExecutionIdentity(raw: unknown): SessionExecutionIdentity | undefined;
|
|
29
|
+
export interface StopBarrierReceipt {
|
|
30
|
+
readonly receiptId: string;
|
|
31
|
+
readonly operationId: string;
|
|
32
|
+
readonly execution: SessionExecutionIdentity;
|
|
33
|
+
readonly admissionClosed: true;
|
|
34
|
+
readonly runnerIdle: true;
|
|
35
|
+
readonly schedulerIdle: true;
|
|
36
|
+
readonly resourceClaims: readonly {
|
|
37
|
+
readonly claimId: string;
|
|
38
|
+
readonly revision: number;
|
|
39
|
+
}[];
|
|
40
|
+
readonly unknownCalls: readonly string[];
|
|
41
|
+
readonly completedAt: string;
|
|
42
|
+
readonly scope: 'managed_execution';
|
|
43
|
+
}
|
|
44
|
+
export interface SessionControlOperation {
|
|
45
|
+
readonly operationId: string;
|
|
46
|
+
readonly requestDigest: string;
|
|
47
|
+
readonly revision: number;
|
|
48
|
+
readonly workspaceId: string;
|
|
49
|
+
readonly parentConversationId: string;
|
|
50
|
+
readonly sessionId: string;
|
|
51
|
+
readonly planId: string;
|
|
52
|
+
readonly kind: 'pause' | 'cancel' | 'takeover' | 'resume';
|
|
53
|
+
readonly authorityRef: string;
|
|
54
|
+
readonly hostEpoch?: string;
|
|
55
|
+
/** Pid of the process that recorded the operation. By itself this is not a death proof. */
|
|
56
|
+
readonly hostPid?: number;
|
|
57
|
+
readonly recorder?: {
|
|
58
|
+
readonly bootId: string;
|
|
59
|
+
readonly pid: number;
|
|
60
|
+
readonly pidStart: string;
|
|
61
|
+
readonly hostId: string;
|
|
62
|
+
readonly acquiredAt: string;
|
|
63
|
+
};
|
|
64
|
+
readonly unproven?: boolean;
|
|
65
|
+
readonly recoveryFactsDigest?: string;
|
|
66
|
+
readonly priorStopReceiptId?: string;
|
|
67
|
+
readonly expectedExecution: SessionExecutionIdentity;
|
|
68
|
+
readonly phase: 'recorded' | 'draining' | 'reconciling' | 'settled';
|
|
69
|
+
readonly outcome?: 'applied' | 'superseded' | 'rejected';
|
|
70
|
+
readonly supersededBy?: string;
|
|
71
|
+
readonly nextAction?: string;
|
|
72
|
+
readonly stopReceipt?: StopBarrierReceipt;
|
|
73
|
+
readonly updatedAt: string;
|
|
74
|
+
}
|
|
75
|
+
export type ExecutionResourceBlocker = {
|
|
76
|
+
readonly kind: 'owner';
|
|
77
|
+
readonly code: 'resource_busy';
|
|
78
|
+
readonly resourceRef: string;
|
|
79
|
+
readonly claimId: string;
|
|
80
|
+
readonly sessionId: string;
|
|
81
|
+
readonly title: string;
|
|
82
|
+
} | {
|
|
83
|
+
readonly kind: 'protection';
|
|
84
|
+
readonly nextAction?: 'reconcile_execution_outcome' | 'confirm_execution_stopped' | 'close_execution_claim';
|
|
85
|
+
readonly code: 'execution_outcome_unknown' | 'execution_stop_unconfirmed';
|
|
86
|
+
readonly resourceRef: string;
|
|
87
|
+
readonly claimId: string;
|
|
88
|
+
readonly sessionId?: string;
|
|
89
|
+
readonly operationId?: string;
|
|
90
|
+
readonly evidenceCalls: readonly string[];
|
|
91
|
+
readonly closeClaimAvailable?: boolean;
|
|
92
|
+
readonly scope?: ExecutionResourceScope;
|
|
93
|
+
readonly unknownOutcomePolicy?: UnknownOutcomePolicyTier;
|
|
94
|
+
readonly reconciliationAvailable?: boolean;
|
|
95
|
+
readonly resolutionTier?: UnknownOutcomeResolutionTier;
|
|
96
|
+
} | {
|
|
97
|
+
readonly kind: 'recovery';
|
|
98
|
+
readonly nextAction?: 'inspect_resource_recovery';
|
|
99
|
+
readonly code: string;
|
|
100
|
+
readonly resourceRef?: string;
|
|
101
|
+
};
|
|
102
|
+
/** A user-authorized end to one resource claim. It is not a stop receipt or a tool result. */
|
|
103
|
+
export interface ExecutionClaimClosure {
|
|
104
|
+
readonly closureId: string;
|
|
105
|
+
readonly claimId: string;
|
|
106
|
+
readonly claimRevision: number;
|
|
107
|
+
readonly execution: SessionExecutionIdentity;
|
|
108
|
+
readonly resourceRef: string;
|
|
109
|
+
readonly unknownCalls: readonly string[];
|
|
110
|
+
readonly authorityRef: string;
|
|
111
|
+
readonly proof: 'verified_dead' | 'legacy_user_confirmed';
|
|
112
|
+
/** ADR 127: present when reconciliation evidence, not a user card, authorized this closure. */
|
|
113
|
+
readonly resolution?: {
|
|
114
|
+
readonly resolutionId: string;
|
|
115
|
+
readonly tier: 'user_confirmed' | 'bot_verified';
|
|
116
|
+
readonly verdict: 'no_effect_observed' | 'effect_observed';
|
|
117
|
+
readonly evidenceDigest: string;
|
|
118
|
+
readonly policyRef?: string;
|
|
119
|
+
};
|
|
120
|
+
readonly scope: 'managed_execution';
|
|
121
|
+
readonly at: string;
|
|
122
|
+
}
|
|
123
|
+
/** ADR 127: user-delegated closure policy for unknown outcomes. Bound to the bot subject (ADR 101); the model reads it but can never write it. */
|
|
124
|
+
export type UnknownOutcomePolicyTier = 'ask' | 'bot_verified';
|
|
125
|
+
export interface UnknownOutcomePolicy {
|
|
126
|
+
readonly workspaceId: string;
|
|
127
|
+
readonly agentConversationId: string;
|
|
128
|
+
readonly tier: UnknownOutcomePolicyTier;
|
|
129
|
+
readonly policyId: string;
|
|
130
|
+
readonly revision: number;
|
|
131
|
+
readonly delegatedAt?: string;
|
|
132
|
+
readonly updatedAt: string;
|
|
133
|
+
}
|
|
134
|
+
export type ReconciliationVerdict = 'no_effect_observed' | 'effect_observed' | 'inconclusive' | 'unfenced_external';
|
|
135
|
+
export type ReconciliationProbeKind = 'process' | 'handle' | 'workspace' | 'git' | 'receipt';
|
|
136
|
+
export interface ReconciliationProbe {
|
|
137
|
+
readonly kind: ReconciliationProbeKind;
|
|
138
|
+
readonly ref: string;
|
|
139
|
+
readonly result: string;
|
|
140
|
+
readonly observedAt: string;
|
|
141
|
+
readonly digest: string;
|
|
142
|
+
}
|
|
143
|
+
/** Host-computed probe bundle. Its verdict can end occupancy at most; it never turns an unknown call into a success. */
|
|
144
|
+
export interface ReconciliationEvidence {
|
|
145
|
+
readonly execution: SessionExecutionIdentity;
|
|
146
|
+
readonly claimId: string;
|
|
147
|
+
readonly claimRevision: number;
|
|
148
|
+
readonly scope: ExecutionResourceScope;
|
|
149
|
+
readonly probes: readonly ReconciliationProbe[];
|
|
150
|
+
readonly verdict: ReconciliationVerdict;
|
|
151
|
+
readonly evidenceDigest: string;
|
|
152
|
+
}
|
|
153
|
+
export type UnknownOutcomeResolutionTier = 'user_confirmed' | 'bot_verified';
|
|
154
|
+
/** Ends occupancy for one claim (ADR 127). Unknown calls stay retained; this is not a tool result, a stop receipt or a success claim. */
|
|
155
|
+
export interface UnknownOutcomeResolution {
|
|
156
|
+
readonly resolutionId: string;
|
|
157
|
+
readonly claimId: string;
|
|
158
|
+
readonly claimRevision: number;
|
|
159
|
+
readonly execution: SessionExecutionIdentity;
|
|
160
|
+
readonly scope: ExecutionResourceScope;
|
|
161
|
+
readonly verdict: ReconciliationVerdict;
|
|
162
|
+
readonly evidenceDigest: string;
|
|
163
|
+
readonly tier: UnknownOutcomeResolutionTier;
|
|
164
|
+
readonly policyRef?: string;
|
|
165
|
+
readonly authorityRef: string;
|
|
166
|
+
readonly unknownCalls: readonly string[];
|
|
167
|
+
readonly at: string;
|
|
168
|
+
}
|
|
169
|
+
/** ADR 131: local transport ownership only; never proof of remote tool effects. */
|
|
170
|
+
export interface NativeMcpHandleObservation {
|
|
171
|
+
readonly schemaVersion: 1;
|
|
172
|
+
readonly role: 'rpc' | 'connection';
|
|
173
|
+
readonly transport: 'stdio' | 'streamable_http' | 'sse';
|
|
174
|
+
readonly registryRevision: string;
|
|
175
|
+
readonly ownerRecorder: NonNullable<SessionControlOperation['recorder']>;
|
|
176
|
+
readonly childRecorder?: NonNullable<SessionControlOperation['recorder']>;
|
|
177
|
+
readonly ownerStopObservation?: 'original_owner_dead';
|
|
178
|
+
readonly childStopObservation?: 'group_absent';
|
|
179
|
+
}
|
|
180
|
+
export interface ExecutionResourceClaim {
|
|
181
|
+
readonly claimId: string;
|
|
182
|
+
readonly resourceRef: string;
|
|
183
|
+
readonly execution: SessionExecutionIdentity;
|
|
184
|
+
readonly workspaceId: string;
|
|
185
|
+
readonly hostEpoch: string;
|
|
186
|
+
readonly state: 'reserved' | 'active' | 'draining' | 'reconciling' | 'released';
|
|
187
|
+
readonly revision: number;
|
|
188
|
+
readonly handles?: Readonly<Record<string, {
|
|
189
|
+
readonly handleId: string;
|
|
190
|
+
readonly toolCallId: string;
|
|
191
|
+
readonly state: 'active' | 'ended' | 'unknown';
|
|
192
|
+
readonly completedAt?: string;
|
|
193
|
+
readonly nativeMcp?: NativeMcpHandleObservation;
|
|
194
|
+
}>>;
|
|
195
|
+
readonly evidenceCalls: readonly string[];
|
|
196
|
+
/** Absent means the legacy directory scope derived from resourceRef; dispatch-declared scopes arrive with claim scope convergence. */
|
|
197
|
+
readonly scope?: ExecutionResourceScope;
|
|
198
|
+
}
|
|
199
|
+
/** Feed the existing lifecycle projector; a stale compatibility mirror cannot revive an old stop. */
|
|
200
|
+
export declare function controlPhasesForOrigin(origin: {
|
|
201
|
+
readonly executionControl?: SessionControlOperation;
|
|
202
|
+
readonly cancellation?: {
|
|
203
|
+
readonly phase: string;
|
|
204
|
+
};
|
|
205
|
+
readonly takeover?: {
|
|
206
|
+
readonly phase: string;
|
|
207
|
+
};
|
|
208
|
+
}): {
|
|
209
|
+
cancellationPhase?: string;
|
|
210
|
+
takeoverPhase?: string;
|
|
211
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function normalizeExecutionResourceScope(raw) {
|
|
2
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw) || ![Object.prototype, null].includes(Object.getPrototypeOf(raw)))
|
|
3
|
+
return;
|
|
4
|
+
const value = raw;
|
|
5
|
+
if (Object.keys(value).length !== 2)
|
|
6
|
+
return;
|
|
7
|
+
if ((value.kind === 'directory' || value.kind === 'file' || value.kind === 'git_common_dir') && typeof value.path === 'string'
|
|
8
|
+
&& value.path.length > 0 && value.path.length <= 2048 && !/[\u0000-\u001f]/.test(value.path))
|
|
9
|
+
return { kind: value.kind, path: value.path };
|
|
10
|
+
if ((value.kind === 'git_ref' || value.kind === 'remote_object') && typeof value.ref === 'string'
|
|
11
|
+
&& /^[A-Za-z0-9][A-Za-z0-9_.:/-]{0,511}$/.test(value.ref) && !value.ref.includes('..'))
|
|
12
|
+
return { kind: value.kind, ref: value.ref };
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
/** Shape only; a host must still compare it with the current canonical plan. */
|
|
16
|
+
export function normalizeSessionExecutionIdentity(raw) {
|
|
17
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw) || ![Object.prototype, null].includes(Object.getPrototypeOf(raw)))
|
|
18
|
+
return;
|
|
19
|
+
const value = raw;
|
|
20
|
+
const token = (item) => typeof item === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/.test(item) && !item.includes('..');
|
|
21
|
+
if (Object.entries(Object.getOwnPropertyDescriptors(value)).some(([key, descriptor]) => !['planId', 'sessionId', 'executionEpoch', 'goalRevision', 'generation'].includes(key) || !('value' in descriptor))
|
|
22
|
+
|| !token(value.planId) || !token(value.sessionId) || typeof value.executionEpoch !== 'string' || !value.executionEpoch.length || value.executionEpoch.length > 512
|
|
23
|
+
|| /[\u0000-\u001f]/.test(value.executionEpoch) || value.generation !== undefined && !token(value.generation)
|
|
24
|
+
|| value.goalRevision !== undefined && (!Number.isSafeInteger(value.goalRevision) || Number(value.goalRevision) < 0))
|
|
25
|
+
return;
|
|
26
|
+
return { planId: value.planId, sessionId: value.sessionId, executionEpoch: value.executionEpoch,
|
|
27
|
+
...(value.generation !== undefined ? { generation: value.generation } : {}), ...(value.goalRevision !== undefined ? { goalRevision: Number(value.goalRevision) } : {}) };
|
|
28
|
+
}
|
|
29
|
+
/** Feed the existing lifecycle projector; a stale compatibility mirror cannot revive an old stop. */
|
|
30
|
+
export function controlPhasesForOrigin(origin) {
|
|
31
|
+
const control = origin.executionControl;
|
|
32
|
+
if (!control)
|
|
33
|
+
return { cancellationPhase: origin.cancellation?.phase, takeoverPhase: origin.takeover?.phase };
|
|
34
|
+
// A barrier that has already recorded why it cannot confirm the stop is not still stopping.
|
|
35
|
+
// Draining remains the in-progress label. This does not turn the refusal into a completed stop.
|
|
36
|
+
const refused = control.phase === 'reconciling' && (Boolean(control.stopReceipt?.unknownCalls.length)
|
|
37
|
+
|| control.nextAction === 'execution_stop_unconfirmed'
|
|
38
|
+
|| control.nextAction === 'execution_outcome_unknown'
|
|
39
|
+
|| control.nextAction === 'reconcile_execution_outcome');
|
|
40
|
+
const stopping = refused ? 'awaiting_outcome' : 'stopping';
|
|
41
|
+
return {
|
|
42
|
+
cancellationPhase: control.kind === 'cancel'
|
|
43
|
+
? control.phase === 'settled' && control.outcome === 'applied' ? 'completed' : stopping
|
|
44
|
+
: origin.cancellation?.phase,
|
|
45
|
+
takeoverPhase: control.phase === 'settled' && control.stopReceipt ? undefined
|
|
46
|
+
: control.kind === 'takeover' ? stopping : origin.takeover?.phase,
|
|
47
|
+
};
|
|
48
|
+
}
|