@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.
- package/CHANGELOG.md +39 -0
- package/dist/authorization/command-line.d.ts +66 -19
- package/dist/authorization/command-line.d.ts.map +1 -1
- package/dist/authorization/command-line.js +130 -270
- package/dist/authorization/command-line.js.map +1 -1
- package/dist/authorization/gate.d.ts +7 -0
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +1 -1
- package/dist/authorization/gate.js.map +1 -1
- package/dist/authorization/rules.d.ts +10 -1
- package/dist/authorization/rules.d.ts.map +1 -1
- package/dist/authorization/rules.js +21 -5
- package/dist/authorization/rules.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +138 -0
- package/dist/authorization/shell-lexer.d.ts.map +1 -0
- package/dist/authorization/shell-lexer.js +2143 -0
- package/dist/authorization/shell-lexer.js.map +1 -0
- package/dist/authorization/skill-grant.d.ts +182 -0
- package/dist/authorization/skill-grant.d.ts.map +1 -0
- package/dist/authorization/skill-grant.js +314 -0
- package/dist/authorization/skill-grant.js.map +1 -0
- package/dist/persona/assembler.d.ts.map +1 -1
- package/dist/persona/assembler.js +5 -2
- package/dist/persona/assembler.js.map +1 -1
- package/dist/public-runtime.d.ts +1 -0
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +4 -0
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +2 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +3 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.d.ts +2 -2
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +6 -2
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +34 -40
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +81 -51
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +7 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +6 -0
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +7 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +48 -0
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +11 -0
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +32 -0
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +3 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +1 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/skills/loader.d.ts +8 -0
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +7 -1
- package/dist/skills/loader.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +18 -6
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts +2 -9
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +59 -51
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/command-shell.d.ts +90 -0
- package/dist/tools/command-shell.d.ts.map +1 -0
- package/dist/tools/command-shell.js +129 -0
- package/dist/tools/command-shell.js.map +1 -0
- package/dist/tools/defineTool.d.ts +11 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +29 -1
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/types/hitl/index.d.ts +23 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +67 -5
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/utils/frontmatter.d.ts +17 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +32 -2
- package/dist/utils/frontmatter.js.map +1 -1
- package/package.json +1 -1
- package/src/authorization/command-line.ts +148 -293
- package/src/authorization/gate.ts +8 -0
- package/src/authorization/rules.ts +33 -4
- package/src/authorization/shell-lexer.ts +2319 -0
- package/src/authorization/skill-grant.ts +400 -0
- package/src/persona/assembler.ts +5 -2
- package/src/public-runtime.ts +9 -0
- package/src/public-tools.ts +2 -1
- package/src/public-types.ts +7 -0
- package/src/runtime/jobs/registry.ts +19 -11
- package/src/runtime/query/executor.ts +99 -55
- package/src/runtime/query/index.ts +7 -0
- package/src/runtime/query/iteration/index.ts +5 -0
- package/src/runtime/query/iteration/phases/context.ts +7 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +45 -0
- package/src/runtime/query/review-policy.ts +53 -0
- package/src/runtime/query/tooling.ts +4 -0
- package/src/skills/loader.ts +8 -1
- package/src/tools/builtins/bash.ts +24 -6
- package/src/tools/builtins/skill.ts +74 -53
- package/src/tools/command-shell.ts +166 -0
- package/src/tools/defineTool.ts +33 -1
- package/src/types/hitl/index.ts +21 -0
- package/src/types/tool/index.ts +67 -5
- 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
|
-
|
|
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
|