@peer-agent/protocol 0.1.0-rc.5 → 0.1.0-rc.51
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 +84 -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/group-chat.d.ts +87 -0
- package/dist/group-chat.js +1 -0
- package/dist/hook-observation.d.ts +2 -0
- package/dist/hook-observation.js +19 -0
- package/dist/index.d.ts +117 -25
- package/dist/index.js +41 -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 +117 -12
- 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/persistent-workspace.d.ts +519 -0
- package/dist/persistent-workspace.js +1 -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 +359 -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 +233 -0
- package/dist/project.js +134 -5
- package/dist/prompt-skill.d.ts +31 -0
- package/dist/prompt-skill.js +1 -0
- 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 +110 -0
- package/dist/resource-feedback.js +168 -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/routine.d.ts +82 -0
- package/dist/routine.js +1 -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/dist/workspace.d.ts +35 -0
- package/dist/workspace.js +1 -0
- package/package.json +1 -1
package/dist/memory.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project memory contracts. Entries are facts for continuity, not instructions.
|
|
3
3
|
*/
|
|
4
|
+
export function isMemoryScopeKey(value) {
|
|
5
|
+
if (value === 'global')
|
|
6
|
+
return true;
|
|
7
|
+
if (typeof value !== 'string' || !value.startsWith('project:'))
|
|
8
|
+
return false;
|
|
9
|
+
const workspace = value.slice('project:'.length);
|
|
10
|
+
return /^[a-z0-9][a-z0-9_.-]{0,127}$(?![\s\S])/i.test(workspace) && !workspace.endsWith('.') &&
|
|
11
|
+
!/^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(workspace);
|
|
12
|
+
}
|
|
13
|
+
export function isMemoryRevision(value) {
|
|
14
|
+
return typeof value === 'string' && /^[a-f0-9]{64}$(?![\s\S])/.test(value);
|
|
15
|
+
}
|
|
4
16
|
const SECRET = /sk-[A-Za-z0-9]{8,}|api[_-]?key\s*[:=]|bearer\s+[A-Za-z0-9._\-]{8,}/i;
|
|
5
17
|
const LOOSENING = /不用确认|跳过批准|跳过审批|always allow|skip approval|full_local|不用我批/i;
|
|
6
18
|
const STANDING_ORDER = /以后都|下次都|always do this/i;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Provider-declared effort values. Unknown capabilities do not create UI choices. */
|
|
2
|
+
export type ModelReasoningEffort = 'off' | 'low' | 'medium' | 'default' | 'high' | 'xhigh' | 'max';
|
|
3
|
+
export declare function isModelReasoningEffort(value: unknown): value is ModelReasoningEffort;
|
|
4
|
+
export declare function modelReasoningLevels(provider: {
|
|
5
|
+
readonly supportsReasoning?: unknown;
|
|
6
|
+
readonly reasoningEffortLevels?: unknown;
|
|
7
|
+
readonly reasoningEffortMap?: unknown;
|
|
8
|
+
}): readonly ModelReasoningEffort[];
|
|
9
|
+
export declare function modelDefaultReasoningEffort(provider: {
|
|
10
|
+
readonly supportsReasoning?: unknown;
|
|
11
|
+
readonly reasoningEffortLevels?: unknown;
|
|
12
|
+
readonly reasoningEffortMap?: unknown;
|
|
13
|
+
readonly reasoningEffort?: unknown;
|
|
14
|
+
readonly reasoningDefaultEffort?: unknown;
|
|
15
|
+
readonly defaultEffort?: unknown;
|
|
16
|
+
}): ModelReasoningEffort | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const ORDER = ['off', 'low', 'medium', 'default', 'high', 'xhigh', 'max'];
|
|
2
|
+
export function isModelReasoningEffort(value) {
|
|
3
|
+
return ORDER.includes(value);
|
|
4
|
+
}
|
|
5
|
+
export function modelReasoningLevels(provider) {
|
|
6
|
+
if (provider.supportsReasoning === false)
|
|
7
|
+
return [];
|
|
8
|
+
if (Array.isArray(provider.reasoningEffortLevels)) {
|
|
9
|
+
const declared = provider.reasoningEffortLevels;
|
|
10
|
+
return ORDER.filter(value => declared.includes(value));
|
|
11
|
+
}
|
|
12
|
+
if (provider.reasoningEffortMap && typeof provider.reasoningEffortMap === 'object' && !Array.isArray(provider.reasoningEffortMap)) {
|
|
13
|
+
const keys = Object.keys(provider.reasoningEffortMap);
|
|
14
|
+
return ORDER.filter(value => keys.includes(value));
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
export function modelDefaultReasoningEffort(provider) {
|
|
19
|
+
const levels = modelReasoningLevels(provider);
|
|
20
|
+
for (const value of [provider.reasoningEffort, provider.reasoningDefaultEffort, provider.defaultEffort, 'default', 'medium', 'high', 'low', ...levels]) {
|
|
21
|
+
if (isModelReasoningEffort(value) && levels.includes(value))
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
package/dist/model-routing.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { type ModelReasoningEffort } from './model-reasoning.ts';
|
|
1
2
|
/**
|
|
2
3
|
* Role and tier model routing. Resolution is pure; hosts apply the result.
|
|
3
4
|
* Order and filters follow ADR 83. An empty candidate set is an error, not a silent downgrade.
|
|
4
5
|
*/
|
|
5
6
|
export type ModelTier = 'strong' | 'fast' | 'economy' | 'vision';
|
|
6
|
-
export type ModelRole = 'project_agent' | 'session_worker' | 'explorer' | 'verifier' | 'visual_verifier' | 'memory_curator' | 'objective_probe' | 'compactor';
|
|
7
|
-
export type RoleSetting = {
|
|
7
|
+
export type ModelRole = 'project_agent' | 'session_worker' | 'explorer' | 'verifier' | 'visual_verifier' | 'memory_curator' | 'objective_probe' | 'compactor' | 'input_predictor';
|
|
8
|
+
export type RoleSetting = ({
|
|
8
9
|
readonly mode: 'tier';
|
|
9
10
|
readonly tier: ModelTier;
|
|
10
11
|
} | {
|
|
@@ -13,11 +14,26 @@ export type RoleSetting = {
|
|
|
13
14
|
} | {
|
|
14
15
|
readonly mode: 'auto';
|
|
15
16
|
readonly pool: readonly string[];
|
|
17
|
+
}) & {
|
|
18
|
+
/** Undefined inherits the tier; null explicitly uses the model default. */
|
|
19
|
+
readonly reasoningEffort?: ModelReasoningEffort | null;
|
|
20
|
+
/** Undefined inherits the tier; false explicitly selects the normal channel. */
|
|
21
|
+
readonly fastMode?: boolean;
|
|
16
22
|
};
|
|
17
23
|
export interface ModelTierBinding {
|
|
18
24
|
readonly primary: string;
|
|
19
25
|
readonly fallbacks?: readonly string[];
|
|
26
|
+
readonly reasoningEffort?: ModelReasoningEffort;
|
|
27
|
+
readonly fastMode?: boolean;
|
|
20
28
|
}
|
|
29
|
+
/** Admission matches the existing priority request encoders, never a model-name guess. */
|
|
30
|
+
export declare function modelSupportsFastMode(provider: {
|
|
31
|
+
readonly authMethod?: unknown;
|
|
32
|
+
}): boolean;
|
|
33
|
+
export declare function routingParameters(setting: RoleSetting, tiers: Partial<Record<ModelTier, ModelTierBinding>>): {
|
|
34
|
+
reasoningEffort: ModelReasoningEffort | undefined;
|
|
35
|
+
fastMode: boolean;
|
|
36
|
+
};
|
|
21
37
|
export interface ModelRoutingSettings {
|
|
22
38
|
readonly tiers: Partial<Record<ModelTier, ModelTierBinding>>;
|
|
23
39
|
readonly roles: Partial<Record<ModelRole, RoleSetting>>;
|
|
@@ -40,6 +56,8 @@ export interface RuntimeModelSelection {
|
|
|
40
56
|
readonly modelId: string;
|
|
41
57
|
readonly modelProviderId: string;
|
|
42
58
|
readonly reasoningEffort?: string;
|
|
59
|
+
/** Subscription priority channel. Encoding still admits only ChatGPT and Grok OAuth. */
|
|
60
|
+
readonly fastMode?: boolean;
|
|
43
61
|
readonly family: string;
|
|
44
62
|
}
|
|
45
63
|
export interface ModelSelectionSnapshot {
|
|
@@ -65,7 +83,15 @@ export interface ModelRoutingMenuOption {
|
|
|
65
83
|
readonly supportsTools: boolean;
|
|
66
84
|
readonly supportsStructured: boolean;
|
|
67
85
|
readonly contextTokens: number;
|
|
86
|
+
readonly available?: boolean;
|
|
87
|
+
readonly reasoningEffortLevels?: readonly ModelReasoningEffort[];
|
|
88
|
+
readonly defaultReasoningEffort?: ModelReasoningEffort;
|
|
89
|
+
}
|
|
90
|
+
export interface BotRoleModelView {
|
|
91
|
+
readonly resolution: ModelResolution;
|
|
92
|
+
readonly eligibleModelIds: readonly string[];
|
|
68
93
|
}
|
|
94
|
+
export type BotModelViews = Partial<Record<ModelRole, BotRoleModelView>>;
|
|
69
95
|
/** Project one configured provider into the routing menu contract. */
|
|
70
96
|
export declare function projectModelRoutingMenuOption(provider: {
|
|
71
97
|
readonly id?: unknown;
|
|
@@ -81,6 +107,14 @@ export declare function projectModelRoutingMenuOption(provider: {
|
|
|
81
107
|
readonly toolUse?: unknown;
|
|
82
108
|
} | null;
|
|
83
109
|
readonly contextWindow?: unknown;
|
|
110
|
+
readonly apiKeyConfigured?: unknown;
|
|
111
|
+
readonly enabled?: unknown;
|
|
112
|
+
readonly supportsReasoning?: unknown;
|
|
113
|
+
readonly reasoningEffortLevels?: unknown;
|
|
114
|
+
readonly reasoningEffortMap?: unknown;
|
|
115
|
+
readonly reasoningEffort?: unknown;
|
|
116
|
+
readonly reasoningDefaultEffort?: unknown;
|
|
117
|
+
readonly defaultEffort?: unknown;
|
|
84
118
|
} | null | undefined): ModelRoutingMenuOption | null;
|
|
85
119
|
export interface CatalogModel {
|
|
86
120
|
readonly modelProviderId: string;
|
|
@@ -93,6 +127,8 @@ export interface CatalogModel {
|
|
|
93
127
|
readonly contextTokens?: number;
|
|
94
128
|
readonly local?: boolean;
|
|
95
129
|
readonly reasoningEffort?: string;
|
|
130
|
+
readonly reasoningEffortLevels?: readonly ModelReasoningEffort[];
|
|
131
|
+
readonly supportsFastMode?: boolean;
|
|
96
132
|
}
|
|
97
133
|
export type ModelResolution = {
|
|
98
134
|
readonly ok: true;
|
|
@@ -101,7 +137,7 @@ export type ModelResolution = {
|
|
|
101
137
|
readonly sameFamilyAsWorker?: boolean;
|
|
102
138
|
} | {
|
|
103
139
|
readonly ok: false;
|
|
104
|
-
readonly reason: 'capability' | 'scope' | 'auto_pool' | 'empty';
|
|
140
|
+
readonly reason: 'capability' | 'scope' | 'auto_pool' | 'empty' | 'reasoning' | 'fast_mode';
|
|
105
141
|
readonly missing: string;
|
|
106
142
|
};
|
|
107
143
|
export interface RoleModelRequest {
|
package/dist/model-routing.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { modelDefaultReasoningEffort, modelReasoningLevels } from "./model-reasoning.js";
|
|
2
|
+
/** Admission matches the existing priority request encoders, never a model-name guess. */
|
|
3
|
+
export function modelSupportsFastMode(provider) {
|
|
4
|
+
return provider.authMethod === 'oauth_chatgpt' || provider.authMethod === 'oauth_grok';
|
|
5
|
+
}
|
|
6
|
+
export function routingParameters(setting, tiers) {
|
|
7
|
+
const tier = setting.mode === 'tier' ? tiers[setting.tier] : undefined;
|
|
8
|
+
return {
|
|
9
|
+
reasoningEffort: (setting.reasoningEffort === undefined ? tier?.reasoningEffort : setting.reasoningEffort) ?? undefined,
|
|
10
|
+
fastMode: setting.fastMode ?? tier?.fastMode ?? false,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
5
13
|
/** Project one configured provider into the routing menu contract. */
|
|
6
14
|
export function projectModelRoutingMenuOption(provider) {
|
|
7
15
|
if (!provider || typeof provider.id !== 'string' || !provider.id.trim())
|
|
@@ -24,6 +32,9 @@ export function projectModelRoutingMenuOption(provider) {
|
|
|
24
32
|
supportsTools: provider.supportsTools !== false && provider.capabilities?.toolUse !== false,
|
|
25
33
|
supportsStructured: provider.supportsStructured !== false,
|
|
26
34
|
contextTokens: Number.isFinite(context) && context > 0 ? context : 128_000,
|
|
35
|
+
available: provider.enabled !== false && provider.apiKeyConfigured === true,
|
|
36
|
+
reasoningEffortLevels: modelReasoningLevels(provider),
|
|
37
|
+
defaultReasoningEffort: modelDefaultReasoningEffort(provider),
|
|
27
38
|
};
|
|
28
39
|
}
|
|
29
40
|
const EXPLORER_MIN_CONTEXT = 8_000;
|
|
@@ -45,6 +56,7 @@ function roleNeeds(input) {
|
|
|
45
56
|
case 'objective_probe':
|
|
46
57
|
return { tools: true, vision: false, structured: false, minContext: 0 };
|
|
47
58
|
case 'compactor':
|
|
59
|
+
case 'input_predictor':
|
|
48
60
|
return { tools: false, vision: false, structured: false, minContext: Math.max(context, 1) };
|
|
49
61
|
default:
|
|
50
62
|
return { tools: false, vision: false, structured: false, minContext: 0 };
|
|
@@ -75,6 +87,10 @@ function inScope(model, policy) {
|
|
|
75
87
|
return true;
|
|
76
88
|
}
|
|
77
89
|
function missingText(input, reason) {
|
|
90
|
+
if (reason === 'fast_mode')
|
|
91
|
+
return '所选连接不支持快速通道,请选择正常通道或支持的连接';
|
|
92
|
+
if (reason === 'reasoning')
|
|
93
|
+
return '所选模型不支持该推理强度';
|
|
78
94
|
if (reason === 'auto_pool')
|
|
79
95
|
return '所选模型不在自动池内';
|
|
80
96
|
const localOnly = input.projectPolicy?.scope?.localOnly === true;
|
|
@@ -226,10 +242,20 @@ export function resolveRoleModel(input) {
|
|
|
226
242
|
const chosen = ordered[0];
|
|
227
243
|
if (!chosen)
|
|
228
244
|
return fail(input, 'empty');
|
|
245
|
+
const parameters = routingParameters(layer.setting, input.routing.tiers);
|
|
246
|
+
const requestedEffort = parameters.reasoningEffort;
|
|
247
|
+
if (requestedEffort !== undefined && !chosen.reasoningEffortLevels?.includes(requestedEffort))
|
|
248
|
+
return fail(input, 'reasoning');
|
|
249
|
+
if (parameters.fastMode && chosen.supportsFastMode !== true)
|
|
250
|
+
return fail(input, 'fast_mode');
|
|
229
251
|
const source = layer.setting.mode === 'auto' ? 'auto' : layer.source;
|
|
230
252
|
return {
|
|
231
253
|
ok: true,
|
|
232
|
-
selection:
|
|
254
|
+
selection: {
|
|
255
|
+
...toSelection(chosen),
|
|
256
|
+
...(requestedEffort !== undefined ? { reasoningEffort: requestedEffort } : {}),
|
|
257
|
+
fastMode: parameters.fastMode,
|
|
258
|
+
},
|
|
233
259
|
source,
|
|
234
260
|
...(input.role === 'verifier'
|
|
235
261
|
? { sameFamilyAsWorker: sameFamily(chosen, input.workerModel) }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SessionControlOperation } from './session-control.ts';
|
|
2
|
+
import { type SessionExecutionIdentity } from './session-control.ts';
|
|
3
|
+
type Recorder = NonNullable<SessionControlOperation['recorder']>;
|
|
4
|
+
export interface NativeOwnedProcess {
|
|
5
|
+
readonly schemaVersion: 1;
|
|
6
|
+
readonly kind: 'command';
|
|
7
|
+
readonly handleId: string;
|
|
8
|
+
readonly toolCallId: string;
|
|
9
|
+
readonly dispatchId: string;
|
|
10
|
+
readonly execution: SessionExecutionIdentity;
|
|
11
|
+
readonly generation: number;
|
|
12
|
+
readonly state: 'not_started' | 'starting' | 'running' | 'ended';
|
|
13
|
+
readonly owner: Recorder;
|
|
14
|
+
readonly child?: Recorder | null;
|
|
15
|
+
readonly stopObservation?: 'owned_completion' | 'owner_dead_not_started' | 'owner_dead_group_absent' | null;
|
|
16
|
+
}
|
|
17
|
+
/** Envelope shape only. Execution identity is validated by each owning contract. */
|
|
18
|
+
export declare function nativeProcessEnvelopeValid(raw: unknown): boolean;
|
|
19
|
+
/** Shape only: no value here proves local execution or process death. */
|
|
20
|
+
export declare function nativeProcessesInWork(work: unknown): readonly NativeOwnedProcess[];
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { normalizeSessionExecutionIdentity } from "./session-control.js";
|
|
2
|
+
const object = (v) => v !== null && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
3
|
+
const text = (v, bytes) => typeof v === 'string' && v.length > 0 && v.length <= bytes && new TextEncoder().encode(v).length <= bytes;
|
|
4
|
+
const recorder = (v) => {
|
|
5
|
+
const r = object(v);
|
|
6
|
+
return Number.isInteger(r.pid) && r.pid > 0 && r.pid <= 2147483647
|
|
7
|
+
&& ['bootId', 'pidStart', 'hostId', 'acquiredAt'].every(k => text(r[k], 8192));
|
|
8
|
+
};
|
|
9
|
+
/** Envelope shape only. Execution identity is validated by each owning contract. */
|
|
10
|
+
export function nativeProcessEnvelopeValid(raw) {
|
|
11
|
+
const p = object(raw), owner = object(p.owner), child = object(p.child);
|
|
12
|
+
const keys = ['schemaVersion', 'kind', 'handleId', 'toolCallId', 'dispatchId', 'execution', 'generation', 'state', 'owner', 'child', 'stopObservation'];
|
|
13
|
+
const validChild = p.child == null || recorder(child) && ['hostId', 'acquiredAt', 'bootId'].every(k => child[k] === owner[k]);
|
|
14
|
+
const gen = Number.isInteger(p.generation) && p.generation >= 0 && p.generation <= 64;
|
|
15
|
+
const phase = p.state === 'not_started' ? p.generation === 0 && p.child == null && p.stopObservation == null
|
|
16
|
+
: p.state === 'starting' ? p.generation > 0 && p.child == null && p.stopObservation == null
|
|
17
|
+
: p.state === 'running' ? p.generation > 0 && p.child != null && p.stopObservation == null
|
|
18
|
+
: p.state === 'ended' && (p.stopObservation === 'owned_completion'
|
|
19
|
+
|| p.stopObservation === 'owner_dead_not_started' && p.generation === 0 && p.child == null
|
|
20
|
+
|| p.stopObservation === 'owner_dead_group_absent' && p.generation > 0 && p.child != null);
|
|
21
|
+
return p.schemaVersion === 1 && p.kind === 'command' && !Object.keys(p).some(k => !keys.includes(k))
|
|
22
|
+
&& ['handleId', 'toolCallId', 'dispatchId'].every(k => text(p[k], 200))
|
|
23
|
+
&& !!gen && !!phase && recorder(owner) && !!validChild;
|
|
24
|
+
}
|
|
25
|
+
/** Shape only: no value here proves local execution or process death. */
|
|
26
|
+
export function nativeProcessesInWork(work) {
|
|
27
|
+
const budget = object(object(work).budget);
|
|
28
|
+
const rows = [...Object.values(object(budget.attempts)).flatMap(a => {
|
|
29
|
+
const pending = object(a).pendingTools;
|
|
30
|
+
return Array.isArray(pending) ? pending : [];
|
|
31
|
+
}), ...(Array.isArray(budget.uncertainDispatches) ? budget.uncertainDispatches : [])];
|
|
32
|
+
const result = [];
|
|
33
|
+
for (const raw of rows) {
|
|
34
|
+
const row = object(raw);
|
|
35
|
+
if (!Object.hasOwn(row, 'nativeProcess'))
|
|
36
|
+
continue;
|
|
37
|
+
const p = object(row.nativeProcess), owner = object(p.owner);
|
|
38
|
+
const original = object(object(row.nativeRecorder).recorder);
|
|
39
|
+
const execution = normalizeSessionExecutionIdentity(p.execution);
|
|
40
|
+
const recordedExecution = normalizeSessionExecutionIdentity(object(row.nativeRecorder).execution);
|
|
41
|
+
if (!nativeProcessEnvelopeValid(p) || !recorder(original) || !execution || !recordedExecution
|
|
42
|
+
|| JSON.stringify(execution) !== JSON.stringify(recordedExecution)
|
|
43
|
+
|| !['pid', 'pidStart', 'bootId', 'hostId', 'acquiredAt'].every(k => owner[k] === original[k])
|
|
44
|
+
|| p.toolCallId !== row.toolCallId || p.dispatchId !== row.dispatchId || result.length >= 128
|
|
45
|
+
|| result.some(old => old.handleId === p.handleId || old.toolCallId === p.toolCallId || old.dispatchId === p.dispatchId)) {
|
|
46
|
+
throw new Error('native_process_invalid');
|
|
47
|
+
}
|
|
48
|
+
result.push(structuredClone(p));
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/** ADR 143 native Core RPC contract. Sequences are unsigned decimal strings. */
|
|
2
|
+
export declare const PARENT_COORDINATION_VERSION = 1;
|
|
3
|
+
export interface CoordinationOption {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
summary: string;
|
|
7
|
+
recommended?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type CoordinationArtifactRef = {
|
|
10
|
+
kind: 'workspace_path';
|
|
11
|
+
path: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'evidence';
|
|
14
|
+
ref: string;
|
|
15
|
+
};
|
|
16
|
+
export type CoordinationExchangeKind = 'notice' | 'question' | 'parent_answer' | 'parent_steer' | 'parent_dispatch' | 'parent_acknowledged' | 'escalated' | 'user_decision' | 'delivery';
|
|
17
|
+
export interface CoordinationExchangeItem {
|
|
18
|
+
seq: string;
|
|
19
|
+
itemId: string;
|
|
20
|
+
kind: CoordinationExchangeKind;
|
|
21
|
+
actorRole: 'worker' | 'parent' | 'user' | 'host';
|
|
22
|
+
occurredAt: string;
|
|
23
|
+
sessionId: string;
|
|
24
|
+
followUpEpoch: number;
|
|
25
|
+
matterId?: string;
|
|
26
|
+
requestId?: string;
|
|
27
|
+
noticeId?: string;
|
|
28
|
+
relatedItemIds: string[];
|
|
29
|
+
summary: string;
|
|
30
|
+
detail?: string;
|
|
31
|
+
options?: CoordinationOption[];
|
|
32
|
+
artifactRefs?: CoordinationArtifactRef[];
|
|
33
|
+
disposition?: string;
|
|
34
|
+
erased?: boolean;
|
|
35
|
+
erasureGeneration?: string;
|
|
36
|
+
}
|
|
37
|
+
export type CoordinationLogQuery = {
|
|
38
|
+
workspaceId: string;
|
|
39
|
+
beforeCursor?: string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
} & ({
|
|
42
|
+
sessionId: string;
|
|
43
|
+
followUpEpoch?: number;
|
|
44
|
+
matterId?: never;
|
|
45
|
+
} | {
|
|
46
|
+
matterId: string;
|
|
47
|
+
sessionId?: never;
|
|
48
|
+
followUpEpoch?: never;
|
|
49
|
+
});
|
|
50
|
+
export interface CoordinationLogPage {
|
|
51
|
+
items: CoordinationExchangeItem[];
|
|
52
|
+
nextCursor?: string;
|
|
53
|
+
highWatermark: string;
|
|
54
|
+
}
|
|
55
|
+
export type SubmitCoordinationDecision = {
|
|
56
|
+
workspaceId: string;
|
|
57
|
+
requestId: string;
|
|
58
|
+
expectedRevision: number;
|
|
59
|
+
actorRef: string;
|
|
60
|
+
inputId: string;
|
|
61
|
+
} & ({
|
|
62
|
+
actionKind: 'answer';
|
|
63
|
+
chosenOptionId: string;
|
|
64
|
+
freeText?: never;
|
|
65
|
+
} | {
|
|
66
|
+
actionKind: 'answer';
|
|
67
|
+
freeText: string;
|
|
68
|
+
chosenOptionId?: never;
|
|
69
|
+
} | {
|
|
70
|
+
actionKind: 'cancel';
|
|
71
|
+
chosenOptionId?: never;
|
|
72
|
+
freeText?: never;
|
|
73
|
+
});
|
|
74
|
+
export interface UserDecisionReceipt {
|
|
75
|
+
receiptId: string;
|
|
76
|
+
requestId: string;
|
|
77
|
+
actionKind: 'answer' | 'cancel';
|
|
78
|
+
chosenOption?: CoordinationOption;
|
|
79
|
+
freeText?: string;
|
|
80
|
+
answeredAt: string;
|
|
81
|
+
actorRef: string;
|
|
82
|
+
inputId: string;
|
|
83
|
+
requestRevision: number;
|
|
84
|
+
}
|
|
85
|
+
export type CoordinationDecisionCardOption = (CoordinationOption & {
|
|
86
|
+
actionKind: 'answer';
|
|
87
|
+
}) | {
|
|
88
|
+
actionKind: 'free_text' | 'cancel';
|
|
89
|
+
label: string;
|
|
90
|
+
};
|
|
91
|
+
export interface CoordinationDecisionCard {
|
|
92
|
+
kind: 'needs-you';
|
|
93
|
+
requestId: string;
|
|
94
|
+
revision: number;
|
|
95
|
+
question: string;
|
|
96
|
+
context?: string | null;
|
|
97
|
+
parentRationale: string;
|
|
98
|
+
options: CoordinationDecisionCardOption[];
|
|
99
|
+
freeText: true;
|
|
100
|
+
recentQuestions?: {
|
|
101
|
+
question: string;
|
|
102
|
+
answer: string;
|
|
103
|
+
}[] | null;
|
|
104
|
+
}
|