nx-kv 0.65.0 → 0.65.3
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/CHANGELOG.md +59 -0
- package/package.json +1 -1
- package/src/core/db/seed-templates.ts +2 -86
- package/src/core/db/settings.ts +1 -1
- package/src/core/instruction-template.ts +1 -1
- package/src/core/workflow/plugin-registry.ts +1 -1
- package/src/core/workflow/types.ts +4 -4
- package/src/modules/claim/actions/_manifest.generated.ts +23 -0
- package/src/modules/{localtask → claim}/actions/localtask-claim.ts +4 -4
- package/src/modules/{localtask → claim}/actions/localtask-preview.ts +4 -4
- package/src/modules/{localtask → claim}/actions/localtask-wait.ts +4 -4
- package/src/modules/{tasktool → claim}/get.ts +3 -3
- package/src/modules/claim/index.ts +25 -0
- package/src/modules/{tasktool → claim}/panel-escort.ts +2 -2
- package/src/modules/{tasktool → claim}/params.ts +1 -1
- package/src/modules/claim/wait.ts +305 -0
- package/src/modules/{tasktool/plugins → claim}/waitgoal-config.ts +4 -28
- package/src/modules/delivery/assemble.ts +151 -0
- package/src/modules/{tasktool → delivery}/attach-resource.ts +2 -2
- package/src/modules/{tasktool → delivery}/attach-template.ts +1 -1
- package/src/modules/{tasktool → delivery}/attach.ts +1 -1
- package/src/modules/{tasktool → delivery}/delivery-text.ts +2 -2
- package/src/modules/{tasktool → delivery}/doc-inline.ts +1 -1
- package/src/modules/{tasktool → delivery}/groupctx.ts +1 -1
- package/src/modules/delivery/host.ts +231 -0
- package/src/modules/delivery/index.ts +18 -0
- package/src/modules/{tasktool → delivery}/preview.ts +5 -6
- package/src/modules/{tasktool → goals}/actions/timegoal-check.ts +1 -1
- package/src/modules/{tasktool → goals}/actions/timegoal-clear.ts +1 -1
- package/src/modules/{tasktool → goals}/actions/timegoal-list.ts +1 -1
- package/src/modules/{tasktool → goals}/actions/timegoal-log.ts +1 -1
- package/src/modules/{tasktool → goals}/actions/timegoal-set.ts +1 -1
- package/src/modules/{tasktool → goals}/actions/timegoal-show.ts +1 -1
- package/src/modules/{tasktool → goals}/actions/timegoal-update.ts +1 -1
- package/src/modules/goals/index.ts +25 -0
- package/src/modules/{tasktool → goals}/plugins/discover.ts +3 -3
- package/src/modules/{tasktool → goals}/plugins/index.ts +0 -2
- package/src/modules/{tasktool → goals}/plugins/taskgoal-store.ts +3 -3
- package/src/modules/{tasktool → goals}/plugins/timegoal-task-store.ts +2 -2
- package/src/modules/localtask/action-render.ts +1 -1
- package/src/modules/localtask/actions/_manifest.generated.ts +0 -9
- package/src/modules/localtask/actions/localtask-add.ts +2 -2
- package/src/modules/localtask/actions/localtask-attach-note.ts +1 -1
- package/src/modules/localtask/actions/localtask-attach.ts +1 -1
- package/src/modules/localtask/actions/localtask-attachments.ts +1 -1
- package/src/modules/localtask/actions/localtask-detach.ts +1 -1
- package/src/modules/localtask/actions/localtask-get.ts +1 -1
- package/src/modules/localtask/actions/localtask-reopen.ts +1 -1
- package/src/modules/localtask/actions/localtask-timegoalLog.ts +1 -1
- package/src/modules/localtask/actions/localtask-update.ts +2 -2
- package/src/modules/{tasktool → localtask}/add.ts +3 -3
- package/src/modules/localtask/engine.ts +1 -1
- package/src/modules/{tasktool → localtask}/group-store.ts +2 -2
- package/src/modules/localtask/mutator/index.ts +1 -1
- package/src/modules/localtask/panel-presence.ts +2 -2
- package/src/modules/localtask/scheduler/state-drive.ts +1 -1
- package/src/modules/{tasktool → localtask}/support.ts +1 -1
- package/src/modules/localtask/task-lifecycle.ts +5 -5
- package/src/modules/localtask/task-ops.ts +1 -1
- package/src/modules/localtask/task-templates.ts +1 -1
- package/src/modules/localtask/task-view.ts +1 -1
- package/src/modules/{tasktool → localtask}/update.ts +1 -1
- package/src/modules/localtask/waiters.ts +1 -1
- package/src/modules/localtask/writes.ts +1 -1
- package/src/modules/promptplug/factory.ts +5 -5
- package/src/modules/promptplug/index.ts +5 -5
- package/src/modules/promptplug/plugins/attachment.ts +1 -1
- package/src/modules/promptplug/plugins/context.ts +1 -1
- package/src/modules/promptplug/plugins/getloop.ts +8 -7
- package/src/modules/{tasktool/plugins/goal-template.ts → promptplug/plugins/goal-prompt.ts} +4 -3
- package/src/modules/repos/service/crud.ts +1 -1
- package/src/modules/templates/actions/templates-default.ts +2 -5
- package/src/modules/templates/actions/templates-update.ts +1 -3
- package/src/modules/templates/service.ts +11 -13
- package/src/modules/templates/support.ts +0 -15
- package/src/runtime/registry.ts +6 -2
- package/src/web/frontend/App.tsx +0 -12
- package/src/web/frontend/api/cli-tree.json +138 -138
- package/src/web/frontend/api/client.generated.ts +90 -88
- package/src/web/frontend/components/md/live-block.tsx +1 -5
- package/src/web/frontend/components/md/md-panes-root.tsx +0 -4
- package/src/web/frontend/components/md/md-panes.tsx +1 -11
- package/src/web/frontend/modules/md/styles/docs.css +0 -7
- package/src/web/frontend/modules/md/styles/editor.css +0 -17
- package/src/web/frontend/modules/md/use-templates.ts +3 -13
- package/src/web/frontend/page/dir/index.tsx +3 -15
- package/src/web/frontend/page/dir/task-actions.ts +1 -16
- package/src/web/frontend/page/dir/task.tsx +2 -16
- package/src/web/frontend/page/group/index.tsx +6 -19
- package/src/web/frontend/page/settings/index.tsx +1 -1
- package/src/web/frontend/page/templates/index.tsx +5 -54
- package/src/web/frontend/page/templates/manage.tsx +1 -5
- package/src/web/frontend/page/templates/style.css +1 -43
- package/src/web/frontend/page/templates/template-list.tsx +7 -15
- package/src/web/frontend/routes/route-eq.ts +2 -3
- package/src/web/frontend/routes/templates.ts +0 -10
- package/src/web/frontend/styles-v2/shell.css +7 -0
- package/src/web/frontend/types.ts +2 -1
- package/src/web/public/assets/{bar-csH6ZW39.js → bar-Dc5Tq1eE.js} +1 -1
- package/src/web/public/assets/{composer-launch-Ba9cBxhb.js → composer-launch-fp2IzGzQ.js} +1 -1
- package/src/web/public/assets/{composer-panel-7SHKllt5.js → composer-panel-Dh681iO6.js} +1 -1
- package/src/web/public/assets/dir-d16q1GLe.js +3 -0
- package/src/web/public/assets/{doc-BmGb9F-k.js → doc-DRSKD0Re.js} +1 -1
- package/src/web/public/assets/group-Dc3ZgW24.js +1 -0
- package/src/web/public/assets/{index-D1wpt-oL.css → index-BIVxGd6t.css} +1 -1
- package/src/web/public/assets/index-Bg0m8gbJ.js +2 -0
- package/src/web/public/assets/{md-history-DVI47hu4.js → md-history-DNtgaIdH.js} +6 -6
- package/src/web/public/assets/{refs-P8HrKv4T.js → refs-TzxZYy7T.js} +1 -1
- package/src/web/public/assets/{repo-form-modal-BiBZ63DZ.js → repo-form-modal-Dg3hJWUV.js} +1 -1
- package/src/web/public/assets/{repos-B9D8q6U7.js → repos-uNqSR5YB.js} +1 -1
- package/src/web/public/assets/task-DuFOXLPC.js +11 -0
- package/src/web/public/assets/{task-utils-DPGXUIOk.js → task-utils-DAPxKm4c.js} +1 -1
- package/src/web/public/assets/templates-CwYDIBYn.css +1 -0
- package/src/web/public/assets/templates-DNiGvmdq.js +10 -0
- package/src/web/public/assets/{use-rail-drag-TGx8CLcY.js → use-rail-drag-DxIYcszo.js} +1 -1
- package/src/web/public/index.html +6 -7
- package/src/core/workflow/edges.ts +0 -28
- package/src/core/workflow/layout.ts +0 -118
- package/src/modules/tasktool/facade/get.ts +0 -54
- package/src/modules/tasktool/facade/index.ts +0 -4
- package/src/modules/tasktool/facade/submit.ts +0 -61
- package/src/modules/tasktool/facade/wait.ts +0 -3
- package/src/modules/tasktool/getloop.ts +0 -2
- package/src/modules/tasktool/index.ts +0 -24
- package/src/modules/tasktool/plugins/runtime.ts +0 -73
- package/src/modules/tasktool/plugins/waitgoal.ts +0 -75
- package/src/modules/tasktool/wait.ts +0 -572
- package/src/web/frontend/modules/md/fill-session.ts +0 -36
- package/src/web/frontend/modules/md/new-task-from-template.ts +0 -22
- package/src/web/frontend/modules/md/task-intent.ts +0 -29
- package/src/web/frontend/modules/prompts/render-template-body.ts +0 -14
- package/src/web/frontend/modules/prompts/template-preview.ts +0 -62
- package/src/web/frontend/page/templates/fill.tsx +0 -126
- package/src/web/public/assets/dir-D5AImCiy.js +0 -3
- package/src/web/public/assets/fill-session-fHxQHFaD.js +0 -1
- package/src/web/public/assets/group-CTktws14.js +0 -1
- package/src/web/public/assets/index-Byb7MFTl.js +0 -2
- package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +0 -1
- package/src/web/public/assets/render-template-body-bXdedFig.js +0 -1
- package/src/web/public/assets/task-BBk0TQZi.js +0 -11
- package/src/web/public/assets/task-intent-CX5DZccN.js +0 -1
- package/src/web/public/assets/templates-BN9i9-6c.js +0 -11
- package/src/web/public/assets/templates-plA8R7jJ.css +0 -1
- /package/src/modules/{tasktool → goals}/actions/_manifest.generated.ts +0 -0
- /package/src/modules/{tasktool → goals}/actions/timegoal-prune.ts +0 -0
- /package/src/modules/{tasktool → goals}/plugins/base.ts +0 -0
- /package/src/modules/{tasktool → goals}/plugins/blockgoal.ts +0 -0
- /package/src/modules/{tasktool → goals}/plugins/container.ts +0 -0
- /package/src/modules/{tasktool → goals}/plugins/taskgoal.ts +0 -0
- /package/src/modules/{tasktool → goals}/plugins/timegoal-core-store.ts +0 -0
- /package/src/modules/{tasktool → goals}/plugins/timegoal-cwd-store.ts +0 -0
- /package/src/modules/{tasktool → goals}/plugins/timegoal-store.ts +0 -0
- /package/src/modules/{tasktool → goals}/plugins/timegoal.ts +0 -0
- /package/src/modules/{tasktool → goals}/taskgoal.ts +0 -0
- /package/src/modules/{tasktool → goals}/timegoal.ts +0 -0
|
@@ -1,572 +0,0 @@
|
|
|
1
|
-
// tasktool/wait.js —— wait/get 的阻塞编排(从 localtask/service.js 整体迁入)。
|
|
2
|
-
//
|
|
3
|
-
// 边界(tasktool = 任务工具语义,localtask = 队列本体):
|
|
4
|
-
// - 队列读写、唤醒注册表、presence/面板注册表都在 localtask(serve 路由与
|
|
5
|
-
// panel-guard 的一半也长在那边),这里只做**队列编排**:快路径领取 → 阻塞窗口
|
|
6
|
-
// (跨进程轮询 / goal 到点收尾 / 用户关闭)→ 交付组装。
|
|
7
|
-
// - 面板随行(确保主面板 / 深链 / 窗口重开防风暴)已拆到 panel-escort.js——
|
|
8
|
-
// 这里只经 escortPanel({ stop() }) 一点相接。
|
|
9
|
-
// - 与队列的耦合全部走 localtask/service.js 的导出面;与计时目标的耦合走
|
|
10
|
-
// 同模块的 timegoal.js(探针只读 + 交付时刻的目标上下文)。
|
|
11
|
-
import { DEFAULT_PORT } from '../../core/paths.js';
|
|
12
|
-
import { formatGoalTiming, renderInstruction } from '../../core/instruction-template.js';
|
|
13
|
-
import { parseFrontmatter } from '../../shared/frontmatter.js';
|
|
14
|
-
import { reorderRoundsForDelivery } from '../../shared/feedback-text.js';
|
|
15
|
-
import {
|
|
16
|
-
clampTimeoutSec,
|
|
17
|
-
clearWaiting,
|
|
18
|
-
consumeCancelRequest,
|
|
19
|
-
consumeFirstPending,
|
|
20
|
-
getSettings,
|
|
21
|
-
GLOBAL_KEY,
|
|
22
|
-
isGlobalKey,
|
|
23
|
-
normalizeCwd,
|
|
24
|
-
normalizeSummary,
|
|
25
|
-
pendingQueueInfo,
|
|
26
|
-
probeEffectivePresence,
|
|
27
|
-
registerGlobalWaiter,
|
|
28
|
-
registerTopicWaiter,
|
|
29
|
-
repoContextIndex,
|
|
30
|
-
repoCtxOf,
|
|
31
|
-
setWaiting,
|
|
32
|
-
unregisterTopicWaiter,
|
|
33
|
-
} from '../localtask/service.js';
|
|
34
|
-
import { ensureMainPanel, deepLinkUrl, escortPanel } from './panel-escort.js';
|
|
35
|
-
import { ensureTaskGoal, previewTaskGoal } from './taskgoal.js';
|
|
36
|
-
import { formatDuration } from '../../core/instruction-template.js';
|
|
37
|
-
import { readGroupContext } from './groupctx.js';
|
|
38
|
-
import { annotateTaskDelivery, attachTemplateCtx } from './attach.js';
|
|
39
|
-
import { compose, type RenderTraceEntry, type SegmentMeta } from '../promptplug/compose.js';
|
|
40
|
-
import { buildPlugins } from '../promptplug/index.js';
|
|
41
|
-
import * as timegoal from './timegoal.js';
|
|
42
|
-
|
|
43
|
-
// 跨进程兜底轮询间隔(只定这里的读取节奏;队列写入节奏与它无关)
|
|
44
|
-
const POLL_MS = 500;
|
|
45
|
-
|
|
46
|
-
// 「YYYY-MM-DD HH:mm:ss」→ epoch ms(任务级 goal 的起点 = consumedAt);解析不了返回 NaN
|
|
47
|
-
function parseStampMs(v: unknown): number {
|
|
48
|
-
const m = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})$/.exec(String(v || ''));
|
|
49
|
-
if (!m) return NaN;
|
|
50
|
-
return new Date(Number(m?.[1]), Number(m?.[2]) - 1, Number(m?.[3]), Number(m?.[4]), Number(m?.[5]), Number(m?.[6])).getTime();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// goal 上下文的**时间运算字段**统一在这里补齐(任务 #82:模板层要能拿剩余/超时做运算,
|
|
54
|
-
// 不能只有人话的 remainingHuman)。目录级 show 自带 reached/remainingSec/overtimeSec;
|
|
55
|
-
// 任务级只有 deadline 戳——同式解析补算。缺哪个补哪个,已有的不覆盖。
|
|
56
|
-
export function enrichGoalTiming(g: any): any {
|
|
57
|
-
if (!g) return g;
|
|
58
|
-
let { remainingSec, overtimeSec, reached } = g;
|
|
59
|
-
remainingSec = Number(remainingSec);
|
|
60
|
-
overtimeSec = Number(overtimeSec);
|
|
61
|
-
if (!Number.isFinite(remainingSec) && !Number.isFinite(overtimeSec)) {
|
|
62
|
-
const ms = parseStampMs(g.deadline);
|
|
63
|
-
if (Number.isFinite(ms)) {
|
|
64
|
-
const diff = Math.round((ms - Date.now()) / 1000);
|
|
65
|
-
remainingSec = diff >= 0 ? diff : 0;
|
|
66
|
-
overtimeSec = diff >= 0 ? 0 : -diff;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (reached === undefined) {
|
|
70
|
-
if (Number.isFinite(overtimeSec)) reached = overtimeSec > 0;
|
|
71
|
-
else if (Number.isFinite(remainingSec)) reached = remainingSec <= 0;
|
|
72
|
-
}
|
|
73
|
-
if (Number.isFinite(remainingSec)) {
|
|
74
|
-
g.remainingSec = remainingSec;
|
|
75
|
-
g.remainingMin = Math.ceil(remainingSec / 60);
|
|
76
|
-
}
|
|
77
|
-
if (Number.isFinite(overtimeSec)) g.overtimeSec = overtimeSec;
|
|
78
|
-
if (reached !== undefined) g.reached = reached;
|
|
79
|
-
// 任务 #87:模板里要能直接写「持续 {{goal.durationHuman}}」——人话时长统一在这里补。
|
|
80
|
-
if (Number.isFinite(Number(g.durationSec)) && Number(g.durationSec) > 0) {
|
|
81
|
-
g.durationHuman = g.durationHuman || formatDuration(Number(g.durationSec));
|
|
82
|
-
}
|
|
83
|
-
if (Number.isFinite(Number(g.elapsedSec))) {
|
|
84
|
-
g.elapsedHuman = g.elapsedHuman || formatDuration(Number(g.elapsedSec));
|
|
85
|
-
}
|
|
86
|
-
return g;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ─── 时间目标探针与交付时刻的目标上下文 ──────────────────────────────
|
|
90
|
-
//
|
|
91
|
-
// 与 localtask wait 的两处融合(都 fail-open:timegoal 坏了绝不拖垮 wait):
|
|
92
|
-
// - 阻塞期间到点 → 本轮立刻收尾(goalPoll,见 waitForTask);
|
|
93
|
-
// - 返回时刻把目标状态渲染进 instruction(goal 段)。
|
|
94
|
-
// 探针按 key 服务于 500ms 轮询;上下文按 cwd 走 showTimegoal——只有它带
|
|
95
|
-
// prompt 原文与 remainingSec/overtimeSec。读取时机是**返回时刻**不是阻塞开始。
|
|
96
|
-
|
|
97
|
-
// 等待期到点探针(只读、不写盘):返回该目录目标的截止 epoch ms;已到点/无目标 → 0
|
|
98
|
-
async function readGoalDeadlineMs(key: unknown): Promise<number> {
|
|
99
|
-
if (!key || isGlobalKey(key)) return 0;
|
|
100
|
-
try {
|
|
101
|
-
const g = await timegoal.probeGoalExpiry(key);
|
|
102
|
-
if (!g || g.reached) return 0; // 已经到点的:不参与自动取消
|
|
103
|
-
const ms = Number(g.deadlineMs);
|
|
104
|
-
return Number.isFinite(ms) && ms > 0 ? ms : 0;
|
|
105
|
-
} catch {
|
|
106
|
-
return 0;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// wait/get **返回时刻**的目标上下文(渲染 instruction 用)。fail-open:加载失败 /
|
|
111
|
-
// 读不到 / 没目标 / 出错 → null,instruction 照常渲染(goal 段被整段丢弃)。
|
|
112
|
-
// 绝不写盘:showTimegoal 走 loadRecycledStore({persist:false})——timegoals.json
|
|
113
|
-
// 字节数不变,goal-expiry 单测字节比对钉着。
|
|
114
|
-
async function readGoalCtx(cwd: unknown): Promise<Record<string, any> | null> {
|
|
115
|
-
if (!cwd || isGlobalKey(cwd)) return null; // cwd 是路径,isGlobalKey 恒 false——纯防御
|
|
116
|
-
try {
|
|
117
|
-
const show = await timegoal.showTimegoal({ cwd });
|
|
118
|
-
if (!show || !show.hasGoal) return null;
|
|
119
|
-
const g = show.goal || {};
|
|
120
|
-
return {
|
|
121
|
-
name: g.name || show.name || '',
|
|
122
|
-
deadline: g.deadline || '',
|
|
123
|
-
prompt: g.prompt || '',
|
|
124
|
-
reached: !!show.reached,
|
|
125
|
-
remainingSec: show.remainingSec,
|
|
126
|
-
overtimeSec: show.overtimeSec,
|
|
127
|
-
remainingHuman: formatGoalTiming({
|
|
128
|
-
reached: show.reached,
|
|
129
|
-
remainingSec: show.remainingSec,
|
|
130
|
-
overtimeSec: show.overtimeSec,
|
|
131
|
-
}),
|
|
132
|
-
};
|
|
133
|
-
} catch {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ─── 阻塞等待:核心入口 ─────────────────────────────────────────────
|
|
139
|
-
|
|
140
|
-
// 组装 wait/get 返回的任务载荷 + 指令。**单一路径**:
|
|
141
|
-
// 所有段落(上下文 / 附件 / 时间目标 / ack / 持续 get)一律进返回载荷的
|
|
142
|
-
// instruction 字段;task.text 始终是库存原文,绝不把系统提示词拼进正文。
|
|
143
|
-
// 旧 rule 区块已删除:done 指令与收尾要求统一由 ack 区块承载。
|
|
144
|
-
// 任何异常都降级为「只回任务」——wait 绝不能因渲染挂掉(与探针同一条 fail-open 纪律)。
|
|
145
|
-
//
|
|
146
|
-
// preview / trace(任务 #65「预览 get 提示词」):
|
|
147
|
-
// preview=true → **零副作用**:不启动任务级 timegoal 计时、不写库、不领取;
|
|
148
|
-
// timegoal 的 check 指令用声明现算(与真实领取同一份)。其余渲染路径与真实领取
|
|
149
|
-
// 完全同一条代码,所以预览出来的字符串就是 agent 会拿到的那一份。
|
|
150
|
-
// trace=[] → 按顺序记下每一段的来源(谁贡献的、开关是否开着),供面板展示
|
|
151
|
-
// 「这段是哪来的」。真实领取不传 trace,行为与改造前逐字节一致。
|
|
152
|
-
export interface DeliveryOptions {
|
|
153
|
-
source?: string;
|
|
154
|
-
summary?: unknown;
|
|
155
|
-
cwd?: unknown;
|
|
156
|
-
name?: unknown;
|
|
157
|
-
topicKey?: unknown;
|
|
158
|
-
params?: Record<string, string>;
|
|
159
|
-
preview?: boolean;
|
|
160
|
-
trace?: RenderTraceEntry[];
|
|
161
|
-
getLoopTpl?: string;
|
|
162
|
-
getLoopWaitMinutes?: number;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export async function buildTaskDelivery(
|
|
166
|
-
task: any,
|
|
167
|
-
{ source, summary, cwd, name, topicKey, params, preview = false, trace, getLoopTpl = '', getLoopWaitMinutes = 0 }: DeliveryOptions = {},
|
|
168
|
-
): Promise<Record<string, any>> {
|
|
169
|
-
// 附件标注(任务 #15:正文里的  嵌入 → 附件清单 + 本地路径)。
|
|
170
|
-
// fail-open:标注失败绝不拖垮交付;正文没有引用时 annotateTaskDelivery 返回
|
|
171
|
-
// null,载荷与改造前**逐字节一致**(与 localtask 读任务的同一条纪律)。
|
|
172
|
-
let att: any = null;
|
|
173
|
-
try {
|
|
174
|
-
// inlineDocs(#162):文档资料绑定(role=doc)随交付带全文——只读盘(自有树 /
|
|
175
|
-
// 绑定闭包),预览同样安全;读不到内容留空,不阻断交付。
|
|
176
|
-
const a = await annotateTaskDelivery(task, { topicKey, inlineDocs: true });
|
|
177
|
-
if (a) {
|
|
178
|
-
task = a.task;
|
|
179
|
-
att = a;
|
|
180
|
-
}
|
|
181
|
-
} catch {
|
|
182
|
-
/* 标注失败照常交付(agent 还能从正文里的嵌入自行处理) */
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
// 任务级 timegoal(发布带 --duration):**领取即计时**——这里起表(幂等),
|
|
186
|
-
// goal 上下文换成任务级(prompt = check 指令,固化进 timegoal 存储,之后每轮原文回显)。
|
|
187
|
-
// 目录级 goal 仍作兜底:任务没带时间目标时,渲染等待方目录的目标状态。
|
|
188
|
-
let taskGoalCtx: any = null;
|
|
189
|
-
if (task && task.timegoal && topicKey) {
|
|
190
|
-
const title = (String(task.text || '')
|
|
191
|
-
.split('\n')
|
|
192
|
-
.map((l) => l.trim())
|
|
193
|
-
.find(Boolean) || `任务 #${task.id}`).slice(0, 40);
|
|
194
|
-
// 预览走只读版本:同一份 check 指令文本,但不落盘、不起表
|
|
195
|
-
taskGoalCtx = preview
|
|
196
|
-
? await previewTaskGoal({ topicKey, taskId: task.id, cwd, name: title, timegoal: task.timegoal, text: task.text })
|
|
197
|
-
: await ensureTaskGoal({
|
|
198
|
-
topicKey,
|
|
199
|
-
taskId: task.id,
|
|
200
|
-
cwd,
|
|
201
|
-
name: title,
|
|
202
|
-
text: task.text,
|
|
203
|
-
timegoal: task.timegoal,
|
|
204
|
-
startedAtMs: parseStampMs(task.consumedAt) || undefined,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
const goal = enrichGoalTiming(taskGoalCtx || (await readGoalCtx(cwd)));
|
|
208
|
-
|
|
209
|
-
// 项目组上下文(组概念 + 本项目位置 + 兄弟成员 + 参考文件地址):只进 instruction。
|
|
210
|
-
// #64 作用域:组材料只挂**组任务**(正文 frontmatter 带 board);单 repo 主题里
|
|
211
|
-
// 提交的纯项目任务只带项目介绍,不把所属组的材料挂进来。
|
|
212
|
-
const boardMark = String(parseFrontmatter(String((task && task.text) || '')).board || '').trim();
|
|
213
|
-
const groupCtx = await readGroupContext(cwd as string, { board: boardMark });
|
|
214
|
-
const settings: any = (await getSettings().catch(() => null)) || {};
|
|
215
|
-
|
|
216
|
-
// ── 插件化组装(promptplug):宿主完成领域取数,插件 data() 做同步变换 ──
|
|
217
|
-
// 任务级 goal → 完整 check 指令;目录级 goal → 状态行(二者都进 timecheck 段)。
|
|
218
|
-
const goalCheck = taskGoalCtx ? taskGoalCtx.prompt : null;
|
|
219
|
-
const goalStatus = !taskGoalCtx && goal
|
|
220
|
-
? `〔时间目标「${goal.name || ''}」${goal.remainingHuman || ''}〕`
|
|
221
|
-
: null;
|
|
222
|
-
const goalCtx = goal
|
|
223
|
-
? {
|
|
224
|
-
...goal,
|
|
225
|
-
// 任务 #87:goal.extra(附加要求,领取后可动态改)与 goalKey 供模板直接引用
|
|
226
|
-
extra: taskGoalCtx ? taskGoalCtx.extra || '' : '',
|
|
227
|
-
goalKey: taskGoalCtx ? taskGoalCtx.goalKey || '' : '',
|
|
228
|
-
check: goalCheck || '',
|
|
229
|
-
statusLine: goalStatus || '',
|
|
230
|
-
}
|
|
231
|
-
: null;
|
|
232
|
-
const attach = att ? attachTemplateCtx(att.task.attachments).attach : null;
|
|
233
|
-
|
|
234
|
-
// 「持续 get」指令模板自身也是模板(可含 {{task.id}} 等):先渲染成文本,
|
|
235
|
-
// 再由 getloop 插件放进 ctx。渲染失败记告警(不静默)。
|
|
236
|
-
// 注:渲染上下文用 seed(task / goal / cwd…)——默认指令只引用 task.id /
|
|
237
|
-
// getloop.waitMinutes;历史 baseCtx 里的 repo/attach 变量不进入项目级收尾指令。
|
|
238
|
-
const renderWarnings: { block: string; label: string; message: string }[] = [];
|
|
239
|
-
// 平面扩展(原 buildDeliveryCtx 语义):外部参数 {{k}} 顶层直接取,内建键不被覆盖
|
|
240
|
-
const flat: Record<string, unknown> = {};
|
|
241
|
-
for (const [k, v] of Object.entries(params || {})) {
|
|
242
|
-
if (['task', 'goal', 'cwd', 'source', 'summary', 'name', 'repo', 'group', 'refRepos', 'groups'].includes(k)) continue;
|
|
243
|
-
flat[k] = v;
|
|
244
|
-
}
|
|
245
|
-
const seedCtx: Record<string, any> = {
|
|
246
|
-
task: task ? { id: task.id, text: reorderRoundsForDelivery(String(task.text || '')) } : null,
|
|
247
|
-
goal: goalCtx,
|
|
248
|
-
source: source || '',
|
|
249
|
-
summary: summary || '',
|
|
250
|
-
cwd: cwd || '',
|
|
251
|
-
name: name || '',
|
|
252
|
-
params: { ...(params || {}) },
|
|
253
|
-
...flat,
|
|
254
|
-
};
|
|
255
|
-
let loopText = '';
|
|
256
|
-
if (getLoopTpl) {
|
|
257
|
-
try {
|
|
258
|
-
loopText = renderInstruction(getLoopTpl, seedCtx) || '';
|
|
259
|
-
} catch (e) {
|
|
260
|
-
renderWarnings.push({
|
|
261
|
-
block: 'getloop',
|
|
262
|
-
label: '持续 get 指令(项目级)',
|
|
263
|
-
message: String((e as Error).message || e).replace(/\s+/g, ' ').trim(),
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// ext(队列余量):同主题还有多少待领取任务 + 标题。现算(同主题一次读取);
|
|
269
|
-
// 读取失败不阻断领取:按缺失处理,并把原因记进 renderWarnings。
|
|
270
|
-
let queueInfo: { topic: string; count: number; list: { id: number; title: string }[] } | null = null;
|
|
271
|
-
try {
|
|
272
|
-
const q = await pendingQueueInfo(topicKey as string, task && task.id);
|
|
273
|
-
if (q && q.count > 0) queueInfo = { topic: q.topic, count: q.count, list: q.list };
|
|
274
|
-
} catch (e) {
|
|
275
|
-
renderWarnings.push({
|
|
276
|
-
block: 'ext',
|
|
277
|
-
label: '待领取队列(ext)',
|
|
278
|
-
message: String((e as Error).message || e).replace(/\s+/g, ' ').trim(),
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const mode: 'xml' | 'plain' = settings.appendMode === 'plain' ? 'plain' : 'xml';
|
|
283
|
-
// #152:模板是插件类的内置正文(不再从 settings 解析)。
|
|
284
|
-
// 交付一次给全三条链(get → check → done,合并后按类声明的 order 全局排序):
|
|
285
|
-
// - check(时间目标 / 进度提示)与 done(完成门禁)没有独立的注入点——
|
|
286
|
-
// 它们本来就是「领取时告诉 agent 每轮怎么检查、什么时候才能收口」,
|
|
287
|
-
// 等 agent 真去 done 再给已经晚了;三者链内都是条件渲染,无数据即不出段。
|
|
288
|
-
const plugins = [...buildPlugins('get', {
|
|
289
|
-
groupCtx: () => groupCtx,
|
|
290
|
-
attach: () => attach,
|
|
291
|
-
queueInfo: () => queueInfo,
|
|
292
|
-
loopText: () => loopText,
|
|
293
|
-
waitMinutes: () => Number(getLoopWaitMinutes) || 0,
|
|
294
|
-
}), ...buildPlugins('check'), ...buildPlugins('done')];
|
|
295
|
-
const segments: SegmentMeta[] = [
|
|
296
|
-
{ id: 'context', label: '组 / 项目上下文(模板)', traceId: 'delivery' },
|
|
297
|
-
{ id: 'attachment', label: '附件段(清单 / 本地路径)', traceId: 'attach' },
|
|
298
|
-
{ id: 'timegoal', label: '时间目标启动(介绍 / 每轮怎么做)', traceId: 'goal' },
|
|
299
|
-
{ id: 'doneguard', label: '完成门禁提示(timegoal)', traceId: 'doneguard' },
|
|
300
|
-
{ id: 'ext', label: '待领取队列(ext)', traceId: 'ext' },
|
|
301
|
-
{ id: 'ack', label: 'ack 完成总结提示词', traceId: 'ack' },
|
|
302
|
-
{ id: 'getloop', label: '持续 get 指令(项目级)', traceId: 'getloop' },
|
|
303
|
-
];
|
|
304
|
-
const full = await compose({
|
|
305
|
-
plugins,
|
|
306
|
-
groups: ['get', 'check', 'done'],
|
|
307
|
-
seed: seedCtx,
|
|
308
|
-
mode,
|
|
309
|
-
trace,
|
|
310
|
-
segments,
|
|
311
|
-
});
|
|
312
|
-
const warnField = renderWarnings.length ? { renderWarnings } : {};
|
|
313
|
-
if (!full) {
|
|
314
|
-
return { task, ...warnField };
|
|
315
|
-
}
|
|
316
|
-
// coversBody = 本次交付链的任一模板含 {{task.text}}(instruction 自包含任务正文)。
|
|
317
|
-
// 由服务端判定,避免 CLI 端做子串猜测。
|
|
318
|
-
return {
|
|
319
|
-
task,
|
|
320
|
-
instruction: full,
|
|
321
|
-
coversBody: plugins.some((p) => /\{\{\s*task\.text\s*\}\}/.test(p.get())),
|
|
322
|
-
...warnField,
|
|
323
|
-
};
|
|
324
|
-
} catch {
|
|
325
|
-
return { task };
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export interface WaitForTaskOptions {
|
|
330
|
-
/** 工作目录(主题按目录名识别);缺省 → 进程当前 cwd。显式传 cwd **不会**关闭全局兜底 */
|
|
331
|
-
cwd?: unknown;
|
|
332
|
-
/** 当前现状(#171 起不再必填:面板上没有对应输入界面) */
|
|
333
|
-
summary?: unknown;
|
|
334
|
-
/** 阻塞上限(秒);缺省 → 页面配置(推荐 180,最大 600) */
|
|
335
|
-
timeoutSec?: number;
|
|
336
|
-
/** 兼容旧参数(毫秒) */
|
|
337
|
-
timeoutMs?: number;
|
|
338
|
-
/** 是否自动打开浏览器弹窗(测试可关) */
|
|
339
|
-
open?: boolean;
|
|
340
|
-
/** 服务器就绪回调 {addr,key,cwd,name,summary}(测试/集成钩子) */
|
|
341
|
-
onReady?: (info: { addr: string; key: string; cwd: string; name: string; summary: string }) => unknown | Promise<unknown>;
|
|
342
|
-
/** 外部参数(平面扩展):进交付模板的 ctx(--param k=v) */
|
|
343
|
-
params?: Record<string, string>;
|
|
344
|
-
/** get 的「直接领」形态:没有 pending 立即空手而回,不开窗不阻塞 */
|
|
345
|
-
instant?: boolean;
|
|
346
|
-
/** 项目级「持续 get」模板(仅 get/preview 传;wait 不传 → 不出现该区块) */
|
|
347
|
-
getLoopTpl?: string;
|
|
348
|
-
/** 项目级阻塞窗口(分钟):进 getloop 模板 ctx,让 agent 知道每轮会等多久 */
|
|
349
|
-
getLoopWaitMinutes?: number;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/** 阻塞等待的唤醒结果(三个生产者 + 超时) */
|
|
353
|
-
type WaitOutcome =
|
|
354
|
-
| { kind: 'task'; task: any; delivered: boolean; source?: string }
|
|
355
|
-
| { kind: 'timeout' }
|
|
356
|
-
| { kind: 'cancelled'; reason?: string };
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* 针对某主题(工作目录)等待用户回填下一条任务。
|
|
360
|
-
* 领取顺序:本目录队列 → 全局主题(共享池)→ 阻塞(两个来源任一到达即唤醒)。
|
|
361
|
-
* 返回带 source: 'local' | 'global' 标明任务来自哪个队列。
|
|
362
|
-
*/
|
|
363
|
-
export async function waitForTask({
|
|
364
|
-
cwd: rawCwd,
|
|
365
|
-
summary: rawSummary,
|
|
366
|
-
timeoutSec,
|
|
367
|
-
timeoutMs,
|
|
368
|
-
open = true,
|
|
369
|
-
onReady,
|
|
370
|
-
params = {}, // 外部参数(平面扩展):进交付模板的 ctx(--param k=v)
|
|
371
|
-
instant = false, // get 的「直接领」形态:没有 pending 立即空手而回,不开窗不阻塞
|
|
372
|
-
getLoopTpl = '', // 项目级「持续 get」模板(仅 get/preview 传;wait 不传 → 不出现该区块)
|
|
373
|
-
getLoopWaitMinutes = 0, // 项目级阻塞窗口(分钟):进 getloop 模板 ctx,让 agent 知道每轮会等多久
|
|
374
|
-
}: WaitForTaskOptions = {}): Promise<Record<string, any>> {
|
|
375
|
-
// paths.normalizeCwd 的 @returns 标注漏了 name(运行时恒返回 {cwd, name, key})
|
|
376
|
-
const { key, cwd, name } = normalizeCwd(rawCwd as string) as { cwd: string; key: string; name: string };
|
|
377
|
-
const summary = normalizeSummary(rawSummary, { optional: true }); // #171:现状不再必填
|
|
378
|
-
// 领取方身份:记进 task.claimedBy(事后能看出"这条被谁领的")
|
|
379
|
-
const by = { key, cwd, name };
|
|
380
|
-
// 仓库上下文:这个目录属于哪个已登记仓库、周围关联哪些看板。
|
|
381
|
-
// 跟着 wait 的结果一起给出去 —— agent 领到任务就知道自己的" surroundings"。
|
|
382
|
-
const repoIndex = await repoContextIndex();
|
|
383
|
-
const repoCtx = repoCtxOf(repoIndex, cwd);
|
|
384
|
-
|
|
385
|
-
// 超时:显式 --timeout(秒/毫秒)优先;否则用页面配置;统一夹到 1-600
|
|
386
|
-
// T03:设置走 settings 表(repo/settings),不再有 JSON store 对象
|
|
387
|
-
const startSettings = await getSettings();
|
|
388
|
-
let sec: unknown;
|
|
389
|
-
if (timeoutSec !== undefined && timeoutSec !== null) sec = timeoutSec;
|
|
390
|
-
else if (timeoutMs !== undefined && timeoutMs !== null) sec = Number(timeoutMs) / 1000;
|
|
391
|
-
else sec = startSettings.timeoutSec;
|
|
392
|
-
const tmo = clampTimeoutSec(sec) * 1000;
|
|
393
|
-
|
|
394
|
-
// 1. 主题队列已有 pending → 立即取走,不开窗、不阻塞;记录本轮完成总结
|
|
395
|
-
const queued = await consumeFirstPending(key, summary, by);
|
|
396
|
-
if (queued) {
|
|
397
|
-
const delivery = await buildTaskDelivery(queued, { source: 'local', summary, cwd, name, topicKey: key, params, getLoopTpl, getLoopWaitMinutes });
|
|
398
|
-
return { status: 'ok', key, cwd, name, summary, ...delivery, queued: true, source: 'local', repo: repoCtx };
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// 1b. 本地空 → 去全局主题(共享池)领。这是所有 wait 的**无条件默认兜底**:
|
|
402
|
-
// 与是否显式传 --cwd 无关——本地取不到就一定来全局扫一眼,全局也没有才阻塞。
|
|
403
|
-
// (防止调用方习惯性传 cwd 导致共享池永远无人领取。)
|
|
404
|
-
// instant(localtask get 默认形态):两处快路径都没货 → 立即返回,不进阻塞窗口。
|
|
405
|
-
// 「无任务时唤起阻塞等待」是 waitgoal(项目 getLoop)的语义,见 tasktool/get.js。
|
|
406
|
-
if (instant) {
|
|
407
|
-
return { status: 'timeout', key, cwd, name, summary, timeoutMs: 0, instant: true };
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const fromGlobal = await consumeFirstPending(GLOBAL_KEY, summary, by);
|
|
411
|
-
if (fromGlobal) {
|
|
412
|
-
// 全局池投递渲染的仍是**等待方目录**的 goal——目标绑定在等待中的 agent 目录上,
|
|
413
|
-
// 与任务来自哪个队列无关。
|
|
414
|
-
const delivery = await buildTaskDelivery(fromGlobal, { source: 'global', summary, cwd, name, topicKey: key, params, getLoopTpl, getLoopWaitMinutes });
|
|
415
|
-
return {
|
|
416
|
-
status: 'ok',
|
|
417
|
-
key,
|
|
418
|
-
cwd,
|
|
419
|
-
name,
|
|
420
|
-
summary,
|
|
421
|
-
...delivery,
|
|
422
|
-
queued: true,
|
|
423
|
-
source: 'global',
|
|
424
|
-
repo: repoCtx,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// 1c. 这个目录的时间目标**还在跑** → 记下它的截止时刻。
|
|
429
|
-
// 等待期间一旦越过这个时刻,本轮立刻收尾(见下方 goalPoll)。
|
|
430
|
-
// 目标早就过期的(reached)不记:那是"这一局已经结束了",
|
|
431
|
-
// 该由 agent 自己的 `timegoal check` 去处理,不该把 wait 焊死在这个目录上。
|
|
432
|
-
const goalDeadlineMs = await readGoalDeadlineMs(key);
|
|
433
|
-
|
|
434
|
-
// 2. 没有 pending → 复用常驻主面板(不再起随机端口临时弹窗):
|
|
435
|
-
// a) 确保主面板在跑(不存在就 detached 拉起 serve --no-open --auto-exit);
|
|
436
|
-
// b) 探测活动 SSE 连接:有活标签就不开新页(避免 Edge 重复开标签);
|
|
437
|
-
// 没活标签就 openBrowser 深链到当前主题。
|
|
438
|
-
// 失败只降级为纯阻塞——绝不抛错中断 wait。
|
|
439
|
-
// --no-open 模式(冒烟/CI)不发起任何面板相关动作:不开浏览器、不拉起 serve、不开 SSE。
|
|
440
|
-
// 这样可避免在测试里 spawn 出一堆孤儿进程占着 7877 端口。
|
|
441
|
-
const panelInfo = open
|
|
442
|
-
? await ensureMainPanel()
|
|
443
|
-
: { running: false, started: false, port: 0, url: '' };
|
|
444
|
-
// 活性判据:「本地任务」页的活动 SSE 标签,或面板停在任意页(App 壳 ping 兜底)。
|
|
445
|
-
// 只认 SSE 的旧口径在用户切到别的页时会误判「没开」,于是每次 wait 都重开一个标签。
|
|
446
|
-
const presence = panelInfo.running ? await probeEffectivePresence() : 0;
|
|
447
|
-
const deepLink = deepLinkUrl(key, panelInfo.port || DEFAULT_PORT);
|
|
448
|
-
|
|
449
|
-
// 3. 结果承诺:三个生产者(同进程本地 waiter / 同进程全局 FIFO / 跨进程轮询)+ 超时
|
|
450
|
-
let resolveOutcome!: (r: WaitOutcome) => void;
|
|
451
|
-
const outcome = new Promise<WaitOutcome>((r) => {
|
|
452
|
-
resolveOutcome = r;
|
|
453
|
-
});
|
|
454
|
-
registerTopicWaiter(key, {
|
|
455
|
-
resolve: (task: any) => resolveOutcome({ kind: 'task', task, delivered: true }),
|
|
456
|
-
});
|
|
457
|
-
// 全局兜底:同进程有人 addTask({global:true}) 时按 FIFO 唤醒本 wait
|
|
458
|
-
const unregisterGlobal = registerGlobalWaiter(
|
|
459
|
-
(task: any) => resolveOutcome({ kind: 'task', task, delivered: true, source: 'global' }),
|
|
460
|
-
summary,
|
|
461
|
-
// by 承载 {key,cwd,name} 对象(领取后记进 task.claimedBy,见 task-ops 的 gw.by 消费);
|
|
462
|
-
// waiters 层的 by 已按 WaiterBy 标注(曾误标 string),此处直接透传
|
|
463
|
-
by
|
|
464
|
-
);
|
|
465
|
-
|
|
466
|
-
const timer = setTimeout(() => resolveOutcome({ kind: 'timeout' }), tmo);
|
|
467
|
-
|
|
468
|
-
// 三个 500ms 节拍的轮询合一为一个 ticker(原 poll/cancelPoll/goalPoll 三个 setInterval):
|
|
469
|
-
// ① 跨进程兜底轮询:先查本地,再查全局(本地优先;同轮至多 resolve 一次)
|
|
470
|
-
// ② 关闭轮询:用户在面板点了「关闭」→ 立即收尾本轮(走与超时同一条出口,只多带
|
|
471
|
-
// cancelled 标记,agent 不必认识新状态,照常结束本轮)
|
|
472
|
-
// ③ 时间目标到点 → 立刻收尾本轮(等的是"下一条任务",预算用完了就没必要等)。
|
|
473
|
-
// 与②同一条出口:status:"timeout" + cancelled:true。
|
|
474
|
-
// 只认"等待开始时还在跑"的目标(goalDeadlineMs>0)——已经过期的目标不参与。
|
|
475
|
-
// 同拍内①②各自异步,谁先 resolve 谁赢(resolveOutcome 幂等)——拆分前多个独立
|
|
476
|
-
// setInterval 的同拍相对顺序本就不保证,语义等价。unref 收尾:进程存活由 ref 的
|
|
477
|
-
// timeout timer 兜着,ticker 不必单独撑事件循环(面板窗口复查的 5s 节拍在
|
|
478
|
-
// panel-escort.js,自带起停,不并入)。
|
|
479
|
-
const ticker = setInterval(() => {
|
|
480
|
-
if (goalDeadlineMs && Date.now() >= goalDeadlineMs) {
|
|
481
|
-
resolveOutcome({ kind: 'cancelled', reason: 'goal_expired' });
|
|
482
|
-
}
|
|
483
|
-
consumeFirstPending(key, undefined, by)
|
|
484
|
-
.then((task: any) => {
|
|
485
|
-
if (task) {
|
|
486
|
-
resolveOutcome({ kind: 'task', task, delivered: false, source: 'local' });
|
|
487
|
-
return null;
|
|
488
|
-
}
|
|
489
|
-
return consumeFirstPending(GLOBAL_KEY, undefined, by);
|
|
490
|
-
})
|
|
491
|
-
.then((task: any) => {
|
|
492
|
-
if (task) resolveOutcome({ kind: 'task', task, delivered: false, source: 'global' });
|
|
493
|
-
})
|
|
494
|
-
.catch(() => {
|
|
495
|
-
/* 瞬时读写错误,下一轮再试 */
|
|
496
|
-
});
|
|
497
|
-
consumeCancelRequest(key)
|
|
498
|
-
.then((yes: any) => {
|
|
499
|
-
if (yes) resolveOutcome({ kind: 'cancelled' });
|
|
500
|
-
})
|
|
501
|
-
.catch(() => {});
|
|
502
|
-
}, POLL_MS);
|
|
503
|
-
ticker.unref?.();
|
|
504
|
-
|
|
505
|
-
// 登记「等待中」(含截止时刻与现状),面板据此显示倒计时
|
|
506
|
-
await setWaiting(key, cwd, summary, true, new Date(Date.now() + tmo));
|
|
507
|
-
|
|
508
|
-
// 登记之后再查一次关闭标记:setWaiting 刚清掉上一轮残留的标记,因此这里若有值
|
|
509
|
-
// 一定是新一次关闭请求——立刻收尾,不让用户白等。
|
|
510
|
-
if (await consumeCancelRequest(key).catch(() => false)) {
|
|
511
|
-
resolveOutcome({ kind: 'cancelled' });
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// waiter/轮询就位后再回调,保证 onReady 里立刻回填也能被接住
|
|
515
|
-
if (typeof onReady === 'function') {
|
|
516
|
-
try {
|
|
517
|
-
await onReady({ addr: deepLink, key, cwd, name, summary });
|
|
518
|
-
} catch {
|
|
519
|
-
/* 钩子异常不得影响 wait */
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// 没活标签且主面板在跑 → 开浏览器深链 + 周期复查重开(含初次开页判定)。
|
|
524
|
-
// 全部细节(节流/冷却/上限/降级)在 panel-escort.js;这里只管起停。
|
|
525
|
-
const escort = escortPanel({ open, panelInfo, deepLink, initialPresence: presence });
|
|
526
|
-
|
|
527
|
-
let result: Record<string, any>;
|
|
528
|
-
try {
|
|
529
|
-
const r = await outcome;
|
|
530
|
-
// 交付指令在**返回时刻**组装(此刻的 goal 状态才是真实状态;阻塞期间到点会渲染出已到点)。
|
|
531
|
-
// 只对拿到任务的结果生效——timeout/goal_expired/cancelled 的返回形状是钉死的契约,不动。
|
|
532
|
-
const delivery =
|
|
533
|
-
r.kind === 'task'
|
|
534
|
-
? await buildTaskDelivery(r.task, { source: r.source || 'local', summary, cwd, name, topicKey: key, params, getLoopTpl, getLoopWaitMinutes })
|
|
535
|
-
: null;
|
|
536
|
-
result =
|
|
537
|
-
r.kind === 'timeout'
|
|
538
|
-
? { status: 'timeout', key, cwd, summary, timeoutMs: tmo }
|
|
539
|
-
: r.kind === 'cancelled'
|
|
540
|
-
? {
|
|
541
|
-
status: 'timeout',
|
|
542
|
-
key,
|
|
543
|
-
cwd,
|
|
544
|
-
summary,
|
|
545
|
-
timeoutMs: tmo,
|
|
546
|
-
cancelled: true,
|
|
547
|
-
// 为什么取消:'goal_expired' = 时间目标到点、这一局预算用完;
|
|
548
|
-
// 缺省 = 用户在面板点了「关闭等待」。
|
|
549
|
-
...(r.reason ? { reason: r.reason } : {}),
|
|
550
|
-
}
|
|
551
|
-
: {
|
|
552
|
-
status: 'ok',
|
|
553
|
-
key,
|
|
554
|
-
cwd,
|
|
555
|
-
name,
|
|
556
|
-
summary,
|
|
557
|
-
...(delivery || { task: r.task }),
|
|
558
|
-
delivered: r.delivered,
|
|
559
|
-
queued: false,
|
|
560
|
-
source: r.source || 'local',
|
|
561
|
-
repo: repoCtx,
|
|
562
|
-
};
|
|
563
|
-
} finally {
|
|
564
|
-
clearInterval(ticker);
|
|
565
|
-
escort.stop();
|
|
566
|
-
clearTimeout(timer);
|
|
567
|
-
unregisterTopicWaiter(key);
|
|
568
|
-
unregisterGlobal();
|
|
569
|
-
await clearWaiting(key);
|
|
570
|
-
}
|
|
571
|
-
return result;
|
|
572
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// 参数填写页的一次性会话(#151):从「新建任务」下拉点带槽位的模板时建立,
|
|
2
|
-
// 路由只带 sessionId(#/templates/fill/<id>),上下文放这里,避免给 AppRoute 加
|
|
3
|
-
// 一堆一次性的 query 键。会话是内存态——这是中间页,刷新即丢是可接受的。
|
|
4
|
-
export interface FillSession {
|
|
5
|
-
templateId: string;
|
|
6
|
-
/** 可见域三把钥匙(用于主题级模板管理返回等,当前主要供展示) */
|
|
7
|
-
topic?: string;
|
|
8
|
-
group?: string;
|
|
9
|
-
repo?: string;
|
|
10
|
-
/** 新建落点:dirKey 开目录任务页;groupId 开组锚定页 */
|
|
11
|
-
dirKey?: string;
|
|
12
|
-
groupId?: string;
|
|
13
|
-
/** 任务正文 frontmatter 的归属(组任务路由用) */
|
|
14
|
-
board?: string;
|
|
15
|
-
project?: string;
|
|
16
|
-
/** 填完是否直接提交落库(false = 进编辑页保留草稿) */
|
|
17
|
-
submit?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let seq = 0;
|
|
21
|
-
const sessions = new Map<string, FillSession>();
|
|
22
|
-
|
|
23
|
-
export function putFillSession(session: FillSession): string {
|
|
24
|
-
seq += 1;
|
|
25
|
-
const id = `fill_${Date.now().toString(36)}_${seq}`;
|
|
26
|
-
sessions.set(id, { ...session });
|
|
27
|
-
return id;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function getFillSession(id: unknown): FillSession | undefined {
|
|
31
|
-
return sessions.get(String(id || ''));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function dropFillSession(id: unknown): void {
|
|
35
|
-
sessions.delete(String(id || ''));
|
|
36
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// 「按模板新建任务」的统一入口(#151):模板正文里有 {{槽位}} 时先去参数填写
|
|
2
|
-
// 中间页,否则直接走原来的纯文本草稿路径。目录页与组页共用这一层,避免两版
|
|
3
|
-
// 下拉又漂移(用户明确要求「以 repo 那个为准」)。
|
|
4
|
-
import { putFillSession, type FillSession } from './fill-session.js';
|
|
5
|
-
import { templateSlots } from '../prompts/template-preview.js';
|
|
6
|
-
|
|
7
|
-
interface NavApp {
|
|
8
|
-
onNavigate?: (hash: string) => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** 含有槽位 → 已转向参数页并返回 true;无槽位 → 调用方继续原来的新建路径。 */
|
|
12
|
-
export function startFillIfSlotted(
|
|
13
|
-
tpl: { id?: string; body?: unknown } | null | undefined,
|
|
14
|
-
ctx: Omit<FillSession, 'templateId'>,
|
|
15
|
-
app: NavApp,
|
|
16
|
-
): boolean {
|
|
17
|
-
const slots = templateSlots(tpl?.body);
|
|
18
|
-
if (!slots.length || !tpl?.id) return false;
|
|
19
|
-
const sessionId = putFillSession({ ...ctx, templateId: String(tpl.id) });
|
|
20
|
-
app.onNavigate?.(`#/templates/fill/${sessionId}`);
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// 参数填写页 → 任务编辑器的一次性意图(#151)。
|
|
2
|
-
//
|
|
3
|
-
// 「直接提交」按钮需要:参数页渲染出纯文本草稿 → 开任务页 → 任务页自动触发提交
|
|
4
|
-
// 落库为待领取任务。App.openPage 的 config 只认 {dirKey|groupId, task},多带字段
|
|
5
|
-
// 会被丢掉(路由反向映射也只认这套键),所以不往 config 里塞 autoSubmit 标志,
|
|
6
|
-
// 改用一个以 docId 为键的一次性 intent:参数页 set,任务页 mount 时 take(取后即删)。
|
|
7
|
-
// StrictMode 双跑 / 重复挂载都只会消费一次。
|
|
8
|
-
export interface TaskIntent {
|
|
9
|
-
/** 进页后自动触发 submit() 落库为待领取任务 */
|
|
10
|
-
submit?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const pending = new Map<string, TaskIntent>();
|
|
14
|
-
|
|
15
|
-
const keyOf = (id: unknown): string => String(id || '');
|
|
16
|
-
|
|
17
|
-
export function setTaskIntent(id: unknown, intent: TaskIntent): void {
|
|
18
|
-
const k = keyOf(id);
|
|
19
|
-
if (k) pending.set(k, { ...intent });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** 取走并清除(同一 docId 只消费一次)。 */
|
|
23
|
-
export function takeTaskIntent(id: unknown): TaskIntent | undefined {
|
|
24
|
-
const k = keyOf(id);
|
|
25
|
-
if (!k) return undefined;
|
|
26
|
-
const v = pending.get(k);
|
|
27
|
-
if (v) pending.delete(k);
|
|
28
|
-
return v;
|
|
29
|
-
}
|