@namzu/sdk 63.1.0 → 64.1.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 (200) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -1
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/agents/file-definitions.d.ts +10 -0
  6. package/dist/agents/file-definitions.d.ts.map +1 -1
  7. package/dist/agents/file-definitions.js +10 -2
  8. package/dist/agents/file-definitions.js.map +1 -1
  9. package/dist/compaction/hooks.d.ts +57 -0
  10. package/dist/compaction/hooks.d.ts.map +1 -0
  11. package/dist/compaction/hooks.js +44 -0
  12. package/dist/compaction/hooks.js.map +1 -0
  13. package/dist/compaction/manual.d.ts +9 -0
  14. package/dist/compaction/manual.d.ts.map +1 -1
  15. package/dist/compaction/manual.js +74 -5
  16. package/dist/compaction/manual.js.map +1 -1
  17. package/dist/compaction/model-summary.d.ts +6 -0
  18. package/dist/compaction/model-summary.d.ts.map +1 -1
  19. package/dist/compaction/model-summary.js +13 -3
  20. package/dist/compaction/model-summary.js.map +1 -1
  21. package/dist/compaction/verifier.d.ts +8 -2
  22. package/dist/compaction/verifier.d.ts.map +1 -1
  23. package/dist/compaction/verifier.js +23 -7
  24. package/dist/compaction/verifier.js.map +1 -1
  25. package/dist/plugin/file-change-hooks.d.ts +53 -0
  26. package/dist/plugin/file-change-hooks.d.ts.map +1 -0
  27. package/dist/plugin/file-change-hooks.js +111 -0
  28. package/dist/plugin/file-change-hooks.js.map +1 -0
  29. package/dist/plugin/file-change-watch.d.ts +111 -0
  30. package/dist/plugin/file-change-watch.d.ts.map +1 -0
  31. package/dist/plugin/file-change-watch.js +324 -0
  32. package/dist/plugin/file-change-watch.js.map +1 -0
  33. package/dist/plugin/hook-context.d.ts +16 -0
  34. package/dist/plugin/hook-context.d.ts.map +1 -1
  35. package/dist/plugin/hook-context.js +40 -0
  36. package/dist/plugin/hook-context.js.map +1 -1
  37. package/dist/plugin/index.d.ts +14 -4
  38. package/dist/plugin/index.d.ts.map +1 -1
  39. package/dist/plugin/index.js +10 -3
  40. package/dist/plugin/index.js.map +1 -1
  41. package/dist/plugin/lifecycle.d.ts +60 -1
  42. package/dist/plugin/lifecycle.d.ts.map +1 -1
  43. package/dist/plugin/lifecycle.js +118 -7
  44. package/dist/plugin/lifecycle.js.map +1 -1
  45. package/dist/plugin/loader.d.ts.map +1 -1
  46. package/dist/plugin/loader.js +24 -1
  47. package/dist/plugin/loader.js.map +1 -1
  48. package/dist/plugin/session-hook-env.d.ts +140 -0
  49. package/dist/plugin/session-hook-env.d.ts.map +1 -0
  50. package/dist/plugin/session-hook-env.js +458 -0
  51. package/dist/plugin/session-hook-env.js.map +1 -0
  52. package/dist/plugin/shell-hook-command.d.ts +25 -0
  53. package/dist/plugin/shell-hook-command.d.ts.map +1 -0
  54. package/dist/plugin/shell-hook-command.js +218 -0
  55. package/dist/plugin/shell-hook-command.js.map +1 -0
  56. package/dist/plugin/shell-hook-env.d.ts +107 -0
  57. package/dist/plugin/shell-hook-env.d.ts.map +1 -0
  58. package/dist/plugin/shell-hook-env.js +272 -0
  59. package/dist/plugin/shell-hook-env.js.map +1 -0
  60. package/dist/plugin/shell-hook-tool-names.d.ts +20 -0
  61. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -0
  62. package/dist/plugin/shell-hook-tool-names.js +43 -0
  63. package/dist/plugin/shell-hook-tool-names.js.map +1 -0
  64. package/dist/plugin/shell-hook.d.ts +167 -22
  65. package/dist/plugin/shell-hook.d.ts.map +1 -1
  66. package/dist/plugin/shell-hook.js +651 -106
  67. package/dist/plugin/shell-hook.js.map +1 -1
  68. package/dist/plugin/worktree-hook-answer.d.ts +26 -0
  69. package/dist/plugin/worktree-hook-answer.d.ts.map +1 -0
  70. package/dist/plugin/worktree-hook-answer.js +132 -0
  71. package/dist/plugin/worktree-hook-answer.js.map +1 -0
  72. package/dist/public-runtime.d.ts +5 -3
  73. package/dist/public-runtime.d.ts.map +1 -1
  74. package/dist/public-runtime.js +4 -3
  75. package/dist/public-runtime.js.map +1 -1
  76. package/dist/public-types.d.ts +9 -2
  77. package/dist/public-types.d.ts.map +1 -1
  78. package/dist/runtime/query/compact-session.d.ts +7 -1
  79. package/dist/runtime/query/compact-session.d.ts.map +1 -1
  80. package/dist/runtime/query/compact-session.js +8 -3
  81. package/dist/runtime/query/compact-session.js.map +1 -1
  82. package/dist/runtime/query/executor/tool-call-admission.d.ts +1 -1
  83. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  84. package/dist/runtime/query/executor/tool-call-admission.js +4 -3
  85. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  86. package/dist/runtime/query/executor.d.ts +5 -0
  87. package/dist/runtime/query/executor.d.ts.map +1 -1
  88. package/dist/runtime/query/executor.js +8 -3
  89. package/dist/runtime/query/executor.js.map +1 -1
  90. package/dist/runtime/query/finalize-turn.d.ts.map +1 -1
  91. package/dist/runtime/query/finalize-turn.js +9 -2
  92. package/dist/runtime/query/finalize-turn.js.map +1 -1
  93. package/dist/runtime/query/index.d.ts +9 -0
  94. package/dist/runtime/query/index.d.ts.map +1 -1
  95. package/dist/runtime/query/index.js +3 -0
  96. package/dist/runtime/query/index.js.map +1 -1
  97. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  98. package/dist/runtime/query/iteration/index.js +2 -1
  99. package/dist/runtime/query/iteration/index.js.map +1 -1
  100. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  101. package/dist/runtime/query/iteration/phases/compaction.js +24 -12
  102. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  103. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  104. package/dist/runtime/query/iteration/phases/tool-review.js +2 -0
  105. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  106. package/dist/runtime/query/plugin-hooks.d.ts +13 -0
  107. package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
  108. package/dist/runtime/query/plugin-hooks.js +29 -2
  109. package/dist/runtime/query/plugin-hooks.js.map +1 -1
  110. package/dist/runtime/query/tooling.d.ts +5 -0
  111. package/dist/runtime/query/tooling.d.ts.map +1 -1
  112. package/dist/runtime/query/tooling.js +3 -0
  113. package/dist/runtime/query/tooling.js.map +1 -1
  114. package/dist/session/workspace/hooked-driver.d.ts +72 -0
  115. package/dist/session/workspace/hooked-driver.d.ts.map +1 -0
  116. package/dist/session/workspace/hooked-driver.js +204 -0
  117. package/dist/session/workspace/hooked-driver.js.map +1 -0
  118. package/dist/session/workspace/index.d.ts +2 -0
  119. package/dist/session/workspace/index.d.ts.map +1 -1
  120. package/dist/session/workspace/index.js +1 -0
  121. package/dist/session/workspace/index.js.map +1 -1
  122. package/dist/skills/index.d.ts +1 -1
  123. package/dist/skills/index.d.ts.map +1 -1
  124. package/dist/skills/index.js +1 -1
  125. package/dist/skills/index.js.map +1 -1
  126. package/dist/skills/loader.d.ts +22 -0
  127. package/dist/skills/loader.d.ts.map +1 -1
  128. package/dist/skills/loader.js +41 -0
  129. package/dist/skills/loader.js.map +1 -1
  130. package/dist/tools/builtins/bash-cwd.d.ts +6 -1
  131. package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
  132. package/dist/tools/builtins/bash-cwd.js +27 -2
  133. package/dist/tools/builtins/bash-cwd.js.map +1 -1
  134. package/dist/tools/builtins/bash.js +1 -1
  135. package/dist/tools/builtins/bash.js.map +1 -1
  136. package/dist/tools/builtins/skill.d.ts.map +1 -1
  137. package/dist/tools/builtins/skill.js +93 -16
  138. package/dist/tools/builtins/skill.js.map +1 -1
  139. package/dist/types/agent/query.d.ts +8 -0
  140. package/dist/types/agent/query.d.ts.map +1 -1
  141. package/dist/types/plugin/index.d.ts +130 -13
  142. package/dist/types/plugin/index.d.ts.map +1 -1
  143. package/dist/types/plugin/index.js +5 -0
  144. package/dist/types/plugin/index.js.map +1 -1
  145. package/dist/types/skills/index.d.ts +8 -0
  146. package/dist/types/skills/index.d.ts.map +1 -1
  147. package/dist/types/skills/index.js.map +1 -1
  148. package/dist/types/tool/index.d.ts +68 -0
  149. package/dist/types/tool/index.d.ts.map +1 -1
  150. package/dist/types/tool/index.js.map +1 -1
  151. package/dist/types/workspace/ref.d.ts +6 -0
  152. package/dist/types/workspace/ref.d.ts.map +1 -1
  153. package/dist/utils/frontmatter.d.ts +16 -0
  154. package/dist/utils/frontmatter.d.ts.map +1 -1
  155. package/dist/utils/frontmatter.js +31 -1
  156. package/dist/utils/frontmatter.js.map +1 -1
  157. package/package.json +1 -1
  158. package/src/agents/QueryAgent.ts +2 -1
  159. package/src/agents/file-definitions.ts +17 -2
  160. package/src/compaction/hooks.ts +104 -0
  161. package/src/compaction/manual.ts +117 -4
  162. package/src/compaction/model-summary.ts +19 -3
  163. package/src/compaction/verifier.ts +33 -3
  164. package/src/plugin/file-change-hooks.ts +131 -0
  165. package/src/plugin/file-change-watch.ts +367 -0
  166. package/src/plugin/hook-context.ts +46 -0
  167. package/src/plugin/index.ts +53 -1
  168. package/src/plugin/lifecycle.ts +162 -8
  169. package/src/plugin/loader.ts +22 -1
  170. package/src/plugin/session-hook-env.ts +475 -0
  171. package/src/plugin/shell-hook-command.ts +215 -0
  172. package/src/plugin/shell-hook-env.ts +335 -0
  173. package/src/plugin/shell-hook-tool-names.ts +46 -0
  174. package/src/plugin/shell-hook.ts +818 -100
  175. package/src/plugin/worktree-hook-answer.ts +142 -0
  176. package/src/public-runtime.ts +44 -0
  177. package/src/public-types.ts +22 -1
  178. package/src/runtime/query/compact-session.ts +16 -4
  179. package/src/runtime/query/executor/tool-call-admission.ts +10 -2
  180. package/src/runtime/query/executor.ts +13 -2
  181. package/src/runtime/query/finalize-turn.ts +9 -2
  182. package/src/runtime/query/index.ts +12 -0
  183. package/src/runtime/query/iteration/index.ts +2 -1
  184. package/src/runtime/query/iteration/phases/compaction.ts +31 -12
  185. package/src/runtime/query/iteration/phases/tool-review.ts +2 -0
  186. package/src/runtime/query/plugin-hooks.ts +32 -2
  187. package/src/runtime/query/tooling.ts +8 -0
  188. package/src/session/workspace/hooked-driver.ts +272 -0
  189. package/src/session/workspace/index.ts +7 -0
  190. package/src/skills/index.ts +3 -0
  191. package/src/skills/loader.ts +47 -0
  192. package/src/tools/builtins/bash-cwd.ts +25 -1
  193. package/src/tools/builtins/bash.ts +1 -1
  194. package/src/tools/builtins/skill.ts +115 -26
  195. package/src/types/agent/query.ts +9 -0
  196. package/src/types/plugin/index.ts +150 -23
  197. package/src/types/skills/index.ts +9 -0
  198. package/src/types/tool/index.ts +74 -0
  199. package/src/types/workspace/ref.ts +6 -0
  200. package/src/utils/frontmatter.ts +52 -1
@@ -0,0 +1,25 @@
1
+ /**
2
+ * What a hook's `if` on a shell command sees beyond the line as typed.
3
+ *
4
+ * A filter such as `Bash(git push *)` is written about a command, and the
5
+ * same command runs behind a wrapper (`sudo git push`, `env A=1 git push`,
6
+ * `nohup git push &`, `xargs git push`, `find . -exec git push {} ;`), under
7
+ * its full path (`/usr/bin/git push`) and with options in front of its
8
+ * subcommand (`git -C repo push`). The hook is attached to stop things, so a
9
+ * filter that misses one of those spellings switches the guard off. Each
10
+ * command of the line is therefore also read with its wrappers peeled, its
11
+ * program named by its basename and git's global options dropped, and the
12
+ * filter matches if any of those readings does.
13
+ *
14
+ * A command whose name is not known until the line runs (`$(echo git) push`,
15
+ * `$CMD push`) cannot be compared with anything: `unknowable` says so, and
16
+ * the caller runs the hook.
17
+ */
18
+ export interface HookCommandReading {
19
+ /** Every spelling of every command the line runs, as words joined by one space. */
20
+ readonly candidates: readonly string[];
21
+ /** The line runs something whose name cannot be read from it. */
22
+ readonly unknowable: boolean;
23
+ }
24
+ export declare function readHookCommand(line: string): HookCommandReading;
25
+ //# sourceMappingURL=shell-hook-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-hook-command.d.ts","sourceRoot":"","sources":["../../src/plugin/shell-hook-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,WAAW,kBAAkB;IAClC,mFAAmF;IACnF,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,iEAAiE;IACjE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;CAC5B;AA8KD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAehE"}
@@ -0,0 +1,218 @@
1
+ /**
2
+ * What a hook's `if` on a shell command sees beyond the line as typed.
3
+ *
4
+ * A filter such as `Bash(git push *)` is written about a command, and the
5
+ * same command runs behind a wrapper (`sudo git push`, `env A=1 git push`,
6
+ * `nohup git push &`, `xargs git push`, `find . -exec git push {} ;`), under
7
+ * its full path (`/usr/bin/git push`) and with options in front of its
8
+ * subcommand (`git -C repo push`). The hook is attached to stop things, so a
9
+ * filter that misses one of those spellings switches the guard off. Each
10
+ * command of the line is therefore also read with its wrappers peeled, its
11
+ * program named by its basename and git's global options dropped, and the
12
+ * filter matches if any of those readings does.
13
+ *
14
+ * A command whose name is not known until the line runs (`$(echo git) push`,
15
+ * `$CMD push`) cannot be compared with anything: `unknowable` says so, and
16
+ * the caller runs the hook.
17
+ */
18
+ import { basename, lexShellCommandLine } from '../authorization/shell-lexer.js';
19
+ const MAX_VARIANTS = 48;
20
+ /** Options of a wrapper that take the next word as their value. */
21
+ const WRAPPER_VALUE_OPTIONS = {
22
+ env: new Set(['-u', '--unset', '-C', '--chdir', '-S', '--split-string']),
23
+ sudo: new Set([
24
+ '-u',
25
+ '--user',
26
+ '-g',
27
+ '--group',
28
+ '-h',
29
+ '--host',
30
+ '-p',
31
+ '--prompt',
32
+ '-C',
33
+ '-D',
34
+ '-R',
35
+ '-T',
36
+ '-U',
37
+ ]),
38
+ doas: new Set(['-u', '-C']),
39
+ nice: new Set(['-n', '--adjustment']),
40
+ ionice: new Set(['-c', '-n', '-p', '-P', '-u']),
41
+ timeout: new Set(['-s', '--signal', '-k', '--kill-after']),
42
+ xargs: new Set([
43
+ '-I',
44
+ '-i',
45
+ '-n',
46
+ '-P',
47
+ '-d',
48
+ '-L',
49
+ '-l',
50
+ '-s',
51
+ '-E',
52
+ '-e',
53
+ '-a',
54
+ '--max-args',
55
+ '--max-procs',
56
+ '--delimiter',
57
+ '--max-lines',
58
+ '--max-chars',
59
+ '--arg-file',
60
+ ]),
61
+ stdbuf: new Set(['-i', '-o', '-e']),
62
+ command: new Set(),
63
+ nohup: new Set(),
64
+ exec: new Set(['-a']),
65
+ builtin: new Set(),
66
+ time: new Set(['-f', '--format', '-o', '--output']),
67
+ setsid: new Set(),
68
+ chroot: new Set(),
69
+ busybox: new Set(),
70
+ watch: new Set(['-n', '--interval']),
71
+ flock: new Set(['-w', '--timeout', '-E', '--conflict-exit-code']),
72
+ };
73
+ /** Global options of git that stand between `git` and its subcommand. */
74
+ const GIT_VALUE_OPTIONS = new Set([
75
+ '-C',
76
+ '-c',
77
+ '--git-dir',
78
+ '--work-tree',
79
+ '--namespace',
80
+ '--exec-path',
81
+ '--super-prefix',
82
+ '--config-env',
83
+ ]);
84
+ /** The words after the wrapper at `words[0]`, or `undefined` when it is not one. */
85
+ function peelWrapper(words) {
86
+ const head = basename(words[0] ?? '');
87
+ const valueOptions = WRAPPER_VALUE_OPTIONS[head];
88
+ if (valueOptions === undefined)
89
+ return undefined;
90
+ let index = 1;
91
+ while (index < words.length) {
92
+ const word = words[index];
93
+ if (word === '--') {
94
+ index += 1;
95
+ break;
96
+ }
97
+ if (head === 'env' && /^[A-Za-z_][A-Za-z0-9_]*=/.test(word)) {
98
+ index += 1;
99
+ continue;
100
+ }
101
+ if (word.startsWith('-') && word.length > 1) {
102
+ index += valueOptions.has(word) ? 2 : 1;
103
+ continue;
104
+ }
105
+ // `timeout 5 cmd`, `nice 10 cmd` (old form): a bare duration or number.
106
+ if ((head === 'timeout' || head === 'nice') && /^\d+(?:\.\d+)?[smhd]?$/.test(word)) {
107
+ index += 1;
108
+ continue;
109
+ }
110
+ break;
111
+ }
112
+ // `flock <lockfile> cmd`: the first word after the options is the lock, not the command.
113
+ if (head === 'flock')
114
+ index += 1;
115
+ const rest = words.slice(index);
116
+ return rest.length > 0 ? rest : undefined;
117
+ }
118
+ /** The commands after each `-exec`, `-execdir` or `-ok` of a `find`. */
119
+ function findExecutions(words) {
120
+ if (basename(words[0] ?? '') !== 'find')
121
+ return [];
122
+ const found = [];
123
+ for (let index = 1; index < words.length; index += 1) {
124
+ const word = words[index];
125
+ if (word !== '-exec' && word !== '-execdir' && word !== '-ok' && word !== '-okdir')
126
+ continue;
127
+ const body = [];
128
+ for (let next = index + 1; next < words.length; next += 1) {
129
+ const each = words[next];
130
+ if (each === ';' || each === ';' || each === '+')
131
+ break;
132
+ body.push(each);
133
+ }
134
+ if (body.length > 0)
135
+ found.push(body);
136
+ }
137
+ return found;
138
+ }
139
+ /** `git -C repo push` as `git push`. */
140
+ function dropGitGlobals(words) {
141
+ if (basename(words[0] ?? '') !== 'git')
142
+ return undefined;
143
+ const kept = ['git'];
144
+ let index = 1;
145
+ let dropped = false;
146
+ while (index < words.length) {
147
+ const word = words[index];
148
+ if (!word.startsWith('-'))
149
+ break;
150
+ const name = word.split('=')[0];
151
+ if (GIT_VALUE_OPTIONS.has(name)) {
152
+ index += word.includes('=') ? 1 : 2;
153
+ dropped = true;
154
+ }
155
+ else if (word === '--no-pager' ||
156
+ word === '-p' ||
157
+ word === '-P' ||
158
+ word === '--paginate' ||
159
+ word === '--no-optional-locks' ||
160
+ word === '--bare' ||
161
+ word === '--no-replace-objects') {
162
+ index += 1;
163
+ dropped = true;
164
+ }
165
+ else {
166
+ break;
167
+ }
168
+ }
169
+ if (!dropped)
170
+ return undefined;
171
+ return [...kept, ...words.slice(index)];
172
+ }
173
+ function variantsOf(start) {
174
+ const seen = new Map();
175
+ const queue = [[...start]];
176
+ while (queue.length > 0 && seen.size < MAX_VARIANTS) {
177
+ const words = queue.shift();
178
+ const key = words.join('\u0000');
179
+ if (seen.has(key))
180
+ continue;
181
+ seen.set(key, words);
182
+ const first = words[0];
183
+ if (first === undefined)
184
+ continue;
185
+ const peeled = peelWrapper(words);
186
+ if (peeled !== undefined)
187
+ queue.push([...peeled]);
188
+ for (const body of findExecutions(words))
189
+ queue.push(body);
190
+ const git = dropGitGlobals(words);
191
+ if (git !== undefined)
192
+ queue.push([...git]);
193
+ const base = basename(first);
194
+ if (base !== first)
195
+ queue.push([base, ...words.slice(1)]);
196
+ }
197
+ return [...seen.values()];
198
+ }
199
+ export function readHookCommand(line) {
200
+ const lexed = lexShellCommandLine(line, { dialect: 'sh' });
201
+ if (!lexed.complete)
202
+ return { candidates: [], unknowable: true };
203
+ const candidates = new Set();
204
+ let unknowable = false;
205
+ for (const command of lexed.commands) {
206
+ const words = command.words.slice(command.assignments);
207
+ const head = words[0];
208
+ if (head === undefined)
209
+ continue;
210
+ if (head.expands && /[$`]/.test(head.text))
211
+ unknowable = true;
212
+ for (const variant of variantsOf(words.map((word) => word.value))) {
213
+ candidates.add(variant.join(' '));
214
+ }
215
+ }
216
+ return { candidates: [...candidates], unknowable };
217
+ }
218
+ //# sourceMappingURL=shell-hook-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-hook-command.js","sourceRoot":"","sources":["../../src/plugin/shell-hook-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AAS/E,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB,mEAAmE;AACnE,MAAM,qBAAqB,GAAkD;IAC5E,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACxE,IAAI,EAAE,IAAI,GAAG,CAAC;QACb,IAAI;QACJ,QAAQ;QACR,IAAI;QACJ,SAAS;QACT,IAA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CAAA;IAC1D,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;AAC1B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY;IAC3C,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IAC1D,IAAI,CAAC,KAAK,CAAC,QAAQ;QAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAA;IAChE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAA;IACpC,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QACtD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACrB,IAAI,IAAI,KAAK,SAAS;YAAE,SAAQ;QAChC,IAAI,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,UAAU,GAAG,IAAI,CAAA;QAC7D,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACnE,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QAClC,CAAC;IACF,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,CAAC,GAAG,UAAU,CAAC,EAAE,UAAU,EAAE,CAAA;AACnD,CAAC"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The environment a shell hook command is started with, beyond what the
3
+ * kernel always sets: the entry's own `env` map, and variables a moved
4
+ * command expects.
5
+ *
6
+ * A hooks block brought from elsewhere often starts a command with a variable
7
+ * for the project folder, named for the tool it was written for. That tool's
8
+ * name is not ours to know, so the rule here reads the shape of the name: a
9
+ * variable the command or its arguments refer to, that is not set, and whose
10
+ * name ends in one of {@link MOVED_FOLDER_ENDINGS}, is set to that folder.
11
+ * Nothing already set is ever replaced.
12
+ */
13
+ /** A name a hook is started with that `env` may not replace: the kernel sets these itself. */
14
+ export declare const SHELL_HOOK_RESERVED_ENV: readonly string[];
15
+ /** The folders a name's ending can stand for. */
16
+ export type MovedFolder = 'project' | 'plugin' | 'pluginData' | 'skill' | 'envFile';
17
+ /** Endings read by shape; the name looked for is the whole variable name. */
18
+ export declare const MOVED_FOLDER_ENDINGS: readonly {
19
+ readonly ending: string;
20
+ readonly folder: MovedFolder;
21
+ }[];
22
+ /**
23
+ * The folder a variable name stands for, or `undefined` when it has none here.
24
+ * A skill's folder answers `_SKILL_ROOT` and also `_PLUGIN_ROOT`, unless the
25
+ * entry belongs to a plugin (then `_PLUGIN_ROOT` is the plugin's folder).
26
+ */
27
+ export declare function movedFolderFor(name: string, folders: Readonly<Partial<Record<MovedFolder, string>>>): string | undefined;
28
+ /** The folders a plugin-shipped entry is given. */
29
+ export interface PluginFolders {
30
+ /** The plugin's own folder. */
31
+ readonly root: string;
32
+ /** The folder kept for the plugin's data, under the Namzu home and never inside `root`. */
33
+ readonly dataDir: string;
34
+ }
35
+ /** Whether a variable name stands for a plugin folder by its ending. */
36
+ export declare function isPluginFolderVariable(name: string): boolean;
37
+ /**
38
+ * `${NAME}` and `$NAME` in a command or argument, for a name that ends in
39
+ * `_PLUGIN_ROOT` or `_PLUGIN_DATA`, become the folder's path, so an entry in
40
+ * the exec form (which no shell reads) finds its own folder too. A reference
41
+ * with a modifier (`${NAME:-x}`) is left to the shell, which has the variable.
42
+ */
43
+ export declare function substitutePluginFolders(text: string, folders: PluginFolders | undefined): string;
44
+ /**
45
+ * For the exec form, which no shell reads: `${NAME}` and `$NAME` for a name
46
+ * that ends in one of {@link MOVED_FOLDER_ENDINGS} become the value the hook is
47
+ * started with (`env` is the environment {@link movedEnvironment} built, so a
48
+ * value the entry or the host already set wins). A reference with a modifier is
49
+ * left as written, as is a name with no value.
50
+ */
51
+ export declare function substituteMovedFolders(text: string, env: Readonly<Record<string, string | undefined>>): string;
52
+ /**
53
+ * The program that reads a shell hook's command, found on the host's own
54
+ * `PATH`. An entry may set `PATH` in its `env` to something that does not hold
55
+ * `sh`; the command is still read by it, so the shell is looked up before that
56
+ * `env` is applied. `undefined` when no change is needed or none is found.
57
+ */
58
+ export declare function shellPathOutsideEnv(name: string, hostPath: string | undefined, startedWith: string | undefined, isExecutable: (path: string) => boolean, separator: string): string | undefined;
59
+ /** What is wrong with an `env` name, or `undefined` when it can be used. */
60
+ export declare function shellHookEnvNameProblem(name: string): string | undefined;
61
+ /** The problems in an `env` value as a whole, each naming the variable. Empty when it is usable. */
62
+ export declare function shellHookEnvProblems(env: unknown): string[];
63
+ /**
64
+ * The variables the texts refer to, in order of first appearance. A reference
65
+ * with a default (`${NAME:-x}`, `${NAME-x}`, `${NAME:+x}`, `${NAME=x}`) is
66
+ * left out unless `withDefaults` is set: it works without the variable.
67
+ */
68
+ export declare function referencedVariables(texts: readonly string[], options?: {
69
+ readonly withDefaults?: boolean;
70
+ }): string[];
71
+ /**
72
+ * Whether the command text itself gives the variable a value (`NAME=...`,
73
+ * `for NAME in`, `select NAME in`, `read NAME`, `getopts opts NAME`).
74
+ */
75
+ export declare function assignedWithin(texts: readonly string[], name: string): boolean;
76
+ /** Whether the name is one a shell keeps for itself (`RANDOM`, `PPID`, `PWD`, ...). */
77
+ export declare function isShellOwnVariable(name: string): boolean;
78
+ /** `$NAME` and `${NAME}` in an `env` value become the value the hook already has; any other text stays as written. */
79
+ export declare function expandHookEnvValue(value: string, have: Readonly<Record<string, string | undefined>>): string;
80
+ export interface MovedEnvironment {
81
+ /** The environment to start the command with. */
82
+ readonly env: Record<string, string | undefined>;
83
+ /** Variables the command refers to that are set nowhere (and not by the command itself). */
84
+ readonly unset: readonly string[];
85
+ }
86
+ /**
87
+ * Layer the entry's `env` map and the by-shape variables over `base` (the
88
+ * inherited environment with the kernel's own variables). `kernel` holds the
89
+ * variables the kernel always sets; they are applied last and win.
90
+ */
91
+ export declare function movedEnvironment(entry: {
92
+ readonly command: string;
93
+ readonly args?: readonly string[];
94
+ readonly env?: unknown;
95
+ }, base: Readonly<Record<string, string | undefined>>, kernel: Readonly<Record<string, string | undefined>>, folders: Readonly<Partial<Record<MovedFolder, string>>>): MovedEnvironment;
96
+ /**
97
+ * The sentence added to a hook's failure when it could not find what it ran
98
+ * and its command refers to variables that are set nowhere; `undefined` when
99
+ * the failure does not look like a missing program or file, or nothing is unset.
100
+ */
101
+ export declare function hookUnsetVariableHint(outcome: {
102
+ readonly exitCode: number | null;
103
+ readonly stderr: string;
104
+ readonly spawnError?: string;
105
+ readonly unsetVariables?: readonly string[];
106
+ }): string | undefined;
107
+ //# sourceMappingURL=shell-hook-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-hook-env.d.ts","sourceRoot":"","sources":["../../src/plugin/shell-hook-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,8FAA8F;AAC9F,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EASpD,CAAA;AAED,iDAAiD;AACjD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,OAAO,GAAG,SAAS,CAAA;AAEnF,6EAA6E;AAC7E,eAAO,MAAM,oBAAoB,EAAE,SAAS;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC5B,EAgBA,CAAA;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CA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AAM,EAAE,CAAA;CAC3C,GAAG,MAAM,GAAG,SAAS,CAarB"}
@@ -0,0 +1,272 @@
1
+ /**
2
+ * The environment a shell hook command is started with, beyond what the
3
+ * kernel always sets: the entry's own `env` map, and variables a moved
4
+ * command expects.
5
+ *
6
+ * A hooks block brought from elsewhere often starts a command with a variable
7
+ * for the project folder, named for the tool it was written for. That tool's
8
+ * name is not ours to know, so the rule here reads the shape of the name: a
9
+ * variable the command or its arguments refer to, that is not set, and whose
10
+ * name ends in one of {@link MOVED_FOLDER_ENDINGS}, is set to that folder.
11
+ * Nothing already set is ever replaced.
12
+ */
13
+ /** A name a hook is started with that `env` may not replace: the kernel sets these itself. */
14
+ export const SHELL_HOOK_RESERVED_ENV = [
15
+ 'NAMZU_HOOK_EVENT',
16
+ 'NAMZU_SESSION_ID',
17
+ 'NAMZU_PROJECT_DIR',
18
+ 'NAMZU_TURN_ID',
19
+ 'NAMZU_TOOL_NAME',
20
+ 'NAMZU_TOOL_PATH',
21
+ 'NAMZU_ENV_FILE',
22
+ 'NAMZU_STARTED_BY_SESSION',
23
+ ];
24
+ /** Endings read by shape; the name looked for is the whole variable name. */
25
+ export const MOVED_FOLDER_ENDINGS = [
26
+ { ending: '_PROJECT_DIR', folder: 'project' },
27
+ // A plugin's own folder and the folder kept for its data. These are set only
28
+ // for a hook entry a plugin ships; a name like this in a config file's entry
29
+ // has no folder to stand for and is left unset (and reported).
30
+ { ending: '_PLUGIN_ROOT', folder: 'plugin' },
31
+ { ending: '_PLUGIN_DATA', folder: 'pluginData' },
32
+ // A skill's own folder, for a hook that came from a skill. A skill moved as
33
+ // written names its folder `..._PLUGIN_ROOT` (see `movedFolderFor`); it has
34
+ // no data folder, so `_PLUGIN_DATA` is never given to one.
35
+ { ending: '_SKILL_ROOT', folder: 'skill' },
36
+ // The file a hook may append `export NAME=value` lines to, on the events
37
+ // that have one (`session_start`, `cwd_changed`, `file_changed`): the same
38
+ // file `NAMZU_ENV_FILE` names. On any other event there is no such file and
39
+ // the name is left unset (and reported).
40
+ { ending: '_ENV_FILE', folder: 'envFile' },
41
+ ];
42
+ /**
43
+ * The folder a variable name stands for, or `undefined` when it has none here.
44
+ * A skill's folder answers `_SKILL_ROOT` and also `_PLUGIN_ROOT`, unless the
45
+ * entry belongs to a plugin (then `_PLUGIN_ROOT` is the plugin's folder).
46
+ */
47
+ export function movedFolderFor(name, folders) {
48
+ const moved = MOVED_FOLDER_ENDINGS.find((each) => name.endsWith(each.ending));
49
+ if (moved === undefined)
50
+ return undefined;
51
+ if (moved.folder === 'plugin')
52
+ return folders.plugin ?? folders.skill;
53
+ return folders[moved.folder];
54
+ }
55
+ /** Whether a variable name stands for a plugin folder by its ending. */
56
+ export function isPluginFolderVariable(name) {
57
+ return MOVED_FOLDER_ENDINGS.some((each) => (each.folder === 'plugin' || each.folder === 'pluginData') && name.endsWith(each.ending));
58
+ }
59
+ /**
60
+ * `${NAME}` and `$NAME` in a command or argument, for a name that ends in
61
+ * `_PLUGIN_ROOT` or `_PLUGIN_DATA`, become the folder's path, so an entry in
62
+ * the exec form (which no shell reads) finds its own folder too. A reference
63
+ * with a modifier (`${NAME:-x}`) is left to the shell, which has the variable.
64
+ */
65
+ export function substitutePluginFolders(text, folders) {
66
+ if (folders === undefined)
67
+ return text;
68
+ return text.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (whole, braced, bare) => {
69
+ const name = (braced ?? bare);
70
+ const moved = MOVED_FOLDER_ENDINGS.find((each) => name.endsWith(each.ending));
71
+ if (moved === undefined)
72
+ return whole;
73
+ if (moved.folder === 'plugin')
74
+ return folders.root;
75
+ if (moved.folder === 'pluginData')
76
+ return folders.dataDir;
77
+ return whole;
78
+ });
79
+ }
80
+ /**
81
+ * For the exec form, which no shell reads: `${NAME}` and `$NAME` for a name
82
+ * that ends in one of {@link MOVED_FOLDER_ENDINGS} become the value the hook is
83
+ * started with (`env` is the environment {@link movedEnvironment} built, so a
84
+ * value the entry or the host already set wins). A reference with a modifier is
85
+ * left as written, as is a name with no value.
86
+ */
87
+ export function substituteMovedFolders(text, env) {
88
+ return text.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (whole, braced, bare) => {
89
+ const name = (braced ?? bare);
90
+ if (!MOVED_FOLDER_ENDINGS.some((each) => name.endsWith(each.ending)))
91
+ return whole;
92
+ return env[name] ?? whole;
93
+ });
94
+ }
95
+ /**
96
+ * The program that reads a shell hook's command, found on the host's own
97
+ * `PATH`. An entry may set `PATH` in its `env` to something that does not hold
98
+ * `sh`; the command is still read by it, so the shell is looked up before that
99
+ * `env` is applied. `undefined` when no change is needed or none is found.
100
+ */
101
+ export function shellPathOutsideEnv(name, hostPath, startedWith, isExecutable, separator) {
102
+ if (hostPath === undefined || hostPath === startedWith)
103
+ return undefined;
104
+ for (const dir of hostPath.split(separator)) {
105
+ if (dir === '')
106
+ continue;
107
+ const candidate = `${dir.replace(/[\\/]$/, '')}/${name}`;
108
+ if (isExecutable(candidate))
109
+ return candidate;
110
+ }
111
+ return undefined;
112
+ }
113
+ const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
114
+ /** What is wrong with an `env` name, or `undefined` when it can be used. */
115
+ export function shellHookEnvNameProblem(name) {
116
+ if (!NAME.test(name)) {
117
+ return 'is not a valid variable name (letters, digits and underscores, not starting with a digit)';
118
+ }
119
+ if (SHELL_HOOK_RESERVED_ENV.includes(name)) {
120
+ return 'is set by Namzu for every hook and cannot be replaced';
121
+ }
122
+ return undefined;
123
+ }
124
+ /** The problems in an `env` value as a whole, each naming the variable. Empty when it is usable. */
125
+ export function shellHookEnvProblems(env) {
126
+ if (env === null || typeof env !== 'object' || Array.isArray(env)) {
127
+ return ['must be a mapping of variable names to text'];
128
+ }
129
+ const problems = [];
130
+ for (const [name, value] of Object.entries(env)) {
131
+ const bad = shellHookEnvNameProblem(name);
132
+ if (bad !== undefined)
133
+ problems.push(`${JSON.stringify(name)} ${bad}`);
134
+ else if (typeof value !== 'string')
135
+ problems.push(`${JSON.stringify(name)} must be text`);
136
+ }
137
+ return problems;
138
+ }
139
+ // `$NAME`, `${NAME}` and `${NAME<modifier>}`: group 2 is the modifier text.
140
+ const REFERENCE = /\$(?:\{([A-Za-z_][A-Za-z0-9_]*)([^}]*)\}|([A-Za-z_][A-Za-z0-9_]*))/g;
141
+ /**
142
+ * The variables the texts refer to, in order of first appearance. A reference
143
+ * with a default (`${NAME:-x}`, `${NAME-x}`, `${NAME:+x}`, `${NAME=x}`) is
144
+ * left out unless `withDefaults` is set: it works without the variable.
145
+ */
146
+ export function referencedVariables(texts, options = {}) {
147
+ const seen = new Set();
148
+ for (const text of texts) {
149
+ for (const match of text.matchAll(REFERENCE)) {
150
+ const name = match[1] ?? match[3];
151
+ if (name === undefined)
152
+ continue;
153
+ const modifier = match[2] ?? '';
154
+ const hasDefault = /^:?[-+=]/.test(modifier);
155
+ if (hasDefault && options.withDefaults !== true)
156
+ continue;
157
+ seen.add(name);
158
+ }
159
+ }
160
+ return [...seen];
161
+ }
162
+ /**
163
+ * Whether the command text itself gives the variable a value (`NAME=...`,
164
+ * `for NAME in`, `select NAME in`, `read NAME`, `getopts opts NAME`).
165
+ */
166
+ export function assignedWithin(texts, name) {
167
+ const assign = new RegExp(`(?<![A-Za-z0-9_$])${name}=`);
168
+ const loop = new RegExp(`\\b(?:for|select)\\s+${name}\\b`);
169
+ const read = new RegExp(`\\bread\\s+(?:-\\w+\\s+)*(?:[A-Za-z_][A-Za-z0-9_]*\\s+)*${name}\\b`);
170
+ const opts = new RegExp(`\\bgetopts\\s+\\S+\\s+${name}\\b`);
171
+ return texts.some((text) => assign.test(text) || loop.test(text) || read.test(text) || opts.test(text));
172
+ }
173
+ /** Variables a shell sets or keeps for itself; a command that reads one is not missing a value. */
174
+ const SHELL_OWN_VARIABLES = new Set([
175
+ 'BASH',
176
+ 'BASHOPTS',
177
+ 'BASHPID',
178
+ 'BASH_ARGC',
179
+ 'BASH_ARGV',
180
+ 'BASH_COMMAND',
181
+ 'BASH_LINENO',
182
+ 'BASH_REMATCH',
183
+ 'BASH_SOURCE',
184
+ 'BASH_SUBSHELL',
185
+ 'BASH_VERSINFO',
186
+ 'BASH_VERSION',
187
+ 'COLUMNS',
188
+ 'EUID',
189
+ 'FUNCNAME',
190
+ 'GROUPS',
191
+ 'HOSTNAME',
192
+ 'HOSTTYPE',
193
+ 'IFS',
194
+ 'LINENO',
195
+ 'LINES',
196
+ 'MACHTYPE',
197
+ 'OLDPWD',
198
+ 'OPTARG',
199
+ 'OPTERR',
200
+ 'OPTIND',
201
+ 'OSTYPE',
202
+ 'PIPESTATUS',
203
+ 'PPID',
204
+ 'PS1',
205
+ 'PS2',
206
+ 'PS4',
207
+ 'PWD',
208
+ 'RANDOM',
209
+ 'REPLY',
210
+ 'SECONDS',
211
+ 'SHELLOPTS',
212
+ 'SHLVL',
213
+ 'UID',
214
+ ]);
215
+ /** Whether the name is one a shell keeps for itself (`RANDOM`, `PPID`, `PWD`, ...). */
216
+ export function isShellOwnVariable(name) {
217
+ return SHELL_OWN_VARIABLES.has(name);
218
+ }
219
+ /** `$NAME` and `${NAME}` in an `env` value become the value the hook already has; any other text stays as written. */
220
+ export function expandHookEnvValue(value, have) {
221
+ return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (whole, braced, bare) => {
222
+ const found = have[(braced ?? bare)];
223
+ return found === undefined ? whole : found;
224
+ });
225
+ }
226
+ /**
227
+ * Layer the entry's `env` map and the by-shape variables over `base` (the
228
+ * inherited environment with the kernel's own variables). `kernel` holds the
229
+ * variables the kernel always sets; they are applied last and win.
230
+ */
231
+ export function movedEnvironment(entry, base, kernel, folders) {
232
+ const env = { ...base };
233
+ if (entry.env !== null && typeof entry.env === 'object' && !Array.isArray(entry.env)) {
234
+ for (const [name, value] of Object.entries(entry.env)) {
235
+ if (shellHookEnvNameProblem(name) !== undefined || typeof value !== 'string')
236
+ continue;
237
+ env[name] = expandHookEnvValue(value, base);
238
+ }
239
+ }
240
+ Object.assign(env, kernel);
241
+ const texts = [entry.command, ...(entry.args ?? [])];
242
+ const unset = [];
243
+ for (const name of referencedVariables(texts)) {
244
+ if (env[name] !== undefined)
245
+ continue;
246
+ const folder = movedFolderFor(name, folders);
247
+ if (folder !== undefined)
248
+ env[name] = folder;
249
+ else if (!assignedWithin(texts, name) && !isShellOwnVariable(name))
250
+ unset.push(name);
251
+ }
252
+ return { env, unset };
253
+ }
254
+ /**
255
+ * The sentence added to a hook's failure when it could not find what it ran
256
+ * and its command refers to variables that are set nowhere; `undefined` when
257
+ * the failure does not look like a missing program or file, or nothing is unset.
258
+ */
259
+ export function hookUnsetVariableHint(outcome) {
260
+ const unset = outcome.unsetVariables ?? [];
261
+ if (unset.length === 0)
262
+ return undefined;
263
+ const notFound = (outcome.spawnError !== undefined && /ENOENT/.test(outcome.spawnError)) ||
264
+ outcome.exitCode === 127 ||
265
+ /no such file|not found/i.test(outcome.stderr);
266
+ if (!notFound)
267
+ return undefined;
268
+ const shown = unset.slice(0, 3).map((name) => `$${name}`);
269
+ const more = unset.length > 3 ? ` and ${unset.length - 3} more` : '';
270
+ return `its command refers to ${shown.join(', ')}${more}, which ${unset.length === 1 ? 'is' : 'are'} not set for hooks: give ${unset.length === 1 ? 'it' : 'each'} a value with the entry's "env" key`;
271
+ }
272
+ //# sourceMappingURL=shell-hook-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-hook-env.js","sourceRoot":"","sources":["../../src/plugin/shell-hook-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,8FAA8F;AAC9F,MAAM,CAAC,MAAM,uBAAuB,GAAsB;IACzD,kBAAkB;IAClB,kBAAkB;IAClB,mBAAmB;IACnB,eAAe;IACf,iBAAiB;IACjB,iBAAiB;IACjB,gBAAgB;IAChB,0BAA0B;CAC1B,CAAA;AAKD,6EAA6E;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