@peer-agent/protocol 0.0.11 → 0.0.13

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.
@@ -0,0 +1,38 @@
1
+ /** Account observations never contain credentials or raw provider responses. */
2
+ export type AccountUsageSource = 'api_key' | 'oauth' | 'cli' | 'local';
3
+ export type AccountUsageScope = 'account' | 'organization' | 'subscription' | 'api_key' | 'local_only';
4
+ export interface AccountUsageBalance {
5
+ readonly currency: string;
6
+ /** Decimal strings preserve the provider's monetary precision. */
7
+ readonly total: string;
8
+ readonly paid?: string;
9
+ readonly granted?: string;
10
+ readonly source: AccountUsageSource;
11
+ readonly scope: AccountUsageScope;
12
+ }
13
+ export interface AccountUsageSpend {
14
+ readonly period: 'today' | 'week' | 'month' | 'total';
15
+ readonly amount: string;
16
+ readonly currency: string;
17
+ readonly source: AccountUsageSource;
18
+ readonly scope: AccountUsageScope;
19
+ }
20
+ export interface AccountUsageUnavailable {
21
+ readonly dimension: 'balance' | 'windows' | 'spend';
22
+ readonly reason: string;
23
+ readonly requiredAuth?: 'admin_key' | 'web_session' | 'cli_login' | 'oauth' | 'coding_plan_key';
24
+ }
25
+ /** Only retained requests through Peer Agent, never the vendor's account ledger. */
26
+ export interface AccountUsageLocal {
27
+ readonly source: 'local';
28
+ readonly scope: 'local_only';
29
+ readonly requests: number;
30
+ readonly inputTokens: number;
31
+ readonly outputTokens: number;
32
+ readonly cacheReadTokens?: number;
33
+ readonly cacheWriteTokens?: number;
34
+ readonly estimatedCostUsd?: number;
35
+ readonly from?: string;
36
+ readonly to?: string;
37
+ readonly note: string;
38
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/goal.d.ts CHANGED
@@ -13,7 +13,9 @@
13
13
  */
14
14
  import type { ExecutionStatus, HumanConfirmationDecision } from './execution.ts';
15
15
  /** 计划整体状态机,见提案 §2。 */
16
- export type GoalPlanStatus = 'drafting' | 'awaiting_approval' | 'approved' | 'accepted' | 'executing' | 'paused' | 'completed' | 'cancelled' | 'failed';
16
+ export type GoalPlanStatus = 'drafting' | 'awaiting_approval' | 'approved' | 'accepted' | 'executing' | 'paused'
17
+ /** 未消费执行中断的可恢复挂起态(非终态,见 peer-knowledge ADR 73)。 */
18
+ | 'interrupted' | 'completed' | 'cancelled' | 'failed';
17
19
  /** Goal artifact 的工作流语义:Plan 审批门 vs Goal 自驱契约。 */
18
20
  export type GoalWorkflowKind = 'plan_approval' | 'goal_self_driven';
19
21
  /**
@@ -65,6 +67,7 @@ export declare function formatGoalDeliveryHandoff(input: {
65
67
  readonly acceptedAt?: string | null;
66
68
  } | null;
67
69
  readonly deliveryBinding?: GoalDeliveryBinding | null;
70
+ readonly qualityReview?: GoalQualityReview | null;
68
71
  }, options?: {
69
72
  readonly locale?: 'zh' | 'en';
70
73
  }): string | undefined;
@@ -73,6 +76,7 @@ export declare function formatGoalDeliveryHandoffLamp(input: {
73
76
  readonly deliveryHandoff?: GoalDeliveryHandoff | null;
74
77
  readonly deliveryBinding?: GoalDeliveryBinding | null;
75
78
  readonly status?: GoalPlanStatus | null;
79
+ readonly qualityReview?: GoalQualityReview | null;
76
80
  }, options?: {
77
81
  readonly locale?: 'zh' | 'en';
78
82
  }): string | undefined;
@@ -291,6 +295,14 @@ export declare function planRequiresQualityReview(plan: {
291
295
  export declare function isQualityReviewPassed(plan: {
292
296
  readonly qualityReview?: GoalQualityReview | null;
293
297
  } | null | undefined): boolean;
298
+ /**
299
+ * 合回是否仍被「质量自检」拦住。
300
+ * 质检已通过时,过期的 quality_review_pending 快照不再阻断。
301
+ */
302
+ export declare function isQualityReviewBlockingMerge(plan: {
303
+ readonly qualityReview?: GoalQualityReview | null;
304
+ readonly deliveryHandoff?: GoalDeliveryHandoff | null;
305
+ } | null | undefined): boolean;
294
306
  export interface GoalBlockerAudit {
295
307
  readonly fingerprint: string;
296
308
  readonly occurrences: number;
package/dist/goal.js CHANGED
@@ -133,6 +133,10 @@ export function formatGoalDeliveryHandoff(input, options) {
133
133
  : (locale === 'zh' ? '已合进源头' : 'merged into source');
134
134
  }
135
135
  if (handoff.status === 'stopped') {
136
+ if (handoff.stoppedReason === 'quality_review_pending'
137
+ && !isQualityReviewBlockingMerge(input)) {
138
+ return undefined;
139
+ }
136
140
  return handoffStoppedReasonLabel(handoff.stoppedReason, locale, branch);
137
141
  }
138
142
  return undefined;
@@ -167,6 +171,13 @@ export function formatGoalDeliveryHandoffLamp(input, options) {
167
171
  return locale === 'zh' ? `已归档到 ${dest}` : `archived to ${dest}`;
168
172
  }
169
173
  if (handoff.status === 'stopped') {
174
+ if (handoff.stoppedReason === 'quality_review_pending'
175
+ && !isQualityReviewBlockingMerge(input)) {
176
+ if (input.status === 'completed') {
177
+ return locale === 'zh' ? `还没进 ${dest}` : `not on ${dest}`;
178
+ }
179
+ return undefined;
180
+ }
170
181
  return locale === 'zh' ? `合不进 ${dest}` : `blocked from ${dest}`;
171
182
  }
172
183
  return undefined;
@@ -250,3 +261,12 @@ export function planRequiresQualityReview(plan) {
250
261
  export function isQualityReviewPassed(plan) {
251
262
  return plan?.qualityReview?.status === 'passed';
252
263
  }
264
+ /**
265
+ * 合回是否仍被「质量自检」拦住。
266
+ * 质检已通过时,过期的 quality_review_pending 快照不再阻断。
267
+ */
268
+ export function isQualityReviewBlockingMerge(plan) {
269
+ if (plan?.deliveryHandoff?.stoppedReason !== 'quality_review_pending')
270
+ return false;
271
+ return !isQualityReviewPassed(plan);
272
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export type { SelectionRange, SelectionReference, SelectionDraft, SelectionOrigin, SelectionChildSession, SelectionChildSummary, SelectionChildrenPage, SelectionChildRead } from './selection-reference.ts';
2
+ export { buildModelMenuGroups, modelMenuChannelName, type ModelMenuRow } from './model-menu.ts';
1
3
  export type LocalAccessLevel = 'ask_before_local' | 'session_local' | 'restricted_local' | 'full_local';
2
4
  export type { ConversationLifetimeUsage, ProviderRequestUsage, RuntimeTurnUsage, UsageAmounts, UsageScope, } from './usage-accounting.ts';
3
5
  export type CapabilityRiskLevel = 'L0_inert' | 'L1_local_read' | 'L2_local_write' | 'L3_external_write' | 'L4_privileged' | 'L5_destructive';
@@ -68,6 +70,11 @@ export interface SkillSummary {
68
70
  * 例:skillhub、aone-open;本地手工 skill 可为空。
69
71
  */
70
72
  readonly source?: string | null;
73
+ /**
74
+ * 运行时根据安装来源、作用域与路径边界计算的卸载能力。
75
+ * 界面必须使用该字段,不可仅凭 scope 推断,以免误删工作区源码。
76
+ */
77
+ readonly canUninstall?: boolean;
71
78
  }
72
79
  export interface SkillDetail extends SkillSummary {
73
80
  readonly instructions: string;
@@ -415,6 +422,7 @@ export interface LlmOAuthStatus {
415
422
  readonly accountId?: string;
416
423
  readonly expiresAt?: string;
417
424
  }
425
+ export type { AccountUsageSource, AccountUsageScope, AccountUsageBalance, AccountUsageSpend, AccountUsageUnavailable, AccountUsageLocal } from './account-usage.js';
418
426
  /** 订阅额度窗口(session / weekly / model 等)。 */
419
427
  export interface LlmSubscriptionQuotaWindow {
420
428
  readonly id: string;
@@ -422,13 +430,28 @@ export interface LlmSubscriptionQuotaWindow {
422
430
  readonly remainingPercent?: number;
423
431
  readonly usedPercent?: number;
424
432
  readonly resetsAt?: string;
433
+ readonly used?: number;
434
+ readonly limit?: number;
435
+ readonly remaining?: number;
436
+ readonly unit?: 'requests' | 'tokens' | 'credits' | 'currency';
437
+ readonly source?: import('./account-usage.js').AccountUsageSource;
438
+ readonly scope?: import('./account-usage.js').AccountUsageScope;
425
439
  }
426
440
  /**
427
441
  * GPT / Gemini / Grok / Qoder 订阅额度快照。
428
442
  * success=false 时用 status/error 表达未登录、过期或拉取失败,UI 应降级展示。
429
443
  */
430
444
  export interface LlmSubscriptionQuota {
445
+ readonly accountUsageRevision?: string;
446
+ /** Remote query outcome; localUsage can remain available on failure. */
431
447
  readonly success: boolean;
448
+ readonly balances?: readonly import('./account-usage.js').AccountUsageBalance[];
449
+ readonly spend?: readonly import('./account-usage.js').AccountUsageSpend[];
450
+ readonly localUsage?: import('./account-usage.js').AccountUsageLocal;
451
+ readonly unavailable?: readonly import('./account-usage.js').AccountUsageUnavailable[];
452
+ readonly partial?: boolean;
453
+ readonly stale?: boolean;
454
+ readonly channelId?: string;
432
455
  readonly status?: string;
433
456
  readonly providerId?: string;
434
457
  readonly authMethod?: LlmAuthMethod;
@@ -505,6 +528,8 @@ export interface LlmProviderConfig {
505
528
  readonly lastErrorCategory?: LlmDiagnosticErrorCategory;
506
529
  }
507
530
  export interface LlmProviderConfigView extends LlmProviderConfig {
531
+ /** Ephemeral main-owned identity for account observations; contains no credential material. */
532
+ readonly accountUsageRevision?: string;
508
533
  readonly apiKeyMasked: string;
509
534
  readonly apiKeyConfigured: boolean;
510
535
  readonly oauthStatus?: LlmOAuthStatus;
@@ -706,6 +731,34 @@ export interface PermissionGrant {
706
731
  readonly scope?: string;
707
732
  readonly decidedAt: string;
708
733
  }
734
+ /** Application-owned shell process snapshot. Source conversation is provenance, not ownership. */
735
+ export interface ManagedShellTask {
736
+ readonly taskId: string;
737
+ readonly toolCallId?: string;
738
+ readonly command: string;
739
+ readonly cwd?: string;
740
+ readonly conversationId?: string | null;
741
+ readonly runInBackground?: boolean;
742
+ readonly description?: string;
743
+ readonly status: string;
744
+ readonly startedAt?: string;
745
+ readonly completedAt?: string | null;
746
+ readonly exitCode?: number | null;
747
+ readonly timedOut?: boolean;
748
+ readonly stopReason?: string | null;
749
+ readonly promptDetected?: boolean;
750
+ readonly stdout?: string;
751
+ readonly stderr?: string;
752
+ readonly artifactRef?: string | null;
753
+ /** Observed TCP listeners, not HTTP readiness inferred from log output. */
754
+ readonly listeners?: readonly {
755
+ readonly host: string;
756
+ readonly port: number;
757
+ readonly pid: number;
758
+ readonly transport: 'tcp';
759
+ readonly observedAt: string;
760
+ }[];
761
+ }
709
762
  export interface LocalShellExecInput {
710
763
  readonly command: string;
711
764
  readonly cwd?: string;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { buildModelMenuGroups, modelMenuChannelName } from "./model-menu.js";
1
2
  export function resolveLlmModelOptionValues(definitions, values) {
2
3
  if (!definitions?.length)
3
4
  return {};
@@ -0,0 +1,20 @@
1
+ /** Presentation-only model menu projection shared by local clients. No sorting or deduplication. */
2
+ export declare function modelMenuChannelName(name: string | undefined, model: string, authMethod: string | undefined, isZh: boolean): string;
3
+ export interface ModelMenuRow {
4
+ readonly id: string;
5
+ readonly groupId?: string;
6
+ readonly groupLabel: string;
7
+ readonly model: string;
8
+ readonly modelLabel?: string;
9
+ readonly available: boolean;
10
+ }
11
+ export declare function buildModelMenuGroups(rows: readonly ModelMenuRow[], hideDisabled?: boolean): {
12
+ disabled: boolean;
13
+ id: string;
14
+ label: string;
15
+ items: {
16
+ id: string;
17
+ label: string;
18
+ disabled: boolean;
19
+ }[];
20
+ }[];
@@ -0,0 +1,25 @@
1
+ /** Presentation-only model menu projection shared by local clients. No sorting or deduplication. */
2
+ export function modelMenuChannelName(name, model, authMethod, isZh) {
3
+ const trimmed = name?.trim();
4
+ if (authMethod === 'oauth_chatgpt' && (!trimmed || trimmed === 'ChatGPT 订阅' || trimmed === 'ChatGPT Subscription')) {
5
+ return isZh ? 'ChatGPT 订阅' : 'ChatGPT Subscription';
6
+ }
7
+ return trimmed || model;
8
+ }
9
+ export function buildModelMenuGroups(rows, hideDisabled = false) {
10
+ const groups = new Map();
11
+ for (const row of rows) {
12
+ const key = row.groupId || row.id;
13
+ let group = groups.get(key);
14
+ if (!group) {
15
+ group = { id: key, label: row.groupLabel, items: [] };
16
+ groups.set(key, group);
17
+ }
18
+ if (!hideDisabled || row.available) {
19
+ group.items.push({ id: row.id, label: row.modelLabel || row.model, disabled: !row.available });
20
+ }
21
+ }
22
+ return [...groups.values()]
23
+ .filter((group) => !hideDisabled || group.items.length > 0)
24
+ .map((group) => ({ ...group, disabled: group.items.every((item) => item.disabled) }));
25
+ }
@@ -0,0 +1,73 @@
1
+ /** UTF-16 offsets into the persisted message content; code-point length is limited by the host. */
2
+ export interface SelectionRange {
3
+ readonly conversationId: string;
4
+ readonly messageId: string;
5
+ readonly blockId: 'content';
6
+ readonly revision: number;
7
+ readonly start: number;
8
+ readonly end: number;
9
+ readonly exactText: string;
10
+ readonly sourceTextHash: string;
11
+ }
12
+ export interface SelectionReference {
13
+ readonly schemaVersion: 1;
14
+ readonly id: string;
15
+ readonly sourceConversationId: string;
16
+ readonly sourceMessageId: string;
17
+ readonly blockId: string;
18
+ readonly sourceRevision: number;
19
+ readonly sourceRole: 'user' | 'assistant';
20
+ readonly start: number;
21
+ readonly end: number;
22
+ readonly exactText: string;
23
+ readonly textHash: string;
24
+ readonly sourceTextHash: string;
25
+ }
26
+ export interface SelectionDraft {
27
+ readonly text: string;
28
+ readonly references: readonly SelectionReference[];
29
+ }
30
+ export interface SelectionOrigin {
31
+ readonly schemaVersion: 1;
32
+ readonly parentConversationId: string;
33
+ readonly reference: SelectionReference;
34
+ readonly snapshotId: string;
35
+ readonly createdAt: string;
36
+ }
37
+ export interface SelectionChildSession {
38
+ readonly id: string;
39
+ readonly title: string;
40
+ readonly contentRevision: number;
41
+ readonly selectionOrigin: SelectionOrigin;
42
+ readonly selectionDraft: SelectionDraft;
43
+ }
44
+ export interface SelectionChildSummary {
45
+ readonly id: string;
46
+ readonly title: string;
47
+ readonly sourceReference: SelectionReference;
48
+ readonly lifecycle: 'draft' | 'active' | 'archived';
49
+ readonly runState: 'idle' | 'running' | 'error' | 'unknown';
50
+ readonly contentRevision: number;
51
+ readonly createdAt: string;
52
+ readonly updatedAt: string;
53
+ readonly hasDraft: boolean;
54
+ }
55
+ export interface SelectionChildrenPage {
56
+ readonly items: readonly SelectionChildSummary[];
57
+ readonly total: number;
58
+ readonly nextOffset: number | null;
59
+ }
60
+ export interface SelectionChildRead {
61
+ readonly childId: string;
62
+ readonly contentRevision: number;
63
+ readonly messages: readonly {
64
+ id: string;
65
+ role: 'user' | 'assistant';
66
+ content: string;
67
+ contentTruncated?: boolean;
68
+ }[];
69
+ readonly truncated: boolean;
70
+ readonly characterCount: number;
71
+ readonly readAt: string;
72
+ readonly runState: SelectionChildSummary['runState'];
73
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -106,8 +106,9 @@ export interface SkillHubInstallRequest {
106
106
  readonly namespace: string;
107
107
  readonly slug: string;
108
108
  readonly version: string;
109
- /** 默认 global;workspace 需已打开工作区。 */
109
+ /** 默认 global;workspace 必须同时指定一个由 Desktop 主进程校验的登记工作区。 */
110
110
  readonly scope?: SkillHubInstallScope;
111
+ readonly workspacePath?: string;
111
112
  /** 市场图标 URL;安装时写入本地 _meta.json,供已安装列表展示。 */
112
113
  readonly iconUrl?: string | null;
113
114
  }
@@ -204,6 +205,7 @@ export type QoderInstallScope = 'global' | 'workspace';
204
205
  export interface QoderInstallIdentity {
205
206
  readonly skillId: string;
206
207
  readonly scope?: QoderInstallScope;
208
+ readonly workspacePath?: string;
207
209
  readonly iconUrl?: string | null;
208
210
  }
209
211
  export interface QoderInstallResult {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/protocol",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",