nx-kv 0.66.2 → 0.67.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/CHANGELOG.md +69 -0
- package/assets/nx-kv/references/A02-/346/217/220/344/272/244/344/273/273/345/212/241.md +6 -7
- package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +1 -1
- package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +2 -2
- package/package.json +1 -1
- package/src/core/attachmentdb/ids.ts +14 -1
- package/src/core/attachmentdb/query.ts +0 -38
- package/src/core/attachmentdb/repo.ts +98 -0
- package/src/core/attachmentdb.ts +5 -1
- package/src/core/db/import-json/tasks.ts +10 -9
- package/src/core/db/import-json.ts +16 -6
- package/src/core/db/index.ts +1 -1
- package/src/core/db/migrations/index.ts +2 -0
- package/src/core/db/migrations/v15.sql +88 -0
- package/src/core/db/verify.ts +7 -3
- package/src/core/db/version.ts +4 -1
- package/src/core/topic-key.ts +5 -8
- package/src/core/workflow/readiness.ts +1 -1
- package/src/core/workflow/types.ts +1 -1
- package/src/modules/claim/assemble.ts +0 -5
- package/src/modules/claim/host.ts +2 -4
- package/src/modules/claim/preview.ts +0 -1
- package/src/modules/claim/wait.ts +9 -49
- package/src/modules/docs/actions/docs-detach.ts +1 -2
- package/src/modules/docs/attach.ts +3 -17
- package/src/modules/docs/render.ts +4 -13
- package/src/modules/localtask/actions/localtask-add.ts +1 -3
- package/src/modules/localtask/actions/localtask-attach.ts +4 -2
- package/src/modules/localtask/actions/localtask-boardtasks.ts +0 -1
- package/src/modules/localtask/actions/localtask-clone.ts +1 -1
- package/src/modules/localtask/actions/localtask-config.ts +2 -11
- package/src/modules/localtask/actions/localtask-detach.ts +1 -3
- package/src/modules/localtask/infra/events.ts +5 -5
- package/src/modules/localtask/infra/repo/rows.ts +0 -1
- package/src/modules/localtask/infra/repo/settings.ts +1 -9
- package/src/modules/localtask/infra/repo/topics.ts +0 -4
- package/src/modules/localtask/lifecycle/add.ts +2 -9
- package/src/modules/localtask/lifecycle/deletion.ts +7 -15
- package/src/modules/localtask/lifecycle/task-lifecycle.ts +2 -2
- package/src/modules/localtask/lifecycle/task-ops.ts +14 -56
- package/src/modules/localtask/lifecycle/task-templates.ts +0 -13
- package/src/modules/localtask/lifecycle/task-view.ts +2 -3
- package/src/modules/localtask/lifecycle/topics.ts +3 -8
- package/src/modules/localtask/ops/attach-resource.ts +46 -4
- package/src/modules/localtask/ops/attach-template.ts +73 -3
- package/src/modules/localtask/ops/attach.ts +45 -18
- package/src/modules/localtask/paths.ts +7 -17
- package/src/modules/localtask/service.ts +3 -7
- package/src/modules/localtask/ui/action-flags.ts +2 -2
- package/src/modules/localtask/ui/action-render.ts +7 -19
- package/src/modules/localtask/waiting.ts +1 -8
- package/src/modules/promptplug/compose.ts +1 -3
- package/src/modules/promptplug/plugins/attachment.ts +56 -6
- package/src/modules/promptplug/plugins/context.ts +11 -2
- package/src/modules/promptplug/template-store.ts +25 -3
- package/src/modules/templates/scope.ts +1 -1
- package/src/shared/prompt-blocks.ts +2 -23
- package/src/web/frontend/App.tsx +4 -9
- package/src/web/frontend/api/cli-tree.json +6 -6
- package/src/web/frontend/api/client.generated.ts +11 -11
- package/src/web/frontend/api/tasks.ts +117 -0
- package/src/web/frontend/components/Introduction/index.tsx +50 -3
- package/src/web/frontend/components/Introduction/style.css +6 -0
- package/src/web/frontend/components/Introduction/use-intro.ts +25 -0
- package/src/web/frontend/components/md/attachments/attach-area.tsx +9 -11
- package/src/web/frontend/components/md/attachments/attach-common.ts +12 -5
- package/src/web/frontend/components/md/attachments/attach-modal.tsx +54 -9
- package/src/web/frontend/components/md/attachments/attach-repo-pick.tsx +48 -0
- package/src/web/frontend/components/sidebar/index.tsx +52 -48
- package/src/web/frontend/components/sidebar/model.ts +16 -32
- package/src/web/frontend/components/sidebar/queue-nav.ts +3 -4
- package/src/web/frontend/components/sidebar/row-menu.tsx +1 -1
- package/src/web/frontend/components/sidebar/task-children.tsx +53 -32
- package/src/web/frontend/{page/dir → components/task-panel}/dag-editor.tsx +1 -1
- package/src/web/frontend/components/task-panel/task-ops.ts +299 -0
- package/src/web/frontend/components/task-panel/task-page.tsx +495 -0
- package/src/web/frontend/components/tool-acts/modules.ts +3 -0
- package/src/web/frontend/modules/board/board-view.ts +2 -56
- package/src/web/frontend/modules/md/doc-store.ts +2 -3
- package/src/web/frontend/page/dag/head-bar.tsx +0 -1
- package/src/web/frontend/page/dag/index.tsx +1 -4
- package/src/web/frontend/page/dag/model.ts +0 -1
- package/src/web/frontend/page/dir/api.ts +4 -108
- package/src/web/frontend/page/dir/index.tsx +161 -348
- package/src/web/frontend/page/dir/task-actions.ts +20 -32
- package/src/web/frontend/page/dir/task-board-section.tsx +3 -0
- package/src/web/frontend/page/dir/task-chain.ts +6 -10
- package/src/web/frontend/page/dir/task-dock-panel.tsx +3 -6
- package/src/web/frontend/page/dir/task-feedback.ts +9 -17
- package/src/web/frontend/page/dir/task-not-found.tsx +2 -3
- package/src/web/frontend/page/dir/task-utils.ts +0 -1
- package/src/web/frontend/page/dir/task.tsx +14 -18
- package/src/web/frontend/page/doc/doc-dock.tsx +1 -1
- package/src/web/frontend/page/group/api.ts +3 -21
- package/src/web/frontend/page/group/group-project-memo.ts +41 -0
- package/src/web/frontend/page/group/index.tsx +289 -429
- package/src/web/frontend/page/progress/index.tsx +7 -12
- package/src/web/frontend/page/settings/api.ts +1 -2
- package/src/web/frontend/page/settings/prompt-templates-section.tsx +12 -44
- package/src/web/frontend/panels.tsx +1 -1
- package/src/web/frontend/registry.ts +1 -2
- package/src/web/frontend/route-map.ts +0 -1
- package/src/web/frontend/routes/dir.ts +1 -4
- package/src/web/frontend/routes/keys.ts +5 -3
- package/src/web/frontend/svghub/catalog-nav.ts +8 -11
- package/src/web/public/assets/app-context-CngKv8Tc.js +1 -0
- package/src/web/public/assets/{bar-Dy_QDX2h.js → bar-C0Q_Qe4z.js} +1 -1
- package/src/web/public/assets/board-view-C8OQhkyi.js +1 -0
- package/src/web/public/assets/{button-3JlUeln_.js → button-Cs6w2CDi.js} +1 -1
- package/src/web/public/assets/{composer-launch-B7DH53Yf.js → composer-launch-BF3_hyn5.js} +1 -1
- package/src/web/public/assets/{composer-panel-Cj1J16r-.js → composer-panel-D6vBrzCs.js} +1 -1
- package/src/web/public/assets/{dag-DXRPHVl8.js → dag-CZF6sV2_.js} +1 -1
- package/src/web/public/assets/dir-6RhnWw1E.js +1 -0
- package/src/web/public/assets/doc-CVIVBV6n.js +6 -0
- package/src/web/public/assets/doc-DgYKv2wo.css +1 -0
- package/src/web/public/assets/group-AF62Z-_G.js +1 -0
- package/src/web/public/assets/group-project-memo-G-O6sPRw.js +1 -0
- package/src/web/public/assets/index-Bposj22Z.js +3 -0
- package/src/web/public/assets/{list-filter-CWxiOSg_.js → list-search-DFvFY408.js} +1 -1
- package/src/web/public/assets/md-history-COQu16vy.js +47 -0
- package/src/web/public/assets/{member-picker-BZgE3HGb.js → member-picker-CHX0nS0O.js} +1 -1
- package/src/web/public/assets/popup-dBtYqEM1.js +1 -0
- package/src/web/public/assets/progress-CDh6DY7g.js +3 -0
- package/src/web/public/assets/refs-t79ynSY8.js +2 -0
- package/src/web/public/assets/reopen-text-B2d9SZi0.js +13 -0
- package/src/web/public/assets/{repo-form-modal-CNLYR12c.js → repo-form-modal-dZqpHyUj.js} +1 -1
- package/src/web/public/assets/{repos-BGx-yAXd.js → repos-DdhOQJqF.js} +9 -9
- package/src/web/public/assets/{route-crumb-DX9C4jmQ.js → route-crumb-BKq2jry0.js} +1 -1
- package/src/web/public/assets/settings-Bk3clN2f.js +1 -0
- package/src/web/public/assets/task-C8nax2rT.js +13 -0
- package/src/web/public/assets/task-ops-D6E_TgEC.js +2 -0
- package/src/web/public/assets/task-utils-Dh33OFKe.js +1 -0
- package/src/web/public/assets/{templates-Co1Qb1aA.js → templates-Dusbff7Z.js} +3 -3
- package/src/web/public/assets/{tool-bar-D5wLBLRl.js → tool-bar-DPXnjdQF.js} +2 -2
- package/src/web/public/assets/use-rail-drag-B6J0iqFK.js +1 -0
- package/src/web/public/index.html +13 -13
- package/src/web/frontend/page/dir/landing.tsx +0 -553
- package/src/web/public/assets/app-context-BqCBcDsx.js +0 -1
- package/src/web/public/assets/board-view-Cm8189wG.js +0 -1
- package/src/web/public/assets/dir-_M1ciSxM.js +0 -3
- package/src/web/public/assets/doc-Iuxssa-b.css +0 -1
- package/src/web/public/assets/doc-_iteSM2X.js +0 -6
- package/src/web/public/assets/get-loop-modal-DlAfqJMz.js +0 -2
- package/src/web/public/assets/group-CH8qe-eg.js +0 -1
- package/src/web/public/assets/index-Cui4IuGj.js +0 -3
- package/src/web/public/assets/md-history-Bj790fdn.js +0 -46
- package/src/web/public/assets/popup-DZ2Khv2c.js +0 -1
- package/src/web/public/assets/progress-MPse2JLQ.js +0 -3
- package/src/web/public/assets/refs-DiIPoqnJ.js +0 -2
- package/src/web/public/assets/settings-Pt4YgGdY.js +0 -1
- package/src/web/public/assets/task-DOIIpQ4X.js +0 -13
- package/src/web/public/assets/task-utils-CJfMODCP.js +0 -13
- package/src/web/public/assets/use-rail-drag-CNOHXWng.js +0 -1
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import { db, txw } from './open.js';
|
|
4
4
|
import { nowMs, msToStamp } from '../../../../core/db/time.js';
|
|
5
|
-
import { GLOBAL_TOPIC_KEY } from '../../../../core/topic-key.js';
|
|
6
5
|
import { TOPIC_EXT, parseExt, jsonText } from './rows.js';
|
|
7
6
|
import { listTaskRowsByTopic, listAllTaskRows } from './tasks.js';
|
|
8
7
|
import type { DbApi } from '../../../../core/db/driver.js';
|
|
@@ -38,7 +37,6 @@ export interface TopicObject {
|
|
|
38
37
|
waitingUntilMs: number;
|
|
39
38
|
waitingSince: string;
|
|
40
39
|
cancelRequested: boolean;
|
|
41
|
-
isGlobal: boolean;
|
|
42
40
|
ext: Record<string, any>;
|
|
43
41
|
tasks: TaskObject[];
|
|
44
42
|
}
|
|
@@ -63,7 +61,6 @@ export function ensureTopic(key: string, { cwd = '', name = '' }: { cwd?: string
|
|
|
63
61
|
let row: any = conn.get('SELECT id, cwd, name, ext, deleted_at FROM topics WHERE key = :key', { key });
|
|
64
62
|
if (!row) {
|
|
65
63
|
const ext: Record<string, any> = {};
|
|
66
|
-
if (key === GLOBAL_TOPIC_KEY) ext[TOPIC_EXT.GLOBAL] = 1;
|
|
67
64
|
conn.run(
|
|
68
65
|
`INSERT INTO topics (key, repo_key, cwd, group_key, name, next_seq, ext, state, version,
|
|
69
66
|
deleted_at, created_at, updated_at)
|
|
@@ -177,7 +174,6 @@ function assembleTopic(conn: DbApi, row: TopicRow, preloaded: { tasks: TaskObjec
|
|
|
177
174
|
waitingSince: presence && Number(presence.since_ms) > 0 ? msToStamp(Number(presence.since_ms)) : '',
|
|
178
175
|
// cwds(见过的路径)保持 JSON 形状:库里只有主 cwd,历史路径不再有地方放(T03 简化)
|
|
179
176
|
cancelRequested: !!(presence && presence.cancel_requested),
|
|
180
|
-
isGlobal: String(row.key) === GLOBAL_TOPIC_KEY,
|
|
181
177
|
ext,
|
|
182
178
|
tasks: ordered,
|
|
183
179
|
};
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
//
|
|
15
15
|
// 至此三个任务动词(领 get / 等 wait / 派 add)同构:action 层一律一行委托,
|
|
16
16
|
// 编排住在本域(add.js / update.js),队列本体只有 service.js 一处。
|
|
17
|
-
import { badInput } from '../../../core/errors.js';
|
|
18
17
|
import { addTask, normalizeCwd } from '../service.js';
|
|
19
18
|
import { applyGroupFields, parseFrontmatter } from '../../../shared/frontmatter.js';
|
|
20
19
|
import { resolveGroupTarget } from '../ops/board-target.js';
|
|
@@ -47,7 +46,6 @@ export interface SubmitTaskOptions {
|
|
|
47
46
|
* 派任务统一入口。
|
|
48
47
|
*
|
|
49
48
|
* 落点与归属的口径(**归属决定落点,目录不参与归属推断**):
|
|
50
|
-
* 1. 显式 `--global` → 全局共享池(--cwd 被忽略;与 --board/--project 互斥);
|
|
51
49
|
* 2. 显式 `--board` / `--project` → 严格口径:resolveGroupTarget 校验(组要配项目、
|
|
52
50
|
* 项目须是组成员、--cwd 与 --project 不一致直接报错),
|
|
53
51
|
* frontmatter 统一落字段,落点 = 项目登记路径;
|
|
@@ -63,7 +61,6 @@ export async function submitTask({
|
|
|
63
61
|
text: rawText,
|
|
64
62
|
cwd: rawCwd,
|
|
65
63
|
summary,
|
|
66
|
-
global: toGlobal = false,
|
|
67
64
|
board,
|
|
68
65
|
project,
|
|
69
66
|
duration,
|
|
@@ -80,9 +77,6 @@ export async function submitTask({
|
|
|
80
77
|
const timegoal = duration || goalPrompt ? { duration, prompt: goalPrompt } : undefined;
|
|
81
78
|
|
|
82
79
|
if (board || project) {
|
|
83
|
-
if (toGlobal) {
|
|
84
|
-
throw badInput('--global 不能与 --board/--project 同时给:全局池没有工作组/项目归属');
|
|
85
|
-
}
|
|
86
80
|
// --cwd **只在显式给了**时才参与校验(须与 --project 指向同一个项目)。
|
|
87
81
|
// 没给就留空:不能拿「进程当前目录」去跟项目比对——在别的仓库里执行
|
|
88
82
|
// `--project alpha` 是完全正常的用法(给了 --project 就不用再给 --cwd)。
|
|
@@ -105,8 +99,8 @@ export async function submitTask({
|
|
|
105
99
|
text = applyGroupFields(text, target.fields as Record<string, unknown>);
|
|
106
100
|
// 落点跟到解析出的项目队列——**只在调用方没显式给 cwd 时**:显式意图优先,
|
|
107
101
|
// 不静默挪窝(与严格口径「cwd 与 project 冲突直接报错」同一精神,fail-open 只是
|
|
108
|
-
//
|
|
109
|
-
if (target.cwd && !rawCwd
|
|
102
|
+
// 不拦任务,不是替调用方改主意)。
|
|
103
|
+
if (target.cwd && !rawCwd) cwd = target.cwd;
|
|
110
104
|
} catch {
|
|
111
105
|
/* 保留原正文与调用方落点 */
|
|
112
106
|
}
|
|
@@ -118,7 +112,6 @@ export async function submitTask({
|
|
|
118
112
|
text,
|
|
119
113
|
cwd,
|
|
120
114
|
summary,
|
|
121
|
-
global: toGlobal,
|
|
122
115
|
timegoal,
|
|
123
116
|
blockBy,
|
|
124
117
|
blocksFollowing: !!blocksFollowing,
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// (#54 自 service.js 拆出)主题删除:四条删除路径共用的同一套判定(deleteGuard:
|
|
2
|
-
//
|
|
2
|
+
// 等待中/有未领取 → 需 --force)+ 单个/批量删除。
|
|
3
3
|
//
|
|
4
4
|
// 删除 = 软删 topics 行(deleted_at 打标;任务/依赖/presence 保留,同名目录再出现即恢复)。
|
|
5
|
-
// 全局池例外:同一个 key 永远会再出现,软删会被下一次 ensureTopic 复活成「没删掉」,
|
|
6
|
-
// 所以 force 清空全局池走真删(FK 级联清任务)。
|
|
7
5
|
import { badInput } from '../../../core/errors.js';
|
|
8
|
-
import {
|
|
6
|
+
import { normalizeCwd, resolveTopicKey } from '../paths.js';
|
|
9
7
|
import { openLocaltaskStore as openStore, topics as topicsRepo } from '../infra/repo/index.js';
|
|
10
8
|
import { isLiveWaiting, isPending, topicView } from './task-view.js';
|
|
11
9
|
// ─── 删除判定:四条删除路径共用同一套规则 ──────────────────────────────
|
|
@@ -21,7 +19,7 @@ import { isLiveWaiting, isPending, topicView } from './task-view.js';
|
|
|
21
19
|
//
|
|
22
20
|
// force=true 仍然强删(老用法不变)。
|
|
23
21
|
export const DELETE_REASONS = {
|
|
24
|
-
protected: '
|
|
22
|
+
protected: '受保护',
|
|
25
23
|
waiting: '等待中',
|
|
26
24
|
has_pending: '有未领取任务',
|
|
27
25
|
manual: '手动登记',
|
|
@@ -44,11 +42,6 @@ export type DeleteGuardResult =
|
|
|
44
42
|
* @returns {{ok:boolean, reason?:string, pending?:number, message?:string}}
|
|
45
43
|
*/
|
|
46
44
|
export function deleteGuard(topic: any, { force = false, key = '', scope = 'topic' }: DeleteGuardOptions = {}): DeleteGuardResult {
|
|
47
|
-
if (isGlobalKey(key)) {
|
|
48
|
-
return force
|
|
49
|
-
? { ok: true }
|
|
50
|
-
: { ok: false, reason: 'protected', message: '全局主题是共享任务池,默认不能删除(确认要清空请加 --force)' };
|
|
51
|
-
}
|
|
52
45
|
if (isLiveWaiting(topic)) {
|
|
53
46
|
return force
|
|
54
47
|
? { ok: true }
|
|
@@ -96,8 +89,7 @@ export interface RemoveTopicResult {
|
|
|
96
89
|
|
|
97
90
|
// 删除整个主题(连同其全部任务)。默认拒绝删除「等待中」主题——那会让正阻塞的
|
|
98
91
|
// agent 只能等到超时;force=true 才强删(agent 随后超时收尾)。
|
|
99
|
-
|
|
100
|
-
// force=true 清空全局任务池。
|
|
92
|
+
|
|
101
93
|
export async function removeTopic({ cwd: rawCwd, key: rawKey, force = false }: RemoveTopicInput = {}): Promise<RemoveTopicResult> {
|
|
102
94
|
if (!rawKey && !rawCwd) {
|
|
103
95
|
throw badInput('需要 --cwd "<工作目录>" 或 --key "<主题key>"');
|
|
@@ -109,11 +101,11 @@ export async function removeTopic({ cwd: rawCwd, key: rawKey, force = false }: R
|
|
|
109
101
|
const { notFound } = await import('../../../core/errors.js');
|
|
110
102
|
throw notFound(`主题不存在(key ${key})`);
|
|
111
103
|
}
|
|
112
|
-
// 删除判定只写一份(deleteGuard
|
|
104
|
+
// 删除判定只写一份(deleteGuard):等待中 / 有未领取任务 → 都要 --force。
|
|
113
105
|
const guard = deleteGuard(t, { force, key });
|
|
114
106
|
if (!guard.ok) throw badInput(guard.message);
|
|
115
107
|
const view = topicView(t);
|
|
116
|
-
topicsRepo.deleteTopic(key, { purge:
|
|
108
|
+
topicsRepo.deleteTopic(key, { purge: false });
|
|
117
109
|
return { status: 'removed', key, name: t.name, cwd: t.cwd, topic: view };
|
|
118
110
|
}
|
|
119
111
|
|
|
@@ -164,6 +156,6 @@ export async function removeTopics({ keys, cwds, all = false, force = false }: R
|
|
|
164
156
|
}
|
|
165
157
|
removed.push({ key, name: t.name, cwd: t.cwd });
|
|
166
158
|
}
|
|
167
|
-
for (const r of removed) topicsRepo.deleteTopic(r.key, { purge:
|
|
159
|
+
for (const r of removed) topicsRepo.deleteTopic(r.key, { purge: false });
|
|
168
160
|
return { status: 'ok', all: !!all, count: removed.length, removed, skipped };
|
|
169
161
|
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from '../../../shared/feedback-text.js';
|
|
15
15
|
import { findFirstReadyPending } from '../dag.js';
|
|
16
16
|
import { basename } from 'node:path';
|
|
17
|
-
import {
|
|
17
|
+
import { resolveTaskKey, topicKeyFor } from '../paths.js';
|
|
18
18
|
import { normalizeSummary, normalizeText, stampNow } from '../infra/store-io.js';
|
|
19
19
|
import { normalizeTask, foreignResolver, isPending } from './task-view.js';
|
|
20
20
|
import {
|
|
@@ -295,7 +295,7 @@ export async function claimFirstPending(key: string, roundSummary?: string, by?:
|
|
|
295
295
|
const claimed = tx(() =>
|
|
296
296
|
tasksRepo.claimTask(t.id, task.id, {
|
|
297
297
|
summary: roundSummary || t.summary || '',
|
|
298
|
-
from:
|
|
298
|
+
from: 'local',
|
|
299
299
|
byKey: by?.key,
|
|
300
300
|
byName: by?.name,
|
|
301
301
|
})
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// (#54 自 service.js 拆出)单条任务的查/增/改:getTask、addTask(waiter 唤醒链 +
|
|
2
|
-
//
|
|
2
|
+
// 投递与唤醒)、updateTask(正文/时间目标/DAG 依赖/改归属搬家)。
|
|
3
3
|
import { badInput, notFound } from '../../../core/errors.js';
|
|
4
4
|
import { parseFrontmatter, preserveFrontmatter } from '../../../shared/frontmatter.js';
|
|
5
5
|
import { sanitizeTaskGoal } from '../../goals/taskgoal.js';
|
|
6
6
|
import { normalizeBlockBy, isReadyToClaim } from '../dag.js';
|
|
7
7
|
import { MAX_TEXT, normalizeSummary, normalizeText } from '../infra/store-io.js';
|
|
8
8
|
import { openLocaltaskStore as openStore, topics as topicsRepo, tasks as tasksRepo, links as linksRepo, txw as tx, db } from '../infra/repo/index.js';
|
|
9
|
-
import {
|
|
9
|
+
import { normalizeCwd, resolveTaskKey, topicKeyFor } from '../paths.js';
|
|
10
10
|
import { normalizeTask, foreignResolver, queueRelationsOf, relocateTask, resolveForkRef } from './task-view.js';
|
|
11
|
-
import { takeTopicWaiter
|
|
11
|
+
import { takeTopicWaiter } from '../waiters.js';
|
|
12
12
|
import { presence as presenceRepo } from '../infra/repo/index.js';
|
|
13
13
|
|
|
14
14
|
/** 任务寻址入参(--cwd/--key + --id)。 */
|
|
@@ -77,15 +77,13 @@ export async function getTask({ cwd: rawCwd, key: rawKey, id }: TaskAddress = {}
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
81
|
-
* 若本进程正有 wait
|
|
82
|
-
* 全局投递的唤醒链:显式 wait 全局 key 者(罕见)→ globalWaiters FIFO → 入队。
|
|
80
|
+
* 向某主题(工作目录)的队列回填任务(#190 起只有目录队列,没有全局共享池)。
|
|
81
|
+
* 若本进程正有 wait 在等该主题 → 直接投递并唤醒;否则入队堆积。
|
|
83
82
|
*/
|
|
84
83
|
export async function addTask({
|
|
85
84
|
cwd: rawCwd,
|
|
86
85
|
summary: rawSummary,
|
|
87
86
|
text,
|
|
88
|
-
global: toGlobal = false,
|
|
89
87
|
timegoal: rawGoal,
|
|
90
88
|
blockBy: rawBlockBy,
|
|
91
89
|
blocksFollowing = false,
|
|
@@ -103,22 +101,9 @@ export async function addTask({
|
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
openStore();
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (toGlobal) {
|
|
110
|
-
// 全局主题:cwd 恒空、名字固定;--cwd 显式给出也忽略(--global 优先)。
|
|
111
|
-
// 但**不静默**:被忽略的 cwd 会在返回值里带出来(ignoredCwd),
|
|
112
|
-
// 由 CLI/面板如实告诉用户"你给的目录没生效,任务进了全局池"。
|
|
113
|
-
// (gh/kubectl 遇到矛盾参数会直接报错;这里为了不打断既有脚本,
|
|
114
|
-
// 选择"照做 + 明说",而不是改语义。)
|
|
115
|
-
key = GLOBAL_KEY;
|
|
116
|
-
cwd = GLOBAL_CWD;
|
|
117
|
-
t = topicsRepo.ensureTopic(key, { cwd, name: GLOBAL_NAME });
|
|
118
|
-
} else {
|
|
119
|
-
({ key, cwd } = normalizeCwd(rawCwd));
|
|
120
|
-
t = topicsRepo.ensureTopic(key, { cwd });
|
|
121
|
-
}
|
|
104
|
+
// #190:只有目录队列。rawCwd 缺省时由 normalizeCwd 落到当前进程工作目录。
|
|
105
|
+
const { key, cwd } = normalizeCwd(rawCwd);
|
|
106
|
+
const t: { id: number; name: string; summary?: string } = topicsRepo.ensureTopic(key, { cwd });
|
|
122
107
|
const tView = topicsRepo.getTopic(key)!;
|
|
123
108
|
|
|
124
109
|
// 编号只在插入的同一个事务里取(insertTask 用 UPDATE ... RETURNING)。
|
|
@@ -165,26 +150,7 @@ export async function addTask({
|
|
|
165
150
|
const probe = normalizeTask({ ...taskDraft, id: provisionalId }, tView.tasks, readyOpts);
|
|
166
151
|
const canDeliver = isReadyToClaim(probe, tView.tasks, readyOpts);
|
|
167
152
|
|
|
168
|
-
if (canDeliver
|
|
169
|
-
const direct = takeTopicWaiter(GLOBAL_KEY); // 显式等全局 key 的(罕见路径)
|
|
170
|
-
if (direct) {
|
|
171
|
-
wakeMeta = { summary: tView.summary || '', from: 'global', byKey: GLOBAL_KEY, byName: GLOBAL_NAME, wake: direct.resolve };
|
|
172
|
-
delivered = true;
|
|
173
|
-
} else {
|
|
174
|
-
const gw = takeGlobalWaiter(); // FIFO:最早阻塞的先领
|
|
175
|
-
if (gw) {
|
|
176
|
-
wakeMeta = {
|
|
177
|
-
// roundSummary 记领取方 wait 的现状;claimedBy 记领取方是谁
|
|
178
|
-
summary: gw.summary,
|
|
179
|
-
from: 'global',
|
|
180
|
-
byKey: gw.by?.key,
|
|
181
|
-
byName: gw.by?.name,
|
|
182
|
-
wake: gw.onTask,
|
|
183
|
-
};
|
|
184
|
-
delivered = true;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} else if (canDeliver) {
|
|
153
|
+
if (canDeliver) {
|
|
188
154
|
const waiter = takeTopicWaiter(key);
|
|
189
155
|
if (waiter) {
|
|
190
156
|
wakeMeta = { summary: tView.summary || '', from: 'local', byKey: key, byName: tView.name, wake: waiter.resolve };
|
|
@@ -245,7 +211,7 @@ export async function addTask({
|
|
|
245
211
|
if (wakeMeta && wakeMeta.wake) wakeMeta.wake(normalizeTask(task));
|
|
246
212
|
|
|
247
213
|
// DAG 单一写路径:闸门/依赖经 Mutator 投影(fail-open,不挡入队)
|
|
248
|
-
if (
|
|
214
|
+
if (task.blocksFollowing || (task.blockBy && task.blockBy.length)) {
|
|
249
215
|
try {
|
|
250
216
|
const { syncNewTaskDag } = await import('../infra/writes.js');
|
|
251
217
|
await syncNewTaskDag(key, task);
|
|
@@ -260,10 +226,6 @@ export async function addTask({
|
|
|
260
226
|
cwd,
|
|
261
227
|
name: t.name,
|
|
262
228
|
summary: t.summary,
|
|
263
|
-
isGlobal: toGlobal,
|
|
264
|
-
// --global 与 --cwd 同时给时,cwd 被忽略(--global 优先)。不静默:
|
|
265
|
-
// 把被忽略的那个带出来,让调用方能如实告诉用户"任务进了全局池,不是你给的目录"。
|
|
266
|
-
ignoredCwd: toGlobal && rawCwd && String(rawCwd).trim() ? String(rawCwd).trim() : '',
|
|
267
229
|
// key 一并回带:附件标注按 (topic.key, seq) 查 task_attach(与 getTask 同一口径)。
|
|
268
230
|
task: { ...normalizeTask(task), key },
|
|
269
231
|
delivered,
|
|
@@ -360,7 +322,7 @@ export async function updateTask({
|
|
|
360
322
|
);
|
|
361
323
|
}
|
|
362
324
|
// 搬家必须与后面的正文/目标写入同事务:搬到一半再抛错,就是「任务凭空消失」。
|
|
363
|
-
if (movable
|
|
325
|
+
if (movable) {
|
|
364
326
|
const movedTo = relocateTask(t, want, moveTo);
|
|
365
327
|
if (movedTo) {
|
|
366
328
|
host = movedTo.topic;
|
|
@@ -444,7 +406,7 @@ export async function updateTask({
|
|
|
444
406
|
* - 不写 forkOf / forkKind——克隆没有「从哪来」的语义,就是拿内容当模板开新活;
|
|
445
407
|
* - 不继承 timegoal / blockBy / blocksFollowing——约束跟着活走,克隆是新的一件;
|
|
446
408
|
* - 源任务一个字不动(不归档、不改状态)——clone 之后两条并存。
|
|
447
|
-
*
|
|
409
|
+
* 落点:同主题。正文带 frontmatter 时走 addTask 既有口径
|
|
448
410
|
* (归属 fail-open、落点跟项目队列)。
|
|
449
411
|
*/
|
|
450
412
|
export async function cloneTask({ cwd: rawCwd, key: rawKey, id }: TaskAddress = {}): Promise<Record<string, any>> {
|
|
@@ -456,11 +418,9 @@ export async function cloneTask({ cwd: rawCwd, key: rawKey, id }: TaskAddress =
|
|
|
456
418
|
if (!t) throw notFound('主题不存在: ' + key);
|
|
457
419
|
const src = (t.tasks || []).find((x: any) => Number(x.id) === want && !x.deletedAt && !x.migratedTo);
|
|
458
420
|
if (!src) throw notFound('任务不存在或已删除: #' + want);
|
|
459
|
-
const toGlobal = isGlobalKey(key);
|
|
460
421
|
const res = await addTask({
|
|
461
422
|
text: src.text,
|
|
462
|
-
|
|
463
|
-
cwd: toGlobal ? undefined : t.cwd || rawCwd,
|
|
423
|
+
cwd: t.cwd || rawCwd,
|
|
464
424
|
});
|
|
465
425
|
return { ...res, cloned: true, from: { key, id: want } };
|
|
466
426
|
}
|
|
@@ -482,11 +442,9 @@ export async function forkTask({ cwd: rawCwd, key: rawKey, id }: TaskAddress = {
|
|
|
482
442
|
if (!t) throw notFound('主题不存在: ' + key);
|
|
483
443
|
const src = (t.tasks || []).find((x: any) => Number(x.id) === want && !x.deletedAt && !x.migratedTo);
|
|
484
444
|
if (!src) throw notFound('任务不存在或已删除: #' + want);
|
|
485
|
-
const toGlobal = isGlobalKey(key);
|
|
486
445
|
const res = await addTask({
|
|
487
446
|
text: src.text,
|
|
488
|
-
|
|
489
|
-
cwd: toGlobal ? undefined : t.cwd || rawCwd,
|
|
447
|
+
cwd: t.cwd || rawCwd,
|
|
490
448
|
// 跨主题也拼成 'key:id',父任务定位与 reopen 同一条链路
|
|
491
449
|
forkOf: `${key}:${want}`,
|
|
492
450
|
forkKind: 'fork',
|
|
@@ -13,8 +13,6 @@ export const DEFAULT_ACK_PROMPT =
|
|
|
13
13
|
'完成之后必须调用 nx-kv localtask done --id {{task.id}} --summary "<完成总结>" 汇报结果。';
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
-
DEFAULT_APPEND_MODE,
|
|
17
|
-
APPEND_MODES,
|
|
18
16
|
} from '../../../shared/prompt-blocks.js';
|
|
19
17
|
|
|
20
18
|
/** 交付上下文模板(任务 #62)的长度上限——防把整本书塞进设置。 */
|
|
@@ -68,14 +66,3 @@ export function joinAckPrompt(v: unknown): string {
|
|
|
68
66
|
return clampAckPromptList(v).join('\n\n');
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
// ─── 系统上下文追加模式 + XML 区块配置(settings 两键)───────────────
|
|
72
|
-
//
|
|
73
|
-
// appendMode:'xml'(默认,每段包独立标签)| 'plain'(改造前按空行直拼)。
|
|
74
|
-
// 每个区块的模板正文在插件类里(modules/promptplug/plugins/*.ts),不再有落库模型。
|
|
75
|
-
export const APPEND_MODE_IDS = Object.freeze(APPEND_MODES.map((m) => m.id));
|
|
76
|
-
|
|
77
|
-
/** 归一化追加模式:缺省/非法 → xml(默认足够清晰)。 */
|
|
78
|
-
export function clampAppendMode(v: unknown): string {
|
|
79
|
-
const s = String(v ?? '').trim();
|
|
80
|
-
return APPEND_MODE_IDS.includes(s) ? s : DEFAULT_APPEND_MODE;
|
|
81
|
-
}
|
|
@@ -5,7 +5,7 @@ import { existsSync } from 'node:fs';
|
|
|
5
5
|
import { badInput, notFound } from '../../../core/errors.js';
|
|
6
6
|
import { sanitizeTaskGoal } from '../../goals/taskgoal.js';
|
|
7
7
|
import { normalizeBlockBy, isReadyToClaim } from '../dag.js';
|
|
8
|
-
import {
|
|
8
|
+
import { topicKeyFor, resolveTaskKey } from '../paths.js';
|
|
9
9
|
import { parseStampMs, stampNow } from '../infra/store-io.js';
|
|
10
10
|
import { topics as topicsRepo, tasks as tasksRepo, links as linksRepo, db } from '../infra/repo/index.js';
|
|
11
11
|
import { parseFrontmatter } from '../../../shared/frontmatter.js';
|
|
@@ -323,7 +323,7 @@ export function topicView(t: any, repoCtx: any = null, readyOpts: ReadyOpts = {}
|
|
|
323
323
|
cwd: t.cwd || '',
|
|
324
324
|
// 目录还在不在:临时目录被删 / 外接盘未挂载 / 测试残留都会让 cwd 失效。
|
|
325
325
|
// UI 与 prune --missing-dir 都靠它判断「这条主题是幽灵还是真的」。
|
|
326
|
-
cwdExists:
|
|
326
|
+
cwdExists: !!t.cwd && existsSync(String(t.cwd)),
|
|
327
327
|
name: t.name || '',
|
|
328
328
|
summary: t.summary || '',
|
|
329
329
|
// 提交方(add --summary)留下的补充说明:与 agent 的「当前现状」分开存,
|
|
@@ -343,7 +343,6 @@ export function topicView(t: any, repoCtx: any = null, readyOpts: ReadyOpts = {}
|
|
|
343
343
|
waitingUntilMs: Number(t.waitingUntilMs) || 0,
|
|
344
344
|
waitingSince: t.waitingSince || '',
|
|
345
345
|
cancelRequested: !!t.cancelRequested,
|
|
346
|
-
isGlobal: isGlobalKey(t.key),
|
|
347
346
|
// 手动登记的目录(面板「添加目录」):空主题也不被 prune 清掉
|
|
348
347
|
manual: !!t.manual,
|
|
349
348
|
createdAt: t.createdAt,
|
|
@@ -57,7 +57,6 @@ export async function addTopic({ cwd: rawCwd, summary: rawSummary }: { cwd?: str
|
|
|
57
57
|
// 全局主题永远置顶(共享池是所有 worker 的候补来源,放最显眼处)。
|
|
58
58
|
//
|
|
59
59
|
// 注意:**全局主题不在这里凭空造**。全局池空着的时候库里就是没有它
|
|
60
|
-
// (它只有真的往池子里投过东西才存在)。看板层(board.js)负责补一行"全局任务池"
|
|
61
60
|
// 占位,保证用户永远找得到往全局池加任务的入口——服务层的契约保持原样。
|
|
62
61
|
export async function listTasks(): Promise<Record<string, any>> {
|
|
63
62
|
openStore();
|
|
@@ -69,7 +68,6 @@ export async function listTasks(): Promise<Record<string, any>> {
|
|
|
69
68
|
.map((t) => topicView(t, repoCtxOf(repoIndex, t.cwd), readyOpts))
|
|
70
69
|
.sort(
|
|
71
70
|
(a, b) =>
|
|
72
|
-
Number(!!b.isGlobal) - Number(!!a.isGlobal) ||
|
|
73
71
|
String(b.updatedAt).localeCompare(String(a.updatedAt))
|
|
74
72
|
);
|
|
75
73
|
return {
|
|
@@ -139,15 +137,13 @@ export async function pruneTopics({
|
|
|
139
137
|
*/
|
|
140
138
|
export interface UpdateSettingsInput {
|
|
141
139
|
timeoutSec?: unknown;
|
|
142
|
-
appendMode?: unknown;
|
|
143
140
|
}
|
|
144
141
|
|
|
145
142
|
// 配置等待超时(页面可调)。超时推荐 180=3 分钟、最大 600=10 分钟。
|
|
146
|
-
export async function updateSettings({ timeoutSec
|
|
143
|
+
export async function updateSettings({ timeoutSec }: UpdateSettingsInput = {}): Promise<Record<string, any>> {
|
|
147
144
|
const hasTimeout = timeoutSec !== undefined && timeoutSec !== null;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
throw badInput('请至少指定一项:--timeout <秒>,或 --append-mode <xml|plain>');
|
|
145
|
+
if (!hasTimeout) {
|
|
146
|
+
throw badInput('请指定 --timeout <秒>(追加模式已固定为 XML,不再可配)');
|
|
151
147
|
}
|
|
152
148
|
if (hasTimeout) {
|
|
153
149
|
const n = Number(timeoutSec);
|
|
@@ -158,7 +154,6 @@ export async function updateSettings({ timeoutSec, appendMode }: UpdateSettingsI
|
|
|
158
154
|
openStore();
|
|
159
155
|
settingsRepo.setLtSettings({
|
|
160
156
|
timeoutSec: hasTimeout ? timeoutSec : undefined,
|
|
161
|
-
appendMode: hasAppend ? appendMode : undefined,
|
|
162
157
|
});
|
|
163
158
|
return settingsRepo.settingsView();
|
|
164
159
|
}
|
|
@@ -11,7 +11,7 @@ import { existsSync } from 'node:fs';
|
|
|
11
11
|
import { isImageName } from '../../../core/filekind.js';
|
|
12
12
|
import { stripFrontmatter } from '../../../shared/frontmatter.js';
|
|
13
13
|
|
|
14
|
-
const KIND_LABEL: Record<string, string> = { file: '附件', url: '链接', task: '任务', ref: '文档', mdfile: 'md', folder: '文件夹' };
|
|
14
|
+
const KIND_LABEL: Record<string, string> = { file: '附件', url: '链接', task: '任务', ref: '文档', mdfile: 'md', folder: '文件夹', repo: '仓库' };
|
|
15
15
|
const IMAGE_LABEL = '图片';
|
|
16
16
|
export const ORIGIN_LABEL = { inline: '正文内嵌', area: '附件区' };
|
|
17
17
|
export const STATUS_LABEL: Record<string, string> = { pending: '待领取', claimed: '进行中', done: '已完成', cancelled: '已作废' };
|
|
@@ -30,10 +30,10 @@ function metaOf(row: any): Record<string, any> {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/** 资源类型归一:image / 空 / 其它未知值 → file;url/task/ref/mdfile 原样。 */
|
|
33
|
+
/** 资源类型归一:image / 空 / 其它未知值 → file;url/task/ref/mdfile/folder/repo 原样。 */
|
|
34
34
|
function baseKind(row: any): string {
|
|
35
35
|
const k = String((row && row.kind) || '');
|
|
36
|
-
return k === 'url' || k === 'task' || k === 'ref' || k === 'mdfile' || k === 'folder' ? k : 'file';
|
|
36
|
+
return k === 'url' || k === 'task' || k === 'ref' || k === 'mdfile' || k === 'folder' || k === 'repo' ? k : 'file';
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function kindLabelOf(kind: unknown, isImage: unknown): string {
|
|
@@ -205,7 +205,7 @@ export function resourceOf(row: any, lookups: ResourceLookups = {}): any {
|
|
|
205
205
|
areaLabel: ORIGIN_LABEL[origin],
|
|
206
206
|
storage: kind === 'file' ? String(row.storage || '')
|
|
207
207
|
: kind === 'url' ? 'url'
|
|
208
|
-
: kind === 'mdfile' || kind === 'folder' ? 'external' : 'internal',
|
|
208
|
+
: kind === 'mdfile' || kind === 'folder' || kind === 'repo' ? 'external' : 'internal',
|
|
209
209
|
synced: kind !== 'file',
|
|
210
210
|
localPath: '',
|
|
211
211
|
targetKind: String(row.targetKind || ''),
|
|
@@ -281,6 +281,48 @@ export function resourceOf(row: any, lookups: ResourceLookups = {}): any {
|
|
|
281
281
|
};
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
if (kind === 'repo') {
|
|
285
|
+
// #184:参考仓库附件——登记指针,字节留在原 checkout(不 clone / 不复制)。
|
|
286
|
+
// 元数据(key/type/desc/docs)在登记时写进 meta;localPath 的 exists 按盘上现况判定。
|
|
287
|
+
const repoKey = String(meta.repoKey || row.targetKey || '');
|
|
288
|
+
const repoName = String(meta.name || row.name || repoKey);
|
|
289
|
+
const repoDesc = String(meta.desc || '');
|
|
290
|
+
const repoType = String(meta.repoType || '');
|
|
291
|
+
const localPath = String(meta.localPath || row.absPath || row.abs_path || '');
|
|
292
|
+
const exists = !!localPath && existsSync(localPath);
|
|
293
|
+
const missing = !exists || (row.missingAt !== null && row.missingAt !== undefined);
|
|
294
|
+
const branch = String(meta.branch || '');
|
|
295
|
+
const docs = Array.isArray(meta.docs) ? meta.docs.map((x: unknown) => String(x || '')).filter(Boolean) : [];
|
|
296
|
+
const getCmd = `nx-kv repo get --id ${repoKey}`;
|
|
297
|
+
const docCmd = `nx-kv repo doc list --id ${repoKey}`;
|
|
298
|
+
const typeLabel = repoType === 'ref' ? '参考仓库' : repoType === 'dev' ? '开发仓库' : '仓库';
|
|
299
|
+
const locator = `${repoName}(${typeLabel}${localPath ? ` · ${localPath}` : ''})`;
|
|
300
|
+
return {
|
|
301
|
+
...base,
|
|
302
|
+
name: repoName,
|
|
303
|
+
repoKey,
|
|
304
|
+
repoName,
|
|
305
|
+
repoDesc,
|
|
306
|
+
repoType,
|
|
307
|
+
typeLabel,
|
|
308
|
+
localPath,
|
|
309
|
+
exists,
|
|
310
|
+
missing,
|
|
311
|
+
branch,
|
|
312
|
+
docs,
|
|
313
|
+
docCount: docs.length,
|
|
314
|
+
getCmd,
|
|
315
|
+
docCmd,
|
|
316
|
+
target: localPath || repoKey,
|
|
317
|
+
needsSync: false,
|
|
318
|
+
cmd: getCmd,
|
|
319
|
+
locator,
|
|
320
|
+
usage: missing
|
|
321
|
+
? `这是${typeLabel}附件 ${repoKey},但本地 checkout 不可访问(${localPath || '路径为空'}):先 ${getCmd} 确认登记信息,再按 gitRepoRoot 重新 checkout`
|
|
322
|
+
: `这是${typeLabel}附件 ${repoKey}(不是副本,字节就在 ${localPath}):先用 ${getCmd} 确认元数据,实现前必须读该仓库源码(关键文件用 Read 打开 ${localPath});已整理文档用 ${docCmd} 列出后用 nx-kv docs get --ref <refId> 读取`,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
284
326
|
if (kind === 'folder') {
|
|
285
327
|
// 本地文件夹指针:库里只有 abs_path,目录内容不入库;交付只给路径让 agent 自己列目录。
|
|
286
328
|
const absPath = String(row.absPath || row.abs_path || meta.absPath || '');
|
|
@@ -14,12 +14,18 @@ import { hostOfUrl, kindLabelOf, ORIGIN_LABEL, sizeTextOf, STATUS_LABEL } from '
|
|
|
14
14
|
*/
|
|
15
15
|
export const DEFAULT_ATTACH_TEMPLATE = [
|
|
16
16
|
'{{#if attach}}',
|
|
17
|
-
'〔附件〕本任务包含 {{attach.count}} 个附件(正文内嵌 {{attach.inlineCount}} · 附件区 {{attach.areaCount}}
|
|
17
|
+
'〔附件〕本任务包含 {{attach.count}} 个附件(正文内嵌 {{attach.inlineCount}} · 附件区 {{attach.areaCount}})。{{#if attach.hasMandatory}}其中 {{attach.mandatoryCount}} 个是**系统内部资源**(任务 / 文档 / 仓库)——它们必须被实际访问:任务先读正文、文档先读全文、仓库先读源码并确认元数据;**未访问不得直接开始实现或交付**。{{else}}请先识别附件内容(图片先看图、文档先读内容、文件夹先列目录)再开始处理,不要跳过附件。{{/if}}',
|
|
18
18
|
'',
|
|
19
19
|
'附件清单:',
|
|
20
20
|
'{{#each attach.list}}',
|
|
21
|
-
' - [{{originLabel}}] {{kindLabel}} {{name}}{{#if sizeText}}({{sizeText}}){{/if}}:{{#if file}}{{#if file.exists}}{{file.localPath}}{{else}}未同步到本地(fileId {{file.fileId}}){{/if}}{{/if}}{{#if url}}{{url.href}}{{/if}}{{#if task}}{{#if task.resolved}}#{{task.seq}} {{task.title}} · 地址 {{task.address}}({{task.statusLabel}}){{else}}地址 {{task.address}}({{task.statusLabel}}){{/if}}{{/if}}{{#if ref}}{{ref.title}}{{/if}}{{#if mdfile}}{{mdfile.absPath}}{{#if mdfile.missing}}(源文件已不在){{/if}}{{/if}}{{#if folder}}{{folder.absPath}}{{#if folder.missing}}(目录已不在){{/if}}{{/if}}{{#if note}} # {{note}}{{/if}}',
|
|
21
|
+
' - [{{originLabel}}] {{kindLabel}} {{name}}{{#if sizeText}}({{sizeText}}){{/if}}:{{#if file}}{{#if file.exists}}{{file.localPath}}{{else}}未同步到本地(fileId {{file.fileId}}){{/if}}{{/if}}{{#if url}}{{url.href}}{{/if}}{{#if task}}{{#if task.resolved}}#{{task.seq}} {{task.title}} · 地址 {{task.address}}({{task.statusLabel}}){{else}}地址 {{task.address}}({{task.statusLabel}}){{/if}}{{/if}}{{#if ref}}{{ref.title}}{{/if}}{{#if mdfile}}{{mdfile.absPath}}{{#if mdfile.missing}}(源文件已不在){{/if}}{{/if}}{{#if folder}}{{folder.absPath}}{{#if folder.missing}}(目录已不在){{/if}}{{/if}}{{#if repo}}{{repo.typeLabel}} {{repo.key}}{{#if repo.localPath}} · {{repo.localPath}}{{/if}}{{#if repo.missing}}(checkout 已不在){{/if}}{{/if}}{{#if mandatory}}〔必须访问〕{{/if}}{{#if note}} # {{note}}{{/if}}',
|
|
22
22
|
'{{/each}}',
|
|
23
|
+
'{{#if attach.hasMandatory}}',
|
|
24
|
+
'必须访问(内部资源,逐条执行,不得跳过):',
|
|
25
|
+
'{{#each attach.list}}{{#if mandatory}}',
|
|
26
|
+
' - {{kindLabel}}《{{name}}》:{{access}}',
|
|
27
|
+
'{{/if}}{{/each}}',
|
|
28
|
+
'{{/if}}',
|
|
23
29
|
'',
|
|
24
30
|
'取用方式:',
|
|
25
31
|
'{{#each attach.list}}',
|
|
@@ -58,7 +64,7 @@ export const DEFAULT_ATTACH_TEMPLATE = [
|
|
|
58
64
|
* seq / showCmd / refId / target / area / areaLabel。
|
|
59
65
|
*/
|
|
60
66
|
function ctxItemOf(a: any): any {
|
|
61
|
-
const kind = ['url', 'task', 'ref', 'mdfile', 'folder'].includes(a.kind) ? a.kind : 'file';
|
|
67
|
+
const kind = ['url', 'task', 'ref', 'mdfile', 'folder', 'repo'].includes(a.kind) ? a.kind : 'file';
|
|
62
68
|
const isImage = kind === 'file' && (a.isImage === undefined ? isImageName(a.name, a.mime) : !!a.isImage);
|
|
63
69
|
const role = String(a.role || '');
|
|
64
70
|
const origin =
|
|
@@ -85,6 +91,9 @@ function ctxItemOf(a: any): any {
|
|
|
85
91
|
needsSync: !!a.needsSync,
|
|
86
92
|
// 边上的说明(desc,#162):清单行用 {{#if note}} 透出,agent 据此决定是否深入
|
|
87
93
|
note: String(a.note || ''),
|
|
94
|
+
// #184:内部资源(task / ref / repo)强制访问;外部资源(file/url/mdfile/folder)不强制
|
|
95
|
+
mandatory: false,
|
|
96
|
+
access: '',
|
|
88
97
|
// 兼容旧字段
|
|
89
98
|
area: origin,
|
|
90
99
|
areaLabel: a.areaLabel || ORIGIN_LABEL[origin],
|
|
@@ -157,12 +166,63 @@ function ctxItemOf(a: any): any {
|
|
|
157
166
|
...task,
|
|
158
167
|
task,
|
|
159
168
|
usage: String(a.usage || `这是任务引用而不是副本(地址 ${task.address}):用 ${showCmd} 读取最新正文`),
|
|
169
|
+
// #184:任务是系统内部资源——必须先读正文再干活
|
|
170
|
+
mandatory: true,
|
|
171
|
+
access: `必须先读这条任务的最新正文:${showCmd}(读完再开始实现,不得只凭标题猜内容)`,
|
|
160
172
|
cmd: String(a.cmd !== undefined ? a.cmd : showCmd),
|
|
161
173
|
locator: String(a.locator || `#${seq} ${title}${task.topicName || topicKey ? ` · ${task.topicName || topicKey}` : ''}`),
|
|
162
174
|
needsSync: false,
|
|
163
175
|
};
|
|
164
176
|
}
|
|
165
177
|
|
|
178
|
+
if (kind === 'repo') {
|
|
179
|
+
// #184:参考仓库附件——登记指针(字节在原 checkout),模板里强制「实现必须参考该仓库源码」
|
|
180
|
+
const repoKey = String(a.repoKey || a.targetKey || '');
|
|
181
|
+
const repoName = String(a.repoName || a.name || repoKey);
|
|
182
|
+
const repoDesc = String(a.repoDesc || a.desc || '');
|
|
183
|
+
const repoType = String(a.repoType || '');
|
|
184
|
+
const localPath = String(a.localPath || a.absPath || '');
|
|
185
|
+
const exists = a.exists === undefined ? !!localPath : !!a.exists;
|
|
186
|
+
const missing = a.missing === undefined ? !exists : !!a.missing;
|
|
187
|
+
const branch = String(a.branch || '');
|
|
188
|
+
const docs = Array.isArray(a.docs) ? a.docs.map((x: unknown) => String(x || '')).filter(Boolean) : [];
|
|
189
|
+
const getCmd = String(a.getCmd || `nx-kv repo get --id ${repoKey}`);
|
|
190
|
+
const docCmd = String(a.docCmd || `nx-kv repo doc list --id ${repoKey}`);
|
|
191
|
+
const typeLabel = repoType === 'ref' ? '参考仓库' : repoType === 'dev' ? '开发仓库' : '仓库';
|
|
192
|
+
const repo = { key: repoKey, name: repoName, desc: repoDesc, repoType, typeLabel, localPath, exists, missing, branch, docs, docCount: docs.length, getCmd, docCmd, cmd: getCmd };
|
|
193
|
+
const usage = String(a.usage || (missing
|
|
194
|
+
? `这是${typeLabel}附件 ${repoKey},但本地 checkout 不可访问(${localPath || '路径为空'}):先 ${getCmd} 确认登记信息`
|
|
195
|
+
: `这是${typeLabel}附件 ${repoKey}(不是副本,字节就在 ${localPath}):先用 ${getCmd} 确认元数据,再读源码`));
|
|
196
|
+
return {
|
|
197
|
+
...item,
|
|
198
|
+
name: repoName,
|
|
199
|
+
repoKey,
|
|
200
|
+
repoName,
|
|
201
|
+
repoDesc,
|
|
202
|
+
repoType,
|
|
203
|
+
typeLabel,
|
|
204
|
+
localPath,
|
|
205
|
+
path: localPath,
|
|
206
|
+
exists,
|
|
207
|
+
missing,
|
|
208
|
+
branch,
|
|
209
|
+
docs,
|
|
210
|
+
docCount: docs.length,
|
|
211
|
+
getCmd,
|
|
212
|
+
docCmd,
|
|
213
|
+
repo,
|
|
214
|
+
usage,
|
|
215
|
+
// #184:仓库是系统内部资源——实现必须参考源码,禁止臆测
|
|
216
|
+
mandatory: true,
|
|
217
|
+
access: missing
|
|
218
|
+
? `${typeLabel} ${repoKey} 的本地 checkout 不在(${localPath || '路径为空'}):先 ${getCmd} 确认登记,再按 gitRepoRoot 重新 checkout 后才能参考源码`
|
|
219
|
+
: `实现必须参考该仓库源码(路径 ${localPath}),禁止凭记忆臆测 API / 文件结构:先 ${getCmd} 确认仓库元数据,再列 ${localPath} 结构、用 Read 读关键文件;已整理文档用 ${docCmd} 列出后用 nx-kv docs get --ref <refId> 读取`,
|
|
220
|
+
cmd: String(a.cmd !== undefined ? a.cmd : getCmd),
|
|
221
|
+
locator: String(a.locator || `${repoName}(${typeLabel}${localPath ? ` · ${localPath}` : ''})`),
|
|
222
|
+
needsSync: false,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
166
226
|
if (kind === 'folder') {
|
|
167
227
|
const absPath = String(a.absPath || a.localPath || '');
|
|
168
228
|
const exists = a.exists === undefined ? !!absPath : !!a.exists;
|
|
@@ -250,6 +310,13 @@ function ctxItemOf(a: any): any {
|
|
|
250
310
|
...ref,
|
|
251
311
|
ref,
|
|
252
312
|
usage,
|
|
313
|
+
// #184:文档是系统内部资源——必须先读全文(已内联时指向「文档原文」段)
|
|
314
|
+
mandatory: true,
|
|
315
|
+
access: content
|
|
316
|
+
? `文档全文已内联在本清单末尾的「文档原文」段${truncated ? `(有截断,完整版用 ${readCmd})` : ''}:先读完再实现`
|
|
317
|
+
: readCmd
|
|
318
|
+
? `必须先读文档全文:${readCmd}(读完再开始实现)`
|
|
319
|
+
: '必须先定位并读取该文档(refId 缺失):先用 nx-kv docs list 找到它',
|
|
253
320
|
cmd: String(a.cmd !== undefined ? a.cmd : readCmd),
|
|
254
321
|
locator: String(a.locator || title),
|
|
255
322
|
needsSync: false,
|
|
@@ -273,6 +340,9 @@ export function attachTemplateCtx(attachments: unknown): Record<string, any> {
|
|
|
273
340
|
areaCount: items.filter((a) => a.origin === 'area').length,
|
|
274
341
|
hasInline: items.some((a) => a.origin !== 'area'),
|
|
275
342
|
hasArea: items.some((a) => a.origin === 'area'),
|
|
343
|
+
// #184:内部资源(任务 / 文档 / 仓库)数量——模板据此决定是否输出「必须访问」段
|
|
344
|
+
mandatoryCount: items.filter((a) => a.mandatory).length,
|
|
345
|
+
hasMandatory: items.some((a) => a.mandatory),
|
|
276
346
|
// 结构化数组:模板用循环组织清单,不再由服务端拼多行字符串。
|
|
277
347
|
list: items,
|
|
278
348
|
},
|