@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.
Files changed (130) hide show
  1. package/dist/acceptance-close-gate.d.ts +10 -1
  2. package/dist/acceptance-close-gate.js +12 -0
  3. package/dist/agent-supervision.d.ts +81 -0
  4. package/dist/agent-supervision.js +1 -0
  5. package/dist/attention.d.ts +44 -0
  6. package/dist/attention.js +1 -0
  7. package/dist/bot-access-policy.d.ts +29 -0
  8. package/dist/bot-access-policy.js +1 -0
  9. package/dist/bot-conversation-read.d.ts +67 -0
  10. package/dist/bot-conversation-read.js +9 -0
  11. package/dist/bot-direct-step.d.ts +11 -0
  12. package/dist/bot-direct-step.js +1 -0
  13. package/dist/bot-git.d.ts +55 -0
  14. package/dist/bot-git.js +1 -0
  15. package/dist/bot-model-selection.d.ts +13 -0
  16. package/dist/bot-model-selection.js +1 -0
  17. package/dist/browser-window.d.ts +48 -0
  18. package/dist/browser-window.js +23 -0
  19. package/dist/capability-admission.d.ts +20 -0
  20. package/dist/capability-admission.js +1 -0
  21. package/dist/compaction-history-selection.d.ts +15 -0
  22. package/dist/compaction-history-selection.js +30 -0
  23. package/dist/compaction.d.ts +5 -0
  24. package/dist/compaction.js +6 -0
  25. package/dist/context-accounting.d.ts +3 -0
  26. package/dist/conversation-execution.d.ts +68 -0
  27. package/dist/conversation-execution.js +222 -0
  28. package/dist/delegation-coordination.d.ts +81 -0
  29. package/dist/delegation-coordination.js +1 -0
  30. package/dist/delegation.d.ts +260 -7
  31. package/dist/delegation.js +97 -39
  32. package/dist/document-reference.d.ts +111 -0
  33. package/dist/document-reference.js +1 -0
  34. package/dist/evidence-inspection.d.ts +84 -0
  35. package/dist/evidence-inspection.js +1 -0
  36. package/dist/gemini-standard-pricing.json +105 -0
  37. package/dist/goal.d.ts +50 -2
  38. package/dist/group-chat.d.ts +87 -0
  39. package/dist/group-chat.js +1 -0
  40. package/dist/hook-observation.d.ts +2 -0
  41. package/dist/hook-observation.js +19 -0
  42. package/dist/index.d.ts +117 -25
  43. package/dist/index.js +41 -0
  44. package/dist/input-prediction.d.ts +86 -0
  45. package/dist/input-prediction.js +48 -0
  46. package/dist/intent-coordination.d.ts +201 -0
  47. package/dist/intent-coordination.js +1 -0
  48. package/dist/interactive-result.d.ts +363 -0
  49. package/dist/interactive-result.js +215 -0
  50. package/dist/interactive-verification.d.ts +41 -0
  51. package/dist/interactive-verification.js +65 -0
  52. package/dist/local-git.d.ts +44 -0
  53. package/dist/local-git.js +3 -0
  54. package/dist/local-image.d.ts +53 -0
  55. package/dist/local-image.js +5 -0
  56. package/dist/local-read.d.ts +9 -0
  57. package/dist/local-read.js +1 -0
  58. package/dist/memory.d.ts +117 -12
  59. package/dist/memory.js +12 -0
  60. package/dist/model-reasoning.d.ts +16 -0
  61. package/dist/model-reasoning.js +25 -0
  62. package/dist/model-routing.d.ts +39 -3
  63. package/dist/model-routing.js +31 -5
  64. package/dist/native-process.d.ts +21 -0
  65. package/dist/native-process.js +51 -0
  66. package/dist/parent-coordination.d.ts +104 -0
  67. package/dist/parent-coordination.js +2 -0
  68. package/dist/persistent-workspace.d.ts +519 -0
  69. package/dist/persistent-workspace.js +1 -0
  70. package/dist/project-agent-failure.d.ts +30 -0
  71. package/dist/project-agent-failure.js +44 -0
  72. package/dist/project-input-recovery.d.ts +83 -0
  73. package/dist/project-input-recovery.js +25 -0
  74. package/dist/project-matter.d.ts +359 -0
  75. package/dist/project-matter.js +1 -0
  76. package/dist/project-recovery.d.ts +43 -0
  77. package/dist/project-recovery.js +1 -0
  78. package/dist/project.d.ts +233 -0
  79. package/dist/project.js +134 -5
  80. package/dist/prompt-skill.d.ts +31 -0
  81. package/dist/prompt-skill.js +1 -0
  82. package/dist/quiet-reply.d.ts +9 -0
  83. package/dist/quiet-reply.js +43 -0
  84. package/dist/remote-access.d.ts +15 -0
  85. package/dist/remote-access.js +1 -1
  86. package/dist/reply-delivery.d.ts +28 -0
  87. package/dist/reply-delivery.js +1 -0
  88. package/dist/resource-edit-execution.d.ts +68 -0
  89. package/dist/resource-edit-execution.js +96 -0
  90. package/dist/resource-edit.d.ts +237 -0
  91. package/dist/resource-edit.js +134 -0
  92. package/dist/resource-feedback-transport.d.ts +26 -0
  93. package/dist/resource-feedback-transport.js +94 -0
  94. package/dist/resource-feedback.d.ts +110 -0
  95. package/dist/resource-feedback.js +168 -0
  96. package/dist/resource-file-replace.d.ts +36 -0
  97. package/dist/resource-file-replace.js +40 -0
  98. package/dist/resource-reference-hints.d.ts +3 -0
  99. package/dist/resource-reference-hints.js +58 -0
  100. package/dist/resource-window.d.ts +222 -0
  101. package/dist/resource-window.js +252 -0
  102. package/dist/routine.d.ts +82 -0
  103. package/dist/routine.js +1 -0
  104. package/dist/runtime-session-facts.d.ts +58 -0
  105. package/dist/runtime-session-facts.js +57 -0
  106. package/dist/session-control.d.ts +211 -0
  107. package/dist/session-control.js +48 -0
  108. package/dist/session-facts.d.ts +29 -0
  109. package/dist/session-facts.js +35 -0
  110. package/dist/skill-marketplace.d.ts +39 -4
  111. package/dist/spend-budget.d.ts +69 -0
  112. package/dist/spend-budget.js +1 -0
  113. package/dist/system-context.d.ts +7 -0
  114. package/dist/task-overview.d.ts +91 -0
  115. package/dist/task-overview.js +325 -17
  116. package/dist/tool-activity-preview.d.ts +4 -0
  117. package/dist/tool-activity-preview.js +72 -0
  118. package/dist/updater.d.ts +13 -3
  119. package/dist/usage-accounting.d.ts +42 -1
  120. package/dist/user-anchor.d.ts +17 -0
  121. package/dist/user-anchor.js +1 -0
  122. package/dist/work-coordination.d.ts +188 -0
  123. package/dist/work-coordination.js +1 -0
  124. package/dist/work-hook.d.ts +3 -0
  125. package/dist/work-hook.js +76 -0
  126. package/dist/working-plan.d.ts +18 -0
  127. package/dist/working-plan.js +1 -0
  128. package/dist/workspace.d.ts +35 -0
  129. package/dist/workspace.js +1 -0
  130. package/package.json +1 -1
@@ -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
+ }
@@ -0,0 +1,29 @@
1
+ import { type ExecutionOwnership, type LifecycleDecision, type LifecycleFacts } from './task-overview.ts';
2
+ export type { ExecutionOwnership, LifecycleDecision, LifecycleFacts } from './task-overview.ts';
3
+ export interface SessionFactSnapshot {
4
+ readonly status: LifecycleDecision['status'];
5
+ readonly verificationActive: boolean;
6
+ readonly needsUser: boolean;
7
+ readonly blockedReason?: string;
8
+ }
9
+ /**
10
+ * 兼容入口:把扁平事实交给唯一的生命周期决策器。
11
+ * 旧的直接判定逻辑已删除,`status / needsUser / blockedReason` 全部来自 `decideLifecycle`。
12
+ */
13
+ export declare function deriveSessionFacts(input: {
14
+ status?: string;
15
+ phase?: string;
16
+ runnerStatus?: string;
17
+ accepted?: boolean;
18
+ superseded?: boolean;
19
+ needsUser?: boolean;
20
+ blockedReason?: string;
21
+ verificationActive?: boolean;
22
+ interrupted?: boolean;
23
+ interruptionOrigin?: LifecycleFacts['interruptionOrigin'];
24
+ delegated?: boolean;
25
+ cancellationPhase?: string;
26
+ cancellationDisposition?: LifecycleFacts['cancellationDisposition'];
27
+ takeoverPhase?: string;
28
+ executionOwnership?: ExecutionOwnership;
29
+ }): SessionFactSnapshot;
@@ -0,0 +1,35 @@
1
+ import { decideLifecycle, } from "./task-overview.js";
2
+ /**
3
+ * 兼容入口:把扁平事实交给唯一的生命周期决策器。
4
+ * 旧的直接判定逻辑已删除,`status / needsUser / blockedReason` 全部来自 `decideLifecycle`。
5
+ */
6
+ export function deriveSessionFacts(input) {
7
+ const snapshot = {
8
+ conversationId: '',
9
+ title: '',
10
+ planId: '',
11
+ status: (input.status ?? 'executing'),
12
+ ...(input.runnerStatus ? { runnerStatus: input.runnerStatus } : {}),
13
+ };
14
+ const decision = decideLifecycle(snapshot, {
15
+ ...(input.executionOwnership ? { executionOwnership: input.executionOwnership } : {}),
16
+ ...(input.phase ? { phase: input.phase } : {}),
17
+ ...(input.accepted !== undefined ? { accepted: input.accepted } : {}),
18
+ ...(input.superseded !== undefined ? { superseded: input.superseded } : {}),
19
+ ...(input.needsUser !== undefined ? { needsUser: input.needsUser } : {}),
20
+ ...(input.blockedReason ? { blockedReason: input.blockedReason } : {}),
21
+ ...(input.verificationActive !== undefined ? { verificationActive: input.verificationActive } : {}),
22
+ ...(input.interrupted !== undefined ? { interrupted: input.interrupted } : {}),
23
+ ...(input.interruptionOrigin ? { interruptionOrigin: input.interruptionOrigin } : {}),
24
+ ...(input.delegated !== undefined ? { delegated: input.delegated } : {}),
25
+ ...(input.cancellationPhase ? { cancellationPhase: input.cancellationPhase } : {}),
26
+ ...(input.cancellationDisposition ? { cancellationDisposition: input.cancellationDisposition } : {}),
27
+ ...(input.takeoverPhase ? { takeoverPhase: input.takeoverPhase } : {}),
28
+ });
29
+ return {
30
+ status: decision.status,
31
+ verificationActive: decision.verificationActive,
32
+ needsUser: decision.needsUser,
33
+ ...(decision.blockedReason ? { blockedReason: decision.blockedReason } : {}),
34
+ };
35
+ }
@@ -40,6 +40,39 @@ export interface SkillMarketplaceInstallResult {
40
40
  readonly skillId?: string;
41
41
  readonly error?: string;
42
42
  }
43
+ export interface SkillInstallTarget {
44
+ readonly id: string;
45
+ readonly workspaceId: string;
46
+ readonly name: string;
47
+ readonly path: string;
48
+ readonly kind: 'bot' | 'workspace';
49
+ readonly available: boolean;
50
+ readonly unavailableReason?: string;
51
+ readonly isActive: boolean;
52
+ }
53
+ export interface SkillInstallTargetRequest {
54
+ readonly workspaceId?: string;
55
+ readonly workspacePath?: string;
56
+ }
57
+ export type SkillInstallTargetResult = {
58
+ readonly workspaceId: string | null;
59
+ readonly name: string;
60
+ readonly path: string | null;
61
+ } & ({
62
+ readonly ok: true;
63
+ readonly skillId: string;
64
+ } | {
65
+ readonly ok: false;
66
+ readonly error: string;
67
+ readonly code?: string;
68
+ });
69
+ export interface SkillInstallBatchReceipt {
70
+ readonly partial: boolean;
71
+ readonly succeededCount: number;
72
+ readonly failedCount: number;
73
+ readonly results: readonly SkillInstallTargetResult[];
74
+ }
75
+ export type SkillHubInstallResult = SkillMarketplaceInstallResult & Partial<SkillInstallBatchReceipt>;
43
76
  /**
44
77
  * SkillHub 官方列表排序(GET /api/skills?sortBy=):
45
78
  * - score: 全部 / 综合评分
@@ -106,9 +139,10 @@ export interface SkillHubInstallRequest {
106
139
  readonly namespace: string;
107
140
  readonly slug: string;
108
141
  readonly version: string;
109
- /** 默认 global;workspace 必须同时指定一个由 Desktop 主进程校验的登记工作区。 */
142
+ /** 默认 global。工作区安装使用 targets,旧调用方可传 workspacePath。 */
110
143
  readonly scope?: SkillHubInstallScope;
111
144
  readonly workspacePath?: string;
145
+ readonly targets?: readonly SkillInstallTargetRequest[];
112
146
  /** 市场图标 URL;安装时写入本地 _meta.json,供已安装列表展示。 */
113
147
  readonly iconUrl?: string | null;
114
148
  }
@@ -206,12 +240,13 @@ export interface QoderInstallIdentity {
206
240
  readonly skillId: string;
207
241
  readonly scope?: QoderInstallScope;
208
242
  readonly workspacePath?: string;
243
+ readonly targets?: readonly SkillInstallTargetRequest[];
209
244
  readonly iconUrl?: string | null;
210
245
  }
211
- export interface QoderInstallResult {
246
+ export interface QoderInstallResult extends Partial<SkillInstallBatchReceipt> {
212
247
  readonly ok: boolean;
213
248
  readonly skillId: string;
214
- readonly installedSkillId: string;
215
- readonly version: string;
249
+ readonly installedSkillId?: string;
250
+ readonly version?: string;
216
251
  readonly scope: QoderInstallScope;
217
252
  }
@@ -0,0 +1,69 @@
1
+ export type ChannelSpendAnchorSource = 'ai_studio_browser' | 'manual';
2
+ export interface ChannelSpendAnchor {
3
+ readonly periodKey: string;
4
+ readonly amountUsd: string;
5
+ readonly monthlyLimitUsd?: string;
6
+ readonly capturedAtUtc: string;
7
+ readonly source: ChannelSpendAnchorSource;
8
+ readonly projectLabel?: string;
9
+ }
10
+ export interface ChannelSpendBudgetConfig {
11
+ readonly enabled?: boolean;
12
+ readonly monthlyLimitUsd?: string;
13
+ readonly resetTimezone?: string;
14
+ readonly warnThresholds?: readonly [number, number];
15
+ readonly policy?: 'warn_only';
16
+ readonly sharedProjectKey?: string;
17
+ readonly anchor?: ChannelSpendAnchor;
18
+ }
19
+ export interface ChannelLocalBudgetSnapshot {
20
+ readonly groupId: string;
21
+ readonly periodKey: string;
22
+ readonly resetTimezone: string;
23
+ readonly windowStartUtc: string;
24
+ readonly windowEndUtc: string;
25
+ readonly nextResetAtUtc: string;
26
+ readonly effectiveLimitUsd: string | null;
27
+ readonly limitSource: 'configured' | 'anchor' | 'none';
28
+ readonly estimatedSpendUsd: string | null;
29
+ readonly localDeltaSpendUsd: string | null;
30
+ readonly anchor: ChannelSpendAnchor | null;
31
+ readonly anchorActive: boolean;
32
+ readonly anchorExpired: boolean;
33
+ readonly sourceKind: 'local_estimate' | 'anchor_plus_local' | 'manual_anchor_plus_local';
34
+ readonly scopeLabel: 'channel_group' | 'shared_project';
35
+ readonly coverage: 'complete' | 'partial' | 'none';
36
+ readonly unpricedRequestCount: number;
37
+ readonly truncated: boolean;
38
+ readonly percentUsed: number | null;
39
+ readonly alertLevel: 'normal' | 'warning' | 'critical' | 'exceeded';
40
+ readonly pricingNote: string | null;
41
+ }
42
+ export interface ChannelBudgetView {
43
+ readonly revision: string;
44
+ readonly config: ChannelSpendBudgetConfig | null;
45
+ readonly periodKey: string;
46
+ readonly localBudget: ChannelLocalBudgetSnapshot | null;
47
+ }
48
+ export interface ChannelBudgetUpdate {
49
+ readonly groupId: string;
50
+ readonly revision: string;
51
+ readonly config: ChannelSpendBudgetConfig;
52
+ }
53
+ export type BillingSyncResult<T = object> = ({
54
+ readonly ok: true;
55
+ } & T) | {
56
+ readonly ok: false;
57
+ readonly reason: string;
58
+ };
59
+ export interface BillingSyncPreview {
60
+ readonly previewId: string;
61
+ readonly anchor: ChannelSpendAnchor;
62
+ }
63
+ export interface BillingSyncConfirm {
64
+ readonly syncId: string;
65
+ readonly previewId: string;
66
+ readonly amountUsd: string;
67
+ readonly monthlyLimitUsd?: string;
68
+ readonly projectLabel?: string;
69
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,11 @@
1
1
  export type AttachmentContextKind = 'image' | 'text' | 'unsupported';
2
+ /** Host failure facts retained with an interrupted reply; never execution authority. */
3
+ export interface ChatStreamFailure {
4
+ readonly code: string;
5
+ readonly causeCode?: string;
6
+ readonly precedingCode?: string;
7
+ readonly retryAfterMs?: number;
8
+ }
2
9
  export type AttachmentContextTransport = 'provider_image_part' | 'user_text_part' | 'metadata_only' | string;
3
10
  /**
4
11
  * 全局「兜底多模态模型」配置。