@namzu/sdk 69.3.0 → 70.0.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 (131) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/authorization/protected-paths.d.ts +24 -6
  3. package/dist/authorization/protected-paths.d.ts.map +1 -1
  4. package/dist/authorization/protected-paths.js +37 -9
  5. package/dist/authorization/protected-paths.js.map +1 -1
  6. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  7. package/dist/authorization/readonly-commands.js +30 -2
  8. package/dist/authorization/readonly-commands.js.map +1 -1
  9. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  10. package/dist/authorization/shell-lexer.js +263 -0
  11. package/dist/authorization/shell-lexer.js.map +1 -1
  12. package/dist/connector/web/guarded-fetch.d.ts +30 -0
  13. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  14. package/dist/connector/web/guarded-fetch.js +85 -0
  15. package/dist/connector/web/guarded-fetch.js.map +1 -1
  16. package/dist/connector/web/index.d.ts +1 -1
  17. package/dist/connector/web/index.d.ts.map +1 -1
  18. package/dist/connector/web/index.js +1 -1
  19. package/dist/connector/web/index.js.map +1 -1
  20. package/dist/plugin/common-layout/read.js +2 -2
  21. package/dist/plugin/common-layout/read.js.map +1 -1
  22. package/dist/plugin/hook-module/capabilities.d.ts +12 -0
  23. package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
  24. package/dist/plugin/hook-module/capabilities.js +82 -10
  25. package/dist/plugin/hook-module/capabilities.js.map +1 -1
  26. package/dist/plugin/hook-module/consent.d.ts +11 -0
  27. package/dist/plugin/hook-module/consent.d.ts.map +1 -1
  28. package/dist/plugin/hook-module/consent.js +31 -0
  29. package/dist/plugin/hook-module/consent.js.map +1 -1
  30. package/dist/plugin/hook-module/host.d.ts.map +1 -1
  31. package/dist/plugin/hook-module/host.js +69 -23
  32. package/dist/plugin/hook-module/host.js.map +1 -1
  33. package/dist/plugin/hook-module/index.d.ts +1 -1
  34. package/dist/plugin/hook-module/index.d.ts.map +1 -1
  35. package/dist/plugin/hook-module/index.js +1 -1
  36. package/dist/plugin/hook-module/index.js.map +1 -1
  37. package/dist/plugin/hook-module/scan.js +1 -1
  38. package/dist/plugin/hook-module/scan.js.map +1 -1
  39. package/dist/plugin/hook-module/worker-source.d.ts +5 -4
  40. package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
  41. package/dist/plugin/hook-module/worker-source.js +198 -28
  42. package/dist/plugin/hook-module/worker-source.js.map +1 -1
  43. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  44. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  45. package/dist/prompt/coding-agent-doctrine.js +1 -1
  46. package/dist/provider/side-request-reasoning.d.ts.map +1 -1
  47. package/dist/provider/side-request-reasoning.js +5 -1
  48. package/dist/provider/side-request-reasoning.js.map +1 -1
  49. package/dist/public-runtime.d.ts +3 -3
  50. package/dist/public-runtime.d.ts.map +1 -1
  51. package/dist/public-runtime.js +3 -3
  52. package/dist/public-runtime.js.map +1 -1
  53. package/dist/public-tools.d.ts +1 -1
  54. package/dist/public-tools.d.ts.map +1 -1
  55. package/dist/public-tools.js +1 -1
  56. package/dist/public-tools.js.map +1 -1
  57. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  58. package/dist/runtime/query/auto-review/classifier.js +13 -2
  59. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  60. package/dist/runtime/query/auto-review/failure.d.ts +12 -5
  61. package/dist/runtime/query/auto-review/failure.d.ts.map +1 -1
  62. package/dist/runtime/query/auto-review/failure.js +42 -7
  63. package/dist/runtime/query/auto-review/failure.js.map +1 -1
  64. package/dist/runtime/query/executor.d.ts.map +1 -1
  65. package/dist/runtime/query/executor.js +75 -10
  66. package/dist/runtime/query/executor.js.map +1 -1
  67. package/dist/runtime/query/review-policy.d.ts +21 -3
  68. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  69. package/dist/runtime/query/review-policy.js +57 -25
  70. package/dist/runtime/query/review-policy.js.map +1 -1
  71. package/dist/runtime/query/turn/check-scope.d.ts +18 -0
  72. package/dist/runtime/query/turn/check-scope.d.ts.map +1 -0
  73. package/dist/runtime/query/turn/check-scope.js +90 -0
  74. package/dist/runtime/query/turn/check-scope.js.map +1 -0
  75. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  76. package/dist/runtime/query/turn/outcome-ledger.js +13 -0
  77. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  78. package/dist/skills/inline-shell-host.d.ts +6 -0
  79. package/dist/skills/inline-shell-host.d.ts.map +1 -1
  80. package/dist/skills/inline-shell-host.js +8 -0
  81. package/dist/skills/inline-shell-host.js.map +1 -1
  82. package/dist/skills/inline-shell.d.ts +9 -1
  83. package/dist/skills/inline-shell.d.ts.map +1 -1
  84. package/dist/skills/inline-shell.js +78 -10
  85. package/dist/skills/inline-shell.js.map +1 -1
  86. package/dist/tools/builtins/job.d.ts.map +1 -1
  87. package/dist/tools/builtins/job.js +4 -1
  88. package/dist/tools/builtins/job.js.map +1 -1
  89. package/dist/tools/builtins/skill.d.ts.map +1 -1
  90. package/dist/tools/builtins/skill.js +2 -0
  91. package/dist/tools/builtins/skill.js.map +1 -1
  92. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  93. package/dist/tools/builtins/wait-for-job.js +2 -1
  94. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  95. package/dist/types/permission/index.d.ts +11 -2
  96. package/dist/types/permission/index.d.ts.map +1 -1
  97. package/dist/types/permission/index.js +12 -2
  98. package/dist/types/permission/index.js.map +1 -1
  99. package/dist/types/tool/index.d.ts +7 -0
  100. package/dist/types/tool/index.d.ts.map +1 -1
  101. package/dist/types/tool/index.js.map +1 -1
  102. package/package.json +1 -1
  103. package/src/authorization/protected-paths.ts +44 -9
  104. package/src/authorization/readonly-commands.ts +30 -2
  105. package/src/authorization/shell-lexer.ts +242 -0
  106. package/src/connector/web/guarded-fetch.ts +92 -0
  107. package/src/connector/web/index.ts +6 -1
  108. package/src/plugin/common-layout/read.ts +2 -2
  109. package/src/plugin/hook-module/capabilities.ts +94 -10
  110. package/src/plugin/hook-module/consent.ts +36 -0
  111. package/src/plugin/hook-module/host.ts +72 -21
  112. package/src/plugin/hook-module/index.ts +2 -0
  113. package/src/plugin/hook-module/scan.ts +2 -2
  114. package/src/plugin/hook-module/worker-source.ts +199 -28
  115. package/src/prompt/coding-agent-doctrine.ts +1 -1
  116. package/src/provider/side-request-reasoning.ts +5 -1
  117. package/src/public-runtime.ts +6 -0
  118. package/src/public-tools.ts +4 -1
  119. package/src/runtime/query/auto-review/classifier.ts +14 -2
  120. package/src/runtime/query/auto-review/failure.ts +52 -7
  121. package/src/runtime/query/executor.ts +74 -7
  122. package/src/runtime/query/review-policy.ts +72 -19
  123. package/src/runtime/query/turn/check-scope.ts +90 -0
  124. package/src/runtime/query/turn/outcome-ledger.ts +11 -0
  125. package/src/skills/inline-shell-host.ts +16 -0
  126. package/src/skills/inline-shell.ts +90 -8
  127. package/src/tools/builtins/job.ts +4 -1
  128. package/src/tools/builtins/skill.ts +2 -0
  129. package/src/tools/builtins/wait-for-job.ts +3 -1
  130. package/src/types/permission/index.ts +20 -3
  131. package/src/types/tool/index.ts +7 -0
@@ -165,6 +165,29 @@ class Context {
165
165
  opaque(reason) {
166
166
  this.reasons.add(reason);
167
167
  }
168
+ /**
169
+ * A name declared `-i` or `-n` evaluates what is later assigned to it as
170
+ * arithmetic, and an assigned value that holds a subscript runs the
171
+ * command inside it. The lexer keeps no variables, so when one line does
172
+ * both, in either order, it is opaque.
173
+ */
174
+ integerDeclared = false;
175
+ bracketSeen = false;
176
+ declaredArithmetic() {
177
+ this.integerDeclared = true;
178
+ if (this.bracketSeen)
179
+ this.opaque('arithmetic');
180
+ }
181
+ /**
182
+ * A value that may hold a subscript was stored: a literal one, an
183
+ * expanding one, or one a `read`, `mapfile`, `printf -v`, `getopts` or
184
+ * loop variable stores. The lexer cannot see what they hold.
185
+ */
186
+ bracketAssigned() {
187
+ this.bracketSeen = true;
188
+ if (this.integerDeclared)
189
+ this.opaque('arithmetic');
190
+ }
168
191
  dialects = new Map();
169
192
  /** The dialect a string is read in. A string read two ways gets the stricter. */
170
193
  setDialect(src, dialect) {
@@ -272,6 +295,18 @@ const RESERVED = new Set([
272
295
  const COMPOUND_AFTER = /^(?:\(|(?:\{|if|while|until|for|select|case|\[\[)(?=[\s;&|()<>]|$))/;
273
296
  /** Builtins whose arguments may be array assignments. */
274
297
  const ASSIGNMENT_BUILTINS = new Set(['declare', 'typeset', 'local', 'export', 'readonly']);
298
+ /** A `let` argument that evaluates nothing but numbers and an assignment of one. */
299
+ const PLAIN_ARITHMETIC = /^(?:[A-Za-z_][A-Za-z0-9_]*=)?[0-9\s+\-*/%()<>=!&|^~?:,]*$/;
300
+ /** A `declare -i` argument: a bare name, or a name given a plain number. */
301
+ /** A name word that carries a subscript, or one that expands into something that might. */
302
+ function subscriptOrExpands(word) {
303
+ return word.value.includes('[') || word.expands;
304
+ }
305
+ /** A subscript beside something that expands, quoted or not: `a[$(cmd)]`. */
306
+ function subscriptWithExpansion(word) {
307
+ return word.value.includes('[') && (word.expands || /[$`]/.test(word.value));
308
+ }
309
+ const PLAIN_INTEGER_ARGUMENT = /^[A-Za-z_][A-Za-z0-9_]*(?:=[0-9\s+\-*/%()<>=!&|^~?:,]*)?$/;
275
310
  const WORD_BREAK = new Set([' ', '\t', '\n', ';', '&', '|', '(', ')', '<', '>']);
276
311
  const NAME_START = /[A-Za-z_]/;
277
312
  const NAME_CHAR = /[A-Za-z0-9_]/;
@@ -698,6 +733,8 @@ class Parser {
698
733
  if (name.kind !== 'word')
699
734
  throw this.unexpected(name);
700
735
  this.context.compoundWords.push(name.word);
736
+ // The loop variable takes whatever the list holds.
737
+ this.context.bracketAssigned();
701
738
  this.newlines();
702
739
  token = this.peek();
703
740
  if (token.kind === 'word' && !token.word.quoted && token.word.value === 'in') {
@@ -1067,6 +1104,7 @@ class Parser {
1067
1104
  this.context.opaque('parser setting');
1068
1105
  }
1069
1106
  }
1107
+ this.inspectArithmeticBuiltin(command);
1070
1108
  const head = command.words[command.assignments];
1071
1109
  if (head === undefined || head.expands)
1072
1110
  return;
@@ -1105,6 +1143,231 @@ class Parser {
1105
1143
  }
1106
1144
  this.nestedShell(nested.shell, nested.payload);
1107
1145
  }
1146
+ /**
1147
+ * `unset` evaluates a subscript in a name operand, `unset 'a[$(cmd)]'`,
1148
+ * and runs `cmd`. `--` and the options `-v`, `-n` and `-f` (also
1149
+ * clustered, `-fv`) are read; the last of `-f` and `-v` decides, and with
1150
+ * `-f` the operands are function names, which evaluate nothing. Any other
1151
+ * word that holds a `[` or expands, a fused `-v'a[$(cmd)]'` included, is
1152
+ * opaque.
1153
+ */
1154
+ inspectUnset(args) {
1155
+ let functions = false;
1156
+ let options = true;
1157
+ for (const word of args) {
1158
+ if (options && !word.expands && word.value === '--') {
1159
+ options = false;
1160
+ continue;
1161
+ }
1162
+ if (options && !word.expands && /^-[fvn]+$/.test(word.value)) {
1163
+ const last = word.value.replace(/[^fv]/g, '').slice(-1);
1164
+ if (last === 'f')
1165
+ functions = true;
1166
+ else if (last === 'v')
1167
+ functions = false;
1168
+ continue;
1169
+ }
1170
+ if (functions && !word.expands)
1171
+ continue;
1172
+ if (subscriptOrExpands(word)) {
1173
+ this.context.opaque('arithmetic');
1174
+ return;
1175
+ }
1176
+ }
1177
+ }
1178
+ /**
1179
+ * Bash evaluates a name that carries a subscript, `a[$(cmd)]`, as
1180
+ * arithmetic and runs `cmd`, quoted or not. Where that happens: each
1181
+ * `let` argument; `declare -i` (also `typeset`, `local`, clustered flags
1182
+ * such as `-ia`) for each `NAME=value`; the name given to `declare`,
1183
+ * `typeset` or `local` with any flags, to `printf -v` and to `read`; the
1184
+ * operand of `-v` or `-R` in `test` and `[`; and a later plain assignment
1185
+ * to a name declared `-i` or `-n` in the same line. A word that is not
1186
+ * plainly safe is opaque: the line asks instead of showing a command with
1187
+ * no inner one.
1188
+ */
1189
+ inspectArithmeticBuiltin(command) {
1190
+ for (let i = 0; i < command.assignments; i += 1)
1191
+ this.noteBracketAssignment(command.words[i]);
1192
+ let at = command.assignments;
1193
+ for (;;) {
1194
+ const word = command.words[at];
1195
+ if (word === undefined)
1196
+ return;
1197
+ if (word.expands) {
1198
+ // The head may name any builtin: with a subscript that expands in a
1199
+ // later word, the line asks.
1200
+ if (command.words.slice(at + 1).some(subscriptWithExpansion))
1201
+ this.context.opaque('arithmetic');
1202
+ return;
1203
+ }
1204
+ if ((word.value === 'builtin' || word.value === 'command') && command.words[at + 1]) {
1205
+ let next = at + 1;
1206
+ // `--` and `-p` only step over; `-v` and `-V` run nothing; any
1207
+ // other option is not understood, so the line asks.
1208
+ for (;;) {
1209
+ const option = command.words[next];
1210
+ if (option === undefined || option.expands || !option.value.startsWith('-'))
1211
+ break;
1212
+ if (option.value === '--') {
1213
+ next += 1;
1214
+ break;
1215
+ }
1216
+ if (option.value === '-p') {
1217
+ next += 1;
1218
+ continue;
1219
+ }
1220
+ if (word.value === 'command' && (option.value === '-v' || option.value === '-V'))
1221
+ return;
1222
+ this.context.opaque('arithmetic');
1223
+ return;
1224
+ }
1225
+ const target = command.words[next];
1226
+ if (target === undefined || target.expands)
1227
+ return;
1228
+ at = next;
1229
+ continue;
1230
+ }
1231
+ break;
1232
+ }
1233
+ const name = command.words[at].value;
1234
+ const args = command.words.slice(at + 1);
1235
+ if (name === 'eval') {
1236
+ // eval reads its words as a line again, where a name with a subscript
1237
+ // and an expansion can reach `unset` or `declare -i`.
1238
+ if (args.some(subscriptWithExpansion))
1239
+ this.context.opaque('arithmetic');
1240
+ return;
1241
+ }
1242
+ if (name === 'let') {
1243
+ if (args.some((word) => !PLAIN_ARITHMETIC.test(word.value)))
1244
+ this.context.opaque('arithmetic');
1245
+ return;
1246
+ }
1247
+ if (name === 'printf') {
1248
+ for (let i = 0; i < args.length; i += 1) {
1249
+ const value = args[i].value;
1250
+ if (value === '--')
1251
+ break;
1252
+ if (!value.startsWith('-'))
1253
+ break;
1254
+ // The last -v wins, so every leading option is read.
1255
+ if (value === '-v') {
1256
+ this.context.bracketAssigned();
1257
+ const target = args[i + 1];
1258
+ if (target !== undefined && subscriptOrExpands(target))
1259
+ this.context.opaque('arithmetic');
1260
+ i += 1;
1261
+ continue;
1262
+ }
1263
+ if (value.startsWith('-v')) {
1264
+ this.context.bracketAssigned();
1265
+ if (subscriptOrExpands(args[i]))
1266
+ this.context.opaque('arithmetic');
1267
+ }
1268
+ }
1269
+ return;
1270
+ }
1271
+ if (name === 'read') {
1272
+ this.context.bracketAssigned();
1273
+ this.inspectRead(args);
1274
+ return;
1275
+ }
1276
+ if (name === 'unset') {
1277
+ this.inspectUnset(args);
1278
+ return;
1279
+ }
1280
+ if (name === 'mapfile' || name === 'readarray' || name === 'getopts') {
1281
+ this.context.bracketAssigned();
1282
+ if (args.some((word) => subscriptOrExpands(word)))
1283
+ this.context.opaque('arithmetic');
1284
+ return;
1285
+ }
1286
+ if (name === 'test' || name === '[') {
1287
+ for (let i = 0; i < args.length - 1; i += 1) {
1288
+ const value = args[i].value;
1289
+ if ((value === '-v' || value === '-R') && subscriptOrExpands(args[i + 1]))
1290
+ this.context.opaque('arithmetic');
1291
+ }
1292
+ return;
1293
+ }
1294
+ if (name !== 'declare' && name !== 'typeset' && name !== 'local')
1295
+ return;
1296
+ let integer = false;
1297
+ let nameref = false;
1298
+ let flags = true;
1299
+ for (const word of args) {
1300
+ if (flags && word.value === '--')
1301
+ flags = false;
1302
+ else if (flags && /^-[A-Za-z]*i/.test(word.value))
1303
+ integer = true;
1304
+ // A word that expands may be the flag itself.
1305
+ else if (flags && word.expands && !word.value.includes('='))
1306
+ integer = true;
1307
+ if (flags && /^-[A-Za-z]*n/.test(word.value))
1308
+ nameref = true;
1309
+ }
1310
+ if (integer || nameref)
1311
+ this.context.declaredArithmetic();
1312
+ flags = true;
1313
+ for (const word of args) {
1314
+ if (flags && word.value === '--') {
1315
+ flags = false;
1316
+ continue;
1317
+ }
1318
+ if (flags && word.value.startsWith('-') && !word.expands)
1319
+ continue;
1320
+ const equals = word.value.indexOf('=');
1321
+ const nameFor = equals < 0 ? word.value : word.value.slice(0, equals);
1322
+ if (nameFor.includes('[') || (word.expands && /[$`]/.test(nameFor)))
1323
+ this.context.opaque('arithmetic');
1324
+ else if (nameref && word.value.slice(equals + 1).includes('[') && equals >= 0)
1325
+ this.context.opaque('arithmetic');
1326
+ else if (integer && !PLAIN_INTEGER_ARGUMENT.test(word.value))
1327
+ this.context.opaque('arithmetic');
1328
+ else
1329
+ this.noteBracketAssignment(word);
1330
+ }
1331
+ }
1332
+ /** The names `read` stores into, minus the arguments of its options. */
1333
+ inspectRead(args) {
1334
+ let options = true;
1335
+ for (let i = 0; i < args.length; i += 1) {
1336
+ const value = args[i].value;
1337
+ if (options && value === '--') {
1338
+ options = false;
1339
+ continue;
1340
+ }
1341
+ if (options && value.startsWith('-') && value.length > 1) {
1342
+ for (let k = 1; k < value.length; k += 1) {
1343
+ const letter = value[k];
1344
+ if ('dinNptu'.includes(letter) || letter === 'a') {
1345
+ const rest = value.slice(k + 1);
1346
+ const operand = rest.length > 0 ? rest : (args[i + 1]?.value ?? '');
1347
+ if (rest.length === 0)
1348
+ i += 1;
1349
+ if (letter === 'a' && operand.includes('['))
1350
+ this.context.opaque('arithmetic');
1351
+ break;
1352
+ }
1353
+ }
1354
+ continue;
1355
+ }
1356
+ if (subscriptOrExpands(args[i]))
1357
+ this.context.opaque('arithmetic');
1358
+ }
1359
+ }
1360
+ /** A plain `NAME=value` whose value holds a subscript: dangerous once NAME is `-i` or `-n`. */
1361
+ noteBracketAssignment(word) {
1362
+ if (word === undefined)
1363
+ return;
1364
+ const equals = word.value.indexOf('=');
1365
+ if (equals <= 0)
1366
+ return;
1367
+ const value = word.value.slice(equals + 1);
1368
+ if (value.includes('[') || (word.expands && /[$`]/.test(value)))
1369
+ this.context.bracketAssigned();
1370
+ }
1108
1371
  /** Read the payload of `bash -c payload` as a command line of its own. */
1109
1372
  nestedShell(shell, payload) {
1110
1373
  if (this.depth + 1 >= MAX_SHELL_DEPTH) {