@namzu/sdk 44.3.0 → 45.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 (116) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/authorization/command-line.d.ts +66 -19
  3. package/dist/authorization/command-line.d.ts.map +1 -1
  4. package/dist/authorization/command-line.js +130 -270
  5. package/dist/authorization/command-line.js.map +1 -1
  6. package/dist/authorization/gate.d.ts +7 -0
  7. package/dist/authorization/gate.d.ts.map +1 -1
  8. package/dist/authorization/gate.js +1 -1
  9. package/dist/authorization/gate.js.map +1 -1
  10. package/dist/authorization/rules.d.ts +10 -1
  11. package/dist/authorization/rules.d.ts.map +1 -1
  12. package/dist/authorization/rules.js +21 -5
  13. package/dist/authorization/rules.js.map +1 -1
  14. package/dist/authorization/shell-lexer.d.ts +138 -0
  15. package/dist/authorization/shell-lexer.d.ts.map +1 -0
  16. package/dist/authorization/shell-lexer.js +2143 -0
  17. package/dist/authorization/shell-lexer.js.map +1 -0
  18. package/dist/authorization/skill-grant.d.ts +182 -0
  19. package/dist/authorization/skill-grant.d.ts.map +1 -0
  20. package/dist/authorization/skill-grant.js +314 -0
  21. package/dist/authorization/skill-grant.js.map +1 -0
  22. package/dist/persona/assembler.d.ts.map +1 -1
  23. package/dist/persona/assembler.js +5 -2
  24. package/dist/persona/assembler.js.map +1 -1
  25. package/dist/public-runtime.d.ts +1 -0
  26. package/dist/public-runtime.d.ts.map +1 -1
  27. package/dist/public-runtime.js +4 -0
  28. package/dist/public-runtime.js.map +1 -1
  29. package/dist/public-tools.d.ts.map +1 -1
  30. package/dist/public-tools.js +2 -1
  31. package/dist/public-tools.js.map +1 -1
  32. package/dist/public-types.d.ts +3 -1
  33. package/dist/public-types.d.ts.map +1 -1
  34. package/dist/runtime/jobs/registry.d.ts +2 -2
  35. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  36. package/dist/runtime/jobs/registry.js +6 -2
  37. package/dist/runtime/jobs/registry.js.map +1 -1
  38. package/dist/runtime/query/executor.d.ts +34 -40
  39. package/dist/runtime/query/executor.d.ts.map +1 -1
  40. package/dist/runtime/query/executor.js +81 -51
  41. package/dist/runtime/query/executor.js.map +1 -1
  42. package/dist/runtime/query/index.d.ts.map +1 -1
  43. package/dist/runtime/query/index.js +7 -0
  44. package/dist/runtime/query/index.js.map +1 -1
  45. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  46. package/dist/runtime/query/iteration/index.js +6 -0
  47. package/dist/runtime/query/iteration/index.js.map +1 -1
  48. package/dist/runtime/query/iteration/phases/context.d.ts +7 -0
  49. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  50. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  51. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  52. package/dist/runtime/query/iteration/phases/tool-review.js +48 -0
  53. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  54. package/dist/runtime/query/review-policy.d.ts +11 -0
  55. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  56. package/dist/runtime/query/review-policy.js +32 -0
  57. package/dist/runtime/query/review-policy.js.map +1 -1
  58. package/dist/runtime/query/tooling.d.ts +3 -0
  59. package/dist/runtime/query/tooling.d.ts.map +1 -1
  60. package/dist/runtime/query/tooling.js +1 -0
  61. package/dist/runtime/query/tooling.js.map +1 -1
  62. package/dist/skills/loader.d.ts +8 -0
  63. package/dist/skills/loader.d.ts.map +1 -1
  64. package/dist/skills/loader.js +7 -1
  65. package/dist/skills/loader.js.map +1 -1
  66. package/dist/tools/builtins/bash.d.ts.map +1 -1
  67. package/dist/tools/builtins/bash.js +18 -6
  68. package/dist/tools/builtins/bash.js.map +1 -1
  69. package/dist/tools/builtins/skill.d.ts +2 -9
  70. package/dist/tools/builtins/skill.d.ts.map +1 -1
  71. package/dist/tools/builtins/skill.js +59 -51
  72. package/dist/tools/builtins/skill.js.map +1 -1
  73. package/dist/tools/command-shell.d.ts +90 -0
  74. package/dist/tools/command-shell.d.ts.map +1 -0
  75. package/dist/tools/command-shell.js +129 -0
  76. package/dist/tools/command-shell.js.map +1 -0
  77. package/dist/tools/defineTool.d.ts +11 -0
  78. package/dist/tools/defineTool.d.ts.map +1 -1
  79. package/dist/tools/defineTool.js +29 -1
  80. package/dist/tools/defineTool.js.map +1 -1
  81. package/dist/types/hitl/index.d.ts +23 -0
  82. package/dist/types/hitl/index.d.ts.map +1 -1
  83. package/dist/types/hitl/index.js.map +1 -1
  84. package/dist/types/tool/index.d.ts +67 -5
  85. package/dist/types/tool/index.d.ts.map +1 -1
  86. package/dist/types/tool/index.js.map +1 -1
  87. package/dist/utils/frontmatter.d.ts +17 -1
  88. package/dist/utils/frontmatter.d.ts.map +1 -1
  89. package/dist/utils/frontmatter.js +32 -2
  90. package/dist/utils/frontmatter.js.map +1 -1
  91. package/package.json +1 -1
  92. package/src/authorization/command-line.ts +148 -293
  93. package/src/authorization/gate.ts +8 -0
  94. package/src/authorization/rules.ts +33 -4
  95. package/src/authorization/shell-lexer.ts +2319 -0
  96. package/src/authorization/skill-grant.ts +400 -0
  97. package/src/persona/assembler.ts +5 -2
  98. package/src/public-runtime.ts +9 -0
  99. package/src/public-tools.ts +2 -1
  100. package/src/public-types.ts +7 -0
  101. package/src/runtime/jobs/registry.ts +19 -11
  102. package/src/runtime/query/executor.ts +99 -55
  103. package/src/runtime/query/index.ts +7 -0
  104. package/src/runtime/query/iteration/index.ts +5 -0
  105. package/src/runtime/query/iteration/phases/context.ts +7 -0
  106. package/src/runtime/query/iteration/phases/tool-review.ts +45 -0
  107. package/src/runtime/query/review-policy.ts +53 -0
  108. package/src/runtime/query/tooling.ts +4 -0
  109. package/src/skills/loader.ts +8 -1
  110. package/src/tools/builtins/bash.ts +24 -6
  111. package/src/tools/builtins/skill.ts +74 -53
  112. package/src/tools/command-shell.ts +166 -0
  113. package/src/tools/defineTool.ts +33 -1
  114. package/src/types/hitl/index.ts +21 -0
  115. package/src/types/tool/index.ts +67 -5
  116. package/src/utils/frontmatter.ts +52 -2
@@ -10,11 +10,18 @@ import type { ToolDefinition } from '../types/tool/index.js'
10
10
  import { SCOPE_ATTRIBUTE } from '../utils/log/types.js'
11
11
  import type { Logger } from '../utils/logger.js'
12
12
  import { evaluateRule } from './rules.js'
13
+ import type { ShellDialect } from './shell-lexer.js'
13
14
 
14
15
  export interface ToolCallContext {
15
16
  readonly toolName: string
16
17
  readonly toolInput: unknown
17
18
  readonly toolDef: ToolDefinition | undefined
19
+ /**
20
+ * The shell this call's command line will run in, when the caller knows
21
+ * (`ToolDefinition.commandDialect`). Absent, a command line is read in the
22
+ * `sh` dialect, which holds whichever shell runs it.
23
+ */
24
+ readonly commandDialect?: ShellDialect
18
25
  }
19
26
 
20
27
  /**
@@ -206,6 +213,7 @@ export class AuthorizationGate {
206
213
  ctx.toolDef,
207
214
  this.compiledPatterns.get(i),
208
215
  this.nameSets.get(i),
216
+ ctx.commandDialect !== undefined ? { commandDialect: ctx.commandDialect } : {},
209
217
  )
210
218
 
211
219
  if (decision !== null) {
@@ -2,7 +2,17 @@ import { DANGEROUS_PATTERNS } from '../constants/tools/index.js'
2
2
  import { isTrustedReadOnly } from '../tools/trusted-read-only.js'
3
3
  import type { AuthorizationRule, GateDecision } from '../types/authorization/index.js'
4
4
  import type { ToolDefinition } from '../types/tool/index.js'
5
- import { decomposeCommandLine } from './command-line.js'
5
+ import { decodedCommands, decomposeCommandLine } from './command-line.js'
6
+ import type { ShellDialect } from './shell-lexer.js'
7
+
8
+ export interface EvaluateRuleOptions {
9
+ /**
10
+ * The shell the tool will run a command-line argument in. Default `sh`:
11
+ * every construct bash and a POSIX shell read differently makes the line
12
+ * opaque. `ToolDefinition.commandDialect` supplies it for a tool.
13
+ */
14
+ readonly commandDialect?: ShellDialect
15
+ }
6
16
 
7
17
  export function evaluateRule(
8
18
  rule: AuthorizationRule,
@@ -11,7 +21,11 @@ export function evaluateRule(
11
21
  toolDef: ToolDefinition | undefined,
12
22
  compiledPattern?: RegExp,
13
23
  nameSet?: Set<string>,
24
+ options: EvaluateRuleOptions = {},
14
25
  ): GateDecision | null {
26
+ // A command line is read for the shell that will run it. Not knowing
27
+ // which, the reading that holds for every POSIX shell is the safe one.
28
+ const dialect = options.commandDialect ?? 'sh'
15
29
  switch (rule.type) {
16
30
  case 'allow_read_only': {
17
31
  // A server's own claim about its own tool cannot settle this. See
@@ -106,19 +120,34 @@ export function evaluateRule(
106
120
  : undefined
107
121
  if (subject === undefined) return null
108
122
 
123
+ // A path the tool itself declares is a path, not a command line.
124
+ // Read as shell, `app/(auth)/page.tsx` is a syntax error, and an
125
+ // opaque reading would withdraw every allow rule written for it.
126
+ if (
127
+ typeof value === 'string' &&
128
+ toolDef?.pathArgument === rule.argument &&
129
+ toolDef.commandArgument !== rule.argument
130
+ ) {
131
+ return compiledPattern.test(subject) ? rule.decision : null
132
+ }
133
+
109
134
  // A command line is not one string, and testing it as one is how a
110
135
  // prohibition gets bypassed: `^git push` sees `git push origin main`
111
136
  // and does not see `true; git push origin main`. See
112
137
  // `decomposeCommandLine` for the measurement and for why the two
113
138
  // decisions must read the result differently.
114
- const { segments, opaque } = decomposeCommandLine(subject)
139
+ const { segments, opaque } = decomposeCommandLine(subject, dialect)
115
140
 
116
141
  if (rule.decision === 'deny') {
117
142
  // ANY segment. The whole subject is tested first so an
118
143
  // unanchored deny keeps matching across a boundary, which
119
- // splitting alone would have taken away.
144
+ // splitting alone would have taken away. Then each command's
145
+ // words as bash passes them, so that `'git' push` is `git push`.
120
146
  if (compiledPattern.test(subject)) return 'deny'
121
- return segments.some((segment) => compiledPattern.test(segment)) ? 'deny' : null
147
+ if (segments.some((segment) => compiledPattern.test(segment))) return 'deny'
148
+ return decodedCommands(subject, dialect).some((text) => compiledPattern.test(text))
149
+ ? 'deny'
150
+ : null
122
151
  }
123
152
 
124
153
  // EVERY segment, and nothing that hides one. Permission is a claim