@nathapp/nax-agent 0.3.1 → 0.84.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 +12 -0
- package/README.md +7 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/internal/atomic-write.d.ts +16 -0
- package/dist/internal/atomic-write.js +34 -0
- package/dist/internal/command-spec/index.js +1 -1
- package/dist/internal/git-env.d.ts +4 -3
- package/dist/internal/git-env.js +11 -4
- package/dist/internal.d.ts +5 -0
- package/dist/internal.js +5 -0
- package/dist/native/auth.d.ts +2 -0
- package/dist/native/auth.js +11 -1
- package/dist/native/index.d.ts +1 -1
- package/dist/native/index.js +1 -1
- package/dist/native/session/handle-invalid-tool-call.js +1 -0
- package/dist/native/session/instruction-file-name.d.ts +4 -0
- package/dist/native/session/instruction-file-name.js +21 -0
- package/dist/native/session/instruction-interaction.d.ts +7 -0
- package/dist/native/session/instruction-interaction.js +22 -0
- package/dist/native/session/instruction-render.d.ts +6 -0
- package/dist/native/session/instruction-render.js +22 -0
- package/dist/native/session/instruction-session.d.ts +4 -0
- package/dist/native/session/instruction-session.js +31 -0
- package/dist/native/session/instruction-transcript.d.ts +4 -0
- package/dist/native/session/instruction-transcript.js +14 -0
- package/dist/native/session/repository-instructions.d.ts +35 -0
- package/dist/native/session/repository-instructions.js +155 -0
- package/dist/native/session/session.d.ts +8 -0
- package/dist/native/session/session.js +29 -3
- package/dist/native/session/transcript-identity.d.ts +2 -0
- package/dist/native/session/transcript-identity.js +1 -1
- package/dist/native/session/transcript-store.js +4 -2
- package/dist/native/session/transcript-types.d.ts +3 -0
- package/dist/native/session/turn-complete-step.js +4 -2
- package/dist/native/session/turn-event-emitter.d.ts +4 -0
- package/dist/native/session/turn-event-emitter.js +6 -4
- package/dist/native/session/turn-loop-round-trip.js +20 -1
- package/dist/native/session/turn-loop.js +1 -0
- package/dist/native/session-adapter.js +21 -6
- package/dist/permissions/approvals-store.d.ts +3 -1
- package/dist/permissions/approvals-store.js +18 -5
- package/dist/sandbox/session-tmp.js +13 -7
- package/dist/session/agent-session-types.d.ts +4 -0
- package/dist/session/native-backend-options.d.ts +4 -0
- package/dist/session/native-backend-options.js +6 -0
- package/dist/session/native-backend.js +16 -4
- package/dist/session/session-ask-port.js +2 -1
- package/dist/session/session-interaction.js +29 -13
- package/dist/session/session-types.d.ts +10 -0
- package/dist/terminal-auth/index.d.ts +4 -0
- package/dist/terminal-auth/index.js +4 -0
- package/dist/terminal-auth/interaction.d.ts +15 -0
- package/dist/terminal-auth/interaction.js +55 -0
- package/dist/terminal-auth/open-url.d.ts +17 -0
- package/dist/terminal-auth/open-url.js +44 -0
- package/dist/terminal-auth/prompt.d.ts +51 -0
- package/dist/terminal-auth/prompt.js +196 -0
- package/dist/tools/instruction-access.d.ts +13 -0
- package/dist/tools/instruction-access.js +30 -0
- package/dist/tools/runtime.js +6 -1
- package/package.json +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Transport-neutral scope hook, invoked only after coding-tool authorization. */
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import type { ProtectedPathsPolicy } from "./protected-paths.ts";
|
|
4
|
+
import type { ToolPolicy } from "./types.ts";
|
|
5
|
+
type InstructionAccess = (paths: readonly string[], canRead: (path: string) => boolean, protectedPaths?: ProtectedPathsPolicy) => Promise<string | undefined>;
|
|
6
|
+
export declare const _instructionAccessDeps: {
|
|
7
|
+
stat: typeof stat;
|
|
8
|
+
};
|
|
9
|
+
export declare function withInstructionAccess<T>(observer: InstructionAccess, run: () => Promise<T>): Promise<T>;
|
|
10
|
+
export declare function discoverAuthorizedInstructions(name: string, paths: readonly string[], policy: ToolPolicy, protectedPaths?: ProtectedPathsPolicy): Promise<string | undefined>;
|
|
11
|
+
/** A mutation must be proposed again after the model has received new guidance. */
|
|
12
|
+
export declare function enforceInstructionAccess(name: string, paths: readonly string[], policy: ToolPolicy, protectedPaths?: ProtectedPathsPolicy): Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Transport-neutral scope hook, invoked only after coding-tool authorization. */
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
+
import { stat } from "node:fs/promises";
|
|
4
|
+
import { dirname } from "node:path";
|
|
5
|
+
import { NaxError } from "#src/infra/nax-error";
|
|
6
|
+
import { credentialReadRefusal } from "./credential-read-deny.js";
|
|
7
|
+
export const _instructionAccessDeps = { stat };
|
|
8
|
+
const access = new AsyncLocalStorage();
|
|
9
|
+
export function withInstructionAccess(observer, run) {
|
|
10
|
+
return access.run(observer, run);
|
|
11
|
+
}
|
|
12
|
+
export async function discoverAuthorizedInstructions(name, paths, policy, protectedPaths) {
|
|
13
|
+
if (!["Read", "Write", "Edit"].includes(name))
|
|
14
|
+
return;
|
|
15
|
+
const observer = access.getStore();
|
|
16
|
+
if (observer === undefined || paths.some((path) => credentialReadRefusal(protectedPaths, path) !== undefined))
|
|
17
|
+
return;
|
|
18
|
+
const targets = name === "Write" ? paths.map((path) => dirname(path)) : paths;
|
|
19
|
+
const present = await Promise.all(targets.map((path) => _instructionAccessDeps.stat(path).then((metadata) => (name === "Write" ? metadata.isDirectory() : metadata.isFile()), () => false)));
|
|
20
|
+
if (present.some((found) => !found))
|
|
21
|
+
return;
|
|
22
|
+
const guidance = await observer(paths, (path) => policy.check("Read", { pathFields: ["path"] }, { path }).allowed, protectedPaths);
|
|
23
|
+
return name === "Read" ? undefined : guidance || undefined;
|
|
24
|
+
}
|
|
25
|
+
/** A mutation must be proposed again after the model has received new guidance. */
|
|
26
|
+
export async function enforceInstructionAccess(name, paths, policy, protectedPaths) {
|
|
27
|
+
const guidance = await discoverAuthorizedInstructions(name, paths, policy, protectedPaths);
|
|
28
|
+
if (guidance !== undefined)
|
|
29
|
+
throw new NaxError(guidance, "REPOSITORY_INSTRUCTIONS_DISCOVERED", { stage: "coding-tool" });
|
|
30
|
+
}
|
package/dist/tools/runtime.js
CHANGED
|
@@ -17,6 +17,7 @@ import { gitTool } from "./git.js";
|
|
|
17
17
|
import { gitCommitTool } from "./git-commit.js";
|
|
18
18
|
import { globTool } from "./glob.js";
|
|
19
19
|
import { grepTool } from "./grep.js";
|
|
20
|
+
import { enforceInstructionAccess } from "./instruction-access.js";
|
|
20
21
|
import { readTool } from "./read.js";
|
|
21
22
|
import { getCodingTool, registerBuiltinTool } from "./registry.js";
|
|
22
23
|
import { requestCapabilityTool } from "./request-capability.js";
|
|
@@ -224,7 +225,10 @@ export function createCodingToolRuntime(opts) {
|
|
|
224
225
|
log(tool, outcome, resultBytes, input, context, breach, reason, routineErrors, audit, resultBytesPreTruncation);
|
|
225
226
|
tap?.settle(outcome, audit?.approval?.decidedBy, audit?.executed === undefined
|
|
226
227
|
? undefined
|
|
227
|
-
: {
|
|
228
|
+
: {
|
|
229
|
+
executed: audit.executed,
|
|
230
|
+
...(audit.cwd !== undefined ? { cwd: audit.cwd } : {}),
|
|
231
|
+
});
|
|
228
232
|
};
|
|
229
233
|
/**
|
|
230
234
|
* Executes a permitted call and records its outcome. Shared by the
|
|
@@ -249,6 +253,7 @@ export function createCodingToolRuntime(opts) {
|
|
|
249
253
|
// scope.
|
|
250
254
|
const callSignal = context?.signal ?? signal;
|
|
251
255
|
try {
|
|
256
|
+
await enforceInstructionAccess(target.name, resolvedPaths, opts.policy, opts.protectedPaths);
|
|
252
257
|
const result = await target.run(callInput, {
|
|
253
258
|
root: opts.policy.root,
|
|
254
259
|
resolvedPaths,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nax-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.84.0",
|
|
4
4
|
"description": "nax's native coding agent: session contract, native loop, tools, permissions, sandbox, command-safety.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "William Khoo",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@anthropic-ai/sandbox-runtime": "0.0.77",
|
|
45
|
-
"@nathapp/nax-ai": "0.
|
|
45
|
+
"@nathapp/nax-ai": "0.84.0",
|
|
46
46
|
"zod": "^4.3.6"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|