@dirxai/cli 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/dist/index.js +116 -91
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -44,6 +44,7 @@ dirx keys set api.github.com --token ghp_xxxx --sync
44
44
  | `dirx cat <path>` | Read file contents |
45
45
  | `dirx write <path>` | Write data |
46
46
  | `dirx edit <path>` | Partial update |
47
+ | `dirx rm <path>` | Remove a resource |
47
48
  | `dirx grep <pattern> <path>` | Search across services |
48
49
  | `dirx bash <pipeline>` | Execute multi-step pipeline |
49
50
 
@@ -53,6 +54,7 @@ dirx keys set api.github.com --token ghp_xxxx --sync
53
54
  |---------|-------------|
54
55
  | `dirx init [dir]` | Initialize DirX in a project |
55
56
  | `dirx generate [dir]` | Scan and detect route definitions |
57
+ | `dirx generate --register` | Scan and auto-register with the gateway |
56
58
  | `dirx claim <domain>` | Claim domain via DNS verification |
57
59
  | `dirx register` | Register DIR.md with the gateway |
58
60
 
package/dist/index.js CHANGED
@@ -207,12 +207,100 @@ var init_init = __esm({
207
207
  }
208
208
  });
209
209
 
210
+ // src/commands/register.ts
211
+ var register_exports = {};
212
+ __export(register_exports, {
213
+ runRegister: () => runRegister
214
+ });
215
+ async function runRegister(options) {
216
+ const projectDir = options.dir ?? process.cwd();
217
+ const gatewayUrl = options.gatewayUrl ?? process.env.DIRX_GATEWAY_URL ?? "https://api.dirx.ai";
218
+ const domain = options.domain ?? process.env.DIRX_DOMAIN;
219
+ if (!domain) {
220
+ throw new Error(
221
+ "Domain is required. Use --domain or DIRX_DOMAIN env var."
222
+ );
223
+ }
224
+ const token = await resolveToken({
225
+ token: options.token,
226
+ domain,
227
+ gatewayUrl
228
+ });
229
+ const dirMdPath = join(projectDir, "DIR.md");
230
+ let dirMd;
231
+ try {
232
+ dirMd = await readFile(dirMdPath, "utf-8");
233
+ } catch {
234
+ throw new Error(
235
+ `DIR.md not found at ${dirMdPath}. Run 'dirx init' first.`
236
+ );
237
+ }
238
+ if (!dirMd.trim()) {
239
+ throw new Error(`DIR.md is empty at ${dirMdPath}`);
240
+ }
241
+ const baseUrl = gatewayUrl.replace(/\/$/, "");
242
+ const url = `${baseUrl}/registry/services?domain=${encodeURIComponent(domain)}`;
243
+ const res = await fetch(url, {
244
+ method: "POST",
245
+ headers: {
246
+ Authorization: `Bearer ${token}`,
247
+ "Content-Type": "text/markdown"
248
+ },
249
+ body: dirMd
250
+ });
251
+ if (!res.ok) {
252
+ const body = await res.text();
253
+ throw new Error(`Registration failed (${res.status}): ${body}`);
254
+ }
255
+ const result = await res.json();
256
+ console.log(`Registered ${result.name} as ${result.domain}`);
257
+ }
258
+ async function resolveToken(options) {
259
+ if (options.token) return options.token;
260
+ if (process.env.DIRX_PUBLISH_TOKEN) return process.env.DIRX_PUBLISH_TOKEN;
261
+ if (options.domain) {
262
+ const stored = await getToken(options.domain);
263
+ if (stored) return stored;
264
+ const gw = options.gatewayUrl ?? process.env.DIRX_GATEWAY_URL;
265
+ if (gw) {
266
+ const renewed = await renewToken(gw, options.domain);
267
+ if (renewed) return renewed;
268
+ }
269
+ }
270
+ throw new Error(
271
+ "No auth token found. Use `dirx claim <domain>` to obtain a publish token, or provide --token."
272
+ );
273
+ }
274
+ async function renewToken(gatewayUrl, domain) {
275
+ const baseUrl = gatewayUrl.replace(/\/$/, "");
276
+ try {
277
+ const res = await fetch(`${baseUrl}/domains/verify`, {
278
+ method: "POST",
279
+ headers: { "Content-Type": "application/json" },
280
+ body: JSON.stringify({ domain })
281
+ });
282
+ if (!res.ok) return null;
283
+ const data = await res.json();
284
+ if (!data.publishToken) return null;
285
+ await saveToken(domain, data.publishToken);
286
+ console.log(`Token renewed for ${domain}`);
287
+ return data.publishToken;
288
+ } catch {
289
+ return null;
290
+ }
291
+ }
292
+ var init_register = __esm({
293
+ "src/commands/register.ts"() {
294
+ init_credentials();
295
+ }
296
+ });
297
+
210
298
  // src/commands/generate.ts
211
299
  var generate_exports = {};
212
300
  __export(generate_exports, {
213
301
  runGenerate: () => runGenerate
214
302
  });
215
- async function runGenerate(dir) {
303
+ async function runGenerate(dir, opts) {
216
304
  const target = dir === "." ? process.cwd() : dir;
217
305
  const dirJsonPath = join(target, "dir.json");
218
306
  if (!existsSync(dirJsonPath)) {
@@ -242,6 +330,17 @@ No route definitions detected.`);
242
330
  }
243
331
  console.log(`
244
332
  Edit DIR.md and dir.json to describe your API.`);
333
+ if (opts?.register) {
334
+ console.log(`
335
+ Registering with gateway...`);
336
+ const { runRegister: runRegister2 } = await Promise.resolve().then(() => (init_register(), register_exports));
337
+ await runRegister2({
338
+ gatewayUrl: opts.gatewayUrl,
339
+ token: opts.token,
340
+ domain: opts.domain,
341
+ dir: target
342
+ });
343
+ }
245
344
  }
246
345
  function detectFrameworkFromPackage(target) {
247
346
  const pkgPath = join(target, "package.json");
@@ -427,94 +526,6 @@ var init_claim = __esm({
427
526
  }
428
527
  });
429
528
 
430
- // src/commands/register.ts
431
- var register_exports = {};
432
- __export(register_exports, {
433
- runRegister: () => runRegister
434
- });
435
- async function runRegister(options) {
436
- const projectDir = options.dir ?? process.cwd();
437
- const gatewayUrl = options.gatewayUrl ?? process.env.DIRX_GATEWAY_URL ?? "https://api.dirx.ai";
438
- const domain = options.domain ?? process.env.DIRX_DOMAIN;
439
- if (!domain) {
440
- throw new Error(
441
- "Domain is required. Use --domain or DIRX_DOMAIN env var."
442
- );
443
- }
444
- const token = await resolveToken({
445
- token: options.token,
446
- domain,
447
- gatewayUrl
448
- });
449
- const dirMdPath = join(projectDir, "DIR.md");
450
- let dirMd;
451
- try {
452
- dirMd = await readFile(dirMdPath, "utf-8");
453
- } catch {
454
- throw new Error(
455
- `DIR.md not found at ${dirMdPath}. Run 'dirx init' first.`
456
- );
457
- }
458
- if (!dirMd.trim()) {
459
- throw new Error(`DIR.md is empty at ${dirMdPath}`);
460
- }
461
- const baseUrl = gatewayUrl.replace(/\/$/, "");
462
- const url = `${baseUrl}/registry/services?domain=${encodeURIComponent(domain)}`;
463
- const res = await fetch(url, {
464
- method: "POST",
465
- headers: {
466
- Authorization: `Bearer ${token}`,
467
- "Content-Type": "text/markdown"
468
- },
469
- body: dirMd
470
- });
471
- if (!res.ok) {
472
- const body = await res.text();
473
- throw new Error(`Registration failed (${res.status}): ${body}`);
474
- }
475
- const result = await res.json();
476
- console.log(`Registered ${result.name} as ${result.domain}`);
477
- }
478
- async function resolveToken(options) {
479
- if (options.token) return options.token;
480
- if (process.env.DIRX_PUBLISH_TOKEN) return process.env.DIRX_PUBLISH_TOKEN;
481
- if (options.domain) {
482
- const stored = await getToken(options.domain);
483
- if (stored) return stored;
484
- const gw = options.gatewayUrl ?? process.env.DIRX_GATEWAY_URL;
485
- if (gw) {
486
- const renewed = await renewToken(gw, options.domain);
487
- if (renewed) return renewed;
488
- }
489
- }
490
- throw new Error(
491
- "No auth token found. Use `dirx claim <domain>` to obtain a publish token, or provide --token."
492
- );
493
- }
494
- async function renewToken(gatewayUrl, domain) {
495
- const baseUrl = gatewayUrl.replace(/\/$/, "");
496
- try {
497
- const res = await fetch(`${baseUrl}/domains/verify`, {
498
- method: "POST",
499
- headers: { "Content-Type": "application/json" },
500
- body: JSON.stringify({ domain })
501
- });
502
- if (!res.ok) return null;
503
- const data = await res.json();
504
- if (!data.publishToken) return null;
505
- await saveToken(domain, data.publishToken);
506
- console.log(`Token renewed for ${domain}`);
507
- return data.publishToken;
508
- } catch {
509
- return null;
510
- }
511
- }
512
- var init_register = __esm({
513
- "src/commands/register.ts"() {
514
- init_credentials();
515
- }
516
- });
517
-
518
529
  // src/commands/status.ts
519
530
  var status_exports = {};
520
531
  __export(status_exports, {
@@ -771,6 +782,15 @@ function registerFsCommands(program2) {
771
782
  }
772
783
  }
773
784
  );
785
+ program2.command("rm").description("Remove a resource at a DirX path").argument("<path>", "Resource path").action(async (path) => {
786
+ try {
787
+ const client = await createClient();
788
+ const result = await client.execute(`rm ${path}`);
789
+ output(result);
790
+ } catch (err) {
791
+ handleError(err, path);
792
+ }
793
+ });
774
794
  program2.command("bash").description("Execute a multi-step pipeline on the gateway").argument("<pipeline>", "Pipeline expression").action(async (pipeline) => {
775
795
  try {
776
796
  const client = await createClient();
@@ -925,9 +945,14 @@ program.command("init").description("Initialize DirX in the current project").ar
925
945
  const { runInit: runInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
926
946
  await runInit2(dir);
927
947
  });
928
- program.command("generate").description("Scan project and detect route definitions").argument("[dir]", "Project directory", ".").action(async (dir) => {
948
+ program.command("generate").description("Scan project and generate DIR.md, optionally register").argument("[dir]", "Project directory", ".").option("--register", "Register the service with the gateway after generating").option("--gateway-url <url>", "Gateway URL for registration").option("--token <token>", "Auth token for registration").option("--domain <domain>", "Domain name for the service").action(async (dir, opts) => {
929
949
  const { runGenerate: runGenerate2 } = await Promise.resolve().then(() => (init_generate(), generate_exports));
930
- await runGenerate2(dir);
950
+ await runGenerate2(dir, {
951
+ register: opts.register,
952
+ gatewayUrl: opts.gatewayUrl,
953
+ token: opts.token,
954
+ domain: opts.domain
955
+ });
931
956
  });
932
957
  program.command("claim").description("Claim domain ownership via DNS verification").argument("<domain>", "Domain to claim").option("--verify", "Verify DNS record and obtain publish token").option("--gateway-url <url>", "Gateway URL").action(
933
958
  async (domain, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dirxai/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "DirX — Unified Gateway & CLI for Agents",
5
5
  "license": "MIT",
6
6
  "type": "module",