tavi-interaction-chain 0.0.0-stage → 0.3.0
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/README.md +21 -2
- package/dist/chain.d.ts +42 -0
- package/dist/chain.js +163 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/panel-assets.js +2 -0
- package/dist/panel-controller.d.ts +20 -0
- package/dist/panel-controller.js +128 -0
- package/dist/panel.d.ts +8 -0
- package/dist/panel.js +22 -0
- package/dist/tavi-workflow-model.d.ts +201 -0
- package/dist/tavi-workflow-model.js +258 -0
- package/dist/topology.d.ts +28 -0
- package/dist/topology.js +392 -0
- package/dist/workflow-canvas.d.ts +20 -0
- package/dist/workflow-canvas.js +111 -0
- package/package.json +39 -4
- package/schema.json +101 -0
- package/skill/tavi-interaction-chain/SKILL.md +18 -0
- package/style.css +161 -0
- package/theme.css +86 -0
- package/topology.schema.json +88 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Issue → MR 页面的纯逻辑。
|
|
3
|
+
* 列表只来自编排器台账;这里不提供演示 Issue,也不在浏览器里模拟 Agent。
|
|
4
|
+
*/
|
|
5
|
+
export type RunState = 'running' | 'waiting' | 'failed' | 'review' | 'queued' | 'done' | 'canceled';
|
|
6
|
+
export interface WorkflowStage {
|
|
7
|
+
key: string;
|
|
8
|
+
title: string;
|
|
9
|
+
summary: string;
|
|
10
|
+
evidence: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AgentFile {
|
|
13
|
+
name: string;
|
|
14
|
+
content: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentMessage {
|
|
17
|
+
id: string;
|
|
18
|
+
role: 'assistant' | 'user' | 'system';
|
|
19
|
+
at: string;
|
|
20
|
+
source: string;
|
|
21
|
+
text: string;
|
|
22
|
+
files: AgentFile[];
|
|
23
|
+
idempotencyKey?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ArtifactVersion {
|
|
26
|
+
version: number;
|
|
27
|
+
content: string;
|
|
28
|
+
author: string;
|
|
29
|
+
source: string;
|
|
30
|
+
at: string;
|
|
31
|
+
parentVersion: number | null;
|
|
32
|
+
hash: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ConversationState {
|
|
35
|
+
id: string;
|
|
36
|
+
questionId: string;
|
|
37
|
+
revision: number;
|
|
38
|
+
issueRevision: string;
|
|
39
|
+
contextRevision: number;
|
|
40
|
+
status: 'open' | 'resolved' | 'checking';
|
|
41
|
+
hasUnsimulatedInput: boolean;
|
|
42
|
+
autoResumed: boolean;
|
|
43
|
+
artifactName: string;
|
|
44
|
+
selectedVersion: number;
|
|
45
|
+
pendingRevision: {
|
|
46
|
+
content: string;
|
|
47
|
+
baseVersion: number;
|
|
48
|
+
messageId: string;
|
|
49
|
+
} | null;
|
|
50
|
+
pendingDraft?: {
|
|
51
|
+
content: string;
|
|
52
|
+
baseVersion: number;
|
|
53
|
+
hash: string;
|
|
54
|
+
at: string;
|
|
55
|
+
} | null;
|
|
56
|
+
artifactVersions: ArtifactVersion[];
|
|
57
|
+
messages: AgentMessage[];
|
|
58
|
+
}
|
|
59
|
+
export interface BoardMergeRequest {
|
|
60
|
+
repo: string;
|
|
61
|
+
iid?: number;
|
|
62
|
+
state: string;
|
|
63
|
+
label: string;
|
|
64
|
+
url: string | null;
|
|
65
|
+
}
|
|
66
|
+
export interface AutomationIssue {
|
|
67
|
+
id: number;
|
|
68
|
+
projectKey: string;
|
|
69
|
+
project: string;
|
|
70
|
+
title: string;
|
|
71
|
+
state: RunState;
|
|
72
|
+
stateLabel: string;
|
|
73
|
+
/** 自动验证暂停等失败的具体原因。没有可展示的原因时为空。 */
|
|
74
|
+
statusDetail?: string;
|
|
75
|
+
stage: number;
|
|
76
|
+
stageLabel: string;
|
|
77
|
+
progress: number;
|
|
78
|
+
attempt: string;
|
|
79
|
+
mr: string;
|
|
80
|
+
mrUrl: string | null;
|
|
81
|
+
mrState: string;
|
|
82
|
+
/** 当前轮已到 MR 节点时,每个被修改仓库的回执。旧接口未提供时按单条 mr 展示。 */
|
|
83
|
+
mrs?: BoardMergeRequest[];
|
|
84
|
+
updated: string;
|
|
85
|
+
run: string;
|
|
86
|
+
started: string;
|
|
87
|
+
duration: string;
|
|
88
|
+
/** 契约 12:执行中看 runningSince;已结束的 elapsedMs 是最近一次执行,不含更早的重试。 */
|
|
89
|
+
stageTimings?: Record<string, {
|
|
90
|
+
elapsedMs: number | null;
|
|
91
|
+
runningSince: string | null;
|
|
92
|
+
}>;
|
|
93
|
+
branch: string;
|
|
94
|
+
base: string;
|
|
95
|
+
goal: string;
|
|
96
|
+
original: string;
|
|
97
|
+
criteria: string[];
|
|
98
|
+
nonGoals: string[];
|
|
99
|
+
events: Array<[string, string, string]>;
|
|
100
|
+
artifacts: Array<[string, string, string]>;
|
|
101
|
+
completed: number;
|
|
102
|
+
current: number;
|
|
103
|
+
issueKey: string;
|
|
104
|
+
/** 服务端绑定当前失败节点的令牌;旧接口未提供时不显示重试入口。 */
|
|
105
|
+
retryToken?: string | null;
|
|
106
|
+
contextRevision: number;
|
|
107
|
+
conversation: ConversationState | null;
|
|
108
|
+
/** pending:待通过或拒绝。rejected:已拒绝,暂停等待补充。confirmed:已进入 Agent 编码。 */
|
|
109
|
+
prdConfirmation?: 'pending' | 'rejected' | 'confirmed' | null;
|
|
110
|
+
}
|
|
111
|
+
export interface AutomationBoard {
|
|
112
|
+
generatedAt?: string;
|
|
113
|
+
syncedAt: string | null;
|
|
114
|
+
stale: boolean;
|
|
115
|
+
syncError: string | null;
|
|
116
|
+
healthy: boolean;
|
|
117
|
+
totals: {
|
|
118
|
+
tracked: number;
|
|
119
|
+
running: number;
|
|
120
|
+
waiting: number;
|
|
121
|
+
attention: number;
|
|
122
|
+
};
|
|
123
|
+
issues: AutomationIssue[];
|
|
124
|
+
}
|
|
125
|
+
export interface IssueFilters {
|
|
126
|
+
query: string;
|
|
127
|
+
project: string;
|
|
128
|
+
status: string;
|
|
129
|
+
}
|
|
130
|
+
export declare const WORKFLOW_STAGES: WorkflowStage[];
|
|
131
|
+
/** 幂等键必须跟这一次草稿绑定。内容变了还用旧键,服务端会把新正文当成重复提交丢掉。 */
|
|
132
|
+
export declare function messageFingerprint(text: string, files: Array<{
|
|
133
|
+
name: string;
|
|
134
|
+
content: string;
|
|
135
|
+
}>): string;
|
|
136
|
+
export declare function nextMessageIdempotency(current: {
|
|
137
|
+
key: string;
|
|
138
|
+
fingerprint: string;
|
|
139
|
+
}, fingerprint: string, mint: () => string): {
|
|
140
|
+
key: string;
|
|
141
|
+
fingerprint: string;
|
|
142
|
+
};
|
|
143
|
+
export declare function emptyFilters(): IssueFilters;
|
|
144
|
+
/** 搜索框里的草稿要先规范化,未提交前不能拿来过滤列表。 */
|
|
145
|
+
export declare function normalizeFilters(draft: IssueFilters): IssueFilters;
|
|
146
|
+
/** 重置要同时清掉输入草稿和已生效条件。返回新对象,避免后续改草稿又写回列表。 */
|
|
147
|
+
export declare function resetFilters(draft: IssueFilters): IssueFilters;
|
|
148
|
+
export declare function filterIssues(issues: AutomationIssue[], filters: IssueFilters): AutomationIssue[];
|
|
149
|
+
/**
|
|
150
|
+
* 看板一次拉全量,分页只发生在浏览器里。
|
|
151
|
+
* 页码越界时夹回最后一页,避免刷新后列表变短却停在空白页。
|
|
152
|
+
*/
|
|
153
|
+
export declare const ISSUE_LIST_PAGE_SIZE = 10;
|
|
154
|
+
export interface IssuePage<T> {
|
|
155
|
+
items: T[];
|
|
156
|
+
page: number;
|
|
157
|
+
pageSize: number;
|
|
158
|
+
total: number;
|
|
159
|
+
pageCount: number;
|
|
160
|
+
from: number;
|
|
161
|
+
to: number;
|
|
162
|
+
}
|
|
163
|
+
export declare function paginateIssues<T>(items: readonly T[], page: number, pageSize?: number): IssuePage<T>;
|
|
164
|
+
export declare function boardMetrics(issues: AutomationIssue[]): {
|
|
165
|
+
tracked: number;
|
|
166
|
+
running: number;
|
|
167
|
+
waiting: number;
|
|
168
|
+
attention: number;
|
|
169
|
+
};
|
|
170
|
+
export declare function workflowShowsMr(issue: Pick<AutomationIssue, 'stage' | 'state' | 'mr' | 'mrs'>): boolean;
|
|
171
|
+
export declare function mrLabel(issue: Pick<AutomationIssue, 'stage' | 'state' | 'mr' | 'mrs'>): string;
|
|
172
|
+
/** 多仓各一条。旧看板没有 mrs 时,退回原来的单条编号和链接。 */
|
|
173
|
+
export declare function visibleMrs(issue: AutomationIssue): BoardMergeRequest[];
|
|
174
|
+
/** 用台账里的 MR 地址。没有单独存 URL 时,用 Issue 所在项目和 !iid 拼出来。 */
|
|
175
|
+
export declare function gitlabMrUrl(issue: AutomationIssue): string | null;
|
|
176
|
+
/** 用台账里的实例地址和项目路径拼 GitLab Issue 页。拼不出时不伪造链接。 */
|
|
177
|
+
export declare function gitlabIssueUrl(issue: AutomationIssue): string | null;
|
|
178
|
+
/** PRD 已生成,还没通过。拒绝后仍停在这里,补充不能代替通过。 */
|
|
179
|
+
export declare function awaitingPrdConfirmation(issue: AutomationIssue): boolean;
|
|
180
|
+
export declare function canRetryStage(issue: Pick<AutomationIssue, 'state' | 'current' | 'retryToken'>, index: number): boolean;
|
|
181
|
+
/** 对话只属于 PRD;查看历史 PRD 时也不能向正在执行的其他节点发送消息。 */
|
|
182
|
+
export declare function acceptsHuman(issue: AutomationIssue): boolean;
|
|
183
|
+
/** 默认跟随最新正文;主动查看历史时不被轮询跳走。 */
|
|
184
|
+
export declare function nextViewedArtifact(viewed: number, previousLatest: number | undefined, latest: number | undefined): number;
|
|
185
|
+
export declare function stageTone(issue: AutomationIssue, index: number): 'complete' | 'current' | 'blocked' | 'error' | '';
|
|
186
|
+
export declare function stageStateLabel(issue: AutomationIssue, index: number): string;
|
|
187
|
+
export declare function stageElapsedMs(issue: AutomationIssue, index: number, now: number): number | null;
|
|
188
|
+
export declare function formatStageDuration(elapsedMs: number | null): string;
|
|
189
|
+
/** 阶段说明描述目标,只有服务端事件才是执行证据。 */
|
|
190
|
+
/** 产物行能下载时,返回文件名和正文。没有登记正文就不给空文件。 */
|
|
191
|
+
export declare function artifactDocument(issue: AutomationIssue, artifact: [string, string, string]): {
|
|
192
|
+
name: string;
|
|
193
|
+
content: string;
|
|
194
|
+
} | null;
|
|
195
|
+
export declare function stageExecutionLog(issue: AutomationIssue, index: number): string;
|
|
196
|
+
export interface ContextCard {
|
|
197
|
+
title: string;
|
|
198
|
+
body: string;
|
|
199
|
+
source: string;
|
|
200
|
+
}
|
|
201
|
+
export declare function contextCards(issue: AutomationIssue, stageIndex: number): ContextCard[];
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Issue → MR 页面的纯逻辑。
|
|
3
|
+
* 列表只来自编排器台账;这里不提供演示 Issue,也不在浏览器里模拟 Agent。
|
|
4
|
+
*/
|
|
5
|
+
export const WORKFLOW_STAGES = [
|
|
6
|
+
{ key: 'prd', title: 'PRD 生成与确认', summary: '用 Issue 原文和目标代码仓作为上下文生成 PRD。生成完成后必须人工确认,确认前不会进入下一节点。', evidence: 'PRD、Issue 原文与目标仓上下文' },
|
|
7
|
+
{ key: 'coding', title: 'Agent 编码', summary: '在隔离工作区按 PRD 改代码。方案、目标仓、上下文检查和认领都在这一步内部完成。', evidence: '变更摘要、受影响文件、提交 SHA' },
|
|
8
|
+
{ key: 'verify', title: '自动验证', summary: '依次做代码检查、环境与产物准备、就绪检查和场景测试。部署成功或安装包下载成功只表示准备步骤通过;必需用例全部通过后才进入 MR。', evidence: '子步骤、部署环境、安装包、实际命令与日志' },
|
|
9
|
+
{ key: 'mr', title: '创建 MR 并发送 MR', summary: '验证通过后创建 MR,并提交到 GitLab。', evidence: 'MR URL、源 / 目标分支、提交 SHA' },
|
|
10
|
+
];
|
|
11
|
+
/** 幂等键必须跟这一次草稿绑定。内容变了还用旧键,服务端会把新正文当成重复提交丢掉。 */
|
|
12
|
+
export function messageFingerprint(text, files) {
|
|
13
|
+
return JSON.stringify({ text, files: files.map((file) => [file.name, file.content]) });
|
|
14
|
+
}
|
|
15
|
+
export function nextMessageIdempotency(current, fingerprint, mint) {
|
|
16
|
+
if (current.key && current.fingerprint === fingerprint)
|
|
17
|
+
return current;
|
|
18
|
+
return { key: mint(), fingerprint };
|
|
19
|
+
}
|
|
20
|
+
export function emptyFilters() {
|
|
21
|
+
return { query: '', project: 'all', status: 'all' };
|
|
22
|
+
}
|
|
23
|
+
/** 搜索框里的草稿要先规范化,未提交前不能拿来过滤列表。 */
|
|
24
|
+
export function normalizeFilters(draft) {
|
|
25
|
+
return {
|
|
26
|
+
query: draft.query.trim().toLowerCase(),
|
|
27
|
+
project: draft.project,
|
|
28
|
+
status: draft.status,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** 重置要同时清掉输入草稿和已生效条件。返回新对象,避免后续改草稿又写回列表。 */
|
|
32
|
+
export function resetFilters(draft) {
|
|
33
|
+
Object.assign(draft, emptyFilters());
|
|
34
|
+
return emptyFilters();
|
|
35
|
+
}
|
|
36
|
+
export function filterIssues(issues, filters) {
|
|
37
|
+
return issues.filter((item) => {
|
|
38
|
+
const searchable = `${item.id} ${item.title} ${item.project}`.toLowerCase();
|
|
39
|
+
const queryOk = !filters.query || searchable.includes(filters.query);
|
|
40
|
+
const projectOk = filters.project === 'all' || item.projectKey === filters.project;
|
|
41
|
+
const statusOk = filters.status === 'all' || item.state === filters.status;
|
|
42
|
+
return queryOk && projectOk && statusOk;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 看板一次拉全量,分页只发生在浏览器里。
|
|
47
|
+
* 页码越界时夹回最后一页,避免刷新后列表变短却停在空白页。
|
|
48
|
+
*/
|
|
49
|
+
export const ISSUE_LIST_PAGE_SIZE = 10;
|
|
50
|
+
export function paginateIssues(items, page, pageSize = ISSUE_LIST_PAGE_SIZE) {
|
|
51
|
+
const size = Math.max(1, Math.floor(pageSize));
|
|
52
|
+
const total = items.length;
|
|
53
|
+
const pageCount = Math.max(1, Math.ceil(total / size));
|
|
54
|
+
const current = Math.min(pageCount, Math.max(1, Math.floor(page) || 1));
|
|
55
|
+
const start = (current - 1) * size;
|
|
56
|
+
const slice = items.slice(start, start + size);
|
|
57
|
+
return {
|
|
58
|
+
items: slice,
|
|
59
|
+
page: current,
|
|
60
|
+
pageSize: size,
|
|
61
|
+
total,
|
|
62
|
+
pageCount,
|
|
63
|
+
from: total === 0 ? 0 : start + 1,
|
|
64
|
+
to: start + slice.length,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function boardMetrics(issues) {
|
|
68
|
+
return {
|
|
69
|
+
tracked: issues.length,
|
|
70
|
+
running: issues.filter((item) => item.state === 'running').length,
|
|
71
|
+
waiting: issues.filter((item) => item.state === 'waiting').length,
|
|
72
|
+
attention: issues.filter((item) => item.state === 'failed').length,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 当前展示阶段还没到创建 MR 时,不把台账里更早的回执当成已交付。
|
|
77
|
+
* review / done 只在这一轮已经收口到 MR 节点后出现。
|
|
78
|
+
*/
|
|
79
|
+
function atMrStage(issue) {
|
|
80
|
+
return WORKFLOW_STAGES[issue.stage]?.key === 'mr' || issue.state === 'review' || issue.state === 'done';
|
|
81
|
+
}
|
|
82
|
+
export function workflowShowsMr(issue) {
|
|
83
|
+
if (!atMrStage(issue))
|
|
84
|
+
return false;
|
|
85
|
+
if (issue.mrs?.some((item) => item.label && item.label !== '—'))
|
|
86
|
+
return true;
|
|
87
|
+
return Boolean(issue.mr && issue.mr !== '—');
|
|
88
|
+
}
|
|
89
|
+
export function mrLabel(issue) {
|
|
90
|
+
return workflowShowsMr(issue) ? issue.mr : '—';
|
|
91
|
+
}
|
|
92
|
+
/** 多仓各一条。旧看板没有 mrs 时,退回原来的单条编号和链接。 */
|
|
93
|
+
export function visibleMrs(issue) {
|
|
94
|
+
if (!workflowShowsMr(issue))
|
|
95
|
+
return [];
|
|
96
|
+
const listed = (issue.mrs ?? []).filter((item) => item?.label && item.label !== '—');
|
|
97
|
+
if (listed.length) {
|
|
98
|
+
return listed.map((item) => ({
|
|
99
|
+
repo: item.repo || '',
|
|
100
|
+
iid: item.iid,
|
|
101
|
+
state: item.state || '',
|
|
102
|
+
label: item.label,
|
|
103
|
+
url: item.url || null,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
return [{ repo: '', label: issue.mr, state: issue.mrState || '', url: gitlabMrUrl(issue) }];
|
|
107
|
+
}
|
|
108
|
+
/** 用台账里的 MR 地址。没有单独存 URL 时,用 Issue 所在项目和 !iid 拼出来。 */
|
|
109
|
+
export function gitlabMrUrl(issue) {
|
|
110
|
+
if (!workflowShowsMr(issue))
|
|
111
|
+
return null;
|
|
112
|
+
if (issue.mrUrl)
|
|
113
|
+
return issue.mrUrl;
|
|
114
|
+
const iid = issue.mr.match(/^!(\d+)/)?.[1];
|
|
115
|
+
if (!iid)
|
|
116
|
+
return null;
|
|
117
|
+
const parts = issue.issueKey.split('::');
|
|
118
|
+
if (parts.length !== 3)
|
|
119
|
+
return null;
|
|
120
|
+
const [instance] = parts;
|
|
121
|
+
if (!instance.startsWith('https://') || !issue.project.includes('/'))
|
|
122
|
+
return null;
|
|
123
|
+
return `${instance.replace(/\/$/, '')}/${issue.project}/-/merge_requests/${iid}`;
|
|
124
|
+
}
|
|
125
|
+
/** 用台账里的实例地址和项目路径拼 GitLab Issue 页。拼不出时不伪造链接。 */
|
|
126
|
+
export function gitlabIssueUrl(issue) {
|
|
127
|
+
const parts = issue.issueKey.split('::');
|
|
128
|
+
if (parts.length !== 3)
|
|
129
|
+
return null;
|
|
130
|
+
const [instance, , iid] = parts;
|
|
131
|
+
if (!instance.startsWith('https://') || !issue.project.includes('/'))
|
|
132
|
+
return null;
|
|
133
|
+
return `${instance.replace(/\/$/, '')}/${issue.project}/-/issues/${iid}`;
|
|
134
|
+
}
|
|
135
|
+
/** PRD 已生成,还没通过。拒绝后仍停在这里,补充不能代替通过。 */
|
|
136
|
+
export function awaitingPrdConfirmation(issue) {
|
|
137
|
+
return (issue.prdConfirmation === 'pending' || issue.prdConfirmation === 'rejected') && issue.state !== 'canceled';
|
|
138
|
+
}
|
|
139
|
+
export function canRetryStage(issue, index) {
|
|
140
|
+
return issue.state === 'failed' && index === issue.current && Boolean(issue.retryToken);
|
|
141
|
+
}
|
|
142
|
+
/** 对话只属于 PRD;查看历史 PRD 时也不能向正在执行的其他节点发送消息。 */
|
|
143
|
+
export function acceptsHuman(issue) {
|
|
144
|
+
if (issue.state === 'canceled')
|
|
145
|
+
return false;
|
|
146
|
+
if (WORKFLOW_STAGES[issue.current]?.key !== 'prd')
|
|
147
|
+
return false;
|
|
148
|
+
if (issue.prdConfirmation === 'confirmed')
|
|
149
|
+
return false;
|
|
150
|
+
if (issue.prdConfirmation === 'pending' || issue.prdConfirmation === 'rejected')
|
|
151
|
+
return true;
|
|
152
|
+
return issue.state === 'waiting' && Boolean(issue.conversation);
|
|
153
|
+
}
|
|
154
|
+
/** 默认跟随最新正文;主动查看历史时不被轮询跳走。 */
|
|
155
|
+
export function nextViewedArtifact(viewed, previousLatest, latest) {
|
|
156
|
+
return latest !== undefined && (previousLatest === undefined || viewed === previousLatest) ? latest : viewed;
|
|
157
|
+
}
|
|
158
|
+
export function stageTone(issue, index) {
|
|
159
|
+
if (index < issue.completed)
|
|
160
|
+
return 'complete';
|
|
161
|
+
if (index !== issue.current)
|
|
162
|
+
return '';
|
|
163
|
+
if (issue.state === 'failed')
|
|
164
|
+
return 'error';
|
|
165
|
+
if (issue.state === 'waiting')
|
|
166
|
+
return 'blocked';
|
|
167
|
+
return 'current';
|
|
168
|
+
}
|
|
169
|
+
export function stageStateLabel(issue, index) {
|
|
170
|
+
if (index < issue.completed) {
|
|
171
|
+
if ((issue.state === 'review' || issue.state === 'done') && index === WORKFLOW_STAGES.length - 1)
|
|
172
|
+
return 'MR 已提交';
|
|
173
|
+
return '已完成';
|
|
174
|
+
}
|
|
175
|
+
if (index === issue.current)
|
|
176
|
+
return issue.stateLabel;
|
|
177
|
+
return '待执行';
|
|
178
|
+
}
|
|
179
|
+
export function stageElapsedMs(issue, index, now) {
|
|
180
|
+
const stage = WORKFLOW_STAGES[index];
|
|
181
|
+
const timing = stage ? issue.stageTimings?.[stage.key] : undefined;
|
|
182
|
+
if (!timing)
|
|
183
|
+
return null;
|
|
184
|
+
const started = timing.runningSince ? Date.parse(timing.runningSince) : NaN;
|
|
185
|
+
// 执行中只算这一次。服务端若仍带着更早区间的 elapsedMs,也不能加进去。
|
|
186
|
+
if (Number.isFinite(started))
|
|
187
|
+
return Number.isFinite(now) ? Math.max(0, now - started) : null;
|
|
188
|
+
if (typeof timing.elapsedMs !== 'number' || !Number.isFinite(timing.elapsedMs) || timing.elapsedMs < 0)
|
|
189
|
+
return null;
|
|
190
|
+
return timing.elapsedMs;
|
|
191
|
+
}
|
|
192
|
+
export function formatStageDuration(elapsedMs) {
|
|
193
|
+
if (elapsedMs === null || !Number.isFinite(elapsedMs) || elapsedMs < 0)
|
|
194
|
+
return '—';
|
|
195
|
+
const seconds = Math.floor(elapsedMs / 1000);
|
|
196
|
+
const hours = Math.floor(seconds / 3600);
|
|
197
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
198
|
+
const rest = seconds % 60;
|
|
199
|
+
if (hours)
|
|
200
|
+
return `${hours}时 ${String(minutes).padStart(2, '0')}分 ${String(rest).padStart(2, '0')}秒`;
|
|
201
|
+
if (minutes)
|
|
202
|
+
return `${minutes}分 ${String(rest).padStart(2, '0')}秒`;
|
|
203
|
+
return `${rest}秒`;
|
|
204
|
+
}
|
|
205
|
+
/** 阶段说明描述目标,只有服务端事件才是执行证据。 */
|
|
206
|
+
/** 产物行能下载时,返回文件名和正文。没有登记正文就不给空文件。 */
|
|
207
|
+
export function artifactDocument(issue, artifact) {
|
|
208
|
+
const conversation = issue.conversation;
|
|
209
|
+
if (!conversation)
|
|
210
|
+
return null;
|
|
211
|
+
const version = Number(artifact[2].match(/v(\d+)/)?.[1] ?? '');
|
|
212
|
+
const matched = conversation.artifactVersions.find((item) => item.version === version)
|
|
213
|
+
?? (artifact[1] === conversation.artifactName ? conversation.artifactVersions.at(-1) : undefined);
|
|
214
|
+
const content = matched?.content?.trim() ?? '';
|
|
215
|
+
if (!content)
|
|
216
|
+
return null;
|
|
217
|
+
const rawName = artifact[1].trim() || conversation.artifactName || '01-prd.md';
|
|
218
|
+
return { name: rawName.includes('.') ? rawName : `${rawName}.md`, content };
|
|
219
|
+
}
|
|
220
|
+
export function stageExecutionLog(issue, index) {
|
|
221
|
+
if (index > issue.current)
|
|
222
|
+
return '当前台账未登记该阶段的执行结果。';
|
|
223
|
+
if (index !== issue.current)
|
|
224
|
+
return '当前接口未提供该阶段独立日志,请核对已登记产物。';
|
|
225
|
+
return `台账状态:${issue.stateLabel}\n当前阶段:${issue.stageLabel}\n运行:${issue.run}\n尝试:${issue.attempt}\n详细验证结果需查看已登记的证据。`;
|
|
226
|
+
}
|
|
227
|
+
export function contextCards(issue, stageIndex) {
|
|
228
|
+
const stage = WORKFLOW_STAGES[stageIndex] ?? WORKFLOW_STAGES[0];
|
|
229
|
+
const pending = stageIndex > issue.current || issue.state === 'queued';
|
|
230
|
+
const conversation = issue.conversation;
|
|
231
|
+
const unresolved = Boolean(conversation && conversation.status !== 'resolved' && !pending);
|
|
232
|
+
const decision = issue.prdConfirmation === 'rejected'
|
|
233
|
+
? 'PRD 已拒绝。流程暂停,补充后仍需通过才会进入 Agent 编码。'
|
|
234
|
+
: issue.prdConfirmation === 'pending'
|
|
235
|
+
? 'PRD 已生成。通过后进入 Agent 编码;拒绝则暂停并等待补充。'
|
|
236
|
+
: !conversation
|
|
237
|
+
? '当前无待回答问题;满足节点完成契约后自动推进。'
|
|
238
|
+
: conversation.status === 'resolved'
|
|
239
|
+
? `已采用 ${conversation.questionId} 的范围补充。适用 ${conversation.issueRevision}。`
|
|
240
|
+
: conversation.status === 'checking'
|
|
241
|
+
? '对话已收录,产物修改尚未生效。'
|
|
242
|
+
: `${conversation.questionId} 尚未解决,请查看对话中的具体问题。`;
|
|
243
|
+
const cards = [
|
|
244
|
+
{ title: '本节点职责与必要输入', body: `${stage.title}。${stage.summary}`, source: pending ? '待读取' : stage.evidence },
|
|
245
|
+
{ title: '需求与边界来源', body: `${issue.goal} ${issue.original}`, source: `${conversation?.issueRevision ?? 'issue-r1'} · 原文快照` },
|
|
246
|
+
{ title: '仓库与上游证据', body: `${issue.project} · 基线 ${issue.base}。`, source: issue.base && issue.base !== '—' ? '台账记录的基线' : '尚未登记基线 SHA' },
|
|
247
|
+
{ title: '有效决策 / 缺失项', body: decision, source: unresolved ? '关键范围待确定' : `context r${issue.contextRevision}` },
|
|
248
|
+
];
|
|
249
|
+
if (conversation) {
|
|
250
|
+
const version = conversation.artifactVersions[conversation.artifactVersions.length - 1]?.version ?? 1;
|
|
251
|
+
cards.push({
|
|
252
|
+
title: '对话与生效资料',
|
|
253
|
+
body: `${conversation.messages.length} 条消息;${conversation.artifactName} v${version}。${conversation.pendingRevision ? '另有用户修订待复核。' : '当前登记的生效版本。'}`,
|
|
254
|
+
source: '资料修订与原始 Issue 分别保留',
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return cards;
|
|
258
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ChainSnapshot, type ChainStep } from './chain.js';
|
|
2
|
+
export type LinkKind = 'forward' | 'feedback' | 'control';
|
|
3
|
+
export interface TopologyNode extends ChainStep {
|
|
4
|
+
column: number;
|
|
5
|
+
lane?: 'main' | 'input';
|
|
6
|
+
slot?: 0 | 1 | 2;
|
|
7
|
+
channel?: string;
|
|
8
|
+
rateHz?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface TopologyLink {
|
|
11
|
+
from: string;
|
|
12
|
+
to: string;
|
|
13
|
+
kind: LinkKind;
|
|
14
|
+
}
|
|
15
|
+
export interface TopologySnapshot {
|
|
16
|
+
version: 1;
|
|
17
|
+
nodes: readonly TopologyNode[];
|
|
18
|
+
links: readonly TopologyLink[];
|
|
19
|
+
}
|
|
20
|
+
export interface TopologyOptions {
|
|
21
|
+
selectedId?: string;
|
|
22
|
+
onSelect?: (node: TopologyNode) => void;
|
|
23
|
+
onPreview?: (node: TopologyNode | null) => void;
|
|
24
|
+
onClear?: () => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function parseTopology(input: unknown): TopologySnapshot;
|
|
27
|
+
export declare function toTopology(snapshot: ChainSnapshot): TopologySnapshot;
|
|
28
|
+
export declare function renderTopology(host: HTMLElement, input: TopologySnapshot, options: TopologyOptions): void;
|