@peer-agent/protocol 0.0.1-beta.43 → 0.0.1-beta.45

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.
@@ -18,6 +18,17 @@ export interface ConversationCompactionMarker {
18
18
  readonly summary: string;
19
19
  /** 近期关键决策锚点(可为空数组)。 */
20
20
  readonly decisionAnchors: readonly string[];
21
+ /** Canonical checkpoint schema version. Legacy markers omit this field. */
22
+ readonly checkpointVersion?: number;
23
+ /** Final-request-derived budget used to compile this marker. */
24
+ readonly budgetSnapshot?: Readonly<Record<string, unknown>> | null;
25
+ /**
26
+ * Versioned structured checkpoint compiled by the Context Compiler.
27
+ * Narrative summary is a rendering of this object, not the sole continuity truth.
28
+ */
29
+ readonly canonicalCheckpoint?: Readonly<Record<string, unknown>> | null;
30
+ /** Recoverable cold-history refs extracted from compacted content. */
31
+ readonly coldHistoryRefs?: readonly string[] | null;
21
32
  }
22
33
  /**
23
34
  * 两端唯一的 `_compaction` marker 构造器。
@@ -34,4 +45,8 @@ export declare function buildCompactionMarker(input: {
34
45
  readonly afterTokens?: number | null;
35
46
  readonly summary?: string | null;
36
47
  readonly decisionAnchors?: readonly string[] | null;
48
+ readonly checkpointVersion?: number | null;
49
+ readonly budgetSnapshot?: Readonly<Record<string, unknown>> | null;
50
+ readonly canonicalCheckpoint?: Readonly<Record<string, unknown>> | null;
51
+ readonly coldHistoryRefs?: readonly string[] | null;
37
52
  }): ConversationCompactionMarker;
@@ -36,5 +36,19 @@ export function buildCompactionMarker(input) {
36
36
  decisionAnchors: Array.isArray(input.decisionAnchors)
37
37
  ? input.decisionAnchors.filter((anchor) => typeof anchor === 'string' && anchor.length > 0)
38
38
  : [],
39
+ ...(Number.isFinite(input.checkpointVersion) && Number(input.checkpointVersion) > 0
40
+ ? { checkpointVersion: Math.floor(Number(input.checkpointVersion)) }
41
+ : {}),
42
+ ...(input.budgetSnapshot && typeof input.budgetSnapshot === 'object'
43
+ ? { budgetSnapshot: { ...input.budgetSnapshot } }
44
+ : {}),
45
+ ...(input.canonicalCheckpoint && typeof input.canonicalCheckpoint === 'object'
46
+ ? { canonicalCheckpoint: { ...input.canonicalCheckpoint } }
47
+ : {}),
48
+ ...(Array.isArray(input.coldHistoryRefs)
49
+ ? {
50
+ coldHistoryRefs: input.coldHistoryRefs.filter((ref) => typeof ref === 'string' && ref.trim().length > 0),
51
+ }
52
+ : {}),
39
53
  };
40
54
  }
package/dist/goal.d.ts CHANGED
@@ -119,6 +119,45 @@ export interface GoalProgress {
119
119
  /** 0–100 */
120
120
  readonly percent: number;
121
121
  }
122
+ /**
123
+ * Goal 运行时间账本。
124
+ *
125
+ * 由 store 在 plan 状态迁移时维护(不可手填):
126
+ * - active:runner 真正在跑的时间累计(pause / waiting_user / 人在回路 blocked 停表)
127
+ * - wallClock:首次开始执行到终态的日历跨度(含等待)
128
+ * 终态落盘 activeMs / wallClockMs,reload 不依赖重算。
129
+ */
130
+ export interface GoalTiming {
131
+ /** 首次进入 executing / runner 真正开跑;resume 不重置。 */
132
+ readonly startedAt?: string;
133
+ /** 进入终态 completed | failed | cancelled。 */
134
+ readonly completedAt?: string;
135
+ /**
136
+ * 已累计的有效运行毫秒(不含当前未闭合 segment)。
137
+ * pause / blocked(等人) / waiting_user / 终态时结算进账。
138
+ */
139
+ readonly activeAccumulatedMs: number;
140
+ /** 当前有效 segment 起点;runner 在跑时有值,暂停/终态时清空。 */
141
+ readonly activeSegmentStartedAt?: string;
142
+ /** 终态墙钟毫秒:completedAt - startedAt。 */
143
+ readonly wallClockMs?: number;
144
+ /** 终态有效运行毫秒(含终态时未闭合 segment 的结算)。 */
145
+ readonly activeMs?: number;
146
+ }
147
+ /** 投影后的 live / 终态口径,UI 只消费此结构。 */
148
+ export interface ProjectedGoalTiming {
149
+ readonly startedAt?: string;
150
+ readonly completedAt?: string;
151
+ readonly wallClockMs?: number;
152
+ readonly activeMs?: number;
153
+ readonly isLive: boolean;
154
+ }
155
+ /**
156
+ * 统一 live 与终态用时口径。
157
+ * - 终态优先使用落盘 activeMs / wallClockMs
158
+ * - 进行中:active = accumulated + open segment;wall = now - startedAt
159
+ */
160
+ export declare function projectGoalTiming(timing: GoalTiming | null | undefined, nowMs?: number): ProjectedGoalTiming | null;
122
161
  /** 修订记录(来自 reject/revise 的 feedback)。 */
123
162
  export interface GoalRevision {
124
163
  readonly version: number;
@@ -127,7 +166,7 @@ export interface GoalRevision {
127
166
  readonly changedBy?: string;
128
167
  }
129
168
  /** Goal Runner 托管推进器状态。 */
130
- export type GoalRunnerStatus = 'idle' | 'running' | 'paused' | 'exploring' | 'blocked' | 'budget_exhausted' | 'completed' | 'failed';
169
+ export type GoalRunnerStatus = 'idle' | 'running' | 'compacting_context' | 'resuming_after_compaction' | 'paused' | 'exploring' | 'blocked' | 'budget_exhausted' | 'completed' | 'failed';
131
170
  /** Goal Runner 当前推进意图;只描述编排意图,不替代工具执行 Evidence。 */
132
171
  export type GoalRunnerIntent = 'execute' | 'verify' | 'explore' | 'synthesize' | 'block';
133
172
  export type GoalRunnerPhase = 'orient' | 'inspect' | 'plan_scaffold' | 'act' | 'verify' | 'repair' | 'synthesize' | 'blocked';
@@ -292,6 +331,101 @@ export interface GoalManualConfirmation {
292
331
  readonly decidedAt: string;
293
332
  readonly feedback?: string;
294
333
  }
334
+ /**
335
+ * Goal 执行检查点:跨 compaction 的权威“下一动作”真源。
336
+ * 聊天摘要只能解释,不能替代此结构;任务完成仍必须由 Evidence 回写。
337
+ * 详见 peer-knowledge/knowledge/architecture/24-goal-runner-context-checkpoint-and-seamless-resume.md
338
+ */
339
+ export type GoalCheckpointStatus = 'preparing' | 'committed' | 'consumed' | 'superseded' | 'invalid';
340
+ export type GoalCheckpointReason = 'soft_threshold' | 'hard_threshold' | 'provider_overflow' | 'task_boundary' | 'manual_compact' | 'process_recovery';
341
+ export type GoalResumePolicy = 'continue_same_turn' | 'start_recovery_turn' | 'verify_then_continue' | 'wait_for_user';
342
+ export interface GoalCheckpointProgress {
343
+ readonly total: number;
344
+ readonly completed: number;
345
+ readonly failed: number;
346
+ readonly blocked: number;
347
+ readonly percent: number;
348
+ readonly nextRunnableTaskIds: readonly string[];
349
+ }
350
+ export interface GoalCheckpointAction {
351
+ readonly actionId: string;
352
+ readonly kind: 'inspect' | 'edit' | 'write' | 'tool' | 'test' | 'verify' | 'decision';
353
+ readonly summary: string;
354
+ readonly status: 'completed' | 'failed' | 'running' | 'unknown';
355
+ readonly target?: string;
356
+ readonly evidenceRefs: readonly string[];
357
+ readonly result?: string;
358
+ readonly occurredAt?: string;
359
+ }
360
+ export interface GoalCheckpointToolCall {
361
+ readonly toolCallId: string;
362
+ readonly toolName?: string;
363
+ readonly status: 'requested' | 'running' | 'completed' | 'failed' | 'unknown';
364
+ readonly resultEvidenceRefs: readonly string[];
365
+ readonly replayPolicy: 'never' | 'query_status' | 'safe_retry' | 'ask_user';
366
+ readonly idempotencyKey?: string;
367
+ }
368
+ export interface GoalCheckpointFirstAction {
369
+ readonly kind: 'tool' | 'inspect' | 'edit' | 'verify' | 'synthesize' | 'wait_user';
370
+ readonly instruction: string;
371
+ readonly target?: string;
372
+ readonly successCheck: string;
373
+ readonly requiredEvidenceRefs: readonly string[];
374
+ readonly forbiddenUntilComplete?: readonly string[];
375
+ }
376
+ export interface GoalCheckpointBudgetSnapshot {
377
+ readonly contextWindow: number | null;
378
+ readonly beforeTokens: number;
379
+ readonly targetTokens: number;
380
+ readonly systemTokens: number;
381
+ readonly toolsTokens: number;
382
+ readonly checkpointTokens: number;
383
+ readonly continuityTokens: number;
384
+ readonly recentTailTokens: number;
385
+ readonly keepBudgetTokens: number;
386
+ readonly compactionCount: number;
387
+ }
388
+ export interface GoalExecutionCheckpoint {
389
+ readonly schemaVersion: 1;
390
+ readonly checkpointId: string;
391
+ readonly compactionId: string;
392
+ readonly sequence: number;
393
+ readonly status: GoalCheckpointStatus;
394
+ readonly reason: GoalCheckpointReason;
395
+ readonly planId: string;
396
+ readonly planVersion: number;
397
+ readonly runId: string;
398
+ readonly conversationId?: string;
399
+ readonly streamId?: string;
400
+ readonly contextEpochId?: string;
401
+ readonly conversationRevision?: string;
402
+ readonly currentTaskId?: string;
403
+ readonly runnerPhase?: GoalRunnerPhase;
404
+ readonly runnerIntent?: GoalRunnerIntent;
405
+ readonly progress: GoalCheckpointProgress;
406
+ readonly objectiveNow: string;
407
+ readonly currentWork: string;
408
+ readonly recentActions: readonly GoalCheckpointAction[];
409
+ readonly completedSincePrevious: readonly string[];
410
+ readonly mostImportantFact: string;
411
+ readonly decisions: readonly string[];
412
+ readonly blockers: readonly string[];
413
+ readonly risks: readonly string[];
414
+ readonly openQuestions: readonly string[];
415
+ readonly pendingVerifications: readonly string[];
416
+ readonly doNotRepeat: readonly string[];
417
+ readonly handoffNote: string;
418
+ readonly firstAction: GoalCheckpointFirstAction;
419
+ readonly evidenceRefs: readonly string[];
420
+ readonly mustReadEvidenceRefs: readonly string[];
421
+ readonly openToolCalls: readonly GoalCheckpointToolCall[];
422
+ readonly budget: GoalCheckpointBudgetSnapshot;
423
+ readonly resumePolicy: GoalResumePolicy;
424
+ readonly createdAt: string;
425
+ readonly committedAt?: string;
426
+ readonly consumedAt?: string;
427
+ readonly digest: string;
428
+ }
295
429
  /** GoalPlan 内嵌的轻量 runner 状态;不代表工具执行事实,任务完成仍必须由 Evidence 回写。 */
296
430
  export interface GoalRunnerState {
297
431
  readonly enabled: boolean;
@@ -299,6 +433,17 @@ export interface GoalRunnerState {
299
433
  readonly intent?: GoalRunnerIntent;
300
434
  readonly phase?: GoalRunnerPhase;
301
435
  readonly currentTaskId?: string;
436
+ /**
437
+ * 一次逻辑自驱执行的持久化身份;跨 compaction / stream retry 不变。
438
+ * 仅在创建新 Goal 或显式重新运行终态 Goal 时生成新值。
439
+ */
440
+ readonly runId?: string;
441
+ /** 当前已提交、待消费的执行检查点;prompt 只注入这一份。 */
442
+ readonly contextCheckpoint?: GoalExecutionCheckpoint;
443
+ readonly lastConsumedCheckpointId?: string;
444
+ readonly lastConsumedCheckpointSequence?: number;
445
+ readonly compactionCount?: number;
446
+ readonly lastCompactionAt?: string;
302
447
  /** 预算计数:Runner tick 次数,用于 maxTurns 熔断判定。 */
303
448
  readonly turnCount: number;
304
449
  /** 展示计数:模型内部对话轮次,随执行实时爬升;与 turnCount(预算)解耦,仅用于 UI 呈现。 */
@@ -363,6 +508,11 @@ export interface GoalPlan {
363
508
  readonly approval?: GoalApproval;
364
509
  /** 由子任务聚合,派生,不可手填 */
365
510
  readonly progress: GoalProgress;
511
+ /**
512
+ * 运行时间账本;由 store 在状态迁移时维护,旧计划可缺省。
513
+ * UI 请用 projectGoalTiming 统一 live / 终态口径。
514
+ */
515
+ readonly timing?: GoalTiming;
366
516
  /** Goal Runner 托管推进状态;旧计划可缺省。 */
367
517
  readonly runner?: GoalRunnerState;
368
518
  /** Execution/event ledger used by the Goal / Plan / Run right-panel projection. */
package/dist/goal.js CHANGED
@@ -1 +1,69 @@
1
- export {};
1
+ /**
2
+ * 统一 live 与终态用时口径。
3
+ * - 终态优先使用落盘 activeMs / wallClockMs
4
+ * - 进行中:active = accumulated + open segment;wall = now - startedAt
5
+ */
6
+ export function projectGoalTiming(timing, nowMs = Date.now()) {
7
+ if (!timing || typeof timing !== 'object')
8
+ return null;
9
+ const startedAt = typeof timing.startedAt === 'string' && timing.startedAt.trim()
10
+ ? timing.startedAt.trim()
11
+ : undefined;
12
+ if (!startedAt)
13
+ return null;
14
+ const completedAt = typeof timing.completedAt === 'string' && timing.completedAt.trim()
15
+ ? timing.completedAt.trim()
16
+ : undefined;
17
+ const accumulated = Number.isFinite(timing.activeAccumulatedMs)
18
+ ? Math.max(0, Math.floor(timing.activeAccumulatedMs))
19
+ : 0;
20
+ const segmentStart = typeof timing.activeSegmentStartedAt === 'string'
21
+ && timing.activeSegmentStartedAt.trim()
22
+ ? timing.activeSegmentStartedAt.trim()
23
+ : undefined;
24
+ if (completedAt) {
25
+ const startedMs = Date.parse(startedAt);
26
+ const completedMs = Date.parse(completedAt);
27
+ const wallFromMarks = Number.isFinite(startedMs) && Number.isFinite(completedMs)
28
+ ? Math.max(0, completedMs - startedMs)
29
+ : undefined;
30
+ const activeFromMarks = (() => {
31
+ if (typeof timing.activeMs === 'number' && Number.isFinite(timing.activeMs)) {
32
+ return Math.max(0, Math.floor(timing.activeMs));
33
+ }
34
+ let active = accumulated;
35
+ if (segmentStart) {
36
+ const seg = Date.parse(segmentStart);
37
+ if (Number.isFinite(seg) && Number.isFinite(completedMs)) {
38
+ active += Math.max(0, completedMs - seg);
39
+ }
40
+ }
41
+ return active;
42
+ })();
43
+ return {
44
+ startedAt,
45
+ completedAt,
46
+ wallClockMs: typeof timing.wallClockMs === 'number' && Number.isFinite(timing.wallClockMs)
47
+ ? Math.max(0, Math.floor(timing.wallClockMs))
48
+ : wallFromMarks,
49
+ activeMs: activeFromMarks,
50
+ isLive: false,
51
+ };
52
+ }
53
+ const startedMs = Date.parse(startedAt);
54
+ let activeMs = accumulated;
55
+ if (segmentStart) {
56
+ const seg = Date.parse(segmentStart);
57
+ if (Number.isFinite(seg))
58
+ activeMs += Math.max(0, nowMs - seg);
59
+ }
60
+ const wallClockMs = Number.isFinite(startedMs)
61
+ ? Math.max(0, nowMs - startedMs)
62
+ : undefined;
63
+ return {
64
+ startedAt,
65
+ wallClockMs,
66
+ activeMs,
67
+ isLive: true,
68
+ };
69
+ }
package/dist/index.d.ts CHANGED
@@ -47,13 +47,24 @@ export interface CapabilityManifest {
47
47
  */
48
48
  readonly providerLabel?: string;
49
49
  }
50
+ export type SkillScope = 'global' | 'workspace';
50
51
  export interface SkillSummary {
51
52
  readonly skillId: string;
52
53
  readonly name: string;
53
54
  readonly description: string;
55
+ /** Layer 2 清单 reminder 的发现性提示;可为空字符串。 */
56
+ readonly whenToUse: string;
54
57
  readonly version: string;
55
58
  readonly dataLevel: DataLevel;
56
59
  readonly enabled: boolean;
60
+ /** Skill 的安装范围;workspace Skill 只属于对应工作空间。 */
61
+ readonly scope: SkillScope;
62
+ /** scope=workspace 时对应的工作空间绝对路径。 */
63
+ readonly workspacePath?: string | null;
64
+ }
65
+ export interface SkillDetail extends SkillSummary {
66
+ readonly instructions: string;
67
+ readonly sourcePath: string;
57
68
  }
58
69
  /**
59
70
  * 可从外部「借用来源」(如 a1 公共 skill 仓 ~/.agents/skills)借用的技能条目。
@@ -337,7 +348,7 @@ export interface LlmSubscriptionQuotaWindow {
337
348
  readonly resetsAt?: string;
338
349
  }
339
350
  /**
340
- * GPT / Gemini / Grok 订阅额度快照。
351
+ * GPT / Gemini / Grok / Qoder 订阅额度快照。
341
352
  * success=false 时用 status/error 表达未登录、过期或拉取失败,UI 应降级展示。
342
353
  */
343
354
  export interface LlmSubscriptionQuota {
@@ -345,7 +356,7 @@ export interface LlmSubscriptionQuota {
345
356
  readonly status?: string;
346
357
  readonly providerId?: string;
347
358
  readonly authMethod?: LlmAuthMethod;
348
- readonly provider?: 'chatgpt' | 'gemini' | 'grok' | string;
359
+ readonly provider?: 'chatgpt' | 'gemini' | 'grok' | 'qoder' | string;
349
360
  readonly planLabel?: string;
350
361
  readonly remainingPercent?: number;
351
362
  readonly usedPercent?: number;
@@ -356,6 +367,11 @@ export interface LlmSubscriptionQuota {
356
367
  readonly fetchedAt?: string;
357
368
  readonly cached?: boolean;
358
369
  readonly error?: string;
370
+ readonly availableCredits?: number;
371
+ readonly planCreditsUsed?: number;
372
+ readonly planCreditsTotal?: number;
373
+ readonly orgPackageUsed?: number;
374
+ readonly orgPackageCap?: number;
359
375
  }
360
376
  export interface LlmProviderConfig {
361
377
  readonly id: string;
@@ -491,6 +507,8 @@ export interface LlmModelInfo {
491
507
  readonly longContextInputPrice?: number;
492
508
  readonly longContextCacheReadPrice?: number;
493
509
  readonly longContextOutputPrice?: number;
510
+ readonly priceFactor?: number;
511
+ readonly originalPriceFactor?: number;
494
512
  }
495
513
  export interface LlmModelListResult {
496
514
  readonly success: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/protocol",
3
- "version": "0.0.1-beta.43",
3
+ "version": "0.0.1-beta.45",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,12 +10,12 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/yinLiangDream/Peer-Agent.git",
13
+ "url": "git+https://github.com/ly-ccx/Peer-Agent.git",
14
14
  "directory": "packages/protocol"
15
15
  },
16
- "homepage": "https://github.com/yinLiangDream/Peer-Agent#readme",
16
+ "homepage": "https://github.com/ly-ccx/Peer-Agent#readme",
17
17
  "bugs": {
18
- "url": "https://github.com/yinLiangDream/Peer-Agent/issues"
18
+ "url": "https://github.com/ly-ccx/Peer-Agent/issues"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public"