@peer-agent/protocol 0.1.0-beta.3 → 0.1.0-beta.5
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/delegation.d.ts +35 -5
- package/dist/delegation.js +8 -2
- package/dist/goal.d.ts +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/memory.d.ts +17 -2
- package/dist/memory.js +2 -0
- package/dist/model-routing.d.ts +29 -0
- package/dist/model-routing.js +24 -0
- package/dist/objectives.d.ts +109 -9
- package/dist/objectives.js +4 -13
- package/dist/project.d.ts +37 -2
- package/dist/project.js +10 -9
- package/dist/remote-access-settings.d.ts +21 -0
- package/dist/remote-access-settings.js +1 -0
- package/dist/remote-access.d.ts +84 -0
- package/dist/remote-access.js +127 -0
- package/package.json +2 -1
package/dist/delegation.d.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ModelSelectionSnapshot } from './model-routing.ts';
|
|
6
6
|
import { type GoalPlanProjectionSnapshot, type TaskOverviewItem } from './task-overview.ts';
|
|
7
|
-
export type WorkSessionStatus = 'queued' | 'starting' | 'running' | 'waiting_user' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
|
|
7
|
+
export type WorkSessionStatus = 'paused' | 'queued' | 'starting' | 'running' | 'waiting_user' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
|
|
8
|
+
export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
|
|
8
9
|
export type InputSurface = 'desktop' | 'quick_chat' | 'tui' | 'remote';
|
|
9
10
|
export interface DelegationOrigin {
|
|
10
11
|
readonly anchorMessageId: string;
|
|
@@ -12,11 +13,28 @@ export interface DelegationOrigin {
|
|
|
12
13
|
readonly surface: InputSurface;
|
|
13
14
|
readonly memorySnapshotId: string;
|
|
14
15
|
readonly objectiveId?: string;
|
|
16
|
+
readonly objectiveActionId?: string;
|
|
17
|
+
readonly priority?: 'high' | 'normal' | 'low';
|
|
18
|
+
readonly isolation?: 'auto' | 'none' | 'worktree';
|
|
19
|
+
readonly isolationBlock?: 'disk_space' | 'isolation_failed' | null;
|
|
20
|
+
readonly isolationRetainedAt?: string;
|
|
21
|
+
readonly supersededBy?: string;
|
|
22
|
+
readonly supersededAt?: string;
|
|
23
|
+
readonly lastResumeAnchorMessageId?: string;
|
|
24
|
+
readonly handoffAuthorizedAt?: string;
|
|
25
|
+
readonly handoffDeferredAt?: string;
|
|
15
26
|
readonly modelSelection: ModelSelectionSnapshot;
|
|
16
27
|
readonly parentSessionId?: string;
|
|
17
28
|
readonly depth: number;
|
|
18
29
|
}
|
|
19
|
-
export interface
|
|
30
|
+
export interface SessionQueueFacts {
|
|
31
|
+
readonly queuedBehind?: readonly {
|
|
32
|
+
readonly sessionId: string;
|
|
33
|
+
readonly title: string;
|
|
34
|
+
}[];
|
|
35
|
+
readonly queueReason?: 'dependencies' | 'dependency_missing' | 'dependency_failed' | 'read_slot' | 'write_slot' | 'disk_space' | 'isolation_failed' | null;
|
|
36
|
+
}
|
|
37
|
+
export interface WorkSessionConversationMeta extends SessionQueueFacts {
|
|
20
38
|
readonly sessionId?: string;
|
|
21
39
|
readonly conversationId?: string;
|
|
22
40
|
readonly workspaceId: string;
|
|
@@ -26,9 +44,9 @@ export interface WorkSessionConversationMeta {
|
|
|
26
44
|
readonly acceptance?: 'auto' | 'confirm';
|
|
27
45
|
readonly accepted?: boolean;
|
|
28
46
|
readonly verifying?: boolean;
|
|
29
|
-
readonly phase?: 'starting' | 'verifying';
|
|
47
|
+
readonly phase?: 'starting' | 'verifying' | 'paused';
|
|
30
48
|
}
|
|
31
|
-
export interface WorkSession {
|
|
49
|
+
export interface WorkSession extends SessionQueueFacts {
|
|
32
50
|
readonly sessionId: string;
|
|
33
51
|
readonly workspaceId: string;
|
|
34
52
|
readonly title: string;
|
|
@@ -62,18 +80,30 @@ export type JsonValue = null | string | number | boolean | readonly JsonValue[]
|
|
|
62
80
|
export interface DelegationEvent {
|
|
63
81
|
readonly eventId: string;
|
|
64
82
|
readonly kind: DelegationEventKind;
|
|
65
|
-
readonly sessionId
|
|
83
|
+
readonly sessionId?: string;
|
|
84
|
+
readonly workspaceId?: string;
|
|
85
|
+
readonly objectiveId?: string;
|
|
86
|
+
readonly watchId?: string;
|
|
87
|
+
readonly executionKey?: string;
|
|
66
88
|
readonly at: string;
|
|
67
89
|
readonly payload: JsonValue;
|
|
68
90
|
}
|
|
69
91
|
export interface AgentReplyMeta {
|
|
92
|
+
/** Host generated factual delivery keys; model input cannot set them. */
|
|
93
|
+
readonly reportFactKeys?: readonly string[];
|
|
70
94
|
readonly replyTo: readonly string[];
|
|
71
95
|
readonly sources: readonly string[];
|
|
72
96
|
readonly verdictRef?: string;
|
|
97
|
+
/** Host snapshot; accepted only when resultAcceptance has been persisted. */
|
|
98
|
+
readonly sessionStates?: readonly ReplySessionState[];
|
|
73
99
|
readonly memoryUsed: readonly string[];
|
|
74
100
|
readonly memoryLearned: readonly string[];
|
|
75
101
|
readonly surfacing: 'interrupt' | 'message' | 'digest' | 'silent';
|
|
76
102
|
}
|
|
103
|
+
export interface ReplySessionState {
|
|
104
|
+
readonly sessionId: string;
|
|
105
|
+
readonly status: WorkSessionStatus;
|
|
106
|
+
}
|
|
77
107
|
export type MessageDisposition = {
|
|
78
108
|
readonly kind: 'answered';
|
|
79
109
|
readonly messageId: string;
|
package/dist/delegation.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* The user-visible conclusion of a work session is projectGoalPlan's conclusion.
|
|
4
4
|
*/
|
|
5
5
|
import { projectGoalPlan, } from "./task-overview.js";
|
|
6
|
+
export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'verifying',
|
|
7
|
+
'result_ready', 'accepted', 'failed', 'cancelled', 'superseded'];
|
|
6
8
|
function fnv1a(text) {
|
|
7
9
|
let hash = 0x811c9dc5;
|
|
8
10
|
for (let index = 0; index < text.length; index += 1) {
|
|
@@ -42,8 +44,6 @@ export function createDelegationEvent(input) {
|
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
function delegationStatus(snapshot, meta, projected) {
|
|
45
|
-
if (meta.supersededBy)
|
|
46
|
-
return 'superseded';
|
|
47
47
|
if (snapshot.status === 'failed')
|
|
48
48
|
return 'failed';
|
|
49
49
|
if (snapshot.status === 'cancelled')
|
|
@@ -55,6 +55,10 @@ function delegationStatus(snapshot, meta, projected) {
|
|
|
55
55
|
return 'result_ready';
|
|
56
56
|
return 'accepted';
|
|
57
57
|
}
|
|
58
|
+
if (meta.supersededBy)
|
|
59
|
+
return 'superseded';
|
|
60
|
+
if (meta.phase === 'paused')
|
|
61
|
+
return 'paused';
|
|
58
62
|
// 复核进行中盖过「需要你」。草稿、待批准、等回答的计划在独立复核时都显示 verifying。
|
|
59
63
|
if (meta.verifying || meta.phase === 'verifying')
|
|
60
64
|
return 'verifying';
|
|
@@ -93,6 +97,8 @@ export function projectWorkSession(plan, conversationMeta) {
|
|
|
93
97
|
spawnedAt: conversationMeta.spawnedAt ?? plan.updatedAt ?? '',
|
|
94
98
|
...(conversationMeta.conversationId ? { conversationId: conversationMeta.conversationId } : {}),
|
|
95
99
|
origin: conversationMeta.origin,
|
|
100
|
+
...(conversationMeta.queuedBehind ? { queuedBehind: conversationMeta.queuedBehind.map(item => ({ ...item })) } : {}),
|
|
101
|
+
...(conversationMeta.queueReason ? { queueReason: conversationMeta.queueReason } : {}),
|
|
96
102
|
...(conversationMeta.supersededBy ? { supersededBy: conversationMeta.supersededBy } : {}),
|
|
97
103
|
};
|
|
98
104
|
}
|
package/dist/goal.d.ts
CHANGED
|
@@ -164,6 +164,12 @@ export interface EvidenceIndexRecord {
|
|
|
164
164
|
readonly toolName?: string;
|
|
165
165
|
readonly createdAt: string;
|
|
166
166
|
readonly artifactRefs?: readonly string[];
|
|
167
|
+
/** Redacted, bounded execution-time snapshot of a successful file Tool Result. */
|
|
168
|
+
readonly bodyPreview?: {
|
|
169
|
+
readonly kind: 'file';
|
|
170
|
+
readonly text: string;
|
|
171
|
+
readonly truncated: boolean;
|
|
172
|
+
};
|
|
167
173
|
}
|
|
168
174
|
/** 批准事实(Evidence)。 */
|
|
169
175
|
export interface GoalApproval {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export type { DesktopPreviewRequest, DesktopPreviewReply } from './desktop-previ
|
|
|
6
6
|
export type { UiDeliveryIdentity, UiDeliveryRequirement, UiDeliveryObservation, UiDeliveryJudgment, UiDeliveryGap } from './ui-delivery-verification.ts';
|
|
7
7
|
export { REMOTE_PROTOCOL_VERSION, parseRemoteReadRequest, admitRemoteRead } from './remote-access.ts';
|
|
8
8
|
export type { RemoteReadRequest, RemoteReadContext, RemoteReadRejection, RemoteReadAdmission } from './remote-access.ts';
|
|
9
|
+
export { REMOTE_PROJECT_LIMITS, parseRemoteProjectRequest, admitRemoteProject, parseRemoteDelegationProjection } from './remote-access.ts';
|
|
10
|
+
export type { RemoteProjectGrant, RemoteProjectRequest, RemoteProjectContext, RemoteProjectRejection, RemoteProjectAdmission, RemoteDelegationProjection } from './remote-access.ts';
|
|
9
11
|
export type LocalAccessLevel = 'ask_before_local' | 'session_local' | 'restricted_local' | 'full_local';
|
|
10
12
|
export type { ConversationLifetimeUsage, ProviderRequestUsage, RuntimeTurnUsage, UsageAmounts, UsageScope, } from './usage-accounting.ts';
|
|
11
13
|
export type CapabilityRiskLevel = 'L0_inert' | 'L1_local_read' | 'L2_local_write' | 'L3_external_write' | 'L4_privileged' | 'L5_destructive';
|
|
@@ -867,3 +869,4 @@ export * from './delegation.ts';
|
|
|
867
869
|
export * from './model-routing.ts';
|
|
868
870
|
export * from './project.ts';
|
|
869
871
|
export * from './objectives.ts';
|
|
872
|
+
export * from './remote-access-settings.ts';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export { buildModelMenuGroups, modelMenuChannelName } from "./model-menu.js";
|
|
|
2
2
|
export { evaluateUiDelivery } from "./ui-delivery-verification.js";
|
|
3
3
|
export { DESKTOP_PREVIEW_PROTOCOL, DESKTOP_PREVIEW_CAPABILITY, DESKTOP_PREVIEW_TOOL } from "./desktop-preview.js";
|
|
4
4
|
export { REMOTE_PROTOCOL_VERSION, parseRemoteReadRequest, admitRemoteRead } from "./remote-access.js";
|
|
5
|
+
export { REMOTE_PROJECT_LIMITS, parseRemoteProjectRequest, admitRemoteProject, parseRemoteDelegationProjection } from "./remote-access.js";
|
|
5
6
|
export function resolveLlmModelOptionValues(definitions, values) {
|
|
6
7
|
if (!definitions?.length)
|
|
7
8
|
return {};
|
|
@@ -35,3 +36,4 @@ export * from "./delegation.js";
|
|
|
35
36
|
export * from "./model-routing.js";
|
|
36
37
|
export * from "./project.js";
|
|
37
38
|
export * from "./objectives.js";
|
|
39
|
+
export * from "./remote-access-settings.js";
|
package/dist/memory.d.ts
CHANGED
|
@@ -5,7 +5,21 @@ import type { MessageDisposition } from './delegation.ts';
|
|
|
5
5
|
export type MemoryKind = 'fact' | 'preference' | 'decision' | 'procedure' | 'responsibility';
|
|
6
6
|
export type MemoryTrust = 'verified' | 'stated' | 'inferred';
|
|
7
7
|
export type MemoryStatus = 'active' | 'forgotten' | 'expired' | 'conflicted';
|
|
8
|
-
export interface
|
|
8
|
+
export interface MemoryValidityFields {
|
|
9
|
+
readonly expiresAt?: string;
|
|
10
|
+
readonly topicKey?: string;
|
|
11
|
+
readonly topicValue?: string;
|
|
12
|
+
readonly conflictId?: string;
|
|
13
|
+
readonly conflictsWith?: readonly string[];
|
|
14
|
+
readonly supersededBy?: string;
|
|
15
|
+
readonly needsReverify?: boolean;
|
|
16
|
+
readonly fileAnchors?: readonly {
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly contentHash: string;
|
|
19
|
+
readonly commit: string | null;
|
|
20
|
+
}[];
|
|
21
|
+
}
|
|
22
|
+
export interface MemoryItem extends MemoryValidityFields {
|
|
9
23
|
readonly id: string;
|
|
10
24
|
readonly scope: 'project' | 'user';
|
|
11
25
|
readonly workspaceId?: string;
|
|
@@ -37,7 +51,7 @@ export interface MemorySnapshot {
|
|
|
37
51
|
readonly createdAt: string;
|
|
38
52
|
}
|
|
39
53
|
/** 记忆页跨进程载荷。渲染层不读存储。 */
|
|
40
|
-
export interface ProjectMemoryRecord {
|
|
54
|
+
export interface ProjectMemoryRecord extends MemoryValidityFields {
|
|
41
55
|
readonly id: string;
|
|
42
56
|
readonly scope: 'project' | 'user';
|
|
43
57
|
readonly workspaceId?: string;
|
|
@@ -85,6 +99,7 @@ export interface ProjectMemoryForgetRequest {
|
|
|
85
99
|
export interface ProjectMemoryRestoreRequest {
|
|
86
100
|
readonly workspaceId: string;
|
|
87
101
|
readonly id: string;
|
|
102
|
+
readonly resolveConflict?: boolean;
|
|
88
103
|
}
|
|
89
104
|
export interface ProjectMemoryEditRequest {
|
|
90
105
|
readonly workspaceId: string;
|
package/dist/memory.js
CHANGED
|
@@ -15,6 +15,8 @@ export function assessMemoryCandidate(item, options = {}) {
|
|
|
15
15
|
}
|
|
16
16
|
if (item.status === 'conflicted')
|
|
17
17
|
return { ok: false, reason: 'conflicted' };
|
|
18
|
+
if (item.needsReverify === true)
|
|
19
|
+
return { ok: false, reason: 'needs_reverify' };
|
|
18
20
|
if (SECRET.test(item.text))
|
|
19
21
|
return { ok: false, reason: 'sensitive' };
|
|
20
22
|
if (LOOSENING.test(item.text))
|
package/dist/model-routing.d.ts
CHANGED
|
@@ -53,6 +53,35 @@ export interface ModelSelectionSnapshot {
|
|
|
53
53
|
readonly autoReason?: string;
|
|
54
54
|
readonly resolvedAt: string;
|
|
55
55
|
}
|
|
56
|
+
/** Model row shown in the routing menu. Shared by main projection and the renderer. */
|
|
57
|
+
export interface ModelRoutingMenuOption {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly label: string;
|
|
60
|
+
readonly providerName: string;
|
|
61
|
+
readonly groupId: string;
|
|
62
|
+
readonly model: string;
|
|
63
|
+
readonly authMethod: string;
|
|
64
|
+
readonly supportsVision: boolean;
|
|
65
|
+
readonly supportsTools: boolean;
|
|
66
|
+
readonly supportsStructured: boolean;
|
|
67
|
+
readonly contextTokens: number;
|
|
68
|
+
}
|
|
69
|
+
/** Project one configured provider into the routing menu contract. */
|
|
70
|
+
export declare function projectModelRoutingMenuOption(provider: {
|
|
71
|
+
readonly id?: unknown;
|
|
72
|
+
readonly groupId?: unknown;
|
|
73
|
+
readonly name?: unknown;
|
|
74
|
+
readonly model?: unknown;
|
|
75
|
+
readonly modelLabel?: unknown;
|
|
76
|
+
readonly authMethod?: unknown;
|
|
77
|
+
readonly supportsVision?: unknown;
|
|
78
|
+
readonly supportsTools?: unknown;
|
|
79
|
+
readonly supportsStructured?: unknown;
|
|
80
|
+
readonly capabilities?: {
|
|
81
|
+
readonly toolUse?: unknown;
|
|
82
|
+
} | null;
|
|
83
|
+
readonly contextWindow?: unknown;
|
|
84
|
+
} | null | undefined): ModelRoutingMenuOption | null;
|
|
56
85
|
export interface CatalogModel {
|
|
57
86
|
readonly modelProviderId: string;
|
|
58
87
|
readonly providerId: string;
|
package/dist/model-routing.js
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
* Role and tier model routing. Resolution is pure; hosts apply the result.
|
|
3
3
|
* Order and filters follow ADR 83. An empty candidate set is an error, not a silent downgrade.
|
|
4
4
|
*/
|
|
5
|
+
/** Project one configured provider into the routing menu contract. */
|
|
6
|
+
export function projectModelRoutingMenuOption(provider) {
|
|
7
|
+
if (!provider || typeof provider.id !== 'string' || !provider.id.trim())
|
|
8
|
+
return null;
|
|
9
|
+
const id = provider.id.trim();
|
|
10
|
+
const groupId = typeof provider.groupId === 'string' && provider.groupId.trim()
|
|
11
|
+
? provider.groupId.trim()
|
|
12
|
+
: id;
|
|
13
|
+
const label = [provider.modelLabel, provider.model, provider.name, id]
|
|
14
|
+
.find((value) => typeof value === 'string' && value.trim());
|
|
15
|
+
const context = Number(provider.contextWindow);
|
|
16
|
+
return {
|
|
17
|
+
id,
|
|
18
|
+
label: typeof label === 'string' ? label.trim() : id,
|
|
19
|
+
providerName: typeof provider.name === 'string' ? provider.name.trim() : '',
|
|
20
|
+
groupId,
|
|
21
|
+
model: typeof provider.model === 'string' ? provider.model.trim() : '',
|
|
22
|
+
authMethod: typeof provider.authMethod === 'string' ? provider.authMethod.trim() : '',
|
|
23
|
+
supportsVision: provider.supportsVision === true,
|
|
24
|
+
supportsTools: provider.supportsTools !== false && provider.capabilities?.toolUse !== false,
|
|
25
|
+
supportsStructured: provider.supportsStructured !== false,
|
|
26
|
+
contextTokens: Number.isFinite(context) && context > 0 ? context : 128_000,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
5
29
|
const EXPLORER_MIN_CONTEXT = 8_000;
|
|
6
30
|
function roleNeeds(input) {
|
|
7
31
|
const context = input.requiredContextTokens ?? 0;
|
package/dist/objectives.d.ts
CHANGED
|
@@ -1,13 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AutomationSchedule } from './automation.ts';
|
|
2
2
|
export type ObjectiveAutonomy = 'report_only' | 'propose' | 'act';
|
|
3
|
-
export type WatchTrigger = 'schedule' | 'git' | 'file' | 'ci';
|
|
4
3
|
export type ObjectiveStatus = 'active' | 'paused' | 'achieved' | 'abandoned';
|
|
5
|
-
export
|
|
4
|
+
export type WatchSeverity = 'info' | 'notable' | 'urgent';
|
|
5
|
+
export type ObjectiveProbe = {
|
|
6
|
+
readonly type: 'deterministic';
|
|
7
|
+
readonly check: 'git_ref';
|
|
8
|
+
readonly spec: {
|
|
9
|
+
readonly ref: string;
|
|
10
|
+
};
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: 'deterministic';
|
|
13
|
+
readonly check: 'file_hash';
|
|
14
|
+
readonly spec: {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
readonly type: 'deterministic';
|
|
19
|
+
readonly check: 'command';
|
|
20
|
+
readonly spec: {
|
|
21
|
+
readonly command: 'gh_run_list';
|
|
22
|
+
readonly workflow?: string;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: 'agent';
|
|
26
|
+
readonly question: string;
|
|
27
|
+
};
|
|
28
|
+
export type WatchEventSource = {
|
|
29
|
+
readonly type: 'task_event';
|
|
30
|
+
readonly filter: 'failed' | 'ended' | 'verified';
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: 'git';
|
|
33
|
+
readonly ref: string;
|
|
34
|
+
readonly on: 'new_commits' | 'new_tag';
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: 'files';
|
|
37
|
+
readonly paths: readonly string[];
|
|
38
|
+
readonly debounceMs?: 5000;
|
|
39
|
+
};
|
|
40
|
+
export type ObjectiveWatch = ({
|
|
41
|
+
readonly watchId: string;
|
|
42
|
+
readonly kind: 'schedule';
|
|
43
|
+
readonly schedule: AutomationSchedule;
|
|
44
|
+
readonly probe: ObjectiveProbe;
|
|
45
|
+
} | {
|
|
6
46
|
readonly watchId: string;
|
|
7
|
-
readonly
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
|
|
47
|
+
readonly kind: 'event';
|
|
48
|
+
readonly source: WatchEventSource;
|
|
49
|
+
readonly probe?: ObjectiveProbe;
|
|
50
|
+
}) & {
|
|
51
|
+
readonly notificationPolicy?: 'changes' | 'failure_only';
|
|
52
|
+
readonly lastScheduledAt?: string;
|
|
53
|
+
readonly nextRunAt?: string;
|
|
54
|
+
readonly unavailableReason?: string;
|
|
55
|
+
};
|
|
56
|
+
export interface ObjectiveSignal {
|
|
57
|
+
readonly signalId: string;
|
|
58
|
+
readonly watchId: string;
|
|
59
|
+
readonly operator: 'equals' | 'contains' | 'succeeded';
|
|
60
|
+
readonly value?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ObjectiveMilestone {
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly title: string;
|
|
65
|
+
readonly sessionIds: readonly string[];
|
|
66
|
+
readonly status: 'pending' | 'active' | 'done' | 'dropped';
|
|
67
|
+
}
|
|
68
|
+
export interface ObjectiveBudget {
|
|
69
|
+
readonly maxAutoSessionsPerDay: number;
|
|
70
|
+
readonly maxProbeRunsPerDay: number;
|
|
71
|
+
/** Reject this optional policy until the host can enforce a token hard limit. */
|
|
72
|
+
readonly maxTokensPerDay?: number;
|
|
11
73
|
}
|
|
12
74
|
export interface ProjectObjective {
|
|
13
75
|
readonly objectiveId: string;
|
|
@@ -16,15 +78,21 @@ export interface ProjectObjective {
|
|
|
16
78
|
readonly originMessageId: string;
|
|
17
79
|
readonly title: string;
|
|
18
80
|
readonly outcome: string;
|
|
81
|
+
readonly successSignals: readonly ObjectiveSignal[];
|
|
82
|
+
readonly milestones: readonly ObjectiveMilestone[];
|
|
19
83
|
readonly autonomy: ObjectiveAutonomy;
|
|
20
84
|
readonly watches: readonly ObjectiveWatch[];
|
|
85
|
+
readonly budget: ObjectiveBudget;
|
|
21
86
|
readonly status: ObjectiveStatus;
|
|
22
87
|
readonly createdBy: 'user_request' | 'agent_proposal';
|
|
88
|
+
readonly pendingConfirmation?: boolean;
|
|
89
|
+
readonly autoAccept?: boolean;
|
|
90
|
+
readonly autoAcceptApprovedBy?: string;
|
|
23
91
|
readonly deadline?: string;
|
|
24
92
|
readonly createdAt: string;
|
|
25
93
|
readonly updatedAt: string;
|
|
94
|
+
readonly version: number;
|
|
26
95
|
}
|
|
27
|
-
export type WatchSeverity = 'info' | 'notable' | 'urgent';
|
|
28
96
|
export interface WatchObservation {
|
|
29
97
|
readonly objectiveId: string;
|
|
30
98
|
readonly watchId: string;
|
|
@@ -34,8 +102,40 @@ export interface WatchObservation {
|
|
|
34
102
|
readonly evidenceRefs: readonly string[];
|
|
35
103
|
readonly severity: WatchSeverity;
|
|
36
104
|
readonly changed: boolean;
|
|
105
|
+
readonly succeeded?: boolean;
|
|
106
|
+
readonly value?: string;
|
|
107
|
+
readonly executionKey?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface ProjectObjectiveListRequest {
|
|
110
|
+
readonly workspaceId: string;
|
|
111
|
+
}
|
|
112
|
+
export interface ProjectObjectiveCommandRequest extends ProjectObjectiveListRequest {
|
|
113
|
+
readonly objectiveId: string;
|
|
114
|
+
readonly requestId: string;
|
|
115
|
+
}
|
|
116
|
+
export interface ProjectObjectiveUpdateRequest extends ProjectObjectiveCommandRequest {
|
|
117
|
+
readonly patch: Partial<Pick<ProjectObjective, 'title' | 'outcome' | 'watches' | 'milestones' | 'successSignals' | 'autonomy' | 'budget' | 'deadline' | 'autoAccept'>>;
|
|
118
|
+
readonly expectedVersion?: number;
|
|
119
|
+
}
|
|
120
|
+
export interface ProjectObjectiveView extends ProjectObjective {
|
|
121
|
+
readonly lastObservation?: WatchObservation | null;
|
|
122
|
+
readonly usage?: {
|
|
123
|
+
readonly autoSessions: number;
|
|
124
|
+
readonly probes: number;
|
|
125
|
+
readonly date: string;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export interface ProjectObjectiveListResult {
|
|
129
|
+
readonly ok: boolean;
|
|
130
|
+
readonly code?: string;
|
|
131
|
+
readonly items?: readonly ProjectObjectiveView[];
|
|
132
|
+
}
|
|
133
|
+
export interface ProjectObjectiveItemResult {
|
|
134
|
+
readonly ok: boolean;
|
|
135
|
+
readonly code?: string;
|
|
136
|
+
readonly item?: ProjectObjective;
|
|
37
137
|
}
|
|
38
|
-
/**
|
|
138
|
+
/** The first observation is a change; summaries and caller flags cannot override digest truth. */
|
|
39
139
|
export declare function diffWatchObservation(prev: WatchObservation | null | undefined, next: Omit<WatchObservation, 'changed'> & {
|
|
40
140
|
readonly changed?: boolean;
|
|
41
141
|
}): WatchObservation;
|
package/dist/objectives.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
/** A watch reports upward only when its digest changes. The first observation counts as a change. */
|
|
1
|
+
/** The first observation is a change; summaries and caller flags cannot override digest truth. */
|
|
3
2
|
export function diffWatchObservation(prev, next) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
watchId: next.watchId,
|
|
8
|
-
observedAt: next.observedAt,
|
|
9
|
-
digest: next.digest,
|
|
10
|
-
summary: next.summary,
|
|
11
|
-
evidenceRefs: next.evidenceRefs,
|
|
12
|
-
severity: next.severity,
|
|
13
|
-
changed,
|
|
14
|
-
};
|
|
3
|
+
return { objectiveId: next.objectiveId, watchId: next.watchId, observedAt: next.observedAt, digest: next.digest, summary: next.summary,
|
|
4
|
+
evidenceRefs: next.evidenceRefs, severity: next.severity, changed: !prev || prev.digest !== next.digest,
|
|
5
|
+
...(typeof next.succeeded === 'boolean' ? { succeeded: next.succeeded } : {}), ...(typeof next.value === 'string' ? { value: next.value } : {}) };
|
|
15
6
|
}
|
package/dist/project.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Bot list projection. Sort is recent activity only.
|
|
3
3
|
* needsYou changes the badge and the filter, not the order.
|
|
4
4
|
*/
|
|
5
|
+
import type { ProjectModelPolicy } from './model-routing.ts';
|
|
5
6
|
import type { PendingApprovalState, WorkSessionStatus } from './delegation.ts';
|
|
6
7
|
export interface ProjectRegistryEntry {
|
|
7
8
|
readonly workspaceId: string;
|
|
@@ -11,14 +12,33 @@ export interface ProjectRegistryEntry {
|
|
|
11
12
|
readonly previousPaths: readonly string[];
|
|
12
13
|
readonly remoteAlias?: string;
|
|
13
14
|
}
|
|
15
|
+
export interface ProjectHostTakeoverRequest {
|
|
16
|
+
readonly workspaceId: string;
|
|
17
|
+
}
|
|
18
|
+
export type ProjectHostTakeoverResult = {
|
|
19
|
+
readonly ok: true;
|
|
20
|
+
readonly requested: boolean;
|
|
21
|
+
readonly alreadyHost?: boolean;
|
|
22
|
+
} | {
|
|
23
|
+
readonly ok: false;
|
|
24
|
+
readonly code: 'PROJECT_AGENT_DISABLED' | 'NOT_FOUND' | 'HOST_UNAVAILABLE' | 'INVALID_INPUT';
|
|
25
|
+
};
|
|
14
26
|
export type BotAvatar = {
|
|
15
27
|
readonly kind: 'generated';
|
|
16
28
|
readonly shape: string;
|
|
17
29
|
readonly color: string;
|
|
30
|
+
readonly variant?: number;
|
|
18
31
|
} | {
|
|
19
32
|
readonly kind: 'image';
|
|
20
33
|
readonly ref: string;
|
|
21
34
|
};
|
|
35
|
+
export type BotAvatarReadResult = {
|
|
36
|
+
readonly ok: true;
|
|
37
|
+
readonly dataUrl: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly ok: false;
|
|
40
|
+
readonly code: 'PROJECT_AGENT_DISABLED' | 'NOT_FOUND' | 'INVALID_IMAGE';
|
|
41
|
+
};
|
|
22
42
|
export interface BotProfile {
|
|
23
43
|
readonly workspaceId: string;
|
|
24
44
|
readonly displayName: string;
|
|
@@ -28,12 +48,25 @@ export interface BotProfile {
|
|
|
28
48
|
readonly proactivity?: 'inherit' | 'quiet' | 'low' | 'standard' | 'high' | 'muted';
|
|
29
49
|
/** Absent means this bot uses memory. */
|
|
30
50
|
readonly memoryEnabled?: boolean;
|
|
51
|
+
readonly planApproval?: 'never' | 'writes' | 'always';
|
|
52
|
+
readonly acceptancePolicy?: 'auto' | 'confirm';
|
|
53
|
+
/** Policy acceptance keeps a separate merge confirmation unless explicitly enabled. */
|
|
54
|
+
readonly autoHandoffOnPolicyAccept?: boolean;
|
|
55
|
+
/** Archived deletion intent, retained until each cleanup step is persisted. */
|
|
56
|
+
readonly deletionCleanup?: {
|
|
57
|
+
readonly folder: string;
|
|
58
|
+
readonly trashPending: boolean;
|
|
59
|
+
readonly removePending: boolean;
|
|
60
|
+
} | null;
|
|
61
|
+
readonly modelPolicy?: ProjectModelPolicy | null;
|
|
31
62
|
readonly updatedAt?: string;
|
|
32
63
|
}
|
|
33
64
|
export interface BotRowState {
|
|
34
65
|
readonly needsYou: number;
|
|
35
66
|
readonly unread: number;
|
|
36
67
|
readonly running: number;
|
|
68
|
+
/** Ephemeral status of the runner hosted by this desktop process. */
|
|
69
|
+
readonly agentStatus?: 'idle' | 'thinking' | 'waiting_provider' | 'error';
|
|
37
70
|
}
|
|
38
71
|
export interface BotListItem {
|
|
39
72
|
readonly workspaceId: string;
|
|
@@ -61,8 +94,10 @@ export interface BotListMessage {
|
|
|
61
94
|
readonly countUnread?: boolean;
|
|
62
95
|
}
|
|
63
96
|
export declare const BOT_AVATAR_SHAPES: readonly ["circle", "square", "triangle", "diamond", "hex", "pill", "star", "arch"];
|
|
64
|
-
export declare const BOT_AVATAR_COLORS: readonly ["#
|
|
65
|
-
export declare function generateAvatar(workspaceId: string): BotAvatar
|
|
97
|
+
export declare const BOT_AVATAR_COLORS: readonly ["#6474e5", "#f36d63", "#f4ad45", "#61b68c", "#a884e5", "#e774ad", "#55bac7", "#a8a59f"];
|
|
98
|
+
export declare function generateAvatar(workspaceId: string): Extract<BotAvatar, {
|
|
99
|
+
kind: 'generated';
|
|
100
|
+
}>;
|
|
66
101
|
export declare function projectBotListItem(input: {
|
|
67
102
|
readonly profile: BotProfile;
|
|
68
103
|
readonly lastMessage?: BotListMessage | null;
|
package/dist/project.js
CHANGED
|
@@ -13,14 +13,14 @@ export const BOT_AVATAR_SHAPES = [
|
|
|
13
13
|
'arch',
|
|
14
14
|
];
|
|
15
15
|
export const BOT_AVATAR_COLORS = [
|
|
16
|
-
'#
|
|
17
|
-
'#
|
|
18
|
-
'#
|
|
19
|
-
'#
|
|
20
|
-
'#
|
|
21
|
-
'#
|
|
22
|
-
'#
|
|
23
|
-
'#
|
|
16
|
+
'#6474e5',
|
|
17
|
+
'#f36d63',
|
|
18
|
+
'#f4ad45',
|
|
19
|
+
'#61b68c',
|
|
20
|
+
'#a884e5',
|
|
21
|
+
'#e774ad',
|
|
22
|
+
'#55bac7',
|
|
23
|
+
'#a8a59f',
|
|
24
24
|
];
|
|
25
25
|
const NEEDS_YOU_STATUSES = new Set(['waiting_user', 'result_ready']);
|
|
26
26
|
const RUNNING_STATUSES = new Set(['starting', 'running', 'verifying']);
|
|
@@ -36,7 +36,8 @@ export function generateAvatar(workspaceId) {
|
|
|
36
36
|
const hash = fnv1a(workspaceId);
|
|
37
37
|
const shape = BOT_AVATAR_SHAPES[hash % BOT_AVATAR_SHAPES.length] ?? BOT_AVATAR_SHAPES[0];
|
|
38
38
|
const color = BOT_AVATAR_COLORS[(hash >>> 16) % BOT_AVATAR_COLORS.length] ?? BOT_AVATAR_COLORS[0];
|
|
39
|
-
|
|
39
|
+
const variant = (hash >>> 8) % 32;
|
|
40
|
+
return { kind: 'generated', shape, color, variant };
|
|
40
41
|
}
|
|
41
42
|
function latestIso(values) {
|
|
42
43
|
let best = '';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RemoteProjectGrant } from './remote-access.ts';
|
|
2
|
+
/** Local settings contract. Callers cannot supply a delegation version in a patch. */
|
|
3
|
+
export interface RemoteAccessSettings {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
gatewayOrigin: string;
|
|
6
|
+
workspaceId: string;
|
|
7
|
+
projectGrants: readonly RemoteProjectGrant[];
|
|
8
|
+
workspaceIds: readonly string[];
|
|
9
|
+
delegationVersion: number;
|
|
10
|
+
}
|
|
11
|
+
export interface RemoteAccessPatch {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
gatewayOrigin?: string;
|
|
14
|
+
workspaceId?: string;
|
|
15
|
+
projectGrants?: readonly RemoteProjectGrant[];
|
|
16
|
+
}
|
|
17
|
+
export interface RemoteAccessSummary {
|
|
18
|
+
at: number;
|
|
19
|
+
operation: 'project.list' | 'project.conversation.read' | 'project.session.read' | 'project.input.submit';
|
|
20
|
+
workspaceId?: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/remote-access.d.ts
CHANGED
|
@@ -50,3 +50,87 @@ export type RemoteReadAdmission = {
|
|
|
50
50
|
export declare function parseRemoteReadRequest(value: unknown): RemoteReadAdmission;
|
|
51
51
|
/** New submissions only. Duplicate receipt lookup belongs to the persistent host ledger. */
|
|
52
52
|
export declare function admitRemoteRead(value: unknown, context: RemoteReadContext): RemoteReadAdmission;
|
|
53
|
+
export declare const REMOTE_PROJECT_LIMITS: Readonly<{
|
|
54
|
+
projects: 200;
|
|
55
|
+
messages: 50;
|
|
56
|
+
text: 4000;
|
|
57
|
+
requestBytes: number;
|
|
58
|
+
delegationBytes: number;
|
|
59
|
+
resultBytes: number;
|
|
60
|
+
}>;
|
|
61
|
+
export interface RemoteProjectGrant {
|
|
62
|
+
readonly workspaceId: string;
|
|
63
|
+
readonly allowProjectRead: boolean;
|
|
64
|
+
readonly allowProjectMessage: boolean;
|
|
65
|
+
}
|
|
66
|
+
interface RemoteProjectRequestBase {
|
|
67
|
+
readonly protocolVersion: typeof REMOTE_PROTOCOL_VERSION;
|
|
68
|
+
readonly type: 'project.submit';
|
|
69
|
+
readonly requestId: string;
|
|
70
|
+
readonly ownerId: string;
|
|
71
|
+
readonly deviceId: string;
|
|
72
|
+
readonly bindingVersion: number;
|
|
73
|
+
readonly connectionEpoch: number;
|
|
74
|
+
readonly delegationVersion: number;
|
|
75
|
+
readonly expiresAt: number;
|
|
76
|
+
}
|
|
77
|
+
export type RemoteProjectRequest = RemoteProjectRequestBase & ({
|
|
78
|
+
readonly operation: 'project.list';
|
|
79
|
+
} | {
|
|
80
|
+
readonly operation: 'project.conversation.read';
|
|
81
|
+
readonly workspaceId: string;
|
|
82
|
+
readonly limit: number;
|
|
83
|
+
readonly before: string | null;
|
|
84
|
+
} | {
|
|
85
|
+
readonly operation: 'project.session.read';
|
|
86
|
+
readonly workspaceId: string;
|
|
87
|
+
readonly sessionId: string;
|
|
88
|
+
} | {
|
|
89
|
+
readonly operation: 'project.input.submit';
|
|
90
|
+
readonly workspaceId: string;
|
|
91
|
+
readonly text: string;
|
|
92
|
+
});
|
|
93
|
+
export interface RemoteProjectContext extends Omit<RemoteReadContext, 'delegation' | 'task'> {
|
|
94
|
+
readonly delegation: {
|
|
95
|
+
readonly version: number;
|
|
96
|
+
readonly expiresAt: number;
|
|
97
|
+
readonly revoked: boolean;
|
|
98
|
+
readonly workspaceIds: readonly string[];
|
|
99
|
+
readonly allowProjectRead: boolean;
|
|
100
|
+
readonly allowProjectMessage: boolean;
|
|
101
|
+
readonly projectGrants: readonly RemoteProjectGrant[];
|
|
102
|
+
};
|
|
103
|
+
readonly project: {
|
|
104
|
+
readonly workspaceId: string;
|
|
105
|
+
readonly status: string;
|
|
106
|
+
} | null;
|
|
107
|
+
readonly session: {
|
|
108
|
+
readonly workspaceId: string;
|
|
109
|
+
readonly sessionId: string;
|
|
110
|
+
} | null;
|
|
111
|
+
}
|
|
112
|
+
export type RemoteProjectRejection = RemoteReadRejection | 'PROJECT_DENIED' | 'MESSAGE_DENIED' | 'INPUT_TOO_LONG';
|
|
113
|
+
export type RemoteProjectAdmission = {
|
|
114
|
+
readonly ok: true;
|
|
115
|
+
readonly request: RemoteProjectRequest;
|
|
116
|
+
} | {
|
|
117
|
+
readonly ok: false;
|
|
118
|
+
readonly code: RemoteProjectRejection;
|
|
119
|
+
};
|
|
120
|
+
/** Each operation has one exact shape; input acceptance is never a tool grant. */
|
|
121
|
+
export declare function parseRemoteProjectRequest(value: unknown): RemoteProjectAdmission;
|
|
122
|
+
/** The local context remains authoritative, including each bot's capability bits. */
|
|
123
|
+
export declare function admitRemoteProject(value: unknown, context: RemoteProjectContext): RemoteProjectAdmission;
|
|
124
|
+
export interface RemoteDelegationProjection {
|
|
125
|
+
version: number;
|
|
126
|
+
workspaceIds: string[];
|
|
127
|
+
allowTaskRead: boolean;
|
|
128
|
+
allowResultExport: boolean;
|
|
129
|
+
expiresAt: number;
|
|
130
|
+
allowProjectRead?: boolean;
|
|
131
|
+
allowProjectMessage?: boolean;
|
|
132
|
+
projectGrants?: RemoteProjectGrant[];
|
|
133
|
+
}
|
|
134
|
+
/** Shared transport shape only; this projection is never device-side authority. */
|
|
135
|
+
export declare function parseRemoteDelegationProjection(value: unknown, now?: number): RemoteDelegationProjection | null;
|
|
136
|
+
export {};
|
package/dist/remote-access.js
CHANGED
|
@@ -56,3 +56,130 @@ export function admitRemoteRead(value, context) {
|
|
|
56
56
|
return deny('REQUEST_EXPIRED');
|
|
57
57
|
return parsed;
|
|
58
58
|
}
|
|
59
|
+
export const REMOTE_PROJECT_LIMITS = Object.freeze({
|
|
60
|
+
projects: 200, messages: 50, text: 4000,
|
|
61
|
+
requestBytes: 32 * 1024, delegationBytes: 128 * 1024, resultBytes: 2 * 1024 * 1024,
|
|
62
|
+
});
|
|
63
|
+
const projectBaseFields = [
|
|
64
|
+
'protocolVersion', 'type', 'requestId', 'ownerId', 'deviceId',
|
|
65
|
+
'bindingVersion', 'connectionEpoch', 'delegationVersion', 'expiresAt', 'operation',
|
|
66
|
+
];
|
|
67
|
+
const projectFields = {
|
|
68
|
+
'project.list': [],
|
|
69
|
+
'project.conversation.read': ['workspaceId', 'limit', 'before'],
|
|
70
|
+
'project.session.read': ['workspaceId', 'sessionId'],
|
|
71
|
+
'project.input.submit': ['workspaceId', 'text'],
|
|
72
|
+
};
|
|
73
|
+
/** Each operation has one exact shape; input acceptance is never a tool grant. */
|
|
74
|
+
export function parseRemoteProjectRequest(value) {
|
|
75
|
+
const deny = (code) => ({ ok: false, code });
|
|
76
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
77
|
+
return deny('INVALID_REQUEST');
|
|
78
|
+
const r = value;
|
|
79
|
+
if (r.protocolVersion !== REMOTE_PROTOCOL_VERSION)
|
|
80
|
+
return deny('PROTOCOL_UNSUPPORTED');
|
|
81
|
+
const extra = typeof r.operation === 'string' && Object.hasOwn(projectFields, r.operation)
|
|
82
|
+
? projectFields[r.operation] : undefined;
|
|
83
|
+
if (!extra || r.type !== 'project.submit')
|
|
84
|
+
return deny('INVALID_REQUEST');
|
|
85
|
+
const allowed = new Set([...projectBaseFields, ...extra]);
|
|
86
|
+
if (Object.keys(r).length !== allowed.size || Object.keys(r).some(key => !allowed.has(key))
|
|
87
|
+
|| !['requestId', 'ownerId', 'deviceId'].every(key => identifier(r[key]))
|
|
88
|
+
|| !['bindingVersion', 'connectionEpoch', 'delegationVersion', 'expiresAt'].every(key => integer(r[key]))
|
|
89
|
+
|| (r.operation !== 'project.list' && !identifier(r.workspaceId)))
|
|
90
|
+
return deny('INVALID_REQUEST');
|
|
91
|
+
if (r.operation === 'project.conversation.read'
|
|
92
|
+
&& (!integer(r.limit) || r.limit > REMOTE_PROJECT_LIMITS.messages
|
|
93
|
+
|| !(r.before === null || typeof r.before === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/.test(r.before)))) {
|
|
94
|
+
return deny('INVALID_REQUEST');
|
|
95
|
+
}
|
|
96
|
+
if (r.operation === 'project.session.read' && !identifier(r.sessionId))
|
|
97
|
+
return deny('INVALID_REQUEST');
|
|
98
|
+
if (r.operation === 'project.input.submit') {
|
|
99
|
+
if (typeof r.text !== 'string' || !r.text.trim() || /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(r.text)) {
|
|
100
|
+
return deny('INVALID_REQUEST');
|
|
101
|
+
}
|
|
102
|
+
if (Array.from(r.text).length > REMOTE_PROJECT_LIMITS.text)
|
|
103
|
+
return deny('INPUT_TOO_LONG');
|
|
104
|
+
}
|
|
105
|
+
return { ok: true, request: { ...r } };
|
|
106
|
+
}
|
|
107
|
+
/** The local context remains authoritative, including each bot's capability bits. */
|
|
108
|
+
export function admitRemoteProject(value, context) {
|
|
109
|
+
const parsed = parseRemoteProjectRequest(value);
|
|
110
|
+
if (!parsed.ok)
|
|
111
|
+
return parsed;
|
|
112
|
+
const r = parsed.request, d = context.delegation;
|
|
113
|
+
const deny = (code) => ({ ok: false, code });
|
|
114
|
+
if (context.bindingRevoked || r.ownerId !== context.ownerId || r.deviceId !== context.deviceId
|
|
115
|
+
|| r.bindingVersion !== context.bindingVersion)
|
|
116
|
+
return deny('IDENTITY_UNBOUND');
|
|
117
|
+
if (!Number.isFinite(context.now) || !Number.isFinite(d.expiresAt) || d.revoked
|
|
118
|
+
|| d.expiresAt <= context.now || r.delegationVersion !== d.version)
|
|
119
|
+
return deny('DELEGATION_EXPIRED');
|
|
120
|
+
if (!d.allowProjectRead)
|
|
121
|
+
return deny('PROJECT_DENIED');
|
|
122
|
+
if (r.operation !== 'project.list') {
|
|
123
|
+
if (!d.workspaceIds.includes(r.workspaceId))
|
|
124
|
+
return deny('WORKSPACE_DENIED');
|
|
125
|
+
const grant = d.projectGrants.find(item => item.workspaceId === r.workspaceId);
|
|
126
|
+
if (!grant?.allowProjectRead || !context.project || context.project.workspaceId !== r.workspaceId
|
|
127
|
+
|| context.project.status !== 'active')
|
|
128
|
+
return deny('PROJECT_DENIED');
|
|
129
|
+
if (r.operation === 'project.input.submit' && (!d.allowProjectMessage || !grant.allowProjectMessage)) {
|
|
130
|
+
return deny('MESSAGE_DENIED');
|
|
131
|
+
}
|
|
132
|
+
if (r.operation === 'project.session.read' && (!context.session
|
|
133
|
+
|| context.session.workspaceId !== r.workspaceId || context.session.sessionId !== r.sessionId))
|
|
134
|
+
return deny('TASK_DENIED');
|
|
135
|
+
}
|
|
136
|
+
if (!context.online)
|
|
137
|
+
return deny('DEVICE_OFFLINE');
|
|
138
|
+
if (r.connectionEpoch !== context.connectionEpoch)
|
|
139
|
+
return deny('STALE_CONNECTION');
|
|
140
|
+
if (r.expiresAt <= context.now || r.expiresAt - context.now > 30_000)
|
|
141
|
+
return deny('REQUEST_EXPIRED');
|
|
142
|
+
return parsed;
|
|
143
|
+
}
|
|
144
|
+
/** Shared transport shape only; this projection is never device-side authority. */
|
|
145
|
+
export function parseRemoteDelegationProjection(value, now = Date.now()) {
|
|
146
|
+
if (!Number.isSafeInteger(now) || now < 0 || !value || typeof value !== 'object' || Array.isArray(value))
|
|
147
|
+
return null;
|
|
148
|
+
const r = value;
|
|
149
|
+
const legacy = ['version', 'workspaceIds', 'allowTaskRead', 'allowResultExport', 'expiresAt'];
|
|
150
|
+
const extended = Object.hasOwn(r, 'projectGrants');
|
|
151
|
+
const fields = extended ? [...legacy, 'allowProjectRead', 'allowProjectMessage', 'projectGrants'] : legacy;
|
|
152
|
+
if (Object.keys(r).length !== fields.length || Object.keys(r).some(key => !fields.includes(key))
|
|
153
|
+
|| !integer(r.version) || !integer(r.expiresAt) || r.expiresAt <= now
|
|
154
|
+
|| !Array.isArray(r.workspaceIds) || !r.workspaceIds.every(identifier)
|
|
155
|
+
|| r.workspaceIds.length > (extended ? REMOTE_PROJECT_LIMITS.projects + 32 : 32)
|
|
156
|
+
|| !extended && r.workspaceIds.length === 0
|
|
157
|
+
|| typeof r.allowTaskRead !== 'boolean' || typeof r.allowResultExport !== 'boolean')
|
|
158
|
+
return null;
|
|
159
|
+
const result = { version: r.version, workspaceIds: [...r.workspaceIds],
|
|
160
|
+
allowTaskRead: r.allowTaskRead, allowResultExport: r.allowResultExport, expiresAt: r.expiresAt };
|
|
161
|
+
if (extended) {
|
|
162
|
+
if (typeof r.allowProjectRead !== 'boolean' || typeof r.allowProjectMessage !== 'boolean'
|
|
163
|
+
|| !Array.isArray(r.projectGrants) || r.projectGrants.length > REMOTE_PROJECT_LIMITS.projects)
|
|
164
|
+
return null;
|
|
165
|
+
const seen = new Set(), grants = [];
|
|
166
|
+
for (const raw of r.projectGrants) {
|
|
167
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)
|
|
168
|
+
|| Object.keys(raw).sort().join(',') !== 'allowProjectMessage,allowProjectRead,workspaceId'
|
|
169
|
+
|| !identifier(raw.workspaceId) || seen.has(raw.workspaceId)
|
|
170
|
+
|| typeof raw.allowProjectRead !== 'boolean' || typeof raw.allowProjectMessage !== 'boolean'
|
|
171
|
+
|| raw.allowProjectMessage && !raw.allowProjectRead
|
|
172
|
+
|| raw.allowProjectRead && !result.workspaceIds.includes(raw.workspaceId))
|
|
173
|
+
return null;
|
|
174
|
+
seen.add(raw.workspaceId);
|
|
175
|
+
grants.push({ ...raw });
|
|
176
|
+
}
|
|
177
|
+
if (r.allowProjectRead !== grants.some(row => row.allowProjectRead)
|
|
178
|
+
|| r.allowProjectMessage !== grants.some(row => row.allowProjectMessage))
|
|
179
|
+
return null;
|
|
180
|
+
result.allowProjectRead = r.allowProjectRead;
|
|
181
|
+
result.allowProjectMessage = r.allowProjectMessage;
|
|
182
|
+
result.projectGrants = grants;
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peer-agent/protocol",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
4
|
"description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"typescript": "^5.9.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
+
"test": "node --test src/*.test.ts",
|
|
40
41
|
"build": "tsc -p tsconfig.build.json",
|
|
41
42
|
"typecheck": "tsc -p tsconfig.json"
|
|
42
43
|
}
|