agent-yes 1.303.1 → 1.304.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.
Files changed (184) hide show
  1. package/README.md +54 -0
  2. package/default.config.yaml +5 -5
  3. package/dist/{JsonlStore-BpYZZTap.js → JsonlStore-CB_0sfdT.js} +5 -4
  4. package/dist/{SUPPORTED_CLIS-Dq9Lq9WJ.js → SUPPORTED_CLIS-C_1IiOj3.js} +2 -2
  5. package/dist/SUPPORTED_CLIS-Do3GHAY1.js +12 -0
  6. package/dist/{agentShare-suB6yPgO.js → agentShare-BvpEm-Fr.js} +10 -9
  7. package/dist/{askCli-BU3CNCLU.js → askCli-KmMf-3wA.js} +6 -6
  8. package/dist/{browser-BmxN1Ur9.js → browser-BAFPmEvN.js} +2 -2
  9. package/dist/{callback-Ctj3_Wxp.js → callback-BiSUhjw7.js} +6 -6
  10. package/dist/callback-SqLD2mMX.js +17 -0
  11. package/dist/{callbackCore-DSJWhqAe.js → callbackCore-BZ_10zyc.js} +1 -1
  12. package/dist/{callbackCore-BesbQ6-Z.js → callbackCore-Deve5pv3.js} +1 -1
  13. package/dist/{channels-j5nWuzlQ.js → channels-Y36S0ccW.js} +2 -2
  14. package/dist/cli.js +118 -13
  15. package/dist/{cmdDsh-2LP0grim.js → cmdDsh-DZ8bLsH7.js} +1 -1
  16. package/dist/cmdKill-CzSBfWmx.js +116 -0
  17. package/dist/{cmdPs-wc1j85fi.js → cmdPs-DBt23Qz0.js} +11 -10
  18. package/dist/{cwdConflictWarn-skQSMwEh.js → cwdConflictWarn-y-epQyOj.js} +21 -5
  19. package/dist/{cwdPassthroughHint-BUbWMoz0.js → cwdPassthroughHint-CzWh0hrw.js} +1 -1
  20. package/dist/{expose-Dawq1LxC.js → expose-Bhsn5yUz.js} +2 -2
  21. package/dist/forceKill-BDqxx4uQ.js +44 -0
  22. package/dist/{forkNested-CavHyWzA.js → forkNested-3heLs5XC.js} +45 -5
  23. package/dist/{globalPidIndex-CRB5KtyL.js → globalPidIndex-BsjlId-h.js} +6 -5
  24. package/dist/{globalPidIndex-BftWlg2V.js → globalPidIndex-uoz8Esqz.js} +2 -2
  25. package/dist/{hist-Cs0KFSUW.js → hist-DY16wm7g.js} +1 -1
  26. package/dist/{identity-DA7YI9km.js → identity-C0MxfwI2.js} +1 -1
  27. package/dist/{identity-Bk-aG_xl.js → identity-Ckav3-Up.js} +1 -1
  28. package/dist/index.js +7 -7
  29. package/dist/{initMsg-CcTqFtsp.js → initMsg-BEVDWYnv.js} +1 -1
  30. package/dist/{initMsg-D9KJnfgC.js → initMsg-GPU52N-j.js} +1 -1
  31. package/dist/liagent/box-BSIrRRc_.js +2320 -0
  32. package/dist/liagent/box-DloywR57.d.ts +409 -0
  33. package/dist/liagent/box.d.ts +3 -0
  34. package/dist/liagent/box.js +3 -0
  35. package/dist/liagent/cli.d.ts +1 -0
  36. package/dist/liagent/cli.js +908 -0
  37. package/dist/liagent/client.d.ts +28 -0
  38. package/dist/liagent/client.js +240 -0
  39. package/dist/liagent/echo-BvzPSI0x.js +86 -0
  40. package/dist/liagent/echo-W2RcMEny.d.ts +38 -0
  41. package/dist/liagent/hub.d.ts +405 -0
  42. package/dist/liagent/hub.js +1831 -0
  43. package/dist/liagent/index.d.ts +14 -0
  44. package/dist/liagent/index.js +10 -0
  45. package/dist/liagent/liagent.js +339 -0
  46. package/dist/liagent/mic-audio-C3Shud_F.js +754 -0
  47. package/dist/liagent/mic-audio-DMCWtEI-.d.ts +317 -0
  48. package/dist/liagent/mic-button-CtZHFBSG.js +651 -0
  49. package/dist/liagent/mic-button-Y0ioPetQ.d.ts +248 -0
  50. package/dist/liagent/mic.d.ts +3 -0
  51. package/dist/liagent/mic.js +4 -0
  52. package/dist/liagent/progress-CJs08bXb.js +473 -0
  53. package/dist/liagent/progress-CfE-meHr.d.ts +205 -0
  54. package/dist/liagent/progress.d.ts +2 -0
  55. package/dist/liagent/progress.js +3 -0
  56. package/dist/liagent/protocol.d.ts +324 -0
  57. package/dist/liagent/protocol.js +504 -0
  58. package/dist/liagent/speech-rate-DXeJjRTc.js +42 -0
  59. package/dist/liagent/state-tree-BZCmAknI.js +353 -0
  60. package/dist/liagent/tree-BrR7NwMf.js +710 -0
  61. package/dist/liagent/tree-HB9RhX_H.d.ts +295 -0
  62. package/dist/liagent/tree.d.ts +2 -0
  63. package/dist/liagent/tree.js +4 -0
  64. package/dist/liagent/ui-strings-B03le3fh.d.ts +27 -0
  65. package/dist/liagent/ui-strings-CJIwW5Gf.js +794 -0
  66. package/dist/liagent/ui.d.ts +394 -0
  67. package/dist/liagent/ui.js +5 -0
  68. package/dist/liagent/voice-D7yeS9VM.js +802 -0
  69. package/dist/liagent/voice-Qo7SCgi8.d.ts +308 -0
  70. package/dist/liagent/voice.d.ts +3 -0
  71. package/dist/liagent/voice.js +4 -0
  72. package/dist/{notifyDaemon-C7GlfJ1E.js → notifyDaemon-DkUB7GV2.js} +10 -9
  73. package/dist/{openBrowser-1cIo4dJL.js → openBrowser-CQAOIrD6.js} +1 -1
  74. package/dist/oxmgrService-DlYHmqyI.js +37 -0
  75. package/dist/oxmgrService-o9L3I6FX.js +3 -0
  76. package/dist/{parentLink-DoEWVGld.js → parentLink-BcAYcO9L.js} +2 -2
  77. package/dist/{parentLink-B58V1RVd.js → parentLink-MBUD3oY2.js} +2 -2
  78. package/dist/{parentPingLoop-C73bbmCE.js → parentPingLoop-DDO592Wh.js} +5 -5
  79. package/dist/{pidStore-433kvh9D.js → pidStore-C50VPk3E.js} +3 -3
  80. package/dist/pidStore-COkPjpW8.js +6 -0
  81. package/dist/{procStats-BvmrBrOs.js → procStats-DwTxj3rs.js} +1 -1
  82. package/dist/{remotes-MfdV9M8u.js → remotes-BqLoB5GR.js} +2 -2
  83. package/dist/{remotes-DevcBeLl.js → remotes-BsMGvAay.js} +3 -3
  84. package/dist/{roomReplyAlias-DFqg_6IU.js → roomReplyAlias-B-v76TA8.js} +3 -3
  85. package/dist/roomReplyAlias-BzWUBkQy.js +6 -0
  86. package/dist/{rustBinary-7VK7oLlW.js → rustBinary-BrJ2p8wy.js} +2 -2
  87. package/dist/{rustBinary-BV4LxMMn.js → rustBinary-vpfpWj1q.js} +2 -2
  88. package/dist/{schedule-Dp0qkNO1.js → schedule-Bzjhl6-h.js} +15 -44
  89. package/dist/schedulesCli-CLqieyQZ.js +784 -0
  90. package/dist/senderAncestry-CVHeKk1Y.js +173 -0
  91. package/dist/senderAncestry-KhAUPCQs.js +3 -0
  92. package/dist/{serve-BpOIIOVc.js → serve-XwFYE0cE.js} +67 -69
  93. package/dist/{serveRust-CbBrcUrg.js → serveRust-BfWkeL6T.js} +31 -4
  94. package/dist/{setup-DdIBk6Iv.js → setup-D4-s2VZw.js} +5 -5
  95. package/dist/{share-w5oRbvlj.js → share-CbFetL5H.js} +1 -1
  96. package/dist/{share-DrS3LYqf.js → share-_TPYAGWC.js} +1 -1
  97. package/dist/{shareCmd-DDENkBW2.js → shareCmd-DUBsVI3e.js} +10 -10
  98. package/dist/spawnGate-Dfj9V76w.js +5 -0
  99. package/dist/{spawnGate-lr3tvA6U.js → spawnGate-Dj_WaS29.js} +3 -3
  100. package/dist/{subcommands-DxgvDmZX.js → subcommands-B7YZJL8n.js} +471 -307
  101. package/dist/subcommands-BZPxFgkT.js +15 -0
  102. package/dist/{systemPathLink-SjUzgSiq.js → systemPathLink-Y3iC7bYV.js} +1 -1
  103. package/dist/{terminal-C2h7tpe0.js → terminal-13cGj3h6.js} +2 -2
  104. package/dist/terminal.js +1 -1
  105. package/dist/{todoAutomation-TTp_Qz9G.js → todoAutomation-CKlrxuZv.js} +2 -2
  106. package/dist/{todoCli-BWm5nZE0.js → todoCli-CU9vSJSJ.js} +6 -6
  107. package/dist/{todoIdentity-BvXZKWJI.js → todoIdentity-CzS1e7VL.js} +2 -2
  108. package/dist/{todoStore-C9RTz0Vs.js → todoStore-msRCEUi1.js} +2 -2
  109. package/dist/{tray-BeRSozJz.js → tray-CLktEN3G.js} +1 -1
  110. package/dist/{trayApp-QQjqhDv1.js → trayApp-5_OlvQcz.js} +2 -2
  111. package/dist/trayApp-DkAPo0m6.js +5 -0
  112. package/dist/{ts-6LF7f4fx.js → ts-njuddXQz.js} +126 -57
  113. package/dist/{versionChecker-Bc62HNf6.js → versionChecker-BJycAanp.js} +2 -2
  114. package/dist/{webrtcLink-va_gAR77.js → webrtcLink-DcvacEci.js} +1 -1
  115. package/dist/{webrtcLink-SsInrVHU.js → webrtcLink-WxS1nTIs.js} +1 -1
  116. package/dist/{webrtcRemote-BlGyNZDC.js → webrtcRemote-C3xQyf3u.js} +2 -2
  117. package/dist/{widget-Crb5zeHL.js → widget-DmRwOlco.js} +3 -3
  118. package/dist/widgets.js +1 -1
  119. package/dist/{workspaceConfig-BLWB5Wu9.js → workspaceConfig-DBgsu81B.js} +1 -1
  120. package/dist/{ws-DIbwNz8Z.js → ws-ByO6JO6m.js} +3 -3
  121. package/dist/{ws-BRhPG1Vy.js → ws-D0-Jg88z.js} +9 -8
  122. package/lab/ui/index.html +1 -1
  123. package/lab/ui/lab/posts/2026-08-11-slack-term-safe-writes.md +1 -1
  124. package/package.json +73 -8
  125. package/ts/JsonlStore.ts +10 -3
  126. package/ts/cli-idle.bun.spec.ts +1 -1
  127. package/ts/cli-idle.spec.ts +1 -1
  128. package/ts/cli.ts +35 -0
  129. package/ts/cmdKill.bun.spec.ts +155 -0
  130. package/ts/cmdKill.spec.ts +155 -0
  131. package/ts/cmdKill.ts +183 -0
  132. package/ts/composerGuard.edges.spec.ts +91 -0
  133. package/ts/composerGuard.spec.ts +53 -6
  134. package/ts/composerGuard.ts +42 -13
  135. package/ts/conptyModeFilter.spec.ts +30 -0
  136. package/ts/conptyModeFilter.ts +53 -0
  137. package/ts/copyLiagent.ts +42 -0
  138. package/ts/cwdConflictWarn.io.spec.ts +50 -0
  139. package/ts/cwdConflictWarn.spec.ts +34 -1
  140. package/ts/cwdConflictWarn.ts +43 -5
  141. package/ts/cwdGuard.spec.ts +110 -0
  142. package/ts/cwdGuard.ts +118 -0
  143. package/ts/forceKill.ts +52 -0
  144. package/ts/forkNested.bun.spec.ts +41 -0
  145. package/ts/forkNested.spec.ts +41 -0
  146. package/ts/forkNested.ts +48 -1
  147. package/ts/globalPidIndex.edges.spec.ts +125 -0
  148. package/ts/globalPidIndex.ts +6 -2
  149. package/ts/index.ts +13 -1
  150. package/ts/interruptSend.bun.spec.ts +99 -0
  151. package/ts/interruptSend.spec.ts +99 -0
  152. package/ts/interruptSend.ts +51 -0
  153. package/ts/lockRegistry.spec.ts +49 -0
  154. package/ts/lsRenderCache.spec.ts +58 -0
  155. package/ts/needsInput.edges.spec.ts +23 -0
  156. package/ts/parseCliArgs.ts +7 -0
  157. package/ts/pushGatePlan.spec.ts +147 -0
  158. package/ts/roomReplyAlias.io.spec.ts +81 -0
  159. package/ts/schedule.ts +5 -1
  160. package/ts/schedules.bun.spec.ts +397 -0
  161. package/ts/schedules.spec.ts +397 -0
  162. package/ts/schedules.ts +517 -0
  163. package/ts/schedulesCli.ts +386 -0
  164. package/ts/sendControl.bun.spec.ts +12 -0
  165. package/ts/senderAncestry.ts +1 -3
  166. package/ts/serve.ts +22 -33
  167. package/ts/serveRust.spec.ts +29 -2
  168. package/ts/serveRust.ts +27 -2
  169. package/ts/sizeNego.bun.spec.ts +9 -2
  170. package/ts/sizeNego.spec.ts +9 -2
  171. package/ts/sizeNego.ts +10 -5
  172. package/ts/subcommands.spec.ts +348 -9
  173. package/ts/subcommands.ts +513 -93
  174. package/ts/suggestAgents.spec.ts +33 -0
  175. package/ts/terminal/browser.ts +1 -1
  176. package/ts/todoParse.spec.ts +22 -1
  177. package/ts/todoParse.ts +19 -0
  178. package/dist/SUPPORTED_CLIS-ByO5twge.js +0 -12
  179. package/dist/callback-D7qfh_7p.js +0 -16
  180. package/dist/pidStore-BRlKRHXY.js +0 -6
  181. package/dist/roomReplyAlias-DuEkSSDI.js +0 -6
  182. package/dist/spawnGate-DeQBTX-o.js +0 -5
  183. package/dist/subcommands-DmiswRy4.js +0 -14
  184. package/dist/trayApp-C4TAvRvU.js +0 -5
@@ -0,0 +1,353 @@
1
+ //#region src/state-tree.ts
2
+ /** Name of the human owner as an assignee token: `@owner`. */
3
+ const OWNER_NAME = "owner";
4
+ const TAB = " ";
5
+ const ITEM = /^(\s*)[-*+]\s+(.*)$/;
6
+ const HEADING = /^##\s+(.*)$/;
7
+ const ACTION = /^(?:→|->)\s*(.*)$/;
8
+ const SUMMARY = /^≈([A-Za-z]{2,3}(?:-[A-Za-z0-9]+)?)?\s+(.*)$/;
9
+ const BOX = /^\[([ xX~!])\]\s*/;
10
+ const OWNER = /\(!\)/g;
11
+ const ANY_ORDER = /\(any order\)/gi;
12
+ const DONE_AT = /\(done\s+(\d{4}-\d{2}-\d{2}(?:[T ][\d:]+)?)\)/i;
13
+ const ASSIGNEE = /(?:^|\s)@([A-Za-z0-9][\w.-]*)(?:#(\S*))?$/;
14
+ /** An agent's opaque id: nothing that could be a host, a pid with a colon, or a token. */
15
+ const AGENT_ID = /^[A-Za-z0-9_-]{1,40}$/;
16
+ const STATUS = {
17
+ " ": "open",
18
+ "~": "doing",
19
+ "!": "blocked",
20
+ x: "done",
21
+ X: "done"
22
+ };
23
+ /** PR refs and URLs in `text`, in order, each once. */
24
+ function findLinks(text, opts = {}) {
25
+ const host = (opts.host ?? "https://github.com").replace(/\/$/, "");
26
+ const out = [];
27
+ const seen = /* @__PURE__ */ new Set();
28
+ const add = (l) => {
29
+ if (seen.has(l.url)) return;
30
+ seen.add(l.url);
31
+ out.push(l);
32
+ };
33
+ for (const m of text.matchAll(/(https?:\/\/[^\s)>\]]+)|(?<![\w/#])([A-Za-z0-9][\w.-]*\/[\w.-]+)#(\d+)\b|(?<![\w/&#])#(\d+)\b/g)) if (m[1]) {
34
+ const url = m[1].replace(/[.,;:]+$/, "");
35
+ add({
36
+ text: url,
37
+ url
38
+ });
39
+ } else if (m[2]) add({
40
+ text: `${m[2]}#${m[3]}`,
41
+ url: `${host}/${m[2]}/pull/${m[3]}`
42
+ });
43
+ else if (m[4] && opts.repo) add({
44
+ text: `#${m[4]}`,
45
+ url: `${host}/${opts.repo}/pull/${m[4]}`
46
+ });
47
+ return out;
48
+ }
49
+ const indentOf = (s) => s.replaceAll(" ", TAB).length;
50
+ /** `@owner` is the human; anything else an agent. */
51
+ function assigneeOf(name, id) {
52
+ if (name === OWNER_NAME) return {
53
+ type: "human",
54
+ name
55
+ };
56
+ return id && AGENT_ID.test(id) ? {
57
+ type: "agent",
58
+ name,
59
+ id
60
+ } : {
61
+ type: "agent",
62
+ name
63
+ };
64
+ }
65
+ /** A node from an item's or a heading's text: box, markers, assignee, links. */
66
+ function node(raw, opts) {
67
+ let text = raw.trim();
68
+ let status;
69
+ const box = BOX.exec(text);
70
+ if (box) {
71
+ status = STATUS[box[1]];
72
+ text = text.slice(box[0].length);
73
+ }
74
+ const needsOwner = OWNER.test(text);
75
+ OWNER.lastIndex = 0;
76
+ if (needsOwner) text = text.replace(OWNER, " ");
77
+ const unordered = ANY_ORDER.test(text);
78
+ ANY_ORDER.lastIndex = 0;
79
+ if (unordered) text = text.replace(ANY_ORDER, " ");
80
+ const at = DONE_AT.exec(text);
81
+ if (at) text = text.replace(at[0], " ");
82
+ text = text.replace(/\s+/g, " ").trim();
83
+ const who = ASSIGNEE.exec(text);
84
+ if (who) text = text.slice(0, who.index).trim();
85
+ const n = {
86
+ title: text,
87
+ links: findLinks(text, opts),
88
+ children: []
89
+ };
90
+ if (status) {
91
+ n.status = status;
92
+ n.done = status === "done";
93
+ }
94
+ if (needsOwner) n.needsOwner = true;
95
+ if (unordered) n.unordered = true;
96
+ if (at) n.doneAt = at[1].replace(" ", "T");
97
+ if (who) n.assignee = assigneeOf(who[1], who[2]);
98
+ return n;
99
+ }
100
+ /** `done: 捷报频传 · doing: 多线并进 · next: 蓄势待发` */
101
+ function parseSummary(text) {
102
+ const out = {};
103
+ for (const part of text.split(/\s*[·|]\s*/)) {
104
+ const m = /^(done|doing|next)\s*[::]\s*(.+)$/i.exec(part.trim());
105
+ if (m) out[m[1].toLowerCase()] = m[2].trim();
106
+ }
107
+ return out;
108
+ }
109
+ function addSummary(n, locale, text) {
110
+ const s = parseSummary(text);
111
+ if (!Object.keys(s).length) return;
112
+ n.summaries ??= {};
113
+ const key = (locale ?? "zh").toLowerCase();
114
+ n.summaries[key] = {
115
+ ...n.summaries[key],
116
+ ...s
117
+ };
118
+ }
119
+ /** Children without an assignee take the nearest ancestor's. */
120
+ function inherit(nodes, from) {
121
+ for (const n of nodes) {
122
+ if (!n.assignee && from) n.assignee = from;
123
+ inherit(n.children, n.assignee);
124
+ }
125
+ }
126
+ /**
127
+ * Parse the whole document into a root node (title "") whose children are the
128
+ * top-level nodes and whose summaries are the `≈` lines before the first `##`.
129
+ * Never throws: odd indentation nests under the nearest shallower item.
130
+ */
131
+ function parseTreeDoc(md, opts = {}) {
132
+ const root = {
133
+ title: "",
134
+ links: [],
135
+ children: []
136
+ };
137
+ /** The open items, shallowest first, each with its indent. */
138
+ let stack = [];
139
+ /** The current `##` heading, if any: items at any indent go under it. */
140
+ let heading = null;
141
+ /** The item that continuation lines (→ actions, notes) belong to. */
142
+ let last = null;
143
+ const text = md.replace(/\r\n?/g, "\n").replace(/<!--[\s\S]*?(?:-->|$)/g, "");
144
+ for (const line of text.split("\n")) {
145
+ if (!line.trim()) continue;
146
+ const h = HEADING.exec(line);
147
+ if (h) {
148
+ heading = node(h[1], opts);
149
+ root.children.push(heading);
150
+ stack = [];
151
+ last = {
152
+ indent: -1,
153
+ node: heading
154
+ };
155
+ continue;
156
+ }
157
+ if (/^#\s/.test(line)) {
158
+ heading = null;
159
+ stack = [];
160
+ last = null;
161
+ continue;
162
+ }
163
+ const it = ITEM.exec(line);
164
+ if (it && !ACTION.test(it[2]) && !SUMMARY.test(it[2])) {
165
+ const indent = indentOf(it[1]);
166
+ const n = node(it[2], opts);
167
+ while (stack.length && stack[stack.length - 1].indent >= indent) stack.pop();
168
+ (stack.length ? stack[stack.length - 1].node : heading ?? root).children.push(n);
169
+ stack.push({
170
+ indent,
171
+ node: n
172
+ });
173
+ last = {
174
+ indent,
175
+ node: n
176
+ };
177
+ continue;
178
+ }
179
+ const indent = indentOf(/^\s*/.exec(line)[0]);
180
+ const body = line.trim().replace(/^[-*+]\s+/, "");
181
+ const sum = SUMMARY.exec(body);
182
+ if (sum && !last && !root.children.length) {
183
+ addSummary(root, sum[1], sum[2]);
184
+ continue;
185
+ }
186
+ const a = ACTION.exec(body);
187
+ const under = !!last && (last.indent < 0 || indent > last.indent);
188
+ if (!under && (!heading || a)) continue;
189
+ const target = under ? last.node : heading;
190
+ if (sum) addSummary(target, sum[1], sum[2]);
191
+ else if (a) {
192
+ const act = a[1].trim();
193
+ if (!act) continue;
194
+ target.action = target.action ? `${target.action}\n${act}` : act;
195
+ for (const l of findLinks(act, opts)) if (!target.links.some((x) => x.url === l.url)) target.links.push(l);
196
+ } else target.note = target.note ? `${target.note} ${body}` : body;
197
+ }
198
+ inherit(root.children, root.assignee);
199
+ return root;
200
+ }
201
+ /** The top-level nodes (parseTreeDoc's root children). */
202
+ function parseTree(md, opts = {}) {
203
+ return parseTreeDoc(md, opts).children;
204
+ }
205
+ /** Open (not done) items below `n`, and those of them that wait on the owner. */
206
+ function countOpen(n) {
207
+ let open = 0;
208
+ let needsOwner = 0;
209
+ for (const c of n.children) {
210
+ if (c.done === false) {
211
+ open++;
212
+ if (c.needsOwner) needsOwner++;
213
+ }
214
+ const sub = countOpen(c);
215
+ open += sub.open;
216
+ needsOwner += sub.needsOwner;
217
+ }
218
+ return {
219
+ open,
220
+ needsOwner
221
+ };
222
+ }
223
+ /**
224
+ * Only the open `(!)` items and their ancestors (the "Needs me" view). A
225
+ * matching item keeps only those of its children that match too.
226
+ */
227
+ function filterNeedsOwner(nodes) {
228
+ const out = [];
229
+ for (const n of nodes) {
230
+ const children = filterNeedsOwner(n.children);
231
+ if (n.needsOwner && n.done !== true || children.length) out.push({
232
+ ...n,
233
+ children
234
+ });
235
+ }
236
+ return out;
237
+ }
238
+ /** `[~]` first, then not started, blocked, done: the order inside an `(any order)` parent. */
239
+ const RANK = {
240
+ doing: 0,
241
+ open: 1,
242
+ blocked: 2,
243
+ done: 3
244
+ };
245
+ const rank = (n) => n.status ? RANK[n.status] : 1;
246
+ /** Depth-first in work order, each with its breadcrumb and its ancestor nodes. */
247
+ function walk(root) {
248
+ const out = [];
249
+ const go = (n, chain) => {
250
+ const kids = n.unordered ? n.children.map((c, i) => [c, i]).sort((a, b) => rank(a[0]) - rank(b[0]) || a[1] - b[1]).map(([c]) => c) : n.children;
251
+ const next = [...chain, n];
252
+ for (const c of kids) {
253
+ if (c.status) {
254
+ const path = next.map((x) => x.title).filter(Boolean);
255
+ out.push({
256
+ node: c,
257
+ path,
258
+ title: c.title,
259
+ assignee: c.assignee,
260
+ chain: next
261
+ });
262
+ }
263
+ go(c, next);
264
+ }
265
+ };
266
+ go(root, []);
267
+ return out;
268
+ }
269
+ /** The summary list to try: the locale, its language, zh, en. */
270
+ function localeChain(locale) {
271
+ const l = (locale ?? "").toLowerCase();
272
+ return [...new Set([
273
+ l,
274
+ l.split("-")[0] ?? "",
275
+ "zh",
276
+ "en"
277
+ ].filter(Boolean))];
278
+ }
279
+ /** The deepest common ancestor of the group with a summary for `key`, in the first locale it has. */
280
+ function summaryFor(group, key, locales) {
281
+ let common = group[0].chain;
282
+ for (const g of group) {
283
+ let i = 0;
284
+ while (i < common.length && i < g.chain.length && common[i] === g.chain[i]) i++;
285
+ common = common.slice(0, i);
286
+ }
287
+ for (let i = common.length - 1; i >= 0; i--) {
288
+ const s = common[i].summaries;
289
+ if (!s) continue;
290
+ for (const l of locales) if (s[l]?.[key]) return s[l][key];
291
+ }
292
+ }
293
+ /** The item without its ancestor nodes. */
294
+ function strip(w) {
295
+ const it = {
296
+ node: w.node,
297
+ path: w.path,
298
+ title: w.title
299
+ };
300
+ if (w.assignee) it.assignee = w.assignee;
301
+ return it;
302
+ }
303
+ function entry(group, pick, key, locales) {
304
+ const e = {
305
+ ...strip(pick),
306
+ count: group.length,
307
+ items: group.map(strip)
308
+ };
309
+ if (group.length > 1) {
310
+ const s = summaryFor(group, key, locales);
311
+ if (s) e.summary = s;
312
+ }
313
+ return e;
314
+ }
315
+ /**
316
+ * The three lines: ✓ the most recently done, ▶ in progress (an open `(!)`
317
+ * item before any `[~]`), › the next not yet started. Blocked items are on
318
+ * none of them, unless they wait on the owner.
319
+ */
320
+ function frontier(input, opts = {}) {
321
+ let root = Array.isArray(input) ? {
322
+ title: "",
323
+ links: [],
324
+ children: input
325
+ } : input;
326
+ for (const t of opts.scope ?? []) {
327
+ const hit = root.children.find((c) => c.title === t);
328
+ if (!hit) return {};
329
+ root = hit;
330
+ }
331
+ const locales = localeChain(opts.locale);
332
+ const all = walk(root);
333
+ const out = {};
334
+ const done = all.filter((w) => w.node.status === "done");
335
+ if (done.length) {
336
+ const dated = done.filter((w) => w.node.doneAt);
337
+ out.done = entry(done, dated.length ? dated.reduce((a, b) => b.node.doneAt >= a.node.doneAt ? b : a) : done[done.length - 1], "done", locales);
338
+ }
339
+ const doing = [...all.filter((w) => w.node.needsOwner && w.node.status !== "done"), ...all.filter((w) => w.node.status === "doing" && !w.node.needsOwner)];
340
+ if (doing.length) out.doing = entry(doing, doing[0], "doing", locales);
341
+ const next = all.filter((w) => w.node.status === "open" && !w.node.needsOwner);
342
+ if (next.length) {
343
+ const now = out.doing && !out.doing.node.needsOwner ? all.indexOf(doing[0]) : -1;
344
+ out.next = entry(next, next.find((w) => all.indexOf(w) > now) ?? next[0], "next", locales);
345
+ }
346
+ return out;
347
+ }
348
+ /** `/words › Learning Partner` */
349
+ const crumbs = (path) => path.join(" › ");
350
+
351
+ //#endregion
352
+ export { filterNeedsOwner as a, localeChain as c, crumbs as i, parseTree as l, assigneeOf as n, findLinks as o, countOpen as r, frontier as s, OWNER_NAME as t, parseTreeDoc as u };
353
+ //# sourceMappingURL=state-tree-BZCmAknI.js.map