aicommunicator 0.0.0-stage → 0.2.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/LICENSE +55 -0
- package/README.md +93 -2
- package/bin/aic.js +20427 -0
- package/host-ui/host.js +5151 -0
- package/host-ui/index.html +483 -0
- package/host-ui/lang-en.js +631 -0
- package/package.json +30 -4
- package/plugin-guide.md +997 -0
- package/plugins/plugin-animation/LICENSE +55 -0
- package/plugins/plugin-animation/dist/logic.js +2225 -0
- package/plugins/plugin-animation/docs/manual.md +217 -0
- package/plugins/plugin-animation/manifest.json +31 -0
- package/plugins/plugin-animation/ui/icon.svg +6 -0
- package/plugins/plugin-animation/ui/index.html +2266 -0
- package/plugins/plugin-html-design/LICENSE +55 -0
- package/plugins/plugin-html-design/dist/logic.js +972 -0
- package/plugins/plugin-html-design/docs/manual.md +100 -0
- package/plugins/plugin-html-design/manifest.json +39 -0
- package/plugins/plugin-html-design/samples/exhibition-page.json +570 -0
- package/plugins/plugin-html-design/ui/icon.svg +5 -0
- package/plugins/plugin-html-design/ui/index.html +1241 -0
- package/plugins/plugin-html-slides/LICENSE +55 -0
- package/plugins/plugin-html-slides/dist/logic.js +1323 -0
- package/plugins/plugin-html-slides/docs/manual.md +121 -0
- package/plugins/plugin-html-slides/manifest.json +39 -0
- package/plugins/plugin-html-slides/samples/first-week-lecture.json +1129 -0
- package/plugins/plugin-html-slides/ui/icon.svg +5 -0
- package/plugins/plugin-html-slides/ui/index.html +1349 -0
- package/plugins/plugin-mindmap/LICENSE +55 -0
- package/plugins/plugin-mindmap/dist/logic.js +966 -0
- package/plugins/plugin-mindmap/docs/manual.md +145 -0
- package/plugins/plugin-mindmap/manifest.json +39 -0
- package/plugins/plugin-mindmap/samples/book-club.json +480 -0
- package/plugins/plugin-mindmap/ui/icon.svg +5 -0
- package/plugins/plugin-mindmap/ui/index.html +1774 -0
- package/plugins/plugin-plan/LICENSE +55 -0
- package/plugins/plugin-plan/dist/logic.js +1029 -0
- package/plugins/plugin-plan/docs/manual.md +261 -0
- package/plugins/plugin-plan/manifest.json +51 -0
- package/plugins/plugin-plan/samples/kimchi-day.json +1514 -0
- package/plugins/plugin-plan/samples/meeting-outline.json +653 -0
- package/plugins/plugin-plan/samples/reading-class.json +1577 -0
- package/plugins/plugin-plan/ui/icon.svg +7 -0
- package/plugins/plugin-plan/ui/index.html +1523 -0
- package/plugins/plugin-png/LICENSE +55 -0
- package/plugins/plugin-png/dist/logic.js +1758 -0
- package/plugins/plugin-png/docs/manual.md +344 -0
- package/plugins/plugin-png/manifest.json +35 -0
- package/plugins/plugin-png/ui/icon.svg +5 -0
- package/plugins/plugin-png/ui/index.html +2885 -0
- package/plugins/plugin-process-log/LICENSE +55 -0
- package/plugins/plugin-process-log/dist/logic.js +406 -0
- package/plugins/plugin-process-log/docs/manual.md +131 -0
- package/plugins/plugin-process-log/manifest.json +43 -0
- package/plugins/plugin-process-log/samples/design-decisions.json +241 -0
- package/plugins/plugin-process-log/ui/icon.svg +7 -0
- package/plugins/plugin-process-log/ui/index.html +721 -0
- package/plugins/plugin-story/LICENSE +55 -0
- package/plugins/plugin-story/dist/logic.js +2201 -0
- package/plugins/plugin-story/docs/manual.md +428 -0
- package/plugins/plugin-story/manifest.json +49 -0
- package/plugins/plugin-story/samples/scene-body.json +758 -0
- package/plugins/plugin-story/samples/time-and-groups.json +989 -0
- package/plugins/plugin-story/ui/icon.svg +4 -0
- package/plugins/plugin-story/ui/index.html +2783 -0
- package/plugins/plugin-svg/LICENSE +55 -0
- package/plugins/plugin-svg/dist/logic.js +2150 -0
- package/plugins/plugin-svg/docs/manual.md +314 -0
- package/plugins/plugin-svg/manifest.json +45 -0
- package/plugins/plugin-svg/samples/rocket-icon.json +1305 -0
- package/plugins/plugin-svg/samples/yard-cat.json +7796 -0
- package/plugins/plugin-svg/ui/icon.svg +4 -0
- package/plugins/plugin-svg/ui/index.html +2017 -0
- package/plugins/plugin-tree/LICENSE +55 -0
- package/plugins/plugin-tree/dist/logic.js +505 -0
- package/plugins/plugin-tree/docs/manual.md +140 -0
- package/plugins/plugin-tree/manifest.json +45 -0
- package/plugins/plugin-tree/samples/book-club.json +473 -0
- package/plugins/plugin-tree/samples/sort-memos.json +604 -0
- package/plugins/plugin-tree/ui/icon.svg +7 -0
- package/plugins/plugin-tree/ui/index.html +1305 -0
- package/schema/aic_describe.input.json +11 -0
- package/schema/aic_describe.output.json +67 -0
- package/schema/aic_observe.input.json +14 -0
- package/schema/aic_observe.output.json +47 -0
- package/schema/aic_send.input.json +15 -0
- package/schema/aic_send.output.json +38 -0
- package/schema/aic_update.input.json +19 -0
- package/schema/aic_update.output.json +39 -0
- package/schema/common.json +127 -0
- package/template/plugin/LICENSE +55 -0
- package/template/plugin/README.md +27 -0
- package/template/plugin/docs/manual.md +31 -0
- package/template/plugin/logic.js +337 -0
- package/template/plugin/manifest.json +27 -0
- package/template/plugin/ui/icon.svg +4 -0
- package/template/plugin/ui/index.html +269 -0
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// packages/plugin-sdk/src/index.ts
|
|
4
|
+
var SEPARATOR = " ";
|
|
5
|
+
var ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
6
|
+
function sortKey(order, id) {
|
|
7
|
+
return `${order}${SEPARATOR}${id}`;
|
|
8
|
+
}
|
|
9
|
+
function boundAfterOrder(order) {
|
|
10
|
+
return `${order}!`;
|
|
11
|
+
}
|
|
12
|
+
function between(lo, hi) {
|
|
13
|
+
const out = [];
|
|
14
|
+
for (const c of ALPHABET) {
|
|
15
|
+
if ((lo === void 0 || c > lo) && (hi === void 0 || c < hi)) out.push(c);
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
function orderBetween(left, right) {
|
|
20
|
+
if (left === void 0 && right === void 0) return "V";
|
|
21
|
+
const L = left ?? "";
|
|
22
|
+
const U = right;
|
|
23
|
+
if (U !== void 0 && !(L < U)) throw new Error(`orderBetween: \uC67C\uCABD ${L} \uC774 \uC624\uB978\uCABD ${U} \uBCF4\uB2E4 \uC55E\uC774\uC5B4\uC57C \uD55C\uB2E4`);
|
|
24
|
+
let i = 0;
|
|
25
|
+
while (U !== void 0 && i < L.length && i < U.length && L[i] === U[i]) i += 1;
|
|
26
|
+
if (U === void 0) i = 0;
|
|
27
|
+
if (i >= L.length && U !== void 0) {
|
|
28
|
+
let prefix = U.slice(0, i);
|
|
29
|
+
for (let k = i; k < U.length; k += 1) {
|
|
30
|
+
const uc2 = U[k];
|
|
31
|
+
const cands2 = between(void 0, uc2);
|
|
32
|
+
if (cands2.length > 0) return prefix + cands2[cands2.length - 1];
|
|
33
|
+
if (prefix !== "" && !prefix.endsWith(SEPARATOR) && uc2 > SEPARATOR) return prefix;
|
|
34
|
+
prefix += uc2;
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`orderBetween: ${L} \uACFC ${U} \uC0AC\uC774\uC5D0 \uAC12\uC744 \uB9CC\uB4E4 \uC218 \uC5C6\uB2E4`);
|
|
37
|
+
}
|
|
38
|
+
const lc = L[i];
|
|
39
|
+
const uc = U === void 0 ? void 0 : U[i];
|
|
40
|
+
const cands = between(lc, uc);
|
|
41
|
+
if (cands.length > 0) {
|
|
42
|
+
if (uc === void 0) return L.slice(0, i) + cands[0];
|
|
43
|
+
return L.slice(0, i) + cands[Math.floor(cands.length / 2)];
|
|
44
|
+
}
|
|
45
|
+
for (let j = i + 1; j < L.length; j += 1) {
|
|
46
|
+
const up = between(L[j], void 0);
|
|
47
|
+
if (up.length > 0) return L.slice(0, j) + up[0];
|
|
48
|
+
}
|
|
49
|
+
return `${L}V`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// packages/protocol/src/index.ts
|
|
53
|
+
function isCoreId(id) {
|
|
54
|
+
return /^(memo|intent)\d+$/.test(id);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// packages/plugin-plan/src/logic.ts
|
|
58
|
+
var PACKAGE_ID = "aic.plan";
|
|
59
|
+
var VERSION = "0.1.6";
|
|
60
|
+
var STATUS = { todo: "to do", doing: "in progress", done: "done" };
|
|
61
|
+
var CHECK = { unchecked: "not checked", meets: "meets", partial: "partly", differs: "differs" };
|
|
62
|
+
var Reject = class extends Error {
|
|
63
|
+
constructor(code, message) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.code = code;
|
|
66
|
+
}
|
|
67
|
+
code;
|
|
68
|
+
};
|
|
69
|
+
var all = (s, type) => Object.values(s.records).filter((r) => r.type === type);
|
|
70
|
+
var keyOf = (r) => sortKey(r.content.order, r.id);
|
|
71
|
+
var byKey = (a, b) => keyOf(a) < keyOf(b) ? -1 : 1;
|
|
72
|
+
var byIdNumber = (a, b) => {
|
|
73
|
+
const na = Number(a.id.replace(/\D/g, ""));
|
|
74
|
+
const nb = Number(b.id.replace(/\D/g, ""));
|
|
75
|
+
return na - nb || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
76
|
+
};
|
|
77
|
+
var task = (s, id) => s.records[id]?.content;
|
|
78
|
+
var question = (s, id) => s.records[id]?.content;
|
|
79
|
+
function rootOf(s) {
|
|
80
|
+
return all(s, "task").filter((r) => r.content.parent === null).sort(byIdNumber)[0];
|
|
81
|
+
}
|
|
82
|
+
function childrenOf(s, parent) {
|
|
83
|
+
return all(s, "task").filter((r) => r.content.parent === parent).sort(byKey);
|
|
84
|
+
}
|
|
85
|
+
function questionsOf(s, taskId) {
|
|
86
|
+
return all(s, "question").filter((r) => r.content.task === taskId).sort(byKey);
|
|
87
|
+
}
|
|
88
|
+
function optionsOf(s, q) {
|
|
89
|
+
return all(s, "option").filter((r) => r.content.question === q).sort(byKey);
|
|
90
|
+
}
|
|
91
|
+
function resultsOf(s, taskId) {
|
|
92
|
+
return all(s, "result").filter((r) => r.content.task === taskId).sort(byKey);
|
|
93
|
+
}
|
|
94
|
+
function linksOf(s, taskId) {
|
|
95
|
+
return all(s, "link").filter((r) => r.content.task === taskId).sort(byIdNumber);
|
|
96
|
+
}
|
|
97
|
+
function depsFrom(s, taskId) {
|
|
98
|
+
return all(s, "dep").filter((r) => r.content.from === taskId).sort(byIdNumber);
|
|
99
|
+
}
|
|
100
|
+
function depsTo(s, taskId) {
|
|
101
|
+
return all(s, "dep").filter((r) => r.content.to === taskId).sort(byIdNumber);
|
|
102
|
+
}
|
|
103
|
+
function subtree(s, id) {
|
|
104
|
+
const out = [];
|
|
105
|
+
const seen = /* @__PURE__ */ new Set();
|
|
106
|
+
const walk = (x) => {
|
|
107
|
+
if (seen.has(x)) return;
|
|
108
|
+
seen.add(x);
|
|
109
|
+
out.push(x);
|
|
110
|
+
for (const c of childrenOf(s, x)) walk(c.id);
|
|
111
|
+
};
|
|
112
|
+
walk(id);
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
function ancestors(s, id) {
|
|
116
|
+
const out = [];
|
|
117
|
+
const seen = /* @__PURE__ */ new Set([id]);
|
|
118
|
+
let p = task(s, id)?.parent ?? null;
|
|
119
|
+
while (p !== null && s.records[p]?.type === "task" && !seen.has(p)) {
|
|
120
|
+
out.unshift(p);
|
|
121
|
+
seen.add(p);
|
|
122
|
+
p = task(s, p).parent;
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
var isOpen = (q) => q.answer === null;
|
|
127
|
+
var isDelegatedPending = (q) => q.answer !== null && q.answer.delegated && q.answer.choice === null && q.answer.text === "";
|
|
128
|
+
function waitingOf(s, taskId) {
|
|
129
|
+
const person = [];
|
|
130
|
+
const ai = [];
|
|
131
|
+
for (const r of all(s, "question").sort(byIdNumber)) {
|
|
132
|
+
const q = r.content;
|
|
133
|
+
if (!q.blocks.includes(taskId)) continue;
|
|
134
|
+
if (isOpen(q)) person.push(r.id);
|
|
135
|
+
else if (isDelegatedPending(q)) ai.push(r.id);
|
|
136
|
+
}
|
|
137
|
+
return { person, ai };
|
|
138
|
+
}
|
|
139
|
+
function need(s, id, type, what) {
|
|
140
|
+
if (typeof id !== "string" || id === "") throw new Reject("INVALID_INPUT", `${what} id is required`);
|
|
141
|
+
const r = s.records[id];
|
|
142
|
+
if (!r) throw new Reject("TARGET_NOT_FOUND", `${what} ${id} not found`);
|
|
143
|
+
if (r.type !== type) throw new Reject("INVALID_INPUT", `${id} is not a ${what}`);
|
|
144
|
+
return r;
|
|
145
|
+
}
|
|
146
|
+
function guardTemp(text, ctx) {
|
|
147
|
+
if (ctx.tempNames.includes(text)) throw new Reject("INVALID_INPUT", `"${text}" is the same as a temporary name in this request, so it cannot be used as text`);
|
|
148
|
+
}
|
|
149
|
+
function textInput(input, key, ctx, what) {
|
|
150
|
+
const v = input[key];
|
|
151
|
+
if (typeof v !== "string" || v.trim() === "") throw new Reject("INVALID_INPUT", `${what} (${key}) is empty`);
|
|
152
|
+
guardTemp(v.trim(), ctx);
|
|
153
|
+
return v.trim();
|
|
154
|
+
}
|
|
155
|
+
function optText(input, key, ctx) {
|
|
156
|
+
const v = input[key];
|
|
157
|
+
if (v === void 0 || v === null) return v === null ? "" : void 0;
|
|
158
|
+
if (typeof v !== "string") throw new Reject("INVALID_INPUT", `${key} must be text`);
|
|
159
|
+
guardTemp(v.trim(), ctx);
|
|
160
|
+
return v.trim();
|
|
161
|
+
}
|
|
162
|
+
function statusInput(v) {
|
|
163
|
+
if (v === void 0 || v === null) return void 0;
|
|
164
|
+
if (v !== "todo" && v !== "doing" && v !== "done") throw new Reject("INVALID_INPUT", "status must be one of todo, doing, done");
|
|
165
|
+
return v;
|
|
166
|
+
}
|
|
167
|
+
function checkInput(v) {
|
|
168
|
+
if (v === void 0 || v === null) return void 0;
|
|
169
|
+
if (v !== "unchecked" && v !== "meets" && v !== "partial" && v !== "differs") throw new Reject("INVALID_INPUT", "check must be one of unchecked, meets, partial, differs");
|
|
170
|
+
return v;
|
|
171
|
+
}
|
|
172
|
+
function afterInput(input) {
|
|
173
|
+
const v = input.after;
|
|
174
|
+
if (v === void 0 || v === null) return v;
|
|
175
|
+
if (typeof v !== "string") throw new Reject("INVALID_INPUT", "after must be the id of the sibling before");
|
|
176
|
+
return v;
|
|
177
|
+
}
|
|
178
|
+
function newOrder(sibs, afterId, self) {
|
|
179
|
+
const list = sibs.filter((r) => r.id !== self);
|
|
180
|
+
let leftIdx;
|
|
181
|
+
if (afterId === void 0) leftIdx = list.length - 1;
|
|
182
|
+
else if (afterId === null) leftIdx = -1;
|
|
183
|
+
else {
|
|
184
|
+
leftIdx = list.findIndex((r) => r.id === afterId);
|
|
185
|
+
if (leftIdx < 0) throw new Reject("INVALID_INPUT", `${afterId} is not a sibling in the same place`);
|
|
186
|
+
}
|
|
187
|
+
const left = leftIdx >= 0 ? list[leftIdx] : void 0;
|
|
188
|
+
const right = list[leftIdx + 1];
|
|
189
|
+
const leftKey = left ? left.id.startsWith("$") ? boundAfterOrder(left.content.order) : keyOf(left) : void 0;
|
|
190
|
+
const rightKey = right ? right.id.startsWith("$") ? right.content.order : keyOf(right) : void 0;
|
|
191
|
+
return orderBetween(leftKey, rightKey);
|
|
192
|
+
}
|
|
193
|
+
var posRefs = (after) => typeof after === "string" ? { after } : void 0;
|
|
194
|
+
var label = (s, id) => `(${id}) ${task(s, id)?.title ?? ""}`.trim();
|
|
195
|
+
var CLIP = 40;
|
|
196
|
+
var count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
197
|
+
var clip = (t) => t.length > CLIP ? `${t.slice(0, CLIP)}...` : t;
|
|
198
|
+
var AROUND = 12;
|
|
199
|
+
var SPAN = 60;
|
|
200
|
+
function changedPart(before, after) {
|
|
201
|
+
const a = Array.from(before);
|
|
202
|
+
const b = Array.from(after);
|
|
203
|
+
let p = 0;
|
|
204
|
+
while (p < a.length && p < b.length && a[p] === b[p]) p += 1;
|
|
205
|
+
let q = 0;
|
|
206
|
+
while (q < a.length - p && q < b.length - p && a[a.length - 1 - q] === b[b.length - 1 - q]) q += 1;
|
|
207
|
+
const from = Math.max(0, p - AROUND);
|
|
208
|
+
const to = Math.min(b.length, b.length - q + AROUND);
|
|
209
|
+
const mid = b.slice(from, to);
|
|
210
|
+
const cut = mid.length > SPAN;
|
|
211
|
+
return `${from > 0 ? "..." : ""}${(cut ? mid.slice(0, SPAN) : mid).join("")}${cut || to < b.length ? "..." : ""}`;
|
|
212
|
+
}
|
|
213
|
+
var fieldChange = (name, before, after) => after === "" ? `${name} cleared` : `${name} "${before === "" ? clip(after) : changedPart(before, after)}"`;
|
|
214
|
+
function parentInput(s, v) {
|
|
215
|
+
if (v === void 0 || v === null) {
|
|
216
|
+
const root = rootOf(s);
|
|
217
|
+
if (root) throw new Reject("INVALID_INPUT", `There is only one root. The root ${label(s, root.id)} already exists, so give a branch id as parent`);
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
return need(s, v, "task", "parent branch").id;
|
|
221
|
+
}
|
|
222
|
+
function related(s, a, b) {
|
|
223
|
+
return ancestors(s, a).includes(b) || ancestors(s, b).includes(a);
|
|
224
|
+
}
|
|
225
|
+
function depReaches(s, start, goal, extra) {
|
|
226
|
+
const edges = all(s, "dep").map((r) => r.content);
|
|
227
|
+
if (extra) edges.push(extra);
|
|
228
|
+
const seen = /* @__PURE__ */ new Set();
|
|
229
|
+
const stack = [start];
|
|
230
|
+
while (stack.length) {
|
|
231
|
+
const x = stack.pop();
|
|
232
|
+
if (x === goal) return true;
|
|
233
|
+
if (seen.has(x)) continue;
|
|
234
|
+
seen.add(x);
|
|
235
|
+
for (const e of edges) if (e.from === x) stack.push(e.to);
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
function removeTasks(s, ids) {
|
|
240
|
+
const gone = new Set(ids);
|
|
241
|
+
const changes = ids.map((id) => ({ id, type: "task", after: null }));
|
|
242
|
+
const qs = all(s, "question").filter((r) => gone.has(r.content.task));
|
|
243
|
+
const qGone = new Set(qs.map((r) => r.id));
|
|
244
|
+
const opts = all(s, "option").filter((r) => qGone.has(r.content.question));
|
|
245
|
+
const results = all(s, "result").filter((r) => gone.has(r.content.task));
|
|
246
|
+
const links = all(s, "link").filter((r) => gone.has(r.content.task));
|
|
247
|
+
const deps = all(s, "dep").filter((r) => gone.has(r.content.from) || gone.has(r.content.to));
|
|
248
|
+
for (const r of [...qs, ...opts, ...results, ...links, ...deps]) changes.push({ id: r.id, type: r.type, after: null });
|
|
249
|
+
for (const r of all(s, "question")) {
|
|
250
|
+
if (qGone.has(r.id)) continue;
|
|
251
|
+
const q = r.content;
|
|
252
|
+
if (q.blocks.some((b) => gone.has(b))) changes.push({ id: r.id, type: "question", after: { ...q, blocks: q.blocks.filter((b) => !gone.has(b)) } });
|
|
253
|
+
}
|
|
254
|
+
const parts = [
|
|
255
|
+
ids.length > 1 ? `${count(ids.length - 1, "branch", "branches")} below` : "",
|
|
256
|
+
qs.length ? count(qs.length, "question", "questions") : "",
|
|
257
|
+
results.length ? count(results.length, "result", "results") : "",
|
|
258
|
+
links.length ? count(links.length, "link to another screen", "links to other screens") : "",
|
|
259
|
+
deps.length ? count(deps.length, "dependency", "dependencies") : ""
|
|
260
|
+
].filter(Boolean);
|
|
261
|
+
return { changes, counts: parts.length ? `, also removed: ${parts.join(", ")}` : "" };
|
|
262
|
+
}
|
|
263
|
+
function answerText(s, q) {
|
|
264
|
+
const a = q.answer;
|
|
265
|
+
if (a === null) return "no answer";
|
|
266
|
+
const choice = a.choice ? `(${a.choice}) ${s.records[a.choice]?.content?.title ?? ""}`.trim() : "";
|
|
267
|
+
const body = [choice, a.text ? `"${a.text}"` : ""].filter(Boolean).join(", ");
|
|
268
|
+
if (a.delegated) return body ? `AI decided, the person left it to AI: ${body}` : "left to AI, AI to decide";
|
|
269
|
+
return `answer: ${body}`;
|
|
270
|
+
}
|
|
271
|
+
function depText(s, d) {
|
|
272
|
+
const name = (id) => s.records[id]?.type === "task" ? label(s, id) : `(${id})`;
|
|
273
|
+
return `first ${name(d.to)}, then ${name(d.from)}`;
|
|
274
|
+
}
|
|
275
|
+
var OPERATIONS = {
|
|
276
|
+
"task.add": (s, input, id, ctx) => {
|
|
277
|
+
const parent = parentInput(s, input.parent);
|
|
278
|
+
const after = afterInput(input);
|
|
279
|
+
const title = textInput(input, "title", ctx, "name");
|
|
280
|
+
const content = {
|
|
281
|
+
parent,
|
|
282
|
+
order: parent === null ? orderBetween() : newOrder(childrenOf(s, parent), after),
|
|
283
|
+
title,
|
|
284
|
+
aim: optText(input, "aim", ctx) ?? "",
|
|
285
|
+
conditions: optText(input, "conditions", ctx) ?? "",
|
|
286
|
+
method: optText(input, "method", ctx) ?? "",
|
|
287
|
+
status: statusInput(input.status) ?? "todo"
|
|
288
|
+
};
|
|
289
|
+
return {
|
|
290
|
+
changes: [{ id: id(0), type: "task", prefix: "t", after: content, refs: posRefs(after) }],
|
|
291
|
+
summary: parent === null ? `Goal created: ${title}` : `Branch added (under ${parent}): ${title}`
|
|
292
|
+
};
|
|
293
|
+
},
|
|
294
|
+
"task.update": (s, input, _id, ctx) => {
|
|
295
|
+
const r = need(s, input.task, "task", "branch");
|
|
296
|
+
const c = r.content;
|
|
297
|
+
const title = input.title === void 0 ? c.title : textInput(input, "title", ctx, "name");
|
|
298
|
+
const next = {
|
|
299
|
+
...c,
|
|
300
|
+
title,
|
|
301
|
+
aim: optText(input, "aim", ctx) ?? c.aim,
|
|
302
|
+
conditions: optText(input, "conditions", ctx) ?? c.conditions,
|
|
303
|
+
method: optText(input, "method", ctx) ?? c.method,
|
|
304
|
+
status: statusInput(input.status) ?? c.status
|
|
305
|
+
};
|
|
306
|
+
const what = [];
|
|
307
|
+
if (next.title !== c.title) what.push(`name from "${c.title}" to "${next.title}"`);
|
|
308
|
+
if (next.status !== c.status) what.push(`status ${STATUS[next.status]} (was ${STATUS[c.status]})`);
|
|
309
|
+
if (next.aim !== c.aim) what.push(fieldChange("aim", c.aim, next.aim));
|
|
310
|
+
if (next.conditions !== c.conditions) what.push(fieldChange("conditions", c.conditions, next.conditions));
|
|
311
|
+
if (next.method !== c.method) what.push(fieldChange("method", c.method, next.method));
|
|
312
|
+
return { changes: [{ id: r.id, type: "task", after: next }], summary: `Branch ${r.id} (${next.title}): ${what.length ? what.join(", ") : "nothing changed"}` };
|
|
313
|
+
},
|
|
314
|
+
"task.move": (s, input) => {
|
|
315
|
+
const r = need(s, input.task, "task", "branch");
|
|
316
|
+
const c = r.content;
|
|
317
|
+
if (c.parent === null) throw new Reject("INVALID_INPUT", "The root cannot be moved");
|
|
318
|
+
const parent = need(s, input.parent, "task", "new parent branch").id;
|
|
319
|
+
if (subtree(s, r.id).includes(parent)) throw new Reject("INVALID_INPUT", `${parent} is ${r.id} itself or a branch below it, so ${r.id} cannot move under it`);
|
|
320
|
+
const after = afterInput(input);
|
|
321
|
+
const next = { ...c, parent, order: newOrder(childrenOf(s, parent), after, r.id) };
|
|
322
|
+
const where = parent === c.parent ? "within the same parent" : `under ${label(s, parent)}`;
|
|
323
|
+
return {
|
|
324
|
+
changes: [{ id: r.id, type: "task", after: next, refs: posRefs(after), moved: true }],
|
|
325
|
+
summary: `Moved (${r.id} ${c.title}): ${where}${after ? `, after ${after}` : after === null ? ", to the front" : ""}`
|
|
326
|
+
};
|
|
327
|
+
},
|
|
328
|
+
"task.remove": (s, input) => {
|
|
329
|
+
const r = need(s, input.task, "task", "branch");
|
|
330
|
+
const c = r.content;
|
|
331
|
+
if (c.parent === null) throw new Reject("INVALID_INPUT", "The root cannot be removed. If the goal changed, edit it with task.update");
|
|
332
|
+
const { changes, counts } = removeTasks(s, subtree(s, r.id));
|
|
333
|
+
return { changes, summary: `Branch removed (${r.id}): ${c.title}${counts}` };
|
|
334
|
+
},
|
|
335
|
+
"dep.add": (s, input, id, ctx) => {
|
|
336
|
+
const from = need(s, input.from, "task", "waiting branch").id;
|
|
337
|
+
const to = need(s, input.to, "task", "branch needed first").id;
|
|
338
|
+
if (from === to) throw new Reject("INVALID_INPUT", "A branch cannot wait for itself");
|
|
339
|
+
if (related(s, from, to)) throw new Reject("INVALID_INPUT", `${from} and ${to} are ancestor and descendant. They are already nested, so no dependency is added`);
|
|
340
|
+
if (all(s, "dep").some((r) => r.content.from === from && r.content.to === to)) {
|
|
341
|
+
throw new Reject("INVALID_INPUT", `${from} already waits for ${to}`);
|
|
342
|
+
}
|
|
343
|
+
if (depReaches(s, to, from)) throw new Reject("INVALID_INPUT", `${to} already waits for ${from} through dependencies, so this would make a cycle`);
|
|
344
|
+
const note = optText(input, "note", ctx) ?? "";
|
|
345
|
+
return {
|
|
346
|
+
changes: [{ id: id(0), type: "dep", prefix: "dp", after: { from, to, note } }],
|
|
347
|
+
summary: `Dependency added: ${depText(s, { from, to, note })}`
|
|
348
|
+
};
|
|
349
|
+
},
|
|
350
|
+
"dep.remove": (s, input) => {
|
|
351
|
+
const r = need(s, input.dep, "dep", "dependency");
|
|
352
|
+
const c = r.content;
|
|
353
|
+
return { changes: [{ id: r.id, type: "dep", after: null }], summary: `Dependency removed (${r.id}): ${depText(s, c)}` };
|
|
354
|
+
},
|
|
355
|
+
// 설명만 고친다. 양 끝이 바뀌면 다른 의존이므로 dep.remove 와 dep.add 로 한다(9.3절)
|
|
356
|
+
"dep.update": (s, input, _id, ctx) => {
|
|
357
|
+
const r = need(s, input.dep, "dep", "dependency");
|
|
358
|
+
const c = r.content;
|
|
359
|
+
if (input.from !== void 0 || input.to !== void 0) throw new Reject("INVALID_INPUT", "The two ends of a dependency cannot be changed. For a different dependency, use dep.remove and dep.add");
|
|
360
|
+
const note = optText(input, "note", ctx);
|
|
361
|
+
if (note === void 0) throw new Reject("INVALID_INPUT", "note is required. Give empty text to clear it");
|
|
362
|
+
return { changes: [{ id: r.id, type: "dep", after: { ...c, note } }], summary: `Dependency note edited (${r.id}): ${depText(s, c)}, note "${clip(note)}"` };
|
|
363
|
+
},
|
|
364
|
+
"question.add": (s, input, id, ctx) => {
|
|
365
|
+
const t = need(s, input.task, "task", "branch").id;
|
|
366
|
+
const text = textInput(input, "text", ctx, "question text");
|
|
367
|
+
const raw = input.options === void 0 || input.options === null ? [] : input.options;
|
|
368
|
+
if (!Array.isArray(raw)) throw new Reject("INVALID_INPUT", "options must be a list of [{ title, detail }]");
|
|
369
|
+
const opts = raw.map((o, i) => {
|
|
370
|
+
if (typeof o === "string") return { title: textInput({ t: o }, "t", ctx, `option ${i + 1}`), detail: "" };
|
|
371
|
+
if (typeof o !== "object" || o === null) throw new Reject("INVALID_INPUT", `option ${i + 1} must be { title, detail }`);
|
|
372
|
+
const oo = o;
|
|
373
|
+
return { title: textInput(oo, "title", ctx, `name of option ${i + 1}`), detail: optText(oo, "detail", ctx) ?? "" };
|
|
374
|
+
});
|
|
375
|
+
let recommend = null;
|
|
376
|
+
if (input.recommend !== void 0 && input.recommend !== null) {
|
|
377
|
+
const k = input.recommend;
|
|
378
|
+
if (typeof k === "string") throw new Reject("INVALID_INPUT", "Options have no ids yet in question.add. Give recommend as a position in options (from 0)");
|
|
379
|
+
if (opts.length === 0) throw new Reject("INVALID_INPUT", "A question without options takes no recommend");
|
|
380
|
+
if (typeof k !== "number" || !Number.isInteger(k) || k < 0 || k >= opts.length) throw new Reject("INVALID_INPUT", `recommend is a position in options (0 to ${opts.length - 1})`);
|
|
381
|
+
recommend = id(k + 1);
|
|
382
|
+
}
|
|
383
|
+
const blocks = blocksInput(s, input.blocks) ?? [t];
|
|
384
|
+
const qid = id(0);
|
|
385
|
+
const content = {
|
|
386
|
+
task: t,
|
|
387
|
+
order: newOrder(questionsOf(s, t), void 0),
|
|
388
|
+
text,
|
|
389
|
+
why: optText(input, "why", ctx) ?? "",
|
|
390
|
+
impact: optText(input, "impact", ctx) ?? "",
|
|
391
|
+
recommend,
|
|
392
|
+
blocks,
|
|
393
|
+
answer: null,
|
|
394
|
+
reopened: ""
|
|
395
|
+
};
|
|
396
|
+
const changes = [{ id: qid, type: "question", prefix: "q", after: content }];
|
|
397
|
+
let prev;
|
|
398
|
+
opts.forEach((o, i) => {
|
|
399
|
+
const order = orderBetween(prev === void 0 ? void 0 : boundAfterOrder(prev), void 0);
|
|
400
|
+
prev = order;
|
|
401
|
+
changes.push({ id: id(i + 1), type: "option", prefix: "o", after: { question: qid, order, title: o.title, detail: o.detail } });
|
|
402
|
+
});
|
|
403
|
+
return { changes, summary: `Question added (${t}): ${text}${opts.length ? `, ${count(opts.length, "option", "options")}` : ""}` };
|
|
404
|
+
},
|
|
405
|
+
"question.update": (s, input, _id, ctx) => {
|
|
406
|
+
const r = need(s, input.question, "question", "question");
|
|
407
|
+
const c = r.content;
|
|
408
|
+
let recommend = c.recommend;
|
|
409
|
+
if (input.recommend !== void 0) {
|
|
410
|
+
recommend = input.recommend === null ? null : recommendOf(s, r.id, input.recommend);
|
|
411
|
+
}
|
|
412
|
+
const next = {
|
|
413
|
+
...c,
|
|
414
|
+
text: input.text === void 0 ? c.text : textInput(input, "text", ctx, "question text"),
|
|
415
|
+
why: optText(input, "why", ctx) ?? c.why,
|
|
416
|
+
impact: optText(input, "impact", ctx) ?? c.impact,
|
|
417
|
+
recommend,
|
|
418
|
+
blocks: blocksInput(s, input.blocks) ?? c.blocks
|
|
419
|
+
};
|
|
420
|
+
return { changes: [{ id: r.id, type: "question", after: next }], summary: `Question edited (${r.id}): ${clip(next.text)}` };
|
|
421
|
+
},
|
|
422
|
+
"question.answer": (s, input, _id, ctx) => {
|
|
423
|
+
const r = need(s, input.question, "question", "question");
|
|
424
|
+
const c = r.content;
|
|
425
|
+
const choice = input.choice === void 0 || input.choice === null ? null : optionOf(s, r.id, input.choice, "chosen option").id;
|
|
426
|
+
const text = optText(input, "text", ctx) ?? "";
|
|
427
|
+
if (input.delegated !== void 0 && typeof input.delegated !== "boolean") throw new Reject("INVALID_INPUT", "delegated must be true or false");
|
|
428
|
+
const delegated = input.delegated === void 0 ? Boolean(c.answer?.delegated) : input.delegated;
|
|
429
|
+
if (choice === null && text === "" && !delegated) throw new Reject("INVALID_INPUT", "At least one of choice, text, delegated is required");
|
|
430
|
+
const answer = { choice, text, delegated };
|
|
431
|
+
const next = { ...c, answer };
|
|
432
|
+
const wasPending = c.answer !== null && isDelegatedPending(c);
|
|
433
|
+
if (wasPending && (choice !== null || text !== "")) {
|
|
434
|
+
const picked = [choice ? `chose (${choice}) ${(s.records[choice]?.content).title}` : "", text ? `"${text}"` : ""].filter(Boolean).join(", ");
|
|
435
|
+
return { changes: [{ id: r.id, type: "question", after: next }], summary: `AI decided a question left to it: (${r.id}) ${clip(c.text)} ${picked}` };
|
|
436
|
+
}
|
|
437
|
+
const verb = c.answer === null ? "Answered" : "Answer changed";
|
|
438
|
+
return { changes: [{ id: r.id, type: "question", after: next }], summary: `${verb} (${r.id} ${clip(c.text)}): ${answerText(s, next)}` };
|
|
439
|
+
},
|
|
440
|
+
"question.reopen": (s, input, _id, ctx) => {
|
|
441
|
+
const r = need(s, input.question, "question", "question");
|
|
442
|
+
const c = r.content;
|
|
443
|
+
if (c.answer === null) throw new Reject("INVALID_INPUT", `${r.id} has no answer yet`);
|
|
444
|
+
const reason = textInput(input, "reason", ctx, "what changed");
|
|
445
|
+
return {
|
|
446
|
+
changes: [{ id: r.id, type: "question", after: { ...c, answer: null, reopened: reason } }],
|
|
447
|
+
summary: `Asked again (${r.id} ${clip(c.text)}): ${reason}. Old ${answerText(s, c)}`
|
|
448
|
+
};
|
|
449
|
+
},
|
|
450
|
+
"question.remove": (s, input) => {
|
|
451
|
+
const r = need(s, input.question, "question", "question");
|
|
452
|
+
const opts = optionsOf(s, r.id);
|
|
453
|
+
return {
|
|
454
|
+
changes: [{ id: r.id, type: "question", after: null }, ...opts.map((o) => ({ id: o.id, type: "option", after: null }))],
|
|
455
|
+
summary: `Question removed (${r.id}): ${clip(r.content.text)}${opts.length ? `, ${count(opts.length, "option", "options")}` : ""}`
|
|
456
|
+
};
|
|
457
|
+
},
|
|
458
|
+
"option.add": (s, input, id, ctx) => {
|
|
459
|
+
const q = need(s, input.question, "question", "question");
|
|
460
|
+
const after = afterInput(input);
|
|
461
|
+
const title = textInput(input, "title", ctx, "option name");
|
|
462
|
+
return {
|
|
463
|
+
changes: [{
|
|
464
|
+
id: id(0),
|
|
465
|
+
type: "option",
|
|
466
|
+
prefix: "o",
|
|
467
|
+
refs: posRefs(after),
|
|
468
|
+
after: { question: q.id, order: newOrder(optionsOf(s, q.id), after), title, detail: optText(input, "detail", ctx) ?? "" }
|
|
469
|
+
}],
|
|
470
|
+
summary: `Option added (${q.id}): ${title}`
|
|
471
|
+
};
|
|
472
|
+
},
|
|
473
|
+
"option.update": (s, input, _id, ctx) => {
|
|
474
|
+
const r = need(s, input.option, "option", "option");
|
|
475
|
+
const c = r.content;
|
|
476
|
+
const next = { ...c, title: input.title === void 0 ? c.title : textInput(input, "title", ctx, "option name"), detail: optText(input, "detail", ctx) ?? c.detail };
|
|
477
|
+
return { changes: [{ id: r.id, type: "option", after: next }], summary: `Option edited (${r.id}): ${next.title}` };
|
|
478
|
+
},
|
|
479
|
+
"option.remove": (s, input) => {
|
|
480
|
+
const r = need(s, input.option, "option", "option");
|
|
481
|
+
const c = r.content;
|
|
482
|
+
const q = question(s, c.question);
|
|
483
|
+
if (q.answer?.choice === r.id) throw new Reject("INVALID_STATE", `${r.id} is the chosen answer to ${c.question}. Ask again with question.reopen first`);
|
|
484
|
+
const changes = [{ id: r.id, type: "option", after: null }];
|
|
485
|
+
if (q.recommend === r.id) changes.push({ id: c.question, type: "question", after: { ...q, recommend: null } });
|
|
486
|
+
return { changes, summary: `Option removed (${r.id}): ${c.title}` };
|
|
487
|
+
},
|
|
488
|
+
"result.add": (s, input, id, ctx) => {
|
|
489
|
+
const t = need(s, input.task, "task", "branch").id;
|
|
490
|
+
const text = textInput(input, "text", ctx, "result");
|
|
491
|
+
const artifact = optText(input, "artifact", ctx) || null;
|
|
492
|
+
const check = checkInput(input.check) ?? "unchecked";
|
|
493
|
+
return {
|
|
494
|
+
changes: [{
|
|
495
|
+
id: id(0),
|
|
496
|
+
type: "result",
|
|
497
|
+
prefix: "rs",
|
|
498
|
+
after: { task: t, order: newOrder(resultsOf(s, t), void 0), text, artifact, check, note: optText(input, "note", ctx) ?? "" }
|
|
499
|
+
}],
|
|
500
|
+
summary: `Result added (${t}) [${CHECK[check]}]: "${clip(text)}"`
|
|
501
|
+
};
|
|
502
|
+
},
|
|
503
|
+
"result.update": (s, input, _id, ctx) => {
|
|
504
|
+
const r = need(s, input.result, "result", "result");
|
|
505
|
+
const c = r.content;
|
|
506
|
+
const artifact = input.artifact === void 0 ? c.artifact : optText(input, "artifact", ctx) || null;
|
|
507
|
+
const next = {
|
|
508
|
+
...c,
|
|
509
|
+
text: input.text === void 0 ? c.text : textInput(input, "text", ctx, "result"),
|
|
510
|
+
artifact,
|
|
511
|
+
check: checkInput(input.check) ?? c.check,
|
|
512
|
+
note: optText(input, "note", ctx) ?? c.note
|
|
513
|
+
};
|
|
514
|
+
return { changes: [{ id: r.id, type: "result", after: next }], summary: `Result edited (${r.id}) [${CHECK[next.check]}]: "${clip(next.text)}"${next.note ? `, note "${clip(next.note)}"` : ""}` };
|
|
515
|
+
},
|
|
516
|
+
"result.remove": (s, input) => {
|
|
517
|
+
const r = need(s, input.result, "result", "result");
|
|
518
|
+
return { changes: [{ id: r.id, type: "result", after: null }], summary: `Result removed (${r.id}): ${clip(r.content.text)}` };
|
|
519
|
+
},
|
|
520
|
+
"link.add": (s, input, id, ctx) => {
|
|
521
|
+
const t = need(s, input.task, "task", "branch").id;
|
|
522
|
+
const record = input.record;
|
|
523
|
+
if (typeof record !== "string" || !/^[A-Za-z]+\d+$/.test(record)) throw new Reject("INVALID_INPUT", "record must be a record id in another screen (for example s3)");
|
|
524
|
+
if (s.records[record]) throw new Reject("INVALID_INPUT", `${record} belongs to this plan. Connect branches with dep.add`);
|
|
525
|
+
if (isCoreId(record)) throw new Reject("INVALID_INPUT", `${record} is a core memo. Make the memo point to the branch instead`);
|
|
526
|
+
const lbl = optText(input, "label", ctx) || record;
|
|
527
|
+
return {
|
|
528
|
+
changes: [{ id: id(0), type: "link", prefix: "lk", after: { task: t, record, label: lbl, note: optText(input, "note", ctx) ?? "" } }],
|
|
529
|
+
summary: `Linked to another screen (${t}): ${record} ${lbl === record ? "" : `"${lbl}"`}`.trim()
|
|
530
|
+
};
|
|
531
|
+
},
|
|
532
|
+
"link.remove": (s, input) => {
|
|
533
|
+
const r = need(s, input.link, "link", "link");
|
|
534
|
+
const c = r.content;
|
|
535
|
+
return { changes: [{ id: r.id, type: "link", after: null }], summary: `Link removed (${r.id}): ${c.record}` };
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
function optionOf(s, q, v, what) {
|
|
539
|
+
const o = need(s, v, "option", what);
|
|
540
|
+
if (o.content.question !== q) throw new Reject("INVALID_INPUT", `${o.id} is not an option of ${q}`);
|
|
541
|
+
return o;
|
|
542
|
+
}
|
|
543
|
+
function recommendOf(s, q, v) {
|
|
544
|
+
if (typeof v === "number") {
|
|
545
|
+
const opts = optionsOf(s, q);
|
|
546
|
+
if (!Number.isInteger(v) || v < 0 || v >= opts.length) throw new Reject("INVALID_INPUT", opts.length ? `recommend position must be 0 to ${opts.length - 1}` : `${q} has no options`);
|
|
547
|
+
return opts[v].id;
|
|
548
|
+
}
|
|
549
|
+
return optionOf(s, q, v, "recommended option").id;
|
|
550
|
+
}
|
|
551
|
+
function blocksInput(s, v) {
|
|
552
|
+
if (v === void 0 || v === null) return void 0;
|
|
553
|
+
if (!Array.isArray(v)) throw new Reject("INVALID_INPUT", "blocks must be a list of branch ids");
|
|
554
|
+
const out = [];
|
|
555
|
+
for (const x of v) {
|
|
556
|
+
const id = need(s, x, "task", "branch waiting for the answer").id;
|
|
557
|
+
if (!out.includes(id)) out.push(id);
|
|
558
|
+
}
|
|
559
|
+
return out;
|
|
560
|
+
}
|
|
561
|
+
function refsOf(r) {
|
|
562
|
+
const out = [];
|
|
563
|
+
const add = (to, kind, soft = false) => {
|
|
564
|
+
if (to) out.push({ from: r.id, to, kind, ...soft ? { soft: true } : {} });
|
|
565
|
+
};
|
|
566
|
+
if (r.type === "task") add(r.content.parent, "parent");
|
|
567
|
+
else if (r.type === "question") {
|
|
568
|
+
const c = r.content;
|
|
569
|
+
add(c.task, "question_task");
|
|
570
|
+
for (const b of c.blocks) add(b, "blocks");
|
|
571
|
+
add(c.recommend, "recommend");
|
|
572
|
+
add(c.answer?.choice, "answer_choice");
|
|
573
|
+
} else if (r.type === "option") add(r.content.question, "option_question");
|
|
574
|
+
else if (r.type === "dep") {
|
|
575
|
+
add(r.content.from, "dep_from");
|
|
576
|
+
add(r.content.to, "dep_to");
|
|
577
|
+
} else if (r.type === "result") add(r.content.task, "result_task");
|
|
578
|
+
else if (r.type === "link") {
|
|
579
|
+
add(r.content.task, "link_task");
|
|
580
|
+
add(r.content.record, "outer", true);
|
|
581
|
+
}
|
|
582
|
+
return out;
|
|
583
|
+
}
|
|
584
|
+
var REF_TYPE = {
|
|
585
|
+
parent: "task",
|
|
586
|
+
question_task: "task",
|
|
587
|
+
blocks: "task",
|
|
588
|
+
recommend: "option",
|
|
589
|
+
answer_choice: "option",
|
|
590
|
+
option_question: "question",
|
|
591
|
+
dep_from: "task",
|
|
592
|
+
dep_to: "task",
|
|
593
|
+
result_task: "task",
|
|
594
|
+
link_task: "task"
|
|
595
|
+
};
|
|
596
|
+
function validate(candidate, changed) {
|
|
597
|
+
const out = [];
|
|
598
|
+
const err = (record, code, message) => out.push({ level: "error", code, record, message });
|
|
599
|
+
const changedSet = new Set(changed);
|
|
600
|
+
let structural = false;
|
|
601
|
+
for (const id of changed) {
|
|
602
|
+
const r = candidate.records[id];
|
|
603
|
+
if (!r) continue;
|
|
604
|
+
if (r.type === "task" || r.type === "dep") structural = true;
|
|
605
|
+
for (const ref of refsOf(r)) {
|
|
606
|
+
if (ref.kind === "outer") continue;
|
|
607
|
+
const to = candidate.records[ref.to];
|
|
608
|
+
if (!to) err(id, "dangling_ref", `${ref.to}, which ${id} points to, does not exist`);
|
|
609
|
+
else if (to.type !== REF_TYPE[ref.kind]) err(id, "wrong_ref_type", `${ref.kind} of ${id} must point to a ${REF_TYPE[ref.kind]}, but ${ref.to} is a ${to.type}`);
|
|
610
|
+
}
|
|
611
|
+
if (r.type === "question") {
|
|
612
|
+
const q = r.content;
|
|
613
|
+
for (const o of [q.recommend, q.answer?.choice]) {
|
|
614
|
+
if (o && candidate.records[o]?.type === "option" && candidate.records[o].content.question !== id) {
|
|
615
|
+
err(id, "option_of_other_question", `${o} is not an option of ${id}`);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (r.type === "option") {
|
|
620
|
+
const qid = r.content.question;
|
|
621
|
+
const q = candidate.records[qid]?.content;
|
|
622
|
+
if (q?.answer?.choice && candidate.records[q.answer.choice]?.type === "option" && candidate.records[q.answer.choice].content.question !== qid) {
|
|
623
|
+
err(qid, "option_of_other_question", `${q.answer.choice} is not an option of ${qid}`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (structural) {
|
|
628
|
+
const tasks = all(candidate, "task");
|
|
629
|
+
const roots = tasks.filter((t) => t.content.parent === null);
|
|
630
|
+
if (roots.length > 1) err(roots.map((t) => t.id).find((x) => changedSet.has(x)) ?? roots[1].id, "second_root", `There can be only one root: ${roots.map((t) => t.id).join(", ")}`);
|
|
631
|
+
for (const t of tasks) {
|
|
632
|
+
if (!changedSet.has(t.id)) continue;
|
|
633
|
+
const seen = /* @__PURE__ */ new Set([t.id]);
|
|
634
|
+
let p = t.content.parent;
|
|
635
|
+
while (p !== null && candidate.records[p]?.type === "task") {
|
|
636
|
+
if (seen.has(p)) {
|
|
637
|
+
err(t.id, "containment_cycle", `The nesting of ${t.id} makes a cycle`);
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
seen.add(p);
|
|
641
|
+
p = candidate.records[p].content.parent;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
for (const d of all(candidate, "dep")) {
|
|
645
|
+
const c = d.content;
|
|
646
|
+
if (!candidate.records[c.from] || !candidate.records[c.to]) continue;
|
|
647
|
+
if (c.from === c.to) err(d.id, "dep_self", `Both ends of dependency ${d.id} are the same`);
|
|
648
|
+
else if (related(candidate, c.from, c.to)) err(d.id, "dep_on_ancestor", `The two ends of dependency ${d.id}, ${c.from} and ${c.to}, are ancestor and descendant`);
|
|
649
|
+
}
|
|
650
|
+
const deps = all(candidate, "dep").map((d) => d.content);
|
|
651
|
+
const cyc = all(candidate, "dep").find((d) => {
|
|
652
|
+
const c = d.content;
|
|
653
|
+
return depReaches({ records: Object.fromEntries(Object.entries(candidate.records).filter(([k]) => k !== d.id)) }, c.to, c.from);
|
|
654
|
+
});
|
|
655
|
+
if (cyc && deps.length) err(cyc.id, "dep_cycle", `Dependencies make a cycle (a loop through ${cyc.id})`);
|
|
656
|
+
}
|
|
657
|
+
const gone = changed.filter((id) => !candidate.records[id]);
|
|
658
|
+
if (gone.length > 0) {
|
|
659
|
+
const goneSet = new Set(gone);
|
|
660
|
+
for (const r of Object.values(candidate.records)) {
|
|
661
|
+
if (changedSet.has(r.id)) continue;
|
|
662
|
+
for (const ref of refsOf(r)) if (!ref.soft && goneSet.has(ref.to)) err(r.id, "dangling_ref", `${r.id} points to ${ref.to}, which was removed`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return out;
|
|
666
|
+
}
|
|
667
|
+
function taskScope(s, scope) {
|
|
668
|
+
const ids = scope?.targets ?? (scope?.target !== void 0 ? [scope.target] : null);
|
|
669
|
+
if (ids === null) return null;
|
|
670
|
+
for (const id of ids) {
|
|
671
|
+
const r = s.records[id];
|
|
672
|
+
if (!r) throw new Reject("TARGET_NOT_FOUND", `Branch ${id} not found`);
|
|
673
|
+
if (r.type !== "task") throw new Reject("INVALID_INPUT", `The scope for a narrowed read must be a branch id. ${id} is a ${r.type}`);
|
|
674
|
+
}
|
|
675
|
+
return ids;
|
|
676
|
+
}
|
|
677
|
+
function viewOf(s, ids) {
|
|
678
|
+
if (ids === null) return { full: new Set(all(s, "task").map((t) => t.id)), heads: /* @__PURE__ */ new Set(), extraQuestions: /* @__PURE__ */ new Set() };
|
|
679
|
+
const full = new Set(ids.flatMap((id) => subtree(s, id)));
|
|
680
|
+
const heads = new Set(ids.flatMap((id) => ancestors(s, id)).filter((x) => !full.has(x)));
|
|
681
|
+
const extraQuestions = new Set(
|
|
682
|
+
all(s, "question").filter((r) => {
|
|
683
|
+
const q = r.content;
|
|
684
|
+
return !full.has(q.task) && (heads.has(q.task) || q.blocks.some((b) => full.has(b)));
|
|
685
|
+
}).map((r) => r.id)
|
|
686
|
+
);
|
|
687
|
+
return { full, heads, extraQuestions };
|
|
688
|
+
}
|
|
689
|
+
function statusTags(s, id) {
|
|
690
|
+
const c = task(s, id);
|
|
691
|
+
const w = waitingOf(s, id);
|
|
692
|
+
const tags = [STATUS[c.status]];
|
|
693
|
+
if (w.person.length) tags.push("waiting for answer");
|
|
694
|
+
if (w.ai.length) tags.push("AI to decide");
|
|
695
|
+
return `[${tags.join(", ")}]`;
|
|
696
|
+
}
|
|
697
|
+
function needsCheck(s, id) {
|
|
698
|
+
const kids = childrenOf(s, id);
|
|
699
|
+
return kids.length > 0 && task(s, id).status !== "done" && kids.every((k) => k.content.status === "done");
|
|
700
|
+
}
|
|
701
|
+
function conceptText(s, ids, mine) {
|
|
702
|
+
const starred = new Set(mine.flatMap((m) => m.changes.filter((c) => c.after !== null).map((c) => c.record)));
|
|
703
|
+
const star = (id) => starred.has(id) ? " *" : "";
|
|
704
|
+
const root = rootOf(s);
|
|
705
|
+
if (!root) return "The plan is empty. Write the goal the person gave as the root with task.add (no parent).";
|
|
706
|
+
const v = viewOf(s, ids);
|
|
707
|
+
const lines = [];
|
|
708
|
+
const inView = (id) => v.full.has(id);
|
|
709
|
+
const qs = all(s, "question").sort(byIdNumber).filter((r) => inView(r.content.task) || v.extraQuestions.has(r.id));
|
|
710
|
+
const open = qs.filter((r) => isOpen(r.content));
|
|
711
|
+
const delegated = qs.filter((r) => isDelegatedPending(r.content));
|
|
712
|
+
const doing = all(s, "task").sort(byIdNumber).filter((t) => inView(t.id) && t.content.status === "doing");
|
|
713
|
+
const check = all(s, "task").sort(byIdNumber).filter((t) => inView(t.id) && needsCheck(s, t.id));
|
|
714
|
+
const qLine = (r) => {
|
|
715
|
+
const q = r.content;
|
|
716
|
+
return `(${r.id}) ${q.text} (branch ${q.task}, waiting branches ${q.blocks.join(", ") || "none"})`;
|
|
717
|
+
};
|
|
718
|
+
if (open.length) lines.push(`Questions waiting for an answer: ${open.map(qLine).join("; ")}`);
|
|
719
|
+
if (delegated.length) lines.push(`AI to decide (the person left it to AI): ${delegated.map(qLine).join("; ")}`);
|
|
720
|
+
if (doing.length) lines.push(`In progress: ${doing.map((t) => label(s, t.id)).join("; ")}`);
|
|
721
|
+
if (check.length) lines.push(`All sub-branches are done. Check whether the aim is met: ${check.map((t) => label(s, t.id)).join("; ")}`);
|
|
722
|
+
if (lines.length) lines.push("");
|
|
723
|
+
const questionBlock = (r, pad) => {
|
|
724
|
+
const q = r.content;
|
|
725
|
+
lines.push(`${pad}Question (${r.id})${star(r.id)} ${q.text} [${answerText(s, q)}]`);
|
|
726
|
+
if (q.why) lines.push(`${pad} Why: ${q.why}`);
|
|
727
|
+
if (q.impact) lines.push(`${pad} Impact: ${q.impact}`);
|
|
728
|
+
if (q.answer === null) lines.push(`${pad} Waiting branches: ${q.blocks.length ? q.blocks.map((b) => label(s, b)).join("; ") : "none"}`);
|
|
729
|
+
if (q.reopened && q.answer === null) lines.push(`${pad} Asked again because: ${q.reopened}`);
|
|
730
|
+
for (const o of optionsOf(s, r.id)) {
|
|
731
|
+
const oc = o.content;
|
|
732
|
+
const tags = [q.recommend === o.id ? "recommended" : "", q.answer?.choice === o.id ? "chosen" : ""].filter(Boolean);
|
|
733
|
+
lines.push(`${pad} Option (${o.id})${star(o.id)} ${oc.title}${tags.length ? ` [${tags.join(", ")}]` : ""}${oc.detail ? `: ${oc.detail}` : ""}`);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
const taskBlock = (id, depth) => {
|
|
737
|
+
const c = task(s, id);
|
|
738
|
+
const pad = " ".repeat(Math.max(0, depth - 1));
|
|
739
|
+
const inner = depth === 0 ? " " : `${pad} `;
|
|
740
|
+
lines.push(depth === 0 ? `Goal (${id})${star(id)} ${c.title} ${statusTags(s, id)}` : `${pad}- (${id})${star(id)} ${c.title} ${statusTags(s, id)}`);
|
|
741
|
+
if (c.aim) lines.push(`${inner}Aim: ${c.aim}`);
|
|
742
|
+
if (c.conditions) lines.push(`${inner}Conditions: ${c.conditions}`);
|
|
743
|
+
if (c.method) lines.push(`${inner}Method: ${c.method}`);
|
|
744
|
+
for (const d of depsFrom(s, id)) {
|
|
745
|
+
const dc = d.content;
|
|
746
|
+
lines.push(`${inner}Needs first (${d.id})${star(d.id)}: ${label(s, dc.to)} ${statusTags(s, dc.to)}`);
|
|
747
|
+
if (dc.note) lines.push(`${inner} Note: ${dc.note}`);
|
|
748
|
+
}
|
|
749
|
+
for (const d of depsTo(s, id)) {
|
|
750
|
+
if (inView(d.content.from)) continue;
|
|
751
|
+
lines.push(`${inner}Waited on by: ${label(s, d.content.from)}`);
|
|
752
|
+
}
|
|
753
|
+
for (const r of resultsOf(s, id)) {
|
|
754
|
+
const rc = r.content;
|
|
755
|
+
lines.push(`${inner}Result (${r.id})${star(r.id)} [${CHECK[rc.check]}] ${rc.text}${rc.artifact ? ` (output ${rc.artifact})` : ""}`);
|
|
756
|
+
if (rc.note) lines.push(`${inner} Note: ${rc.note}`);
|
|
757
|
+
}
|
|
758
|
+
for (const r of linksOf(s, id)) {
|
|
759
|
+
const lc = r.content;
|
|
760
|
+
lines.push(`${inner}Link to another screen (${r.id})${star(r.id)}: ${lc.record} "${lc.label}"`);
|
|
761
|
+
if (lc.note) lines.push(`${inner} Note: ${lc.note}`);
|
|
762
|
+
}
|
|
763
|
+
for (const q of questionsOf(s, id)) questionBlock(q, inner);
|
|
764
|
+
for (const k of childrenOf(s, id)) taskBlock(k.id, depth + 1);
|
|
765
|
+
};
|
|
766
|
+
if (ids === null) {
|
|
767
|
+
taskBlock(root.id, 0);
|
|
768
|
+
} else {
|
|
769
|
+
lines.push("Branches above");
|
|
770
|
+
for (const h of [...v.heads].sort((a, b) => ancestors(s, a).length - ancestors(s, b).length)) {
|
|
771
|
+
const c = task(s, h);
|
|
772
|
+
lines.push(`- (${h})${star(h)} ${c.title} ${statusTags(s, h)}`);
|
|
773
|
+
if (c.aim) lines.push(` Aim: ${c.aim}`);
|
|
774
|
+
if (c.conditions) lines.push(` Conditions: ${c.conditions}`);
|
|
775
|
+
for (const q of questionsOf(s, h)) if (v.extraQuestions.has(q.id)) questionBlock(q, " ");
|
|
776
|
+
}
|
|
777
|
+
const elsewhere = [...v.extraQuestions].filter((q) => !v.heads.has(question(s, q).task));
|
|
778
|
+
if (elsewhere.length) {
|
|
779
|
+
lines.push("", "Questions on branches outside the scope that make branches in the scope wait");
|
|
780
|
+
for (const q of elsewhere) questionBlock(s.records[q], "");
|
|
781
|
+
}
|
|
782
|
+
for (const id of ids) {
|
|
783
|
+
lines.push("", `Branch read (${id})`);
|
|
784
|
+
taskBlock(id, 1);
|
|
785
|
+
}
|
|
786
|
+
const linked = /* @__PURE__ */ new Set();
|
|
787
|
+
for (const id of v.full) for (const d of [...depsFrom(s, id), ...depsTo(s, id)]) {
|
|
788
|
+
const c = d.content;
|
|
789
|
+
for (const x of [c.from, c.to]) if (!v.full.has(x)) linked.add(x);
|
|
790
|
+
}
|
|
791
|
+
if (linked.size) {
|
|
792
|
+
lines.push("", "Branches connected by dependencies");
|
|
793
|
+
for (const x of linked) lines.push(`- ${label(s, x)} ${statusTags(s, x)}`);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return lines.join("\n");
|
|
797
|
+
}
|
|
798
|
+
function scopeRecords(s, ids) {
|
|
799
|
+
const v = viewOf(s, ids);
|
|
800
|
+
const out = /* @__PURE__ */ new Set([...v.full, ...v.heads, ...v.extraQuestions]);
|
|
801
|
+
for (const id of v.full) {
|
|
802
|
+
for (const q of questionsOf(s, id)) out.add(q.id);
|
|
803
|
+
for (const r of [...resultsOf(s, id), ...linksOf(s, id), ...depsFrom(s, id), ...depsTo(s, id)]) out.add(r.id);
|
|
804
|
+
}
|
|
805
|
+
for (const q of [...out]) if (s.records[q]?.type === "question") for (const o of optionsOf(s, q)) out.add(o.id);
|
|
806
|
+
return [...out];
|
|
807
|
+
}
|
|
808
|
+
function project(s, scope, mine) {
|
|
809
|
+
const ids = taskScope(s, scope);
|
|
810
|
+
const flat = (type, sort = byKey) => all(s, type).sort(sort).map((r) => ({ id: r.id, ...r.content }));
|
|
811
|
+
const root = rootOf(s);
|
|
812
|
+
return {
|
|
813
|
+
text: conceptText(s, ids, mine),
|
|
814
|
+
scopeLabel: ids ? `Read branches ${ids.join(", ")} and everything below them, the branches above up to the root, the questions on them, and branches connected by dependencies` : "Read everything",
|
|
815
|
+
// 화면은 한 번에 받아 트리를 그린다. 좁혀 읽어도 JSON 은 전체다
|
|
816
|
+
json: {
|
|
817
|
+
root: root?.id ?? null,
|
|
818
|
+
tasks: flat("task"),
|
|
819
|
+
questions: flat("question"),
|
|
820
|
+
options: flat("option"),
|
|
821
|
+
deps: flat("dep", byIdNumber),
|
|
822
|
+
results: flat("result"),
|
|
823
|
+
links: flat("link", byIdNumber)
|
|
824
|
+
},
|
|
825
|
+
...ids ? { records: scopeRecords(s, ids) } : {}
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
var SELECTION_FORMAT = "aic.plan/selection-1";
|
|
829
|
+
var idList = (v) => Array.isArray(v) && v.length <= 2e3 && v.every((x) => typeof x === "string");
|
|
830
|
+
function selectionProblem(v) {
|
|
831
|
+
const x = v;
|
|
832
|
+
if (typeof x !== "object" || x === null || x.format !== SELECTION_FORMAT) return `The format of the selection is not ${SELECTION_FORMAT}`;
|
|
833
|
+
if (typeof x.rev !== "string") return "The selection has no revision it was drawn from (rev)";
|
|
834
|
+
if (!idList(x.tasks) || !idList(x.questions)) return "tasks and questions of the selection must be lists of ids";
|
|
835
|
+
if (x.labels !== void 0 && (typeof x.labels !== "object" || x.labels === null || Array.isArray(x.labels))) return "labels of the selection must be an object from id to text";
|
|
836
|
+
return null;
|
|
837
|
+
}
|
|
838
|
+
var MAX_SELECTION_LINES = 60;
|
|
839
|
+
var MAX_NAMED_CHILDREN = 12;
|
|
840
|
+
function taskSelectionLine(s, id) {
|
|
841
|
+
const c = task(s, id);
|
|
842
|
+
const parts = [`- ${label(s, id)}: ${c.parent === null ? "it is the goal at the root" : `path ${[...ancestors(s, id), id].map((x) => task(s, x).title).join(" > ")}`}. Status: ${STATUS[c.status]}.`];
|
|
843
|
+
if (c.aim) parts.push(`Aim: ${c.aim}.`);
|
|
844
|
+
if (c.conditions) parts.push(`Conditions: ${c.conditions}.`);
|
|
845
|
+
if (c.method) parts.push(`Method: ${c.method}.`);
|
|
846
|
+
const kids = childrenOf(s, id);
|
|
847
|
+
const below = subtree(s, id).length - 1;
|
|
848
|
+
if (below === 0) parts.push("It has no branches under it.");
|
|
849
|
+
else {
|
|
850
|
+
const named = kids.slice(0, MAX_NAMED_CHILDREN).map((k) => label(s, k.id)).join(", ");
|
|
851
|
+
parts.push(`${count(below, "branch", "branches")} under it (${kids.length} directly under: ${named}${kids.length > MAX_NAMED_CHILDREN ? ` and ${kids.length - MAX_NAMED_CHILDREN} more` : ""}).`);
|
|
852
|
+
}
|
|
853
|
+
const qs = questionsOf(s, id);
|
|
854
|
+
if (qs.length) parts.push(`Questions on it: ${qs.map((q) => `(${q.id}) ${clip(q.content.text)} [${answerText(s, q.content)}]`).join("; ")}.`);
|
|
855
|
+
const w = waitingOf(s, id);
|
|
856
|
+
if (w.person.length) parts.push(`Waiting for the person's answer to ${w.person.join(", ")}.`);
|
|
857
|
+
if (w.ai.length) parts.push(`Waiting for AI to decide ${w.ai.join(", ")}.`);
|
|
858
|
+
const first = depsFrom(s, id);
|
|
859
|
+
if (first.length) parts.push(`Needs first: ${first.map((d) => label(s, d.content.to)).join(", ")}.`);
|
|
860
|
+
const results = resultsOf(s, id);
|
|
861
|
+
if (results.length) parts.push(`${count(results.length, "result", "results")}: ${results.map((r) => `(${r.id}) ${clip(r.content.text)} [${CHECK[r.content.check]}]`).join("; ")}.`);
|
|
862
|
+
return parts.join(" ");
|
|
863
|
+
}
|
|
864
|
+
function questionSelectionLine(s, id) {
|
|
865
|
+
const q = question(s, id);
|
|
866
|
+
const opts = optionsOf(s, id);
|
|
867
|
+
const parts = [`- (${id}) ${q.text}: on branch ${label(s, q.task)}. ${answerText(s, q)[0].toUpperCase()}${answerText(s, q).slice(1)}.`];
|
|
868
|
+
if (q.why) parts.push(`Why it was asked: ${q.why}.`);
|
|
869
|
+
if (q.impact) parts.push(`Impact: ${q.impact}.`);
|
|
870
|
+
if (opts.length) parts.push(`Options: ${opts.map((o) => `(${o.id}) ${o.content.title}${q.recommend === o.id ? " (recommended)" : ""}`).join(", ")}.`);
|
|
871
|
+
if (q.answer === null || isDelegatedPending(q)) parts.push(`Waiting branches: ${q.blocks.length ? q.blocks.map((b) => label(s, b)).join(", ") : "none"}.`);
|
|
872
|
+
if (q.reopened && q.answer === null) parts.push(`Asked again because: ${q.reopened}.`);
|
|
873
|
+
return parts.join(" ");
|
|
874
|
+
}
|
|
875
|
+
function describeSelection(s, input) {
|
|
876
|
+
const problem = selectionProblem(input?.selection);
|
|
877
|
+
if (problem) return { error: "INVALID_INPUT", summary: problem };
|
|
878
|
+
const sel = input.selection;
|
|
879
|
+
const targets = [];
|
|
880
|
+
const gone = [];
|
|
881
|
+
const was = (id) => sel.labels?.[id] ?? "name unknown";
|
|
882
|
+
const lines = [];
|
|
883
|
+
const now = typeof input.current === "string" && input.current !== sel.rev ? ` Something changed after that (now ${input.current}). What follows is the current state.` : "";
|
|
884
|
+
lines.push(`Revision when selected: ${sel.rev}.${now}`);
|
|
885
|
+
if (sel.tasks.length === 0 && sel.questions.length === 0) {
|
|
886
|
+
const root = rootOf(s);
|
|
887
|
+
lines.push(root ? `No branch or question is selected. The words are about the whole plan (goal ${label(s, root.id)}).` : "No branch or question is selected. The plan is empty.");
|
|
888
|
+
}
|
|
889
|
+
const section = (ids, type, head, line) => {
|
|
890
|
+
if (!ids.length) return;
|
|
891
|
+
lines.push(`${head} (${ids.length}):`);
|
|
892
|
+
for (const id of ids.slice(0, MAX_SELECTION_LINES)) {
|
|
893
|
+
if (s.records[id]?.type !== type) {
|
|
894
|
+
gone.push(id);
|
|
895
|
+
lines.push(`- (${id}) ${was(id)} (removed since)`);
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
targets.push(id);
|
|
899
|
+
lines.push(line(id));
|
|
900
|
+
}
|
|
901
|
+
if (ids.length > MAX_SELECTION_LINES) lines.push(`- and ${ids.length - MAX_SELECTION_LINES} more. Read them with a branch id as scope`);
|
|
902
|
+
};
|
|
903
|
+
section(sel.tasks, "task", "Selected branches", (id) => taskSelectionLine(s, id));
|
|
904
|
+
section(sel.questions, "question", "Selected questions", (id) => questionSelectionLine(s, id));
|
|
905
|
+
if (sel.tasks.length + sel.questions.length > 1) lines.push("More than one item is selected. If it is not clear which one the person means, ask the person.");
|
|
906
|
+
if (targets.length) lines.push("To read the branches below a selected branch, use its id as scope.");
|
|
907
|
+
return { text: lines.join("\n"), targets, gone };
|
|
908
|
+
}
|
|
909
|
+
function resolveLabel(s, id) {
|
|
910
|
+
const r = s.records[id];
|
|
911
|
+
if (!r) return id;
|
|
912
|
+
switch (r.type) {
|
|
913
|
+
case "task":
|
|
914
|
+
return `Branch ${id}: ${r.content.title}`;
|
|
915
|
+
case "question":
|
|
916
|
+
return `Question ${id}: ${clip(r.content.text)}`;
|
|
917
|
+
case "option":
|
|
918
|
+
return `Option ${id}: ${r.content.title}`;
|
|
919
|
+
case "dep":
|
|
920
|
+
return `Dependency ${id}`;
|
|
921
|
+
case "result":
|
|
922
|
+
return `Result ${id}: ${clip(r.content.text)}`;
|
|
923
|
+
case "link":
|
|
924
|
+
return `Link ${id}: ${r.content.label}`;
|
|
925
|
+
default:
|
|
926
|
+
return id;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
var AI_GUIDE = [
|
|
930
|
+
"This screen is Task Tree. The person sets the outline (the goal and conditions at the root), you break it down into branches of an action plan, and you attach questions only where the person needs to decide.",
|
|
931
|
+
"Write what you write into the work (names, aims, conditions, methods, questions, options, results) in the language the person uses.",
|
|
932
|
+
"Write the goal and conditions the person gave into the root title, aim and conditions, as you understood them. The person checks your understanding on the screen.",
|
|
933
|
+
"Decide the details of how to reach a settled goal yourself. Write the method and a short reason in method, then go ahead. Do not ask about what you can learn by reading material or by testing; make a research or test branch for it instead.",
|
|
934
|
+
`Ask with question.add only when the plan depends on the person's taste, goal or limits. With the question, give why (the reason you cannot decide it yourself), options, recommend, impact (what changes depending on the answer) and blocks (branches waiting for the answer). Do not write only "What should I do?". A question about a fact only the person knows takes no options, and then no recommend either.`,
|
|
935
|
+
"Do not go ahead on a waiting branch with a made-up answer. Meanwhile, work on other branches that do not depend on it.",
|
|
936
|
+
'When the person answers in the conversation, put the answer into the tree with question.answer and fix the affected branches in the same request. Do not leave the answer only in the conversation. When the person says "you decide", set delegated to true and write the chosen option (choice) and your reason (text). A question the person left to you on the screen with "AI may decide" is yours to decide.',
|
|
937
|
+
"Do not ask an answered question again. If the goal above or the grounds change and it needs a new decision, write what changed in the reason of question.reopen. Keep answered questions; do not remove them.",
|
|
938
|
+
"Nesting is not the order of work. Being higher does not mean doing it first. When a branch needs the result of another branch, connect them with dep.add. Do not copy the same work into two branches.",
|
|
939
|
+
"Options are not sub-tasks. Showing options side by side does not mean doing both. Make branches only for the work of the chosen option.",
|
|
940
|
+
"status is todo, doing or done. It is progress information, not approval. Connect the result of the work to its branch with result.add and write in check whether it matches the intent: meets means it matches, partial means only part is done (write what is left in note), differs means it differs from the intent, and unchecked means not checked yet. Even when all sub-branches are done, check that the aim of the branch above is met before setting it to done.",
|
|
941
|
+
"When a goal above changes, check the plan below again, and tell the person in your reply which branches you changed and which you kept. The core makes the change history from your operations. If the person edits a goal directly and it conflicts with an earlier answer, follow the new wording and write in method which answer changed and how. Do not ask again in this case. The person can add, move and remove branches at any time. Do not hold on to the breakdown you first made.",
|
|
942
|
+
"You may also edit fields the person wrote (conditions, names, words added to an answer) to settle conflicts between them or to apply the person's answer. Do not change the meaning, and tell the person you edited them. Do not make edits that only change the person's words into your own style. The person can see the text before your change until it is settled, so they can undo it.",
|
|
943
|
+
`Changes by the person are not merged into the tree until you send your next request; they are in the "changes by other participants" list of the read. If the person's answer (Answered) or a goal edit is there, that is the current answer and goal. Do not ask again even if the tree still shows "no answer".`,
|
|
944
|
+
"If the same work has an instance of another plugin, do not copy an item from that screen. Use link.add with its record id and its current name (label). To read that item, read that instance with read_concept.",
|
|
945
|
+
"If the plan needs to change while you work in another plugin, leave a core memo that points to the branch, and edit it after the person switches to this screen.",
|
|
946
|
+
"This tree is a plan and the grounds for decisions that you review together. Do not write every step of your thinking. For a narrowed read, use a branch id as scope."
|
|
947
|
+
].join(" ");
|
|
948
|
+
var DESCRIPTION = {
|
|
949
|
+
id: PACKAGE_ID,
|
|
950
|
+
version: VERSION,
|
|
951
|
+
title: "Task Tree",
|
|
952
|
+
aiGuide: AI_GUIDE,
|
|
953
|
+
markGuide: 'Text fields are plain text. Do not use marks inside text. To mention another branch, write its id in the text like (t3), or connect it with dep.add. For something created in the same request, give it a $name with "as" and point to it from the input of another operation.',
|
|
954
|
+
operations: [
|
|
955
|
+
{
|
|
956
|
+
op: "task.add",
|
|
957
|
+
input: { parent: "Parent branch id or $name. Leave out only when making the root (the goal)", after: "Id of the sibling before. null for the front, leave out for the end", title: "Name", aim: "What it should achieve", conditions: "Conditions to keep", method: "Chosen method and a short reason", status: "todo, doing, done (todo if left out)" },
|
|
958
|
+
summary: "Makes a branch. There is only one root",
|
|
959
|
+
example: [
|
|
960
|
+
{ op: "task.add", as: "$goal", input: { title: "Let developers add and share concept screens", conditions: "Publish only after the stage 4 test" } },
|
|
961
|
+
{ op: "task.add", input: { parent: "$goal", title: "Make it possible to build plugins", method: "Follow the 032 contract, because it is already settled" } }
|
|
962
|
+
]
|
|
963
|
+
},
|
|
964
|
+
{ op: "task.update", input: { task: "Branch id", title: "Name", aim: "What it should achieve", conditions: "Conditions", method: "Method and reason", status: "todo, doing, done" }, summary: "Edits only the given fields. Empty text clears the field. The id stays the same when the name changes" },
|
|
965
|
+
{ op: "task.move", input: { task: "Branch id", parent: "New parent branch id", after: "Id of the sibling before. null for the front, leave out for the end" }, summary: "Moves under another parent or within the same parent. The id stays the same" },
|
|
966
|
+
{ op: "task.remove", input: { task: "Branch id" }, summary: "Removes the branch and everything below it, with its questions, results, links to other screens and connected dependencies. The root cannot be removed" },
|
|
967
|
+
{ op: "dep.add", input: { from: "Id of the waiting branch", to: "Id of the branch needed first", note: "Why it is needed" }, summary: "from needs the result of to. This is the only way to show the order of work" },
|
|
968
|
+
{ op: "dep.update", input: { dep: "Dependency id", note: "Why it is needed" }, summary: "Edits only the note of a dependency. If the ends change, use dep.remove and dep.add" },
|
|
969
|
+
{ op: "dep.remove", input: { dep: "Dependency id" }, summary: "Removes a dependency" },
|
|
970
|
+
{
|
|
971
|
+
op: "question.add",
|
|
972
|
+
input: { task: "Id of the branch to attach to", text: "What to ask", why: "Why you cannot decide it yourself", impact: "What changes depending on the answer", options: "[{ title, detail }] options. Leave out for a question about a fact only the person knows", recommend: "Position of the recommended option (from 0)", blocks: "List of ids of branches waiting for the answer (the attached branch if left out)" },
|
|
973
|
+
summary: "Attaches a question and options where the person needs to decide",
|
|
974
|
+
example: { op: "question.add", input: { task: "t3", text: "How far should sharing go?", why: "Whether to run a hosting space is a business decision for rawdev", impact: "The number of branches under t3 and the server work", options: [{ title: "Share install files", detail: "2 tasks" }, { title: "Also provide search and a hosting space", detail: "Needs a server and a review process" }], recommend: 0 } }
|
|
975
|
+
},
|
|
976
|
+
{ op: "question.update", input: { question: "Question id", text: "What to ask", why: "Reason", impact: "What changes", recommend: "Position of the option (from 0) or option id, null to remove", blocks: "List of waiting branch ids" }, summary: "Edits a question" },
|
|
977
|
+
{ op: "question.answer", input: { question: "Question id", choice: "Chosen option id", text: "A direction written by the person or words added to the answer; for a question left to you, your reason", delegated: 'true if the person left it to you with "you decide"' }, summary: "Writes the answer into the tree. Also use it for answers the person gave in the conversation" },
|
|
978
|
+
{ op: "question.reopen", input: { question: "Question id", reason: "What changed" }, summary: "Clears the answer and asks again. The old answer stays in the history" },
|
|
979
|
+
{ op: "question.remove", input: { question: "Question id" }, summary: "Removes the question and its options. As a rule, keep answered questions" },
|
|
980
|
+
{ op: "option.add", input: { question: "Question id", after: "Id of the option before", title: "Name", detail: "Difference and amount of work" }, summary: "Adds an option" },
|
|
981
|
+
{ op: "option.update", input: { option: "Option id", title: "Name", detail: "Difference and amount of work" }, summary: "Edits an option" },
|
|
982
|
+
{ op: "option.remove", input: { option: "Option id" }, summary: "Removes an option. The option chosen as the answer cannot be removed before asking again" },
|
|
983
|
+
{ op: "result.add", input: { task: "Branch id", text: "What was done and where it is", artifact: "Output id (optional)", check: "unchecked, meets, partial, differs", note: "If partial or different, what is left or what differs" }, summary: "Connects the result of the work to the branch" },
|
|
984
|
+
{ op: "result.update", input: { result: "Result id", text: "Result", artifact: "Output id", check: "unchecked, meets, partial, differs", note: "Note" }, summary: "Edits a result and its check" },
|
|
985
|
+
{ op: "result.remove", input: { result: "Result id" }, summary: "Removes a result" },
|
|
986
|
+
{ op: "link.add", input: { task: "Branch id", record: "Record id in another screen (for example s3)", label: "Current name of that item", note: "Why it points there" }, summary: "Points to an item in another screen by id, without copying it" },
|
|
987
|
+
{ op: "link.remove", input: { link: "Link id" }, summary: "Removes a link" }
|
|
988
|
+
]
|
|
989
|
+
};
|
|
990
|
+
var run = (f) => {
|
|
991
|
+
try {
|
|
992
|
+
return f();
|
|
993
|
+
} catch (e) {
|
|
994
|
+
if (e instanceof Reject) return { error: e.code, summary: e.message };
|
|
995
|
+
throw e;
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
var logic = {
|
|
999
|
+
describe: () => DESCRIPTION,
|
|
1000
|
+
initialize: () => [],
|
|
1001
|
+
plan(state, op, ctx) {
|
|
1002
|
+
const handler = OPERATIONS[op.op];
|
|
1003
|
+
if (!handler) return { error: "INVALID_INPUT", summary: `Unknown operation ${op.op}. See the list of operations in describe_document` };
|
|
1004
|
+
const id = (k) => k === 0 && op.as ? op.as : `$~${ctx.stepIndex}.${k}`;
|
|
1005
|
+
return run(() => {
|
|
1006
|
+
const out = handler(state, op.input ?? {}, id, ctx);
|
|
1007
|
+
return { ...out, summary: /[.?!]$/.test(out.summary) ? out.summary : `${out.summary}.` };
|
|
1008
|
+
});
|
|
1009
|
+
},
|
|
1010
|
+
validate,
|
|
1011
|
+
project: (state, scope, mine) => run(() => project(state, scope, mine)),
|
|
1012
|
+
extractRefs: refsOf,
|
|
1013
|
+
describeSelection: (state, input) => describeSelection(state, input),
|
|
1014
|
+
prepareGeneration: () => ({ error: "UNSUPPORTED_CAPABILITY", summary: "Task Tree does not make outputs. Make the output in the screen that does that work, then connect it with result.add" }),
|
|
1015
|
+
interpretSelection(state, sel) {
|
|
1016
|
+
const text = sel.text.trim();
|
|
1017
|
+
const candidates = text === "" ? [] : all(state, "task").sort(byIdNumber).filter((t) => {
|
|
1018
|
+
const title = t.content.title;
|
|
1019
|
+
return title !== "" && (text.includes(title) || title.includes(text));
|
|
1020
|
+
}).map((t) => ({ id: t.id, label: resolveLabel(state, t.id), why: "The selected text overlaps the branch name" }));
|
|
1021
|
+
return { candidates };
|
|
1022
|
+
},
|
|
1023
|
+
resolveTarget(state, target) {
|
|
1024
|
+
const r = state.records[target.id];
|
|
1025
|
+
return r ? { found: true, label: resolveLabel(state, r.id) } : { found: false };
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
globalThis.__aicPlugin = logic;
|
|
1029
|
+
})();
|