@peer-agent/protocol 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acceptance-basis.d.ts +26 -0
- package/dist/acceptance-basis.js +36 -0
- package/dist/acceptance-close-gate.d.ts +49 -0
- package/dist/acceptance-close-gate.js +117 -0
- package/dist/context-accounting.d.ts +24 -0
- package/dist/context-accounting.js +56 -0
- package/dist/goal.d.ts +1 -1
- package/dist/goal.js +9 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/system-context.d.ts +5 -0
- package/dist/task-overview.d.ts +18 -0
- package/dist/task-overview.js +65 -2
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GoalPlan } from './goal.ts';
|
|
2
|
+
export type AcceptanceBasisKind = 'grant' | 'tool' | 'artifact' | 'denial';
|
|
3
|
+
export interface AcceptanceBasisEvent {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly kind: AcceptanceBasisKind;
|
|
6
|
+
readonly at?: string;
|
|
7
|
+
readonly title: string;
|
|
8
|
+
readonly detail?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AuthorizationSummary {
|
|
11
|
+
readonly planApproved: boolean;
|
|
12
|
+
readonly approvedAt?: string;
|
|
13
|
+
readonly toolCount: number;
|
|
14
|
+
readonly artifactCount: number;
|
|
15
|
+
readonly denialCount: number;
|
|
16
|
+
}
|
|
17
|
+
export interface AcceptanceBasisProjection {
|
|
18
|
+
readonly events: readonly AcceptanceBasisEvent[];
|
|
19
|
+
readonly authorization: AuthorizationSummary;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 导出用授权摘要:计划是否已批准、持有多少已承认产物。
|
|
23
|
+
* 不投影 runTrace,验收页也不再消费这段时间线。
|
|
24
|
+
*/
|
|
25
|
+
export declare function projectAcceptanceBasis(plan: GoalPlan | null | undefined): AcceptanceBasisProjection;
|
|
26
|
+
export declare function formatAuthorizationSummary(summary: AuthorizationSummary, isZh?: boolean): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { collectHeldEvidenceRefs } from "./acceptance-close-gate.js";
|
|
2
|
+
function trimText(value) {
|
|
3
|
+
if (typeof value !== 'string')
|
|
4
|
+
return null;
|
|
5
|
+
const trimmed = value.trim();
|
|
6
|
+
return trimmed || null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 导出用授权摘要:计划是否已批准、持有多少已承认产物。
|
|
10
|
+
* 不投影 runTrace,验收页也不再消费这段时间线。
|
|
11
|
+
*/
|
|
12
|
+
export function projectAcceptanceBasis(plan) {
|
|
13
|
+
const approval = plan?.approval;
|
|
14
|
+
const approved = approval?.decision === 'approve';
|
|
15
|
+
const approvedAt = trimText(approval?.decidedAt) ?? undefined;
|
|
16
|
+
const artifactCount = collectHeldEvidenceRefs(plan).length;
|
|
17
|
+
return {
|
|
18
|
+
events: [],
|
|
19
|
+
authorization: {
|
|
20
|
+
planApproved: approved,
|
|
21
|
+
approvedAt,
|
|
22
|
+
toolCount: 0,
|
|
23
|
+
artifactCount,
|
|
24
|
+
denialCount: 0,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function formatAuthorizationSummary(summary, isZh = true) {
|
|
29
|
+
const bits = [];
|
|
30
|
+
if (summary.planApproved)
|
|
31
|
+
bits.push(isZh ? '计划已批准' : 'Plan approved');
|
|
32
|
+
if (summary.artifactCount > 0) {
|
|
33
|
+
bits.push(isZh ? `${summary.artifactCount} 份产物` : `${summary.artifactCount} artifacts`);
|
|
34
|
+
}
|
|
35
|
+
return bits.join(' · ');
|
|
36
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { GoalCriterionResult, GoalManualConfirmation, GoalSuccessCriterion } from './goal.ts';
|
|
2
|
+
export declare const ACCEPTANCE_CLOSE_GATE_CODE = "acceptance_evidence_incomplete";
|
|
3
|
+
export type AcceptanceCloseGapReason = 'missing' | 'failed' | 'unresolved';
|
|
4
|
+
export interface AcceptanceCloseGap {
|
|
5
|
+
readonly criterionId: string;
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly reason: AcceptanceCloseGapReason;
|
|
8
|
+
}
|
|
9
|
+
export interface AcceptanceCloseVerdict {
|
|
10
|
+
readonly ok: boolean;
|
|
11
|
+
readonly gaps: readonly AcceptanceCloseGap[];
|
|
12
|
+
readonly message: string;
|
|
13
|
+
}
|
|
14
|
+
export interface AcceptanceCloseTaskLike {
|
|
15
|
+
readonly evidenceRefs?: readonly string[] | null;
|
|
16
|
+
readonly subtasks?: readonly AcceptanceCloseTaskLike[] | null;
|
|
17
|
+
}
|
|
18
|
+
export interface AcceptanceClosePlanLike {
|
|
19
|
+
readonly successCriteria?: readonly GoalSuccessCriterion[] | null;
|
|
20
|
+
readonly criterionResults?: readonly GoalCriterionResult[] | null;
|
|
21
|
+
readonly manualConfirmations?: readonly GoalManualConfirmation[] | null;
|
|
22
|
+
readonly evidenceRefs?: readonly string[] | null;
|
|
23
|
+
readonly tasks?: readonly AcceptanceCloseTaskLike[] | null;
|
|
24
|
+
readonly runTrace?: {
|
|
25
|
+
readonly events?: readonly {
|
|
26
|
+
readonly evidenceRefs?: readonly string[] | null;
|
|
27
|
+
}[] | null;
|
|
28
|
+
} | null;
|
|
29
|
+
}
|
|
30
|
+
export declare class AcceptanceCloseGateError extends Error {
|
|
31
|
+
readonly code = "acceptance_evidence_incomplete";
|
|
32
|
+
readonly gaps: readonly AcceptanceCloseGap[];
|
|
33
|
+
constructor(message: string, gaps?: readonly AcceptanceCloseGap[]);
|
|
34
|
+
}
|
|
35
|
+
/** 计划上已经持有的证据引用。不算 criterionResults 里的自称。 */
|
|
36
|
+
export declare function collectHeldEvidenceRefs(plan: AcceptanceClosePlanLike | null | undefined): readonly string[];
|
|
37
|
+
export declare function evaluateAcceptanceCloseGate(plan: AcceptanceClosePlanLike | null | undefined, options?: {
|
|
38
|
+
readonly knownRefs?: readonly string[] | null;
|
|
39
|
+
readonly locale?: 'zh' | 'en';
|
|
40
|
+
}): AcceptanceCloseVerdict;
|
|
41
|
+
export declare function assertAcceptanceCloseGate(plan: AcceptanceClosePlanLike | null | undefined, options?: {
|
|
42
|
+
readonly knownRefs?: readonly string[] | null;
|
|
43
|
+
readonly locale?: 'zh' | 'en';
|
|
44
|
+
}): void;
|
|
45
|
+
export declare function isAcceptanceClosePatch(previous: {
|
|
46
|
+
readonly acceptedAt?: string | null;
|
|
47
|
+
} | null | undefined, next: {
|
|
48
|
+
readonly acceptedAt?: string | null;
|
|
49
|
+
} | null | undefined): boolean;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const AUTO_CRITERION_KINDS = new Set(['command', 'test', 'file-contains', 'file-exists']);
|
|
2
|
+
export const ACCEPTANCE_CLOSE_GATE_CODE = 'acceptance_evidence_incomplete';
|
|
3
|
+
export class AcceptanceCloseGateError extends Error {
|
|
4
|
+
code = ACCEPTANCE_CLOSE_GATE_CODE;
|
|
5
|
+
gaps;
|
|
6
|
+
constructor(message, gaps = []) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'AcceptanceCloseGateError';
|
|
9
|
+
this.gaps = gaps;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function trimRef(value) {
|
|
13
|
+
if (typeof value !== 'string')
|
|
14
|
+
return null;
|
|
15
|
+
const trimmed = value.trim();
|
|
16
|
+
return trimmed || null;
|
|
17
|
+
}
|
|
18
|
+
function walkTaskRefs(tasks, into) {
|
|
19
|
+
for (const task of tasks ?? []) {
|
|
20
|
+
for (const ref of task.evidenceRefs ?? []) {
|
|
21
|
+
const held = trimRef(ref);
|
|
22
|
+
if (held)
|
|
23
|
+
into.add(held);
|
|
24
|
+
}
|
|
25
|
+
walkTaskRefs(task.subtasks, into);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** 计划上已经持有的证据引用。不算 criterionResults 里的自称。 */
|
|
29
|
+
export function collectHeldEvidenceRefs(plan) {
|
|
30
|
+
const refs = new Set();
|
|
31
|
+
for (const ref of plan?.evidenceRefs ?? []) {
|
|
32
|
+
const held = trimRef(ref);
|
|
33
|
+
if (held)
|
|
34
|
+
refs.add(held);
|
|
35
|
+
}
|
|
36
|
+
walkTaskRefs(plan?.tasks, refs);
|
|
37
|
+
for (const event of plan?.runTrace?.events ?? []) {
|
|
38
|
+
for (const ref of event.evidenceRefs ?? []) {
|
|
39
|
+
const held = trimRef(ref);
|
|
40
|
+
if (held)
|
|
41
|
+
refs.add(held);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [...refs];
|
|
45
|
+
}
|
|
46
|
+
function latestManualApproval(plan, criterionId) {
|
|
47
|
+
const matches = (plan.manualConfirmations ?? [])
|
|
48
|
+
.filter((confirmation) => confirmation.kind === 'manual_dod')
|
|
49
|
+
.filter((confirmation) => confirmation.criterionIds.includes(criterionId))
|
|
50
|
+
.slice()
|
|
51
|
+
.sort((left, right) => String(right.decidedAt || '').localeCompare(String(left.decidedAt || '')));
|
|
52
|
+
return matches[0]?.decision === 'approve';
|
|
53
|
+
}
|
|
54
|
+
function gapMessage(gaps, locale) {
|
|
55
|
+
if (gaps.length === 0)
|
|
56
|
+
return '';
|
|
57
|
+
if (locale === 'en') {
|
|
58
|
+
return gaps.length === 1
|
|
59
|
+
? `Cannot accept yet: ${gaps[0].description} still lacks resolvable evidence.`
|
|
60
|
+
: `Cannot accept yet: ${gaps.length} success criteria still lack resolvable evidence.`;
|
|
61
|
+
}
|
|
62
|
+
return gaps.length === 1
|
|
63
|
+
? `还不能验收:${gaps[0].description} 还缺可解析的对照证据。`
|
|
64
|
+
: `还不能验收:还有 ${gaps.length} 条成功标准缺少可解析的对照证据。`;
|
|
65
|
+
}
|
|
66
|
+
export function evaluateAcceptanceCloseGate(plan, options = {}) {
|
|
67
|
+
const locale = options.locale === 'en' ? 'en' : 'zh';
|
|
68
|
+
const criteria = plan?.successCriteria ?? [];
|
|
69
|
+
if (criteria.length === 0) {
|
|
70
|
+
return { ok: true, gaps: [], message: '' };
|
|
71
|
+
}
|
|
72
|
+
const known = new Set((options.knownRefs ?? collectHeldEvidenceRefs(plan))
|
|
73
|
+
.map((ref) => trimRef(ref))
|
|
74
|
+
.filter((ref) => Boolean(ref)));
|
|
75
|
+
const results = new Map((plan?.criterionResults ?? [])
|
|
76
|
+
.filter((result) => result?.criterionId)
|
|
77
|
+
.map((result) => [result.criterionId, result]));
|
|
78
|
+
const gaps = [];
|
|
79
|
+
for (const criterion of criteria) {
|
|
80
|
+
const id = criterion.id?.trim();
|
|
81
|
+
if (!id)
|
|
82
|
+
continue;
|
|
83
|
+
const description = criterion.description?.trim() || id;
|
|
84
|
+
const isAuto = AUTO_CRITERION_KINDS.has(criterion.kind);
|
|
85
|
+
const result = results.get(id) ?? null;
|
|
86
|
+
if (!isAuto && latestManualApproval(plan ?? {}, id))
|
|
87
|
+
continue;
|
|
88
|
+
if (!result) {
|
|
89
|
+
gaps.push({ criterionId: id, description, reason: 'missing' });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!result.passed) {
|
|
93
|
+
gaps.push({ criterionId: id, description, reason: 'failed' });
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const evidenceRef = trimRef(result.evidenceRef);
|
|
97
|
+
if (!evidenceRef || !known.has(evidenceRef)) {
|
|
98
|
+
gaps.push({ criterionId: id, description, reason: 'unresolved' });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
ok: gaps.length === 0,
|
|
103
|
+
gaps,
|
|
104
|
+
message: gapMessage(gaps, locale),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export function assertAcceptanceCloseGate(plan, options = {}) {
|
|
108
|
+
const verdict = evaluateAcceptanceCloseGate(plan, options);
|
|
109
|
+
if (!verdict.ok) {
|
|
110
|
+
throw new AcceptanceCloseGateError(verdict.message, verdict.gaps);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export function isAcceptanceClosePatch(previous, next) {
|
|
114
|
+
const prevAt = typeof previous?.acceptedAt === 'string' ? previous.acceptedAt.trim() : '';
|
|
115
|
+
const nextAt = typeof next?.acceptedAt === 'string' ? next.acceptedAt.trim() : '';
|
|
116
|
+
return nextAt.length > 0 && nextAt !== prevAt;
|
|
117
|
+
}
|
|
@@ -50,6 +50,28 @@ export interface ContextCountVerification {
|
|
|
50
50
|
readonly status: 'verified' | 'drift';
|
|
51
51
|
readonly verifiedAt: number;
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Presentation composition of the last built provider request.
|
|
55
|
+
*
|
|
56
|
+
* Occupancy authority stays on `authoritativeInputTokens` / `percent`.
|
|
57
|
+
* This breakdown never invents a percentage; hosts may scale category
|
|
58
|
+
* estimates so they sum to the authoritative total.
|
|
59
|
+
*/
|
|
60
|
+
export declare const CONTEXT_USAGE_CATEGORY_IDS: readonly ["system_prompt", "tool_definitions", "rules", "skills", "mcp_tools", "subagents", "summarized_conversation", "conversation"];
|
|
61
|
+
export type ContextUsageCategoryId = (typeof CONTEXT_USAGE_CATEGORY_IDS)[number];
|
|
62
|
+
export type ContextUsageBreakdownQuality = 'projected' | 'scaled';
|
|
63
|
+
export interface ContextUsageCategory {
|
|
64
|
+
readonly id: ContextUsageCategoryId;
|
|
65
|
+
readonly tokens: number;
|
|
66
|
+
}
|
|
67
|
+
export interface ContextUsageBreakdown {
|
|
68
|
+
readonly version: 1;
|
|
69
|
+
readonly quality: ContextUsageBreakdownQuality;
|
|
70
|
+
readonly categories: readonly ContextUsageCategory[];
|
|
71
|
+
readonly estimatedTokens: number;
|
|
72
|
+
}
|
|
73
|
+
/** Drop invalid persisted breakdowns instead of letting them become occupancy truth. */
|
|
74
|
+
export declare function normalizeContextUsageBreakdown(value: unknown): ContextUsageBreakdown | null;
|
|
53
75
|
/**
|
|
54
76
|
* The only cross-host context-capacity state.
|
|
55
77
|
*
|
|
@@ -81,4 +103,6 @@ export interface ContextAccountingSnapshot {
|
|
|
81
103
|
readonly nextCounted?: ContextAccountingCounted;
|
|
82
104
|
readonly lastOverflow?: ContextOverflowEvidence;
|
|
83
105
|
readonly verification?: ContextCountVerification;
|
|
106
|
+
/** Presentation-only request composition. Never occupancy authority. */
|
|
107
|
+
readonly usageBreakdown?: ContextUsageBreakdown;
|
|
84
108
|
}
|
|
@@ -19,3 +19,59 @@ export function contextAccountingModelKey(providerId, modelId) {
|
|
|
19
19
|
const resolvedModel = model || embeddedModel;
|
|
20
20
|
return resolvedModel ? `${baseProvider}::${resolvedModel}` : baseProvider;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Presentation composition of the last built provider request.
|
|
24
|
+
*
|
|
25
|
+
* Occupancy authority stays on `authoritativeInputTokens` / `percent`.
|
|
26
|
+
* This breakdown never invents a percentage; hosts may scale category
|
|
27
|
+
* estimates so they sum to the authoritative total.
|
|
28
|
+
*/
|
|
29
|
+
export const CONTEXT_USAGE_CATEGORY_IDS = [
|
|
30
|
+
'system_prompt',
|
|
31
|
+
'tool_definitions',
|
|
32
|
+
'rules',
|
|
33
|
+
'skills',
|
|
34
|
+
'mcp_tools',
|
|
35
|
+
'subagents',
|
|
36
|
+
'summarized_conversation',
|
|
37
|
+
'conversation',
|
|
38
|
+
];
|
|
39
|
+
const CONTEXT_USAGE_CATEGORY_ID_SET = new Set(CONTEXT_USAGE_CATEGORY_IDS);
|
|
40
|
+
function finitePositiveTokens(value) {
|
|
41
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0
|
|
42
|
+
? Math.floor(value)
|
|
43
|
+
: null;
|
|
44
|
+
}
|
|
45
|
+
/** Drop invalid persisted breakdowns instead of letting them become occupancy truth. */
|
|
46
|
+
export function normalizeContextUsageBreakdown(value) {
|
|
47
|
+
if (!value || typeof value !== 'object')
|
|
48
|
+
return null;
|
|
49
|
+
const record = value;
|
|
50
|
+
if (record.version !== 1)
|
|
51
|
+
return null;
|
|
52
|
+
if (record.quality !== 'projected' && record.quality !== 'scaled')
|
|
53
|
+
return null;
|
|
54
|
+
if (!Array.isArray(record.categories))
|
|
55
|
+
return null;
|
|
56
|
+
const categories = [];
|
|
57
|
+
for (const item of record.categories) {
|
|
58
|
+
if (!item || typeof item !== 'object')
|
|
59
|
+
continue;
|
|
60
|
+
const row = item;
|
|
61
|
+
if (typeof row.id !== 'string' || !CONTEXT_USAGE_CATEGORY_ID_SET.has(row.id))
|
|
62
|
+
continue;
|
|
63
|
+
const tokens = finitePositiveTokens(row.tokens);
|
|
64
|
+
if (tokens == null)
|
|
65
|
+
continue;
|
|
66
|
+
categories.push({ id: row.id, tokens });
|
|
67
|
+
}
|
|
68
|
+
const estimatedTokens = finitePositiveTokens(record.estimatedTokens);
|
|
69
|
+
if (categories.length === 0 || estimatedTokens == null)
|
|
70
|
+
return null;
|
|
71
|
+
return {
|
|
72
|
+
version: 1,
|
|
73
|
+
quality: record.quality,
|
|
74
|
+
categories,
|
|
75
|
+
estimatedTokens,
|
|
76
|
+
};
|
|
77
|
+
}
|
package/dist/goal.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare function formatGoalDeliveryRoute(input: {
|
|
|
56
56
|
readonly locale?: 'zh' | 'en';
|
|
57
57
|
}): string | undefined;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* 用户可见的交回状态。没交付线或没验收时不展示。
|
|
60
60
|
*/
|
|
61
61
|
export declare function formatGoalDeliveryHandoff(input: {
|
|
62
62
|
readonly deliveryHandoff?: GoalDeliveryHandoff | null;
|
package/dist/goal.js
CHANGED
|
@@ -17,6 +17,7 @@ export function formatGoalDeliveryRoute(input, options) {
|
|
|
17
17
|
const repoId = input.deliveryBinding?.repoId?.trim() || input.targetRepoId?.trim() || undefined;
|
|
18
18
|
const target = repoId || targetPath;
|
|
19
19
|
const branch = input.deliveryBinding?.targetBranch?.trim() || input.targetBranch?.trim() || undefined;
|
|
20
|
+
const taskBranch = input.deliveryBinding?.taskBranch?.trim() || undefined;
|
|
20
21
|
const isolation = input.deliveryBinding?.executionIsolation ?? input.executionIsolation;
|
|
21
22
|
const parts = [];
|
|
22
23
|
if (origin && target && origin !== target) {
|
|
@@ -28,7 +29,10 @@ export function formatGoalDeliveryRoute(input, options) {
|
|
|
28
29
|
else if (origin) {
|
|
29
30
|
parts.push(origin);
|
|
30
31
|
}
|
|
31
|
-
if (branch) {
|
|
32
|
+
if (taskBranch && branch) {
|
|
33
|
+
parts.push(`${taskBranch} · from ${branch}`);
|
|
34
|
+
}
|
|
35
|
+
else if (branch) {
|
|
32
36
|
parts.push(branch);
|
|
33
37
|
}
|
|
34
38
|
else if (target || origin) {
|
|
@@ -74,14 +78,16 @@ function handoffStoppedReasonLabel(reason, locale) {
|
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
77
|
-
*
|
|
81
|
+
* 用户可见的交回状态。没交付线或没验收时不展示。
|
|
78
82
|
*/
|
|
79
83
|
export function formatGoalDeliveryHandoff(input, options) {
|
|
80
84
|
const locale = options?.locale === 'en' ? 'en' : 'zh';
|
|
81
85
|
const acceptedAt = input.resultAcceptance?.acceptedAt;
|
|
82
86
|
if (typeof acceptedAt !== 'string' || !acceptedAt.trim())
|
|
83
87
|
return undefined;
|
|
84
|
-
|
|
88
|
+
const hasTaskLine = Boolean(input.deliveryBinding?.taskBranch?.trim());
|
|
89
|
+
const isolated = input.deliveryBinding?.executionIsolation === 'worktree';
|
|
90
|
+
if (!hasTaskLine && !isolated)
|
|
85
91
|
return undefined;
|
|
86
92
|
const handoff = input.deliveryHandoff;
|
|
87
93
|
if (!handoff?.status || handoff.status === 'idle')
|
package/dist/index.d.ts
CHANGED
|
@@ -796,6 +796,8 @@ export * from './context-accounting.ts';
|
|
|
796
796
|
export * from './memory.ts';
|
|
797
797
|
export * from './system-context.ts';
|
|
798
798
|
export * from './goal.ts';
|
|
799
|
+
export * from './acceptance-close-gate.ts';
|
|
800
|
+
export * from './acceptance-basis.ts';
|
|
799
801
|
export * from './updater.ts';
|
|
800
802
|
export * from './appshot.ts';
|
|
801
803
|
export * from './automation.ts';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,8 @@ export * from "./context-accounting.js";
|
|
|
20
20
|
export * from "./memory.js";
|
|
21
21
|
export * from "./system-context.js";
|
|
22
22
|
export * from "./goal.js";
|
|
23
|
+
export * from "./acceptance-close-gate.js";
|
|
24
|
+
export * from "./acceptance-basis.js";
|
|
23
25
|
export * from "./updater.js";
|
|
24
26
|
export * from "./appshot.js";
|
|
25
27
|
export * from "./automation.js";
|
package/dist/system-context.d.ts
CHANGED
|
@@ -76,6 +76,11 @@ export interface ChatStartTaskRequest {
|
|
|
76
76
|
readonly effort?: string;
|
|
77
77
|
/** Request-scoped OpenAI Fast mode; only the ChatGPT subscription adapter consumes it. */
|
|
78
78
|
readonly fastMode?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* User opt-in at new-task start. Stored on the conversation; applied later via
|
|
81
|
+
* existing Goal isolatePlan when a writable delivery line exists. Default none.
|
|
82
|
+
*/
|
|
83
|
+
readonly preferredExecutionIsolation?: 'none' | 'worktree';
|
|
79
84
|
readonly modelProviderId?: string | null;
|
|
80
85
|
readonly attachments?: readonly unknown[];
|
|
81
86
|
}
|
package/dist/task-overview.d.ts
CHANGED
|
@@ -150,8 +150,18 @@ export interface TaskOverviewItem {
|
|
|
150
150
|
* 有效运行时长(毫秒)。
|
|
151
151
|
* GoalPlan 来自 timing 投影(activeMs);缺 timing 时省略。
|
|
152
152
|
* UI 负责格式化为「3m12s」等,不在协议层落展示字符串。
|
|
153
|
+
*
|
|
154
|
+
* live 任务每次 list 都会重算该字段;身份比较 / 卡片复用必须忽略它,
|
|
155
|
+
* 否则一路流式更新会把其余推进卡一起打成新对象。
|
|
153
156
|
*/
|
|
154
157
|
readonly durationMs?: number;
|
|
158
|
+
/** 任务整体计时起点(ISO)。 */
|
|
159
|
+
readonly startedAt?: string;
|
|
160
|
+
/**
|
|
161
|
+
* 当前有效运行片段的起点(ISO)。仅存在时 live 卡片才在本地继续走表;
|
|
162
|
+
* 暂停中的任务保留 durationMs,不随墙钟继续增长。
|
|
163
|
+
*/
|
|
164
|
+
readonly activeSegmentStartedAt?: string;
|
|
155
165
|
/**
|
|
156
166
|
* 任务所用模型的用户可见标签(如 grok-4.5)。
|
|
157
167
|
* 来源:会话级 model / modelProviderId 绑定;无绑定时省略。
|
|
@@ -369,3 +379,11 @@ export declare function projectAutomationRun(snapshot: AutomationProjectionSnaps
|
|
|
369
379
|
* 运行中进 peer_advancing;已结束但短暂可观察时仍投影为 terminal,供右侧面板回看。
|
|
370
380
|
*/
|
|
371
381
|
export declare function projectShellBackgroundTask(snapshot: ShellBackgroundProjectionSnapshot): TaskOverviewItem;
|
|
382
|
+
export declare function areTaskOverviewItemsEqual(current: TaskOverviewItem, next: TaskOverviewItem, options?: {
|
|
383
|
+
readonly ignoreLiveClock?: boolean;
|
|
384
|
+
}): boolean;
|
|
385
|
+
/**
|
|
386
|
+
* 按 taskId 复用未变卡片的对象身份。
|
|
387
|
+
* 首页无 conversationId,只能整表重拉;复用后单路进度不会拖垮其余卡。
|
|
388
|
+
*/
|
|
389
|
+
export declare function reuseUnchangedTaskOverviewItems(current: readonly TaskOverviewItem[], next: readonly TaskOverviewItem[]): TaskOverviewItem[];
|
package/dist/task-overview.js
CHANGED
|
@@ -153,6 +153,10 @@ export function projectGoalPlan(snapshot, options) {
|
|
|
153
153
|
...(snapshot.updatedAt ? { lastActiveAt: snapshot.updatedAt } : {}),
|
|
154
154
|
...(completedAt ? { completedAt } : {}),
|
|
155
155
|
...(durationMs !== undefined ? { durationMs } : {}),
|
|
156
|
+
...(projectedTiming?.startedAt ? { startedAt: projectedTiming.startedAt } : {}),
|
|
157
|
+
...(projectedTiming?.isLive && snapshot.timing?.activeSegmentStartedAt
|
|
158
|
+
? { activeSegmentStartedAt: snapshot.timing.activeSegmentStartedAt }
|
|
159
|
+
: {}),
|
|
156
160
|
...(modelLabel ? { modelLabel } : {}),
|
|
157
161
|
...(providerLabel ? { providerLabel } : {}),
|
|
158
162
|
actionLabel: decision.actionLabel,
|
|
@@ -200,7 +204,7 @@ function decideGoalPlan(snapshot) {
|
|
|
200
204
|
actionRight: 'result_ready',
|
|
201
205
|
nextAction: 'review_result',
|
|
202
206
|
statusLabel: '待用户验收',
|
|
203
|
-
actionLabel: '
|
|
207
|
+
actionLabel: '查看进度',
|
|
204
208
|
};
|
|
205
209
|
}
|
|
206
210
|
if (status === 'completed' && accepted === true && deliveryHandoffStatus !== 'delivered') {
|
|
@@ -209,7 +213,7 @@ function decideGoalPlan(snapshot) {
|
|
|
209
213
|
actionRight: 'result_ready',
|
|
210
214
|
nextAction: 'review_result',
|
|
211
215
|
statusLabel: '交回未完成',
|
|
212
|
-
actionLabel: '
|
|
216
|
+
actionLabel: '查看进度',
|
|
213
217
|
};
|
|
214
218
|
}
|
|
215
219
|
// 只有真实交回进行中才占工作台。仅有 deliveryRoute 不算正在交回。
|
|
@@ -519,3 +523,62 @@ function automationTerminalLabel(status) {
|
|
|
519
523
|
return '已阻塞';
|
|
520
524
|
}
|
|
521
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* live `durationMs` 每次投影都会变。比较「任务身份」时忽略它,
|
|
528
|
+
* 这样一路任务的秒数/流式刷新不会把其余卡片判定为脏数据。
|
|
529
|
+
*/
|
|
530
|
+
function taskOverviewIdentity(item) {
|
|
531
|
+
const { durationMs: _durationMs, ...rest } = item;
|
|
532
|
+
return rest;
|
|
533
|
+
}
|
|
534
|
+
export function areTaskOverviewItemsEqual(current, next, options) {
|
|
535
|
+
if (current === next)
|
|
536
|
+
return true;
|
|
537
|
+
if (!current || !next)
|
|
538
|
+
return false;
|
|
539
|
+
if (current.taskId !== next.taskId)
|
|
540
|
+
return false;
|
|
541
|
+
if (options?.ignoreLiveClock) {
|
|
542
|
+
return JSON.stringify(taskOverviewIdentity(current)) === JSON.stringify(taskOverviewIdentity(next));
|
|
543
|
+
}
|
|
544
|
+
return JSON.stringify(current) === JSON.stringify(next);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* 按 taskId 复用未变卡片的对象身份。
|
|
548
|
+
* 首页无 conversationId,只能整表重拉;复用后单路进度不会拖垮其余卡。
|
|
549
|
+
*/
|
|
550
|
+
export function reuseUnchangedTaskOverviewItems(current, next) {
|
|
551
|
+
if (current === next)
|
|
552
|
+
return current;
|
|
553
|
+
if (!Array.isArray(next) || next.length === 0)
|
|
554
|
+
return next;
|
|
555
|
+
if (!Array.isArray(current) || current.length === 0)
|
|
556
|
+
return next;
|
|
557
|
+
const previousById = new Map();
|
|
558
|
+
for (const item of current) {
|
|
559
|
+
if (item && typeof item.taskId === 'string')
|
|
560
|
+
previousById.set(item.taskId, item);
|
|
561
|
+
}
|
|
562
|
+
let unchanged = current.length === next.length;
|
|
563
|
+
const reused = next.map((item, index) => {
|
|
564
|
+
const previous = item && typeof item.taskId === 'string' ? previousById.get(item.taskId) : undefined;
|
|
565
|
+
if (previous && areTaskOverviewItemsEqual(previous, item, { ignoreLiveClock: true })) {
|
|
566
|
+
if (previous !== current[index])
|
|
567
|
+
unchanged = false;
|
|
568
|
+
return previous;
|
|
569
|
+
}
|
|
570
|
+
unchanged = false;
|
|
571
|
+
return item;
|
|
572
|
+
});
|
|
573
|
+
if (unchanged) {
|
|
574
|
+
for (let index = 0; index < current.length; index += 1) {
|
|
575
|
+
if (current[index] !== reused[index]) {
|
|
576
|
+
unchanged = false;
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
if (unchanged)
|
|
581
|
+
return current;
|
|
582
|
+
}
|
|
583
|
+
return reused;
|
|
584
|
+
}
|