@writ-agent/sdk 0.1.0 → 0.1.1

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.
@@ -3,7 +3,7 @@ export type { ApprovalAnswer, ApprovalRequest, Approver, AskMode, AuthorizeOptio
3
3
  export { guard, guardTools } from "./guard.js";
4
4
  export type { ExecutableTool, GuardOptions, GuardToolsOptions } from "./guard.js";
5
5
  export { WritBlockedError, WritError, WritProtocolError, WritTimeoutError, WritUnavailableError, describeBlock, } from "./errors.js";
6
- export { findOnPath, locateWrit } from "./locate.js";
6
+ export { bundledWrit, findOnPath, locateWrit } from "./locate.js";
7
7
  export type { Launch } from "./locate.js";
8
8
  export { PROTOCOL_VERSION } from "./protocol.js";
9
9
  export type { CallerIdentity, CompleteInput, CompleteResult, Decision, DecisionKind, ServerIdentity, ToolCallInput, TrustVerdict, } from "./protocol.js";
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROTOCOL_VERSION = exports.locateWrit = exports.findOnPath = exports.describeBlock = exports.WritUnavailableError = exports.WritTimeoutError = exports.WritProtocolError = exports.WritError = exports.WritBlockedError = exports.guardTools = exports.guard = exports.shouldDispatch = exports.WritClient = void 0;
3
+ exports.PROTOCOL_VERSION = exports.locateWrit = exports.findOnPath = exports.bundledWrit = exports.describeBlock = exports.WritUnavailableError = exports.WritTimeoutError = exports.WritProtocolError = exports.WritError = exports.WritBlockedError = exports.guardTools = exports.guard = exports.shouldDispatch = exports.WritClient = void 0;
4
4
  var client_js_1 = require("./client.js");
5
5
  Object.defineProperty(exports, "WritClient", { enumerable: true, get: function () { return client_js_1.WritClient; } });
6
6
  Object.defineProperty(exports, "shouldDispatch", { enumerable: true, get: function () { return client_js_1.shouldDispatch; } });
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "WritTimeoutError", { enumerable: true, get: func
15
15
  Object.defineProperty(exports, "WritUnavailableError", { enumerable: true, get: function () { return errors_js_1.WritUnavailableError; } });
16
16
  Object.defineProperty(exports, "describeBlock", { enumerable: true, get: function () { return errors_js_1.describeBlock; } });
17
17
  var locate_js_1 = require("./locate.js");
18
+ Object.defineProperty(exports, "bundledWrit", { enumerable: true, get: function () { return locate_js_1.bundledWrit; } });
18
19
  Object.defineProperty(exports, "findOnPath", { enumerable: true, get: function () { return locate_js_1.findOnPath; } });
19
20
  Object.defineProperty(exports, "locateWrit", { enumerable: true, get: function () { return locate_js_1.locateWrit; } });
20
21
  var protocol_js_1 = require("./protocol.js");
@@ -12,7 +12,13 @@ export declare function launchFor(bin: string): Launch;
12
12
  /** Search PATH for `writ` (`writ.exe` / `writ.com` on Windows). */
13
13
  export declare function findOnPath(name?: string, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string | undefined;
14
14
  /**
15
- * Locate writ: explicit `bin`, then `WRIT_BIN`, then PATH. Throws
16
- * `WritUnavailableError` when nothing is found.
15
+ * The prebuilt binary from the optional `@writ-agent/cli` dependency, if it
16
+ * is installed next to this SDK and ships a binary for this platform.
17
+ */
18
+ export declare function bundledWrit(from?: string | undefined): string | undefined;
19
+ /**
20
+ * Locate writ: explicit `bin`, then `WRIT_BIN`, then the binary bundled by
21
+ * `@writ-agent/cli`, then PATH. Throws `WritUnavailableError` when nothing is
22
+ * found.
17
23
  */
18
24
  export declare function locateWrit(bin?: string, env?: NodeJS.ProcessEnv): Launch;
@@ -2,10 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.launchFor = launchFor;
4
4
  exports.findOnPath = findOnPath;
5
+ exports.bundledWrit = bundledWrit;
5
6
  exports.locateWrit = locateWrit;
6
7
  const node_fs_1 = require("node:fs");
8
+ const node_module_1 = require("node:module");
7
9
  const node_path_1 = require("node:path");
8
10
  const errors_js_1 = require("./errors.js");
11
+ const self_js_1 = require("./self.js");
9
12
  const SCRIPT_EXTENSIONS = new Set([".js", ".mjs", ".cjs"]);
10
13
  function isFile(p) {
11
14
  try {
@@ -47,8 +50,26 @@ function findOnPath(name = "writ", env = process.env, platform = process.platfor
47
50
  return undefined;
48
51
  }
49
52
  /**
50
- * Locate writ: explicit `bin`, then `WRIT_BIN`, then PATH. Throws
51
- * `WritUnavailableError` when nothing is found.
53
+ * The prebuilt binary from the optional `@writ-agent/cli` dependency, if it
54
+ * is installed next to this SDK and ships a binary for this platform.
55
+ */
56
+ function bundledWrit(from = self_js_1.selfUrl) {
57
+ if (from === undefined)
58
+ return undefined;
59
+ try {
60
+ const req = (0, node_module_1.createRequire)(from);
61
+ const cli = req("@writ-agent/cli");
62
+ const path = typeof cli.binaryPath === "function" ? cli.binaryPath() : undefined;
63
+ return path !== undefined && isFile(path) ? path : undefined;
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ }
69
+ /**
70
+ * Locate writ: explicit `bin`, then `WRIT_BIN`, then the binary bundled by
71
+ * `@writ-agent/cli`, then PATH. Throws `WritUnavailableError` when nothing is
72
+ * found.
52
73
  */
53
74
  function locateWrit(bin, env = process.env) {
54
75
  if (bin !== undefined && bin !== "")
@@ -56,9 +77,10 @@ function locateWrit(bin, env = process.env) {
56
77
  const fromEnv = env.WRIT_BIN;
57
78
  if (fromEnv !== undefined && fromEnv !== "")
58
79
  return launchFor(fromEnv);
59
- const found = findOnPath("writ", env);
80
+ const found = bundledWrit() ?? findOnPath("writ", env);
60
81
  if (found === undefined) {
61
- throw new errors_js_1.WritUnavailableError("writ binary not found: set WRIT_BIN or put writ on PATH (fail closed: no tool call will run)");
82
+ throw new errors_js_1.WritUnavailableError("writ binary not found: install @writ-agent/cli, set WRIT_BIN, or put writ on PATH " +
83
+ "(fail closed: no tool call will run)");
62
84
  }
63
85
  return { command: found, args: [] };
64
86
  }
@@ -0,0 +1 @@
1
+ export declare const selfUrl: string | undefined;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selfUrl = require("node:url").pathToFileURL(__filename).href;
@@ -3,7 +3,7 @@ export type { ApprovalAnswer, ApprovalRequest, Approver, AskMode, AuthorizeOptio
3
3
  export { guard, guardTools } from "./guard.js";
4
4
  export type { ExecutableTool, GuardOptions, GuardToolsOptions } from "./guard.js";
5
5
  export { WritBlockedError, WritError, WritProtocolError, WritTimeoutError, WritUnavailableError, describeBlock, } from "./errors.js";
6
- export { findOnPath, locateWrit } from "./locate.js";
6
+ export { bundledWrit, findOnPath, locateWrit } from "./locate.js";
7
7
  export type { Launch } from "./locate.js";
8
8
  export { PROTOCOL_VERSION } from "./protocol.js";
9
9
  export type { CallerIdentity, CompleteInput, CompleteResult, Decision, DecisionKind, ServerIdentity, ToolCallInput, TrustVerdict, } from "./protocol.js";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { WritClient, shouldDispatch } from "./client.js";
2
2
  export { guard, guardTools } from "./guard.js";
3
3
  export { WritBlockedError, WritError, WritProtocolError, WritTimeoutError, WritUnavailableError, describeBlock, } from "./errors.js";
4
- export { findOnPath, locateWrit } from "./locate.js";
4
+ export { bundledWrit, findOnPath, locateWrit } from "./locate.js";
5
5
  export { PROTOCOL_VERSION } from "./protocol.js";
@@ -12,7 +12,13 @@ export declare function launchFor(bin: string): Launch;
12
12
  /** Search PATH for `writ` (`writ.exe` / `writ.com` on Windows). */
13
13
  export declare function findOnPath(name?: string, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string | undefined;
14
14
  /**
15
- * Locate writ: explicit `bin`, then `WRIT_BIN`, then PATH. Throws
16
- * `WritUnavailableError` when nothing is found.
15
+ * The prebuilt binary from the optional `@writ-agent/cli` dependency, if it
16
+ * is installed next to this SDK and ships a binary for this platform.
17
+ */
18
+ export declare function bundledWrit(from?: string | undefined): string | undefined;
19
+ /**
20
+ * Locate writ: explicit `bin`, then `WRIT_BIN`, then the binary bundled by
21
+ * `@writ-agent/cli`, then PATH. Throws `WritUnavailableError` when nothing is
22
+ * found.
17
23
  */
18
24
  export declare function locateWrit(bin?: string, env?: NodeJS.ProcessEnv): Launch;
@@ -1,6 +1,8 @@
1
1
  import { statSync } from "node:fs";
2
+ import { createRequire } from "node:module";
2
3
  import { delimiter, extname, isAbsolute, join, resolve } from "node:path";
3
4
  import { WritUnavailableError } from "./errors.js";
5
+ import { selfUrl } from "./self.js";
4
6
  const SCRIPT_EXTENSIONS = new Set([".js", ".mjs", ".cjs"]);
5
7
  function isFile(p) {
6
8
  try {
@@ -42,8 +44,26 @@ export function findOnPath(name = "writ", env = process.env, platform = process.
42
44
  return undefined;
43
45
  }
44
46
  /**
45
- * Locate writ: explicit `bin`, then `WRIT_BIN`, then PATH. Throws
46
- * `WritUnavailableError` when nothing is found.
47
+ * The prebuilt binary from the optional `@writ-agent/cli` dependency, if it
48
+ * is installed next to this SDK and ships a binary for this platform.
49
+ */
50
+ export function bundledWrit(from = selfUrl) {
51
+ if (from === undefined)
52
+ return undefined;
53
+ try {
54
+ const req = createRequire(from);
55
+ const cli = req("@writ-agent/cli");
56
+ const path = typeof cli.binaryPath === "function" ? cli.binaryPath() : undefined;
57
+ return path !== undefined && isFile(path) ? path : undefined;
58
+ }
59
+ catch {
60
+ return undefined;
61
+ }
62
+ }
63
+ /**
64
+ * Locate writ: explicit `bin`, then `WRIT_BIN`, then the binary bundled by
65
+ * `@writ-agent/cli`, then PATH. Throws `WritUnavailableError` when nothing is
66
+ * found.
47
67
  */
48
68
  export function locateWrit(bin, env = process.env) {
49
69
  if (bin !== undefined && bin !== "")
@@ -51,9 +71,10 @@ export function locateWrit(bin, env = process.env) {
51
71
  const fromEnv = env.WRIT_BIN;
52
72
  if (fromEnv !== undefined && fromEnv !== "")
53
73
  return launchFor(fromEnv);
54
- const found = findOnPath("writ", env);
74
+ const found = bundledWrit() ?? findOnPath("writ", env);
55
75
  if (found === undefined) {
56
- throw new WritUnavailableError("writ binary not found: set WRIT_BIN or put writ on PATH (fail closed: no tool call will run)");
76
+ throw new WritUnavailableError("writ binary not found: install @writ-agent/cli, set WRIT_BIN, or put writ on PATH " +
77
+ "(fail closed: no tool call will run)");
57
78
  }
58
79
  return { command: found, args: [] };
59
80
  }
@@ -0,0 +1 @@
1
+ export declare const selfUrl: string | undefined;
@@ -0,0 +1 @@
1
+ export const selfUrl = import.meta.url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@writ-agent/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "TypeScript/Node client for the writ hook gateway: policy-checked, ledger-recorded tool calls for AI agents (Claude Agent SDK hooks, generic tool wrappers).",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -91,5 +91,8 @@
91
91
  "homepage": "https://github.com/writ-agent/writ/tree/main/adapters/typescript#readme",
92
92
  "bugs": {
93
93
  "url": "https://github.com/writ-agent/writ/issues"
94
+ },
95
+ "optionalDependencies": {
96
+ "@writ-agent/cli": "0.1.1"
94
97
  }
95
98
  }