@rendotdev/rig 0.0.16 → 0.0.18

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 (28) hide show
  1. package/README.md +4 -0
  2. package/dist/cli-0p4wnh3p.js +226 -0
  3. package/dist/{cli-mswdavqx.js → cli-96n231pn.js} +3 -3
  4. package/dist/{cli-7zqnqrah.js → cli-c6y9p8v9.js} +106 -42
  5. package/dist/{cli-dshh1cp9.js → cli-f4k31gtc.js} +1 -1
  6. package/dist/{cli-vx11bmzr.js → cli-ggk7t6dg.js} +2 -2
  7. package/dist/{cli-xv4m20sx.js → cli-jbscjyqq.js} +93 -65
  8. package/dist/{cli-ne7ed594.js → cli-vkw9rcke.js} +8 -2
  9. package/dist/{run-y66hvyxg.js → cli-yahk2r84.js} +158 -16
  10. package/dist/{config-24gwe08t.js → config-8mr59m0q.js} +2 -3
  11. package/dist/{create-59myk91d.js → create-9frp1c7g.js} +7 -8
  12. package/dist/cron-e6whgdf7.js +18 -0
  13. package/dist/{dev-link-jpte1gq9.js → dev-link-x3hjyy3j.js} +7 -4
  14. package/dist/{discover-fd9e6j9j.js → discover-9n7b9ra2.js} +3 -4
  15. package/dist/{help-6k8m07yv.js → help-17a9ywd9.js} +5 -6
  16. package/dist/{inspect-ks3x7s4n.js → inspect-k2g3dt1g.js} +5 -6
  17. package/dist/list-pahq60sp.js +13 -0
  18. package/dist/{paths-hq1vy0wh.js → paths-cxq6fvhp.js} +1 -1
  19. package/dist/{registry-gng9br0x.js → registry-e68a7b4v.js} +2 -3
  20. package/dist/rig.js +80 -35
  21. package/dist/run-apb4mx5d.js +13 -0
  22. package/dist/{runtime-comment-gvmkkcyh.js → runtime-comment-3yq1pmaf.js} +15 -9
  23. package/dist/{sync-zsc35m3f.js → sync-3362wne1.js} +33 -16
  24. package/dist/{typecheck-c2k87ppw.js → typecheck-5325aspe.js} +5 -7
  25. package/dist/{update-check-87p71vrc.js → update-check-a02ydxdb.js} +8 -5
  26. package/package.json +2 -2
  27. package/dist/cli-aj56a1ja.js +0 -48
  28. package/dist/list-f7r354tq.js +0 -14
@@ -1,25 +1,71 @@
1
- import {
2
- RigPackageRoot
3
- } from "./cli-aj56a1ja.js";
4
1
  import {
5
2
  RigError
6
3
  } from "./cli-1c7te5cg.js";
7
4
  import {
8
5
  RigPaths
9
- } from "./cli-ne7ed594.js";
6
+ } from "./cli-vkw9rcke.js";
10
7
  import {
11
8
  __export
12
9
  } from "./cli-b7jgjgy7.js";
13
10
 
14
11
  // src/config/config.ts
15
12
  import { mkdir as mkdir2, readFile as readFile2, rename, writeFile as writeFile2 } from "node:fs/promises";
16
- import { existsSync as existsSync2 } from "node:fs";
17
- import { dirname } from "node:path";
13
+ import { existsSync as existsSync3 } from "node:fs";
14
+ import { dirname as dirname2 } from "node:path";
18
15
 
19
16
  // src/runtime/support.ts
20
- import { existsSync } from "node:fs";
17
+ import { existsSync as existsSync2 } from "node:fs";
21
18
  import { mkdir, readFile, writeFile } from "node:fs/promises";
22
- import { join } from "node:path";
19
+ import { join as join2 } from "node:path";
20
+
21
+ // src/runtime/package-root.ts
22
+ import { existsSync, realpathSync } from "node:fs";
23
+ import { basename, dirname, join, resolve } from "node:path";
24
+ import { fileURLToPath } from "node:url";
25
+
26
+ class RigPackageRoot {
27
+ static find(metaUrl) {
28
+ if (process.env.RIG_PACKAGE_ROOT)
29
+ return resolve(process.env.RIG_PACKAGE_ROOT);
30
+ const argvRoot = this.fromEntrypoint(process.argv[1]);
31
+ if (argvRoot)
32
+ return argvRoot;
33
+ const execRoot = this.fromEntrypoint(process.execPath);
34
+ if (execRoot)
35
+ return execRoot;
36
+ if (this.isBunBinary(metaUrl))
37
+ return dirname(process.execPath);
38
+ return join(dirname(fileURLToPath(metaUrl)), "..", "..");
39
+ }
40
+ static packageFile(metaUrl, ...parts) {
41
+ return join(this.find(metaUrl), ...parts);
42
+ }
43
+ static isBunBinary(metaUrl) {
44
+ return metaUrl.includes("$bunfs") || metaUrl.includes("~BUN") || metaUrl.includes("%7EBUN");
45
+ }
46
+ static fromEntrypoint(entrypoint) {
47
+ if (!entrypoint)
48
+ return;
49
+ const resolved = this.safeRealpath(entrypoint);
50
+ if (!resolved)
51
+ return;
52
+ const parent = dirname(resolved);
53
+ const parentName = basename(parent);
54
+ if (parentName === "src" || parentName === "dist")
55
+ return dirname(parent);
56
+ return;
57
+ }
58
+ static safeRealpath(pathValue) {
59
+ try {
60
+ return realpathSync(pathValue);
61
+ } catch {
62
+ const absolute = resolve(pathValue);
63
+ return existsSync(absolute) ? absolute : undefined;
64
+ }
65
+ }
66
+ }
67
+
68
+ // src/runtime/support.ts
23
69
  class RuntimeSupport {
24
70
  paths;
25
71
  constructor(options = {}) {
@@ -37,7 +83,7 @@ class RuntimeSupport {
37
83
  }
38
84
  async ensureRegistryTsconfig(registryDir) {
39
85
  await mkdir(registryDir, { recursive: true });
40
- const tsconfigPath = join(registryDir, "tsconfig.json");
86
+ const tsconfigPath = join2(registryDir, "tsconfig.json");
41
87
  const content = this.registryTsconfigSource();
42
88
  const existing = await this.readTextIfExists(tsconfigPath);
43
89
  if (existing !== undefined && !existing.startsWith("// Generated by Rig."))
@@ -62,7 +108,7 @@ class RuntimeSupport {
62
108
  return;
63
109
  return file.text();
64
110
  }
65
- if (!existsSync(path))
111
+ if (!existsSync2(path))
66
112
  return;
67
113
  return readFile(path, "utf8");
68
114
  }
@@ -87,7 +133,6 @@ import type { RigToolDefinition, RigToolFactory, RigToolKit } from "./types";
87
133
  import * as zodModule from ${JSON.stringify(zodImport)};
88
134
 
89
135
  export const z: typeof zodNamespace = (zodModule as any).z ?? zodModule;
90
- export const rigSchemaRoleSymbol = Symbol.for("rig.schemaRole");
91
136
 
92
137
  class RigPathRuntime {
93
138
  home() { return homedir(); }
@@ -193,30 +238,12 @@ class RigCommandRunnerRuntime {
193
238
  }
194
239
  }
195
240
 
196
- function isZodSchema(value) {
197
- return typeof value === "object" && value !== null && typeof value.safeParse === "function";
198
- }
199
-
200
- function schema(value, role) {
201
- const result = isZodSchema(value) ? value : z.object(value);
202
- if (result[rigSchemaRoleSymbol] === role) return result;
203
- Object.defineProperty(result, rigSchemaRoleSymbol, {
204
- value: role,
205
- configurable: false,
206
- enumerable: false,
207
- writable: false,
208
- });
209
- return result;
210
- }
211
-
212
241
  const rigShell = new RigShellRuntime();
213
242
 
214
243
  export const rig: RigToolKit = {
215
244
  z,
216
245
  defineTool: (definition) => definition,
217
- command: (definition) => definition,
218
- input: (value) => schema(value, "input"),
219
- output: (value) => schema(value, "output"),
246
+ defineCommand: (definition) => definition,
220
247
  run: (options) => new RigCommandRunnerRuntime().run(options),
221
248
  $: (strings, ...values) => rigShell.$(strings, ...values),
222
249
  args: () => new RigArgsRuntime(),
@@ -237,24 +264,10 @@ export class RigTool {
237
264
  }
238
265
  typesSource() {
239
266
  return `// Generated by Rig. Safe to overwrite.
267
+ import type { Database } from "bun:sqlite";
240
268
  import type { z } from "zod";
241
269
 
242
- declare const RigInputSchemaBrand: unique symbol;
243
- declare const RigOutputSchemaBrand: unique symbol;
244
-
245
- export type RigInputSchema<T extends z.ZodTypeAny = z.ZodTypeAny> = T & {
246
- readonly [RigInputSchemaBrand]: T;
247
- };
248
-
249
- export type RigOutputSchema<T extends z.ZodTypeAny = z.ZodTypeAny> = T & {
250
- readonly [RigOutputSchemaBrand]: T;
251
- };
252
-
253
- export type RigSchemaFromValue<T extends z.ZodTypeAny | z.ZodRawShape> = T extends z.ZodTypeAny
254
- ? T
255
- : T extends z.ZodRawShape
256
- ? z.ZodObject<T>
257
- : never;
270
+ export type RigSchema = z.ZodTypeAny;
258
271
 
259
272
  export type RigShellOptions = {
260
273
  cwd?: string;
@@ -300,11 +313,17 @@ export type RigRunOptions = {
300
313
  dryRun?: boolean;
301
314
  };
302
315
 
303
- export type RigToolRunContext<Input> = {
316
+ export type RigToolDatabase = Database & {
317
+ readonly path: string;
318
+ migrate(version: number, name: string, sql: string): void;
319
+ };
320
+
321
+ export type RigToolRunContext<Input, Env = unknown> = {
304
322
  input: Input;
305
- env: NodeJS.ProcessEnv;
323
+ env: Env;
324
+ processEnv: NodeJS.ProcessEnv;
306
325
  cwd: string;
307
- shell: RigShell;
326
+ db: RigToolDatabase;
308
327
  rig: RigToolKit;
309
328
  };
310
329
 
@@ -316,28 +335,29 @@ export type RigToolExample<Input = any, Output = any> = {
316
335
  };
317
336
 
318
337
  export type RigCommandDefinition<
319
- Input extends RigInputSchema = RigInputSchema,
320
- Output extends RigOutputSchema = RigOutputSchema,
338
+ Input extends RigSchema = RigSchema,
339
+ Output extends RigSchema = RigSchema,
340
+ Env = unknown,
321
341
  > = {
322
342
  description: string;
323
343
  input: Input;
324
344
  output: Output;
325
345
  examples?: RigToolExample<z.input<Input>, z.output<Output>>[];
326
- run: (ctx: RigToolRunContext<z.output<Input>>) => z.input<Output> | Promise<z.input<Output>>;
346
+ run: (ctx: RigToolRunContext<z.output<Input>, Env>) => z.input<Output> | Promise<z.input<Output>>;
327
347
  };
328
348
 
329
- export type RigToolDefinition = {
349
+ export type RigToolDefinition<Env extends RigSchema = RigSchema> = {
330
350
  name: string;
331
351
  description: string;
332
- commands: Record<string, RigCommandDefinition>;
352
+ env?: Env;
353
+ setupDb?: (db: RigToolDatabase) => void | Promise<void>;
354
+ commands: Record<string, RigCommandDefinition<RigSchema, RigSchema, z.output<Env>>>;
333
355
  };
334
356
 
335
357
  export type RigToolKit = {
336
358
  z: typeof z;
337
359
  defineTool<T extends RigToolDefinition>(definition: T): T;
338
- command<I extends RigInputSchema, O extends RigOutputSchema>(definition: RigCommandDefinition<I, O>): RigCommandDefinition<I, O>;
339
- input<T extends z.ZodTypeAny | z.ZodRawShape>(value: T): RigInputSchema<RigSchemaFromValue<T>>;
340
- output<T extends z.ZodTypeAny | z.ZodRawShape>(value: T): RigOutputSchema<RigSchemaFromValue<T>>;
360
+ defineCommand<I extends RigSchema, O extends RigSchema>(definition: RigCommandDefinition<I, O>): RigCommandDefinition<I, O>;
341
361
  run<T = unknown>(options: RigRunOptions): Promise<T>;
342
362
  $(strings: TemplateStringsArray, ...values: unknown[]): Promise<RigShellResult>;
343
363
  args(): RigArgBuilder;
@@ -375,10 +395,10 @@ ${JSON.stringify({
375
395
  jsx: "preserve",
376
396
  lib: ["ES2023", "DOM"],
377
397
  types: ["bun"],
378
- typeRoots: [join(this.repoRoot(), "node_modules/@types")],
398
+ typeRoots: [join2(this.repoRoot(), "node_modules/@types")],
379
399
  baseUrl: this.repoRoot(),
380
400
  paths: {
381
- zod: [join(this.repoRoot(), "node_modules/zod/index.d.ts")]
401
+ zod: [join2(this.repoRoot(), "node_modules/zod/index.d.ts")]
382
402
  }
383
403
  },
384
404
  files: [this.paths.runtimeGlobalsPath, this.paths.runtimeTypesPath],
@@ -14674,18 +14694,26 @@ function date4(params) {
14674
14694
  // node_modules/zod/v4/classic/external.js
14675
14695
  config(en_default());
14676
14696
  // src/config/schema.ts
14697
+ var RigCronJobSchema = exports_external.object({
14698
+ name: exports_external.string().regex(/^[A-Za-z0-9_-]+$/),
14699
+ command: exports_external.string().min(1),
14700
+ schedule: exports_external.string().min(1),
14701
+ input: exports_external.unknown().optional()
14702
+ });
14677
14703
  var RigConfigSchema = exports_external.object({
14678
14704
  version: exports_external.literal(1),
14679
14705
  baseRegistryDir: exports_external.string().min(1),
14680
- customRegistries: exports_external.array(exports_external.string())
14706
+ customRegistries: exports_external.array(exports_external.string()),
14707
+ cronJobs: exports_external.array(RigCronJobSchema).default([])
14681
14708
  });
14682
14709
 
14683
14710
  class RigConfigDefaults {
14684
14711
  static create() {
14685
14712
  return {
14686
14713
  version: 1,
14687
- baseRegistryDir: "~/.rig/tools",
14688
- customRegistries: []
14714
+ baseRegistryDir: "~/rig/tools",
14715
+ customRegistries: [],
14716
+ cronJobs: []
14689
14717
  };
14690
14718
  }
14691
14719
  }
@@ -14700,7 +14728,7 @@ class RigConfigStore {
14700
14728
  }
14701
14729
  async ensure() {
14702
14730
  await mkdir2(this.paths.rigDir, { recursive: true });
14703
- if (!existsSync2(this.paths.configPath)) {
14731
+ if (!existsSync3(this.paths.configPath)) {
14704
14732
  await this.write(RigConfigDefaults.create());
14705
14733
  }
14706
14734
  const config2 = await this.read();
@@ -14737,7 +14765,7 @@ class RigConfigStore {
14737
14765
  if (!result.success) {
14738
14766
  throw new RigError("CONFIG_INVALID", "Rig config is invalid.", result.error.flatten());
14739
14767
  }
14740
- await mkdir2(dirname(this.paths.configPath), { recursive: true });
14768
+ await mkdir2(dirname2(this.paths.configPath), { recursive: true });
14741
14769
  const tmpPath = `${this.paths.configPath}.tmp-${process.pid}`;
14742
14770
  await writeFile2(tmpPath, `${JSON.stringify(result.data, null, 2)}
14743
14771
  `, "utf8");
@@ -14757,4 +14785,4 @@ class RigConfigStore {
14757
14785
  }
14758
14786
  }
14759
14787
 
14760
- export { exports_external, RigConfigStore };
14788
+ export { RigPackageRoot, exports_external, RigConfigStore };
@@ -22,7 +22,7 @@ class RigPaths {
22
22
  return isAbsolute(expanded) ? resolve(expanded) : resolve(process.cwd(), expanded);
23
23
  }
24
24
  get rigDir() {
25
- return join(this.homeDir, ".rig");
25
+ return join(this.homeDir, "rig");
26
26
  }
27
27
  get configPath() {
28
28
  return join(this.rigDir, "rig.json");
@@ -42,11 +42,17 @@ class RigPaths {
42
42
  get runtimeToolTsconfigPath() {
43
43
  return join(this.runtimeDir, "tsconfig.tools.json");
44
44
  }
45
+ get cronDir() {
46
+ return join(this.rigDir, "cron");
47
+ }
48
+ cronWorkerPath(name) {
49
+ return join(this.cronDir, `${name}.ts`);
50
+ }
45
51
  get updateCheckCachePath() {
46
52
  return join(this.rigDir, "update-check.json");
47
53
  }
48
54
  get defaultBaseRegistryDir() {
49
- return "~/.rig/tools";
55
+ return "~/rig/tools";
50
56
  }
51
57
  parentDir(pathValue) {
52
58
  return dirname(pathValue);
@@ -1,20 +1,15 @@
1
1
  import {
2
2
  SchemaRenderer
3
- } from "./cli-dshh1cp9.js";
3
+ } from "./cli-f4k31gtc.js";
4
4
  import {
5
5
  CommandIds,
6
6
  ToolLoader,
7
7
  createRigToolKit
8
- } from "./cli-7zqnqrah.js";
9
- import"./cli-vx11bmzr.js";
10
- import"./cli-xv4m20sx.js";
11
- import"./cli-aj56a1ja.js";
8
+ } from "./cli-c6y9p8v9.js";
12
9
  import {
13
10
  RigError,
14
11
  RigErrors
15
12
  } from "./cli-1c7te5cg.js";
16
- import"./cli-ne7ed594.js";
17
- import"./cli-b7jgjgy7.js";
18
13
 
19
14
  // src/tools/run.ts
20
15
  import { readFile } from "node:fs/promises";
@@ -94,7 +89,11 @@ class OutputTempFileStore {
94
89
  async writeJson(content) {
95
90
  const dir = await mkdtemp(join(tmpdir(), "rig-output-"));
96
91
  const path = join(dir, "data.json");
97
- await writeFile(path, `${content}
92
+ if (typeof Bun !== "undefined")
93
+ await Bun.write(path, `${content}
94
+ `);
95
+ else
96
+ await writeFile(path, `${content}
98
97
  `, "utf8");
99
98
  return path;
100
99
  }
@@ -156,6 +155,138 @@ class RigOutputTruncator {
156
155
  }
157
156
  }
158
157
 
158
+ // src/tools/db.ts
159
+ import { createHash } from "node:crypto";
160
+ import { mkdir } from "node:fs/promises";
161
+ import { dirname, join as join2 } from "node:path";
162
+ class MigrationChecksum {
163
+ digest(version, name, sql) {
164
+ return createHash("sha256").update(`${version}\x00${name}\x00${sql}`).digest("hex");
165
+ }
166
+ }
167
+
168
+ class RigDatabaseMigrator {
169
+ db;
170
+ lastVersion = 0;
171
+ checksums = new MigrationChecksum;
172
+ constructor(db) {
173
+ this.db = db;
174
+ }
175
+ ensureMetadata() {
176
+ this.db.run(`
177
+ create table if not exists _rig_migrations (
178
+ version integer primary key,
179
+ name text not null,
180
+ checksum text not null,
181
+ applied_at text not null
182
+ );
183
+ `);
184
+ }
185
+ migrate(version, name, sql) {
186
+ this.validate(version, name, sql);
187
+ const checksum = this.checksums.digest(version, name, sql);
188
+ const existing = this.existingMigration(version);
189
+ if (existing) {
190
+ this.assertExistingMigrationMatches(version, name, checksum, existing);
191
+ return;
192
+ }
193
+ const apply = this.db.transaction(() => {
194
+ this.db.run(sql);
195
+ this.db.query(`insert into _rig_migrations (version, name, checksum, applied_at)
196
+ values ($version, $name, $checksum, $appliedAt)`).run({ version, name, checksum, appliedAt: new Date().toISOString() });
197
+ });
198
+ apply();
199
+ }
200
+ validate(version, name, sql) {
201
+ if (!Number.isInteger(version) || version <= 0) {
202
+ throw new RigError("TOOL_INVALID", `Migration version must be a positive integer: ${version}`);
203
+ }
204
+ if (version <= this.lastVersion) {
205
+ throw new RigError("TOOL_INVALID", `Migration versions must be declared in ascending order: ${version} after ${this.lastVersion}`);
206
+ }
207
+ if (!name.trim())
208
+ throw new RigError("TOOL_INVALID", "Migration name must not be empty.");
209
+ if (!sql.trim())
210
+ throw new RigError("TOOL_INVALID", `Migration ${version} SQL must not be empty.`);
211
+ this.lastVersion = version;
212
+ }
213
+ existingMigration(version) {
214
+ const row = this.db.query("select name, checksum from _rig_migrations where version = ?").get(version);
215
+ return row ?? undefined;
216
+ }
217
+ assertExistingMigrationMatches(version, name, checksum, existing) {
218
+ if (existing.name === name && existing.checksum === checksum)
219
+ return;
220
+ throw new RigError("TOOL_INVALID", `Migration ${version} has changed since it was applied.`, {
221
+ version,
222
+ expected: existing,
223
+ actual: { name, checksum }
224
+ });
225
+ }
226
+ }
227
+
228
+ class BunSqliteModuleLoader {
229
+ async database() {
230
+ const database = globalThis.rigSqliteDatabaseForTests;
231
+ if (!database)
232
+ return this.nativeDatabase();
233
+ return database;
234
+ }
235
+ async nativeDatabase() {
236
+ const specifier = "bun:sqlite";
237
+ const moduleValue = await import(specifier);
238
+ return moduleValue.Database;
239
+ }
240
+ }
241
+
242
+ class RigToolDatabaseFactory {
243
+ sqlite = new BunSqliteModuleLoader;
244
+ async create(toolPath) {
245
+ const dbPath = this.dbPathForToolPath(toolPath);
246
+ await mkdir(dirname(dbPath), { recursive: true });
247
+ const Database = await this.sqlite.database();
248
+ const db = new Database(dbPath, { create: true, strict: true });
249
+ const migrator = new RigDatabaseMigrator(db);
250
+ Object.defineProperty(db, "path", { value: dbPath, enumerable: true });
251
+ Object.defineProperty(db, "migrate", {
252
+ value: (version, name, sql) => migrator.migrate(version, name, sql),
253
+ enumerable: true
254
+ });
255
+ db.run("PRAGMA journal_mode = WAL;");
256
+ migrator.ensureMetadata();
257
+ return db;
258
+ }
259
+ dbPathForToolPath(toolPath) {
260
+ return join2(dirname(toolPath), "index.sqlite");
261
+ }
262
+ }
263
+
264
+ class UnavailableToolDatabaseFactory {
265
+ create(toolName) {
266
+ return new Proxy({}, {
267
+ get() {
268
+ throw new RigError("TOOL_INVALID", `Tool ${toolName} must define setupDb before using context.db.`, {
269
+ tool: toolName
270
+ });
271
+ }
272
+ });
273
+ }
274
+ }
275
+
276
+ class ToolDatabaseService {
277
+ factory = new RigToolDatabaseFactory;
278
+ async setup(tool) {
279
+ if (!tool.definition.setupDb)
280
+ return;
281
+ const db = await this.factory.create(tool.path);
282
+ await tool.definition.setupDb(db);
283
+ return db;
284
+ }
285
+ dbPathForToolPath(toolPath) {
286
+ return this.factory.dbPathForToolPath(toolPath);
287
+ }
288
+ }
289
+
159
290
  // src/tools/run.ts
160
291
  class RunInputReader {
161
292
  async read(command, options) {
@@ -169,8 +300,8 @@ class RunInputReader {
169
300
  throw new RigError("INPUT_ERROR", "Use args, --input, or --input-file, not more than one.");
170
301
  }
171
302
  if (options.inputFile) {
172
- const raw = await readFile(options.inputFile, "utf8");
173
- return { value: JSON.parse(raw), source: `--input-file ${options.inputFile}` };
303
+ const value = typeof Bun !== "undefined" ? await Bun.file(options.inputFile).json() : JSON.parse(await readFile(options.inputFile, "utf8"));
304
+ return { value, source: `--input-file ${options.inputFile}` };
174
305
  }
175
306
  if (options.input) {
176
307
  return { value: JSON.parse(options.input), source: `--input '${options.input}'` };
@@ -300,16 +431,19 @@ class DryRunPresenter {
300
431
 
301
432
  class ToolRunner {
302
433
  options;
434
+ databases = new ToolDatabaseService;
303
435
  loader;
304
436
  inputReader = new RunInputReader;
305
437
  outputTruncator = new RigOutputTruncator;
438
+ unavailableDatabases = new UnavailableToolDatabaseFactory;
306
439
  constructor(options = {}) {
307
440
  this.options = options;
308
441
  this.loader = new ToolLoader(options);
309
442
  }
310
443
  async run(toolName, commandName, options = {}) {
444
+ let db;
311
445
  try {
312
- const { command } = await this.loader.loadCommand(toolName, commandName);
446
+ const { tool, command } = await this.loader.loadCommand(toolName, commandName);
313
447
  const input = await this.inputReader.read(command, options);
314
448
  const inputResult = command.input.safeParse(input.value);
315
449
  if (!inputResult.success) {
@@ -330,11 +464,13 @@ class ToolRunner {
330
464
  };
331
465
  }
332
466
  const rig = createRigToolKit(this.options);
467
+ db = await this.databases.setup(tool);
333
468
  const data = await command.run({
334
469
  input: inputResult.data,
335
- env: process.env,
470
+ env: tool.env,
471
+ processEnv: process.env,
336
472
  cwd: process.cwd(),
337
- shell: rig.shell,
473
+ db: db ?? this.unavailableDatabases.create(toolName),
338
474
  rig
339
475
  });
340
476
  const outputResult = command.output.safeParse(data);
@@ -357,8 +493,15 @@ class ToolRunner {
357
493
  }),
358
494
  exitCode: 1
359
495
  };
496
+ } finally {
497
+ this.closeDatabase(db);
360
498
  }
361
499
  }
500
+ closeDatabase(db) {
501
+ try {
502
+ db?.close(false);
503
+ } catch {}
504
+ }
362
505
  asInputAwareRigError(error) {
363
506
  if (error instanceof SyntaxError) {
364
507
  return new RigError("INPUT_ERROR", "Input JSON is invalid.", { message: error.message });
@@ -366,6 +509,5 @@ class ToolRunner {
366
509
  return RigErrors.from(error);
367
510
  }
368
511
  }
369
- export {
370
- ToolRunner
371
- };
512
+
513
+ export { ToolRunner };
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  RigConfigStore
3
- } from "./cli-xv4m20sx.js";
4
- import"./cli-aj56a1ja.js";
3
+ } from "./cli-jbscjyqq.js";
5
4
  import"./cli-1c7te5cg.js";
6
- import"./cli-ne7ed594.js";
5
+ import"./cli-vkw9rcke.js";
7
6
  import"./cli-b7jgjgy7.js";
8
7
  export {
9
8
  RigConfigStore
@@ -1,18 +1,17 @@
1
1
  import {
2
2
  ToolLoader
3
- } from "./cli-7zqnqrah.js";
3
+ } from "./cli-c6y9p8v9.js";
4
4
  import {
5
5
  RigToolEntryFiles,
6
6
  ToolDiscoveryService
7
- } from "./cli-vx11bmzr.js";
7
+ } from "./cli-ggk7t6dg.js";
8
8
  import {
9
9
  RigConfigStore
10
- } from "./cli-xv4m20sx.js";
11
- import"./cli-aj56a1ja.js";
10
+ } from "./cli-jbscjyqq.js";
12
11
  import {
13
12
  RigError
14
13
  } from "./cli-1c7te5cg.js";
15
- import"./cli-ne7ed594.js";
14
+ import"./cli-vkw9rcke.js";
16
15
  import"./cli-b7jgjgy7.js";
17
16
 
18
17
  // src/tools/create.ts
@@ -51,12 +50,12 @@ class ToolCreator {
51
50
  name: ${JSON.stringify(name)},
52
51
  description: "Describe what this tool does.",
53
52
  commands: {
54
- example: rig.command({
53
+ example: rig.defineCommand({
55
54
  description: "Example command. Replace this with a real command.",
56
- input: rig.input({
55
+ input: rig.z.object({
57
56
  text: rig.z.string().default("example"),
58
57
  }),
59
- output: rig.output({
58
+ output: rig.z.object({
60
59
  text: rig.z.string(),
61
60
  }),
62
61
  examples: [
@@ -0,0 +1,18 @@
1
+ import {
2
+ RigCronService,
3
+ RigCronWorker,
4
+ cronModuleUrl
5
+ } from "./cli-0p4wnh3p.js";
6
+ import"./cli-yahk2r84.js";
7
+ import"./cli-f4k31gtc.js";
8
+ import"./cli-c6y9p8v9.js";
9
+ import"./cli-ggk7t6dg.js";
10
+ import"./cli-jbscjyqq.js";
11
+ import"./cli-1c7te5cg.js";
12
+ import"./cli-vkw9rcke.js";
13
+ import"./cli-b7jgjgy7.js";
14
+ export {
15
+ cronModuleUrl,
16
+ RigCronWorker,
17
+ RigCronService
18
+ };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./cli-1c7te5cg.js";
4
4
  import {
5
5
  RigPaths
6
- } from "./cli-ne7ed594.js";
6
+ } from "./cli-vkw9rcke.js";
7
7
  import"./cli-b7jgjgy7.js";
8
8
 
9
9
  // src/dev/dev-link.ts
@@ -29,7 +29,10 @@ class DevLinkService {
29
29
  });
30
30
  }
31
31
  await mkdir(binDir, { recursive: true });
32
- await writeFile(shimPath, this.shimSource(repoRoot), "utf8");
32
+ if (typeof Bun !== "undefined")
33
+ await Bun.write(shimPath, this.shimSource(repoRoot));
34
+ else
35
+ await writeFile(shimPath, this.shimSource(repoRoot), "utf8");
33
36
  await chmod(shimPath, 493);
34
37
  return this.status(options);
35
38
  }
@@ -102,7 +105,7 @@ class DevLinkService {
102
105
  return `#!/usr/bin/env bash
103
106
  # Rig dev shim. Safe to overwrite with \`rig dev link\`.
104
107
  RIG_DEV_REPO=${JSON.stringify(repoRoot)}
105
- exec bun run "$RIG_DEV_REPO/src/cli.ts" "$@"
108
+ exec bun --install=fallback run "$RIG_DEV_REPO/src/cli.ts" "$@"
106
109
  `;
107
110
  }
108
111
  async readExistingShim(shimPath) {
@@ -111,7 +114,7 @@ exec bun run "$RIG_DEV_REPO/src/cli.ts" "$@"
111
114
  const stat = await lstat(shimPath);
112
115
  if (!stat.isFile())
113
116
  return { exists: true, isRigDevShim: false, content: "" };
114
- const content = await readFile(shimPath, "utf8");
117
+ const content = typeof Bun !== "undefined" ? await Bun.file(shimPath).text() : await readFile(shimPath, "utf8");
115
118
  return {
116
119
  exists: true,
117
120
  isRigDevShim: content.includes("Rig dev shim"),
@@ -1,11 +1,10 @@
1
1
  import {
2
2
  RigToolEntryFiles,
3
3
  ToolDiscoveryService
4
- } from "./cli-vx11bmzr.js";
5
- import"./cli-xv4m20sx.js";
6
- import"./cli-aj56a1ja.js";
4
+ } from "./cli-ggk7t6dg.js";
5
+ import"./cli-jbscjyqq.js";
7
6
  import"./cli-1c7te5cg.js";
8
- import"./cli-ne7ed594.js";
7
+ import"./cli-vkw9rcke.js";
9
8
  import"./cli-b7jgjgy7.js";
10
9
  export {
11
10
  ToolDiscoveryService,