@pmate/cli 0.16.0 → 0.16.2

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/dist/index.js CHANGED
@@ -18807,167 +18807,6 @@ function parseMessageText(raw) {
18807
18807
  var import_node_fs12 = require("fs");
18808
18808
  var import_node_path17 = __toESM(require("path"));
18809
18809
  init_sessionStore();
18810
- var AgentCommandHandler = class {
18811
- async handle(args) {
18812
- const token = this.readToken();
18813
- const baseUrl = this.resolveBaseUrl(args.baseUrl);
18814
- switch (args.action) {
18815
- case "namespaces": {
18816
- const response = await this.request(
18817
- baseUrl,
18818
- token,
18819
- "GET",
18820
- "/agents/namespaces"
18821
- );
18822
- this.renderNamespaces(response.items, args.json);
18823
- return;
18824
- }
18825
- case "list": {
18826
- const response = await this.request(
18827
- baseUrl,
18828
- token,
18829
- "GET",
18830
- `/agents?namespace=${encodeURIComponent(args.namespace)}`
18831
- );
18832
- this.renderList(response.items, args.json);
18833
- return;
18834
- }
18835
- case "get": {
18836
- const record = await this.request(
18837
- baseUrl,
18838
- token,
18839
- "GET",
18840
- `/agents/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`
18841
- );
18842
- this.renderJson(record, args.json ?? true);
18843
- return;
18844
- }
18845
- case "create": {
18846
- const payload = this.readJsonFile(args.filePath);
18847
- const record = await this.request(
18848
- baseUrl,
18849
- token,
18850
- "POST",
18851
- `/agents/${encodeURIComponent(args.namespace)}`,
18852
- payload
18853
- );
18854
- ui.success(`Created agent ${record.id}`);
18855
- this.renderJson(record, args.json);
18856
- return;
18857
- }
18858
- case "update": {
18859
- const payload = this.readJsonFile(args.filePath);
18860
- const record = await this.request(
18861
- baseUrl,
18862
- token,
18863
- "PUT",
18864
- `/agents/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`,
18865
- payload
18866
- );
18867
- ui.success(`Updated agent ${record.id}`);
18868
- this.renderJson(record, args.json);
18869
- return;
18870
- }
18871
- case "delete": {
18872
- const record = await this.request(
18873
- baseUrl,
18874
- token,
18875
- "DELETE",
18876
- `/agents/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`
18877
- );
18878
- ui.success(`Disabled agent ${record.id}`);
18879
- this.renderJson(record, args.json);
18880
- return;
18881
- }
18882
- }
18883
- }
18884
- resolveBaseUrl(baseUrl) {
18885
- return (baseUrl || process.env.PMATE_AGENT_API_BASE_URL || "https://agent-api.pmate.chat").replace(
18886
- /\/+$/,
18887
- ""
18888
- );
18889
- }
18890
- readToken() {
18891
- return readRequiredSession({
18892
- preferredApp: DEFAULT_APP_ID
18893
- }).token;
18894
- }
18895
- readJsonFile(filePath) {
18896
- const absolutePath = import_node_path17.default.resolve(process.cwd(), filePath);
18897
- if (!(0, import_node_fs12.existsSync)(absolutePath)) {
18898
- throw new Error(`JSON file not found: ${absolutePath}`);
18899
- }
18900
- const raw = (0, import_node_fs12.readFileSync)(absolutePath, "utf8");
18901
- try {
18902
- return JSON.parse(raw);
18903
- } catch (error) {
18904
- const message = error instanceof Error ? error.message : String(error);
18905
- throw new Error(`Invalid JSON in ${absolutePath}: ${message}`);
18906
- }
18907
- }
18908
- async request(baseUrl, token, method, pathname, body) {
18909
- const response = await fetch(`${baseUrl}${pathname}`, {
18910
- method,
18911
- headers: {
18912
- Authorization: `Bearer ${token}`,
18913
- "Content-Type": "application/json"
18914
- },
18915
- ...body !== void 0 ? { body: JSON.stringify(body) } : {}
18916
- });
18917
- let payload = null;
18918
- try {
18919
- payload = await response.json();
18920
- } catch {
18921
- payload = null;
18922
- }
18923
- if (!response.ok || !payload?.success) {
18924
- throw new Error(payload?.message || `Request failed with status ${response.status}`);
18925
- }
18926
- return payload.data;
18927
- }
18928
- renderList(items, asJson) {
18929
- if (asJson) {
18930
- ui.plain(JSON.stringify(items, null, 2));
18931
- return;
18932
- }
18933
- if (items.length === 0) {
18934
- ui.warn("No agents found.");
18935
- return;
18936
- }
18937
- for (const item of items) {
18938
- ui.info(`${item.namespace}/${item.name}`, {
18939
- status: item.status,
18940
- version: item.version
18941
- });
18942
- }
18943
- }
18944
- renderJson(value, asJson) {
18945
- if (!asJson) {
18946
- return;
18947
- }
18948
- ui.plain(JSON.stringify(value, null, 2));
18949
- }
18950
- renderNamespaces(items, asJson) {
18951
- if (asJson) {
18952
- ui.plain(JSON.stringify(items, null, 2));
18953
- return;
18954
- }
18955
- if (items.length === 0) {
18956
- ui.warn("No namespaces found.");
18957
- return;
18958
- }
18959
- for (const item of items) {
18960
- ui.info(item.namespace, {
18961
- status: item.status,
18962
- updatedAt: item.updatedAt
18963
- });
18964
- }
18965
- }
18966
- };
18967
-
18968
- // src/commands/StoreCommandHandler.ts
18969
- var import_node_fs13 = require("fs");
18970
- var import_node_path18 = __toESM(require("path"));
18971
18810
 
18972
18811
  // src/storeClient.ts
18973
18812
  var STORE_LOG_VERSION = 1;
@@ -19015,6 +18854,13 @@ async function requestJson(url, init, fallbackMessage) {
19015
18854
  }
19016
18855
  return payload;
19017
18856
  }
18857
+ function normalizeNamespace(value) {
18858
+ const normalized = value.trim().toLowerCase();
18859
+ if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(normalized)) {
18860
+ throw new Error("Invalid namespace. Use lowercase letters, numbers, and dashes only.");
18861
+ }
18862
+ return normalized;
18863
+ }
19018
18864
  var IndexerClient = class {
19019
18865
  constructor(baseUrl) {
19020
18866
  this.baseUrl = baseUrl;
@@ -19062,9 +18908,16 @@ var BlockLogAppender = class {
19062
18908
  var Namespace = class {
19063
18909
  constructor(options) {
19064
18910
  this.options = options;
19065
- this.appender = new BlockLogAppender(options.chain, options.baseUrl.replace(/\/+$/, ""));
19066
18911
  this.indexerClient = new IndexerClient(options.indexerBaseUrl.replace(/\/+$/, ""));
19067
18912
  }
18913
+ getAppender() {
18914
+ if (!this.options.baseUrl) {
18915
+ throw new Error(
18916
+ "Missing store base URL. Provide --base-url or set PMATE_STORE_BASE_URL / BLOCKCHAIN_BASE_URL."
18917
+ );
18918
+ }
18919
+ return new BlockLogAppender(this.options.chain, this.options.baseUrl.replace(/\/+$/, ""));
18920
+ }
19068
18921
  table(name) {
19069
18922
  const descriptor = createDescriptor({
19070
18923
  chain: this.options.chain,
@@ -19105,7 +18958,7 @@ var Namespace = class {
19105
18958
  v: STORE_LOG_VERSION,
19106
18959
  data: { type: "create", after: data }
19107
18960
  };
19108
- await this.appender.append([log]);
18961
+ await this.getAppender().append([log]);
19109
18962
  },
19110
18963
  updateRow: async (data) => {
19111
18964
  const { id, ...value } = data;
@@ -19117,7 +18970,7 @@ var Namespace = class {
19117
18970
  v: STORE_LOG_VERSION,
19118
18971
  data: { type: "update", id, value }
19119
18972
  };
19120
- await this.appender.append([log]);
18973
+ await this.getAppender().append([log]);
19121
18974
  },
19122
18975
  deleteRow: async (id) => {
19123
18976
  const log = {
@@ -19128,7 +18981,7 @@ var Namespace = class {
19128
18981
  v: STORE_LOG_VERSION,
19129
18982
  data: { type: "delete", id }
19130
18983
  };
19131
- await this.appender.append([log]);
18984
+ await this.getAppender().append([log]);
19132
18985
  }
19133
18986
  };
19134
18987
  }
@@ -19171,7 +19024,7 @@ var Namespace = class {
19171
19024
  v: STORE_LOG_VERSION,
19172
19025
  data: { key, value }
19173
19026
  };
19174
- await this.appender.append([log]);
19027
+ await this.getAppender().append([log]);
19175
19028
  },
19176
19029
  delete: async (key) => {
19177
19030
  const log = {
@@ -19182,13 +19035,325 @@ var Namespace = class {
19182
19035
  v: STORE_LOG_VERSION,
19183
19036
  data: { key, value: null }
19184
19037
  };
19185
- await this.appender.append([log]);
19038
+ await this.getAppender().append([log]);
19039
+ }
19040
+ };
19041
+ }
19042
+ };
19043
+ var NamespaceRegistry = class {
19044
+ constructor(options) {
19045
+ this.options = options;
19046
+ }
19047
+ async list() {
19048
+ return this.request("GET", "/namespaces");
19049
+ }
19050
+ async get(namespace) {
19051
+ const normalized = normalizeNamespace(namespace);
19052
+ const response = await fetch(
19053
+ `${this.options.registryBaseUrl.replace(/\/+$/, "")}/namespaces/${encodeURIComponent(normalized)}`,
19054
+ {
19055
+ method: "GET",
19056
+ headers: {
19057
+ Accept: "application/json",
19058
+ ...this.options.headers
19059
+ }
19060
+ }
19061
+ );
19062
+ if (response.status === 404) {
19063
+ return void 0;
19064
+ }
19065
+ const payload = await response.json();
19066
+ if (!response.ok || !payload?.success) {
19067
+ throw new Error(payload?.message || `Namespace request failed: ${response.status}`);
19068
+ }
19069
+ return payload.data;
19070
+ }
19071
+ async exists(namespace) {
19072
+ return Boolean(await this.get(namespace));
19073
+ }
19074
+ async create(namespace) {
19075
+ return this.request("POST", "/namespaces", {
19076
+ namespace: normalizeNamespace(namespace)
19077
+ });
19078
+ }
19079
+ async require(namespace) {
19080
+ const record = await this.get(namespace);
19081
+ if (!record || record.status !== "active") {
19082
+ throw new Error(`Namespace "${normalizeNamespace(namespace)}" is not registered.`);
19083
+ }
19084
+ if (!this.options.blockchainBaseUrl || !this.options.indexerBaseUrl) {
19085
+ throw new Error("Namespace handle requires blockchain and indexer base URLs.");
19086
+ }
19087
+ return new Namespace({
19088
+ chain: this.options.chain,
19089
+ ns: record.namespace,
19090
+ baseUrl: this.options.blockchainBaseUrl,
19091
+ indexerBaseUrl: this.options.indexerBaseUrl
19092
+ });
19093
+ }
19094
+ async request(method, pathname, body) {
19095
+ const response = await fetch(`${this.options.registryBaseUrl.replace(/\/+$/, "")}${pathname}`, {
19096
+ method,
19097
+ headers: {
19098
+ Accept: "application/json",
19099
+ ...this.options.headers,
19100
+ ...method === "POST" ? { "Content-Type": "application/json" } : {}
19101
+ },
19102
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
19103
+ });
19104
+ const payload = await response.json();
19105
+ if (!response.ok || !payload?.success) {
19106
+ throw new Error(payload?.message || `Namespace request failed: ${response.status}`);
19107
+ }
19108
+ return payload.data;
19109
+ }
19110
+ };
19111
+
19112
+ // src/commands/AgentCommandHandler.ts
19113
+ var AgentCommandHandler = class {
19114
+ async handle(args) {
19115
+ const token = this.readToken();
19116
+ const baseUrl = this.resolveBaseUrl(args.baseUrl);
19117
+ switch (args.action) {
19118
+ case "namespaces": {
19119
+ const response = await this.request(
19120
+ baseUrl,
19121
+ token,
19122
+ "GET",
19123
+ "/agents/namespaces"
19124
+ );
19125
+ this.renderNamespaces(response.items, args.json);
19126
+ return;
19127
+ }
19128
+ case "list": {
19129
+ const response = await this.request(
19130
+ baseUrl,
19131
+ token,
19132
+ "GET",
19133
+ `/agents?namespace=${encodeURIComponent(args.namespace)}`
19134
+ );
19135
+ this.renderList(response.items, args.json);
19136
+ return;
19137
+ }
19138
+ case "get": {
19139
+ const record = await this.request(
19140
+ baseUrl,
19141
+ token,
19142
+ "GET",
19143
+ `/agents/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`
19144
+ );
19145
+ this.renderJson(record, args.json ?? true);
19146
+ return;
19147
+ }
19148
+ case "create": {
19149
+ await this.requireNamespace(args.namespace, baseUrl);
19150
+ const payload = this.readJsonFile(args.filePath);
19151
+ const record = await this.request(
19152
+ baseUrl,
19153
+ token,
19154
+ "POST",
19155
+ `/agents/${encodeURIComponent(args.namespace)}`,
19156
+ payload
19157
+ );
19158
+ ui.success(`Created agent ${record.id}`);
19159
+ this.renderJson(record, args.json);
19160
+ return;
19161
+ }
19162
+ case "update": {
19163
+ const payload = this.readJsonFile(args.filePath);
19164
+ const record = await this.request(
19165
+ baseUrl,
19166
+ token,
19167
+ "PUT",
19168
+ `/agents/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`,
19169
+ payload
19170
+ );
19171
+ ui.success(`Updated agent ${record.id}`);
19172
+ this.renderJson(record, args.json);
19173
+ return;
19186
19174
  }
19175
+ case "delete": {
19176
+ const record = await this.request(
19177
+ baseUrl,
19178
+ token,
19179
+ "DELETE",
19180
+ `/agents/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`
19181
+ );
19182
+ ui.success(`Disabled agent ${record.id}`);
19183
+ this.renderJson(record, args.json);
19184
+ return;
19185
+ }
19186
+ }
19187
+ }
19188
+ resolveBaseUrl(baseUrl) {
19189
+ return (baseUrl || process.env.PMATE_AGENT_API_BASE_URL || "https://agent-api.pmate.chat").replace(
19190
+ /\/+$/,
19191
+ ""
19192
+ );
19193
+ }
19194
+ async requireNamespace(namespace, registryBaseUrl) {
19195
+ const registry = new NamespaceRegistry({
19196
+ chain: "pmate",
19197
+ registryBaseUrl: this.resolveNamespaceBaseUrl(registryBaseUrl)
19198
+ });
19199
+ const exists = await registry.exists(namespace);
19200
+ if (!exists) {
19201
+ throw new Error(`Namespace "${namespace}" is not registered. Run: pmate ns create ${namespace}`);
19202
+ }
19203
+ }
19204
+ resolveNamespaceBaseUrl(baseUrl) {
19205
+ const envBaseUrl = process.env.PMATE_NAMESPACE_API_BASE_URL || process.env.PMATE_APPS_API_BASE_URL;
19206
+ if (envBaseUrl) {
19207
+ return envBaseUrl.replace(/\/+$/, "");
19208
+ }
19209
+ return baseUrl.includes("agent-api") || baseUrl.includes("agent.local") ? baseUrl.replace("agent-api", "apps-api").replace("agent.local", "apps.local") : baseUrl;
19210
+ }
19211
+ readToken() {
19212
+ return readRequiredSession({
19213
+ preferredApp: DEFAULT_APP_ID
19214
+ }).token;
19215
+ }
19216
+ readJsonFile(filePath) {
19217
+ const absolutePath = import_node_path17.default.resolve(process.cwd(), filePath);
19218
+ if (!(0, import_node_fs12.existsSync)(absolutePath)) {
19219
+ throw new Error(`JSON file not found: ${absolutePath}`);
19220
+ }
19221
+ const raw = (0, import_node_fs12.readFileSync)(absolutePath, "utf8");
19222
+ try {
19223
+ return JSON.parse(raw);
19224
+ } catch (error) {
19225
+ const message = error instanceof Error ? error.message : String(error);
19226
+ throw new Error(`Invalid JSON in ${absolutePath}: ${message}`);
19227
+ }
19228
+ }
19229
+ async request(baseUrl, token, method, pathname, body) {
19230
+ const response = await fetch(`${baseUrl}${pathname}`, {
19231
+ method,
19232
+ headers: {
19233
+ Authorization: `Bearer ${token}`,
19234
+ "Content-Type": "application/json"
19235
+ },
19236
+ ...body !== void 0 ? { body: JSON.stringify(body) } : {}
19237
+ });
19238
+ let payload = null;
19239
+ try {
19240
+ payload = await response.json();
19241
+ } catch {
19242
+ payload = null;
19243
+ }
19244
+ if (!response.ok || !payload?.success) {
19245
+ throw new Error(payload?.message || `Request failed with status ${response.status}`);
19246
+ }
19247
+ return payload.data;
19248
+ }
19249
+ renderList(items, asJson) {
19250
+ if (asJson) {
19251
+ ui.plain(JSON.stringify(items, null, 2));
19252
+ return;
19253
+ }
19254
+ if (items.length === 0) {
19255
+ ui.warn("No agents found.");
19256
+ return;
19257
+ }
19258
+ for (const item of items) {
19259
+ ui.info(`${item.namespace}/${item.name}`, {
19260
+ status: item.status,
19261
+ version: item.version
19262
+ });
19263
+ }
19264
+ }
19265
+ renderJson(value, asJson) {
19266
+ if (!asJson) {
19267
+ return;
19268
+ }
19269
+ ui.plain(JSON.stringify(value, null, 2));
19270
+ }
19271
+ renderNamespaces(items, asJson) {
19272
+ if (asJson) {
19273
+ ui.plain(JSON.stringify(items, null, 2));
19274
+ return;
19275
+ }
19276
+ if (items.length === 0) {
19277
+ ui.warn("No namespaces found.");
19278
+ return;
19279
+ }
19280
+ for (const item of items) {
19281
+ ui.info(item.namespace, {
19282
+ status: item.status,
19283
+ updatedAt: item.updatedAt
19284
+ });
19285
+ }
19286
+ }
19287
+ };
19288
+
19289
+ // src/commands/NsCommandHandler.ts
19290
+ init_sessionStore();
19291
+ var NsCommandHandler = class {
19292
+ async handle(args) {
19293
+ switch (args.action) {
19294
+ case "list": {
19295
+ const registry = this.createRegistry(args);
19296
+ const items = await registry.list();
19297
+ this.render(items, args.json);
19298
+ return;
19299
+ }
19300
+ case "get": {
19301
+ const registry = this.createRegistry(args);
19302
+ const item = await registry.get(args.namespace);
19303
+ if (!item) {
19304
+ throw new Error(`Namespace "${args.namespace}" is not registered.`);
19305
+ }
19306
+ this.render(item, true);
19307
+ return;
19308
+ }
19309
+ case "create": {
19310
+ const registry = this.createRegistry(args, this.resolveAuthHeaders());
19311
+ const item = await registry.create(args.namespace);
19312
+ ui.success(`Created namespace ${item.namespace}`);
19313
+ this.render(item, args.json);
19314
+ return;
19315
+ }
19316
+ }
19317
+ }
19318
+ resolveBaseUrl(baseUrl) {
19319
+ return (baseUrl || process.env.PMATE_NAMESPACE_API_BASE_URL || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
19320
+ }
19321
+ resolveAuthHeaders() {
19322
+ return {
19323
+ Authorization: `Bearer ${readRequiredSession({ preferredApp: DEFAULT_APP_ID }).token}`
19187
19324
  };
19188
19325
  }
19326
+ createRegistry(args, headers) {
19327
+ return new NamespaceRegistry({
19328
+ chain: args.chain,
19329
+ registryBaseUrl: this.resolveBaseUrl(args.baseUrl),
19330
+ headers
19331
+ });
19332
+ }
19333
+ render(value, asJson) {
19334
+ if (asJson) {
19335
+ ui.plain(JSON.stringify(value, null, 2));
19336
+ return;
19337
+ }
19338
+ if (Array.isArray(value)) {
19339
+ if (value.length === 0) {
19340
+ ui.warn("No namespaces found.");
19341
+ return;
19342
+ }
19343
+ for (const item of value) {
19344
+ ui.info(`${item.chain ?? "pmate"}/${item.namespace}`, {
19345
+ status: item.status
19346
+ });
19347
+ }
19348
+ return;
19349
+ }
19350
+ ui.plain(JSON.stringify(value, null, 2));
19351
+ }
19189
19352
  };
19190
19353
 
19191
19354
  // src/commands/StoreCommandHandler.ts
19355
+ var import_node_fs13 = require("fs");
19356
+ var import_node_path18 = __toESM(require("path"));
19192
19357
  var StoreCommandHandler = class {
19193
19358
  async handle(args) {
19194
19359
  if (args.scope === "namespace") {
@@ -19196,6 +19361,9 @@ var StoreCommandHandler = class {
19196
19361
  this.renderNamespaceList(items, args.json);
19197
19362
  return;
19198
19363
  }
19364
+ if (this.requiresRegisteredNamespace(args)) {
19365
+ await this.requireNamespace(args);
19366
+ }
19199
19367
  const namespace = this.createNamespace(args);
19200
19368
  if (args.scope === "table") {
19201
19369
  const table = namespace.table(args.name);
@@ -19275,10 +19443,11 @@ var StoreCommandHandler = class {
19275
19443
  }
19276
19444
  }
19277
19445
  createNamespace(args) {
19446
+ const needsWriteBaseUrl = args.scope === "table" && (args.action === "create" || args.action === "update" || args.action === "delete") || args.scope === "kv" && (args.action === "set" || args.action === "delete");
19278
19447
  return new Namespace({
19279
19448
  chain: args.chain,
19280
19449
  ns: args.namespace,
19281
- baseUrl: this.resolveBaseUrl(args.baseUrl),
19450
+ baseUrl: needsWriteBaseUrl ? this.resolveBaseUrl(args.baseUrl) : args.baseUrl,
19282
19451
  indexerBaseUrl: this.resolveIndexerBaseUrl(args.indexerBaseUrl)
19283
19452
  });
19284
19453
  }
@@ -19294,6 +19463,25 @@ var StoreCommandHandler = class {
19294
19463
  resolveIndexerBaseUrl(indexerBaseUrl) {
19295
19464
  return (indexerBaseUrl || process.env.PMATE_STORE_INDEXER_BASE_URL || process.env.INDEXER_BASE_URL || "https://indexer.pmate.chat").replace(/\/+$/, "");
19296
19465
  }
19466
+ async requireNamespace(args) {
19467
+ const registry = new NamespaceRegistry({
19468
+ chain: args.chain,
19469
+ registryBaseUrl: this.resolveRegistryBaseUrl()
19470
+ });
19471
+ const exists = await registry.exists(args.namespace);
19472
+ if (!exists) {
19473
+ throw new Error(`Namespace "${args.namespace}" is not registered. Run: pmate ns create ${args.namespace}`);
19474
+ }
19475
+ }
19476
+ resolveRegistryBaseUrl() {
19477
+ return (process.env.PMATE_NAMESPACE_API_BASE_URL || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
19478
+ }
19479
+ requiresRegisteredNamespace(args) {
19480
+ if (args.scope === "table") {
19481
+ return args.action === "create" || args.action === "update" || args.action === "delete";
19482
+ }
19483
+ return args.action === "set" || args.action === "delete";
19484
+ }
19297
19485
  async listNamespaces(args) {
19298
19486
  const baseUrl = this.resolveIndexerBaseUrl(args.indexerBaseUrl);
19299
19487
  const url = new URL(`/chains/${encodeURIComponent(args.chain)}/namespaces`, `${baseUrl}/`);
@@ -19393,6 +19581,7 @@ var AppCommandHandler = class {
19393
19581
  }
19394
19582
  case "create": {
19395
19583
  const payload = this.readJsonFile(args.filePath);
19584
+ await this.requireNamespace(payload, baseUrl);
19396
19585
  const record = await this.request(
19397
19586
  baseUrl,
19398
19587
  token,
@@ -19471,6 +19660,17 @@ var AppCommandHandler = class {
19471
19660
  }
19472
19661
  return payload.data;
19473
19662
  }
19663
+ async requireNamespace(payload, baseUrl) {
19664
+ const namespace = readNamespaceFromPayload(payload);
19665
+ const registry = new NamespaceRegistry({
19666
+ chain: "pmate",
19667
+ registryBaseUrl: baseUrl
19668
+ });
19669
+ const exists = await registry.exists(namespace);
19670
+ if (!exists) {
19671
+ throw new Error(`Namespace "${namespace}" is not registered. Run: pmate ns create ${namespace}`);
19672
+ }
19673
+ }
19474
19674
  renderList(items, asJson) {
19475
19675
  if (asJson) {
19476
19676
  ui.plain(JSON.stringify(items, null, 2));
@@ -19494,6 +19694,16 @@ var AppCommandHandler = class {
19494
19694
  ui.plain(JSON.stringify(value, null, 2));
19495
19695
  }
19496
19696
  };
19697
+ function readNamespaceFromPayload(payload) {
19698
+ if (!payload || typeof payload !== "object") {
19699
+ throw new Error("App payload must be a JSON object.");
19700
+ }
19701
+ const namespace = payload.namespace;
19702
+ if (typeof namespace !== "string" || !namespace.trim()) {
19703
+ throw new Error("App payload.namespace is required.");
19704
+ }
19705
+ return namespace.trim().toLowerCase();
19706
+ }
19497
19707
 
19498
19708
  // src/commands/VercelCommandHandler.ts
19499
19709
  var import_node_child_process10 = require("child_process");
@@ -19611,7 +19821,7 @@ function parseAgentArgs(tokens) {
19611
19821
  }
19612
19822
  let baseUrl;
19613
19823
  let json = false;
19614
- const takeSharedOptions2 = () => {
19824
+ const takeSharedOptions3 = () => {
19615
19825
  while (rest.length > 0) {
19616
19826
  const token = rest[0];
19617
19827
  if (token === "--base-url") {
@@ -19628,7 +19838,7 @@ function parseAgentArgs(tokens) {
19628
19838
  }
19629
19839
  };
19630
19840
  if (action === "namespaces") {
19631
- takeSharedOptions2();
19841
+ takeSharedOptions3();
19632
19842
  if (rest.length > 0) {
19633
19843
  throw new Error(`Unknown agent namespaces option: ${rest[0]}`);
19634
19844
  }
@@ -19670,7 +19880,7 @@ function parseAgentArgs(tokens) {
19670
19880
  `Usage: agent ${action} [<namespace>] <name> [--base-url <url>] [--json]`
19671
19881
  );
19672
19882
  }
19673
- takeSharedOptions2();
19883
+ takeSharedOptions3();
19674
19884
  if (rest.length > 0) {
19675
19885
  throw new Error(`Unknown agent ${action} option: ${rest[0]}`);
19676
19886
  }
@@ -19751,8 +19961,79 @@ function requireValue(tokens, optionName) {
19751
19961
  return value;
19752
19962
  }
19753
19963
 
19754
- // src/storeCommandParser.ts
19964
+ // src/nsCommandParser.ts
19755
19965
  var DEFAULT_CHAIN = "pmate";
19966
+ function parseNsArgs(tokens) {
19967
+ const rest = [...tokens];
19968
+ const action = rest.shift();
19969
+ if (!action) {
19970
+ throw new Error("Missing ns action. Use: ns list|get|create");
19971
+ }
19972
+ let chain = DEFAULT_CHAIN;
19973
+ let baseUrl;
19974
+ let json = false;
19975
+ if (action === "list") {
19976
+ takeSharedOptions(rest, {
19977
+ onChain: (value) => {
19978
+ chain = value;
19979
+ },
19980
+ onBaseUrl: (value) => {
19981
+ baseUrl = value;
19982
+ },
19983
+ onJson: () => {
19984
+ json = true;
19985
+ }
19986
+ });
19987
+ return { type: "ns" /* Ns */, action, chain, baseUrl, json };
19988
+ }
19989
+ if (action === "get" || action === "create") {
19990
+ const namespace = rest.shift();
19991
+ if (!namespace || namespace.startsWith("-")) {
19992
+ throw new Error(`Usage: ns ${action} <namespace> [--chain <chain>] [--base-url <url>] [--json]`);
19993
+ }
19994
+ takeSharedOptions(rest, {
19995
+ onChain: (value) => {
19996
+ chain = value;
19997
+ },
19998
+ onBaseUrl: (value) => {
19999
+ baseUrl = value;
20000
+ },
20001
+ onJson: () => {
20002
+ json = true;
20003
+ }
20004
+ });
20005
+ return { type: "ns" /* Ns */, action, namespace, chain, baseUrl, json };
20006
+ }
20007
+ throw new Error(`Unknown ns action: ${action}`);
20008
+ }
20009
+ function takeSharedOptions(rest, handlers) {
20010
+ while (rest.length > 0) {
20011
+ const token = rest.shift();
20012
+ switch (token) {
20013
+ case "--chain":
20014
+ handlers.onChain(requireValue2(rest, token));
20015
+ break;
20016
+ case "--base-url":
20017
+ handlers.onBaseUrl(requireValue2(rest, token));
20018
+ break;
20019
+ case "--json":
20020
+ handlers.onJson();
20021
+ break;
20022
+ default:
20023
+ throw new Error(`Unknown ns option: ${token}`);
20024
+ }
20025
+ }
20026
+ }
20027
+ function requireValue2(tokens, optionName) {
20028
+ const value = tokens.shift();
20029
+ if (!value || value.startsWith("-")) {
20030
+ throw new Error(`Missing value for ${optionName}`);
20031
+ }
20032
+ return value;
20033
+ }
20034
+
20035
+ // src/storeCommandParser.ts
20036
+ var DEFAULT_CHAIN2 = "pmate";
19756
20037
  var DEFAULT_NAMESPACE2 = "pmate";
19757
20038
  function parseStoreArgs(tokens) {
19758
20039
  const rest = [...tokens];
@@ -19765,7 +20046,7 @@ function parseStoreArgs(tokens) {
19765
20046
  throw new Error(`Missing store ${scope} action.`);
19766
20047
  }
19767
20048
  const shared = {
19768
- chain: DEFAULT_CHAIN,
20049
+ chain: DEFAULT_CHAIN2,
19769
20050
  namespace: DEFAULT_NAMESPACE2,
19770
20051
  baseUrl: void 0,
19771
20052
  indexerBaseUrl: void 0,
@@ -19775,7 +20056,7 @@ function parseStoreArgs(tokens) {
19775
20056
  if (action !== "list") {
19776
20057
  throw new Error(`Unknown store namespace action: ${action}`);
19777
20058
  }
19778
- takeSharedOptions(rest, shared);
20059
+ takeSharedOptions2(rest, shared);
19779
20060
  if (rest.length > 0) {
19780
20061
  throw new Error(`Unknown store namespace option: ${rest[0]}`);
19781
20062
  }
@@ -19805,7 +20086,7 @@ function parseTableArgs(action, rest, shared) {
19805
20086
  const token = rest.shift();
19806
20087
  switch (token) {
19807
20088
  case "--page":
19808
- page = parsePage(requireValue2(rest, token));
20089
+ page = parsePage(requireValue3(rest, token));
19809
20090
  break;
19810
20091
  default:
19811
20092
  pushSharedOption(token, rest, shared);
@@ -19819,7 +20100,7 @@ function parseTableArgs(action, rest, shared) {
19819
20100
  const token = rest.shift();
19820
20101
  switch (token) {
19821
20102
  case "--id":
19822
- id = requireValue2(rest, token);
20103
+ id = requireValue3(rest, token);
19823
20104
  break;
19824
20105
  default:
19825
20106
  pushSharedOption(token, rest, shared);
@@ -19836,7 +20117,7 @@ function parseTableArgs(action, rest, shared) {
19836
20117
  const token = rest.shift();
19837
20118
  switch (token) {
19838
20119
  case "--file":
19839
- filePath = requireValue2(rest, token);
20120
+ filePath = requireValue3(rest, token);
19840
20121
  break;
19841
20122
  default:
19842
20123
  pushSharedOption(token, rest, shared);
@@ -19860,7 +20141,7 @@ function parseKvArgs(action, rest, shared) {
19860
20141
  const token = rest.shift();
19861
20142
  switch (token) {
19862
20143
  case "--page":
19863
- page = parsePage(requireValue2(rest, token));
20144
+ page = parsePage(requireValue3(rest, token));
19864
20145
  break;
19865
20146
  default:
19866
20147
  pushSharedOption(token, rest, shared);
@@ -19874,7 +20155,7 @@ function parseKvArgs(action, rest, shared) {
19874
20155
  const token = rest.shift();
19875
20156
  switch (token) {
19876
20157
  case "--key":
19877
- key = requireValue2(rest, token);
20158
+ key = requireValue3(rest, token);
19878
20159
  break;
19879
20160
  default:
19880
20161
  pushSharedOption(token, rest, shared);
@@ -19893,13 +20174,13 @@ function parseKvArgs(action, rest, shared) {
19893
20174
  const token = rest.shift();
19894
20175
  switch (token) {
19895
20176
  case "--key":
19896
- key = requireValue2(rest, token);
20177
+ key = requireValue3(rest, token);
19897
20178
  break;
19898
20179
  case "--value":
19899
- value = requireValue2(rest, token);
20180
+ value = requireValue3(rest, token);
19900
20181
  break;
19901
20182
  case "--file":
19902
- filePath = requireValue2(rest, token);
20183
+ filePath = requireValue3(rest, token);
19903
20184
  break;
19904
20185
  default:
19905
20186
  pushSharedOption(token, rest, shared);
@@ -19915,7 +20196,7 @@ function parseKvArgs(action, rest, shared) {
19915
20196
  }
19916
20197
  throw new Error(`Unknown store kv action: ${action}`);
19917
20198
  }
19918
- function takeSharedOptions(rest, shared) {
20199
+ function takeSharedOptions2(rest, shared) {
19919
20200
  while (rest.length > 0) {
19920
20201
  const token = rest.shift();
19921
20202
  pushSharedOption(token, rest, shared);
@@ -19924,17 +20205,17 @@ function takeSharedOptions(rest, shared) {
19924
20205
  function pushSharedOption(token, rest, shared) {
19925
20206
  switch (token) {
19926
20207
  case "--chain":
19927
- shared.chain = requireValue2(rest, token);
20208
+ shared.chain = requireValue3(rest, token);
19928
20209
  break;
19929
20210
  case "--ns":
19930
20211
  case "--namespace":
19931
- shared.namespace = requireValue2(rest, token);
20212
+ shared.namespace = requireValue3(rest, token);
19932
20213
  break;
19933
20214
  case "--base-url":
19934
- shared.baseUrl = requireValue2(rest, token);
20215
+ shared.baseUrl = requireValue3(rest, token);
19935
20216
  break;
19936
20217
  case "--indexer-base-url":
19937
- shared.indexerBaseUrl = requireValue2(rest, token);
20218
+ shared.indexerBaseUrl = requireValue3(rest, token);
19938
20219
  break;
19939
20220
  case "--json":
19940
20221
  shared.json = true;
@@ -19943,7 +20224,7 @@ function pushSharedOption(token, rest, shared) {
19943
20224
  throw new Error(`Unknown store option: ${token}`);
19944
20225
  }
19945
20226
  }
19946
- function requireValue2(tokens, optionName) {
20227
+ function requireValue3(tokens, optionName) {
19947
20228
  const value = tokens.shift();
19948
20229
  if (!value || value.startsWith("-")) {
19949
20230
  throw new Error(`Missing value for ${optionName}`);
@@ -19967,12 +20248,12 @@ function parseAppArgs(tokens) {
19967
20248
  }
19968
20249
  let baseUrl;
19969
20250
  let json = false;
19970
- const takeSharedOptions2 = () => {
20251
+ const takeSharedOptions3 = () => {
19971
20252
  while (rest.length > 0) {
19972
20253
  const token = rest[0];
19973
20254
  if (token === "--base-url") {
19974
20255
  rest.shift();
19975
- baseUrl = requireValue3(rest, token);
20256
+ baseUrl = requireValue4(rest, token);
19976
20257
  continue;
19977
20258
  }
19978
20259
  if (token === "--json") {
@@ -19984,7 +20265,7 @@ function parseAppArgs(tokens) {
19984
20265
  }
19985
20266
  };
19986
20267
  if (action === "list") {
19987
- takeSharedOptions2();
20268
+ takeSharedOptions3();
19988
20269
  if (rest.length > 0) {
19989
20270
  throw new Error(`Unknown app list option: ${rest[0]}`);
19990
20271
  }
@@ -19997,7 +20278,7 @@ function parseAppArgs(tokens) {
19997
20278
  `Usage: app ${action} <id> [--base-url <url>] [--json]`
19998
20279
  );
19999
20280
  }
20000
- takeSharedOptions2();
20281
+ takeSharedOptions3();
20001
20282
  if (rest.length > 0) {
20002
20283
  throw new Error(`Unknown app ${action} option: ${rest[0]}`);
20003
20284
  }
@@ -20009,10 +20290,10 @@ function parseAppArgs(tokens) {
20009
20290
  const token = rest.shift();
20010
20291
  switch (token) {
20011
20292
  case "--file":
20012
- filePath = requireValue3(rest, token);
20293
+ filePath = requireValue4(rest, token);
20013
20294
  break;
20014
20295
  case "--base-url":
20015
- baseUrl = requireValue3(rest, token);
20296
+ baseUrl = requireValue4(rest, token);
20016
20297
  break;
20017
20298
  case "--json":
20018
20299
  json = true;
@@ -20038,10 +20319,10 @@ function parseAppArgs(tokens) {
20038
20319
  const token = rest.shift();
20039
20320
  switch (token) {
20040
20321
  case "--file":
20041
- filePath = requireValue3(rest, token);
20322
+ filePath = requireValue4(rest, token);
20042
20323
  break;
20043
20324
  case "--base-url":
20044
- baseUrl = requireValue3(rest, token);
20325
+ baseUrl = requireValue4(rest, token);
20045
20326
  break;
20046
20327
  case "--json":
20047
20328
  json = true;
@@ -20057,7 +20338,7 @@ function parseAppArgs(tokens) {
20057
20338
  }
20058
20339
  throw new Error(`Unknown app action: ${action}`);
20059
20340
  }
20060
- function requireValue3(tokens, optionName) {
20341
+ function requireValue4(tokens, optionName) {
20061
20342
  const value = tokens.shift();
20062
20343
  if (!value || value.startsWith("-")) {
20063
20344
  throw new Error(`Missing value for ${optionName}`);
@@ -20151,6 +20432,10 @@ var HELP_TEXT = [
20151
20432
  ` ${import_chalk3.default.gray(" update [<namespace>] <name> --file <path> [--base-url <url>] [--json]")}`,
20152
20433
  ` ${import_chalk3.default.gray(" delete [<namespace>] <name> [--base-url <url>] [--json]")}`,
20153
20434
  ` ${import_chalk3.default.gray(" default namespace: pmate; default base URL: https://agent-api.pmate.chat")}`,
20435
+ ` ${import_chalk3.default.cyan("ns")} Manage registered namespaces`,
20436
+ ` ${import_chalk3.default.gray(" list [--chain <chain>] [--base-url <url>] [--json]")}`,
20437
+ ` ${import_chalk3.default.gray(" get <namespace> [--chain <chain>] [--base-url <url>] [--json]")}`,
20438
+ ` ${import_chalk3.default.gray(" create <namespace> [--chain <chain>] [--base-url <url>] [--json]")}`,
20154
20439
  ` ${import_chalk3.default.cyan("store")} Manage @pmate/store namespaces, tables, and kv stores`,
20155
20440
  ` ${import_chalk3.default.gray(" namespace list [--chain <chain>] [--indexer-base-url <url>] [--json]")}`,
20156
20441
  ` ${import_chalk3.default.gray(" table list|get|exists|create|update|delete <name> [options]")}`,
@@ -20223,7 +20508,7 @@ function parseCommandArgs(args) {
20223
20508
  const token = rest.shift();
20224
20509
  switch (token) {
20225
20510
  case "--app":
20226
- app = requireValue4(rest, token);
20511
+ app = requireValue5(rest, token);
20227
20512
  break;
20228
20513
  default:
20229
20514
  throw new Error(`Unknown login option: ${token}`);
@@ -20288,6 +20573,9 @@ function parseCommandArgs(args) {
20288
20573
  if (args.rest[0] === "agent") {
20289
20574
  return parseAgentArgs(args.rest.slice(1));
20290
20575
  }
20576
+ if (args.rest[0] === "ns" || args.rest[0] === "namespace") {
20577
+ return parseNsArgs(args.rest.slice(1));
20578
+ }
20291
20579
  if (args.rest[0] === "store") {
20292
20580
  return parseStoreArgs(args.rest.slice(1));
20293
20581
  }
@@ -20311,7 +20599,7 @@ function parseVercelArgs(tokens) {
20311
20599
  const token = rest.shift();
20312
20600
  switch (token) {
20313
20601
  case "--scope":
20314
- scope = requireValue4(rest, token);
20602
+ scope = requireValue5(rest, token);
20315
20603
  break;
20316
20604
  default:
20317
20605
  throw new Error(`Unknown vercel option: ${token}`);
@@ -20331,10 +20619,10 @@ function parseVercelArgs(tokens) {
20331
20619
  const token = rest.shift();
20332
20620
  switch (token) {
20333
20621
  case "--scope":
20334
- scope = requireValue4(rest, token);
20622
+ scope = requireValue5(rest, token);
20335
20623
  break;
20336
20624
  case "--project":
20337
- project = requireValue4(rest, token);
20625
+ project = requireValue5(rest, token);
20338
20626
  break;
20339
20627
  case "--last-week":
20340
20628
  lastWeek = true;
@@ -20365,16 +20653,16 @@ function parseAddDnsArgs(tokens) {
20365
20653
  const token = rest.shift();
20366
20654
  switch (token) {
20367
20655
  case "--type":
20368
- options.dnsType = requireValue4(rest, token);
20656
+ options.dnsType = requireValue5(rest, token);
20369
20657
  break;
20370
20658
  case "--value":
20371
- options.dnsValue = requireValue4(rest, token);
20659
+ options.dnsValue = requireValue5(rest, token);
20372
20660
  break;
20373
20661
  case "--rr":
20374
- options.dnsRr = requireValue4(rest, token);
20662
+ options.dnsRr = requireValue5(rest, token);
20375
20663
  break;
20376
20664
  case "--ttl": {
20377
- const ttlValue = requireValue4(rest, token);
20665
+ const ttlValue = requireValue5(rest, token);
20378
20666
  const ttl = Number.parseInt(ttlValue, 10);
20379
20667
  if (!Number.isFinite(ttl) || ttl <= 0) {
20380
20668
  throw new Error(`Invalid --ttl value: ${ttlValue}`);
@@ -20383,7 +20671,7 @@ function parseAddDnsArgs(tokens) {
20383
20671
  break;
20384
20672
  }
20385
20673
  case "--domain":
20386
- options.dnsDomain = requireValue4(rest, token);
20674
+ options.dnsDomain = requireValue5(rest, token);
20387
20675
  break;
20388
20676
  default:
20389
20677
  throw new Error(`Unknown add-dns option: ${token}`);
@@ -20416,13 +20704,13 @@ function parseBucketArgs(tokens) {
20416
20704
  options.bucketCreate = true;
20417
20705
  break;
20418
20706
  case "--name":
20419
- options.bucketName = requireValue4(rest, token);
20707
+ options.bucketName = requireValue5(rest, token);
20420
20708
  break;
20421
20709
  case "--subdomain":
20422
- options.bucketSubdomain = requireValue4(rest, token);
20710
+ options.bucketSubdomain = requireValue5(rest, token);
20423
20711
  break;
20424
20712
  case "--domain":
20425
- options.bucketDomain = requireValue4(rest, token);
20713
+ options.bucketDomain = requireValue5(rest, token);
20426
20714
  break;
20427
20715
  default:
20428
20716
  throw new Error(`Unknown bucket option: ${token}`);
@@ -20461,7 +20749,7 @@ function parseDeployArgs(tokens) {
20461
20749
  options.deployAction = "logs";
20462
20750
  break;
20463
20751
  case "--cwd":
20464
- options.deployCwd = requireValue4(rest, token);
20752
+ options.deployCwd = requireValue5(rest, token);
20465
20753
  break;
20466
20754
  default:
20467
20755
  throw new Error(`Unknown deploy option: ${token}`);
@@ -20486,13 +20774,13 @@ function parseLogArgs(tokens) {
20486
20774
  const token = rest.shift();
20487
20775
  switch (token) {
20488
20776
  case "--cwd":
20489
- options.logCwd = requireValue4(rest, token);
20777
+ options.logCwd = requireValue5(rest, token);
20490
20778
  break;
20491
20779
  case "--ns":
20492
- options.logNamespace = requireValue4(rest, token);
20780
+ options.logNamespace = requireValue5(rest, token);
20493
20781
  break;
20494
20782
  case "--page": {
20495
- const value = requireValue4(rest, token);
20783
+ const value = requireValue5(rest, token);
20496
20784
  const page = Number.parseInt(value, 10);
20497
20785
  if (!Number.isFinite(page) || page < 0) {
20498
20786
  throw new Error(`Invalid log page: ${value}`);
@@ -20504,7 +20792,7 @@ function parseLogArgs(tokens) {
20504
20792
  options.logHistory = true;
20505
20793
  break;
20506
20794
  case "--search":
20507
- options.logSearch = requireValue4(rest, token);
20795
+ options.logSearch = requireValue5(rest, token);
20508
20796
  break;
20509
20797
  default:
20510
20798
  throw new Error(`Unknown log option: ${token}`);
@@ -20527,7 +20815,7 @@ function parseInitArgs(tokens) {
20527
20815
  const token = rest.shift();
20528
20816
  switch (token) {
20529
20817
  case "--cwd":
20530
- options.initCwd = requireValue4(rest, token);
20818
+ options.initCwd = requireValue5(rest, token);
20531
20819
  break;
20532
20820
  default:
20533
20821
  throw new Error(`Unknown init option: ${token}`);
@@ -20550,7 +20838,7 @@ function parseDevArgs(tokens) {
20550
20838
  const token = rest.shift();
20551
20839
  switch (token) {
20552
20840
  case "--cwd":
20553
- options.devCwd = requireValue4(rest, token);
20841
+ options.devCwd = requireValue5(rest, token);
20554
20842
  break;
20555
20843
  default:
20556
20844
  throw new Error(`Unknown dev option: ${token}`);
@@ -20580,13 +20868,13 @@ function parseOssArgs(tokens) {
20580
20868
  const token = rest.shift();
20581
20869
  switch (token) {
20582
20870
  case "--bucket":
20583
- bucket = requireValue4(rest, token);
20871
+ bucket = requireValue5(rest, token);
20584
20872
  break;
20585
20873
  case "--file":
20586
- filePath = requireValue4(rest, token);
20874
+ filePath = requireValue5(rest, token);
20587
20875
  break;
20588
20876
  case "--key":
20589
- objectKey = requireValue4(rest, token);
20877
+ objectKey = requireValue5(rest, token);
20590
20878
  break;
20591
20879
  default:
20592
20880
  throw new Error(`Unknown oss option: ${token}`);
@@ -20619,7 +20907,7 @@ function parseEnvArgs(tokens) {
20619
20907
  throw new Error("Only one env action is allowed.");
20620
20908
  }
20621
20909
  action = "set";
20622
- key = requireValue4(rest, token);
20910
+ key = requireValue5(rest, token);
20623
20911
  break;
20624
20912
  case "--list":
20625
20913
  if (action) {
@@ -20632,17 +20920,17 @@ function parseEnvArgs(tokens) {
20632
20920
  throw new Error("Only one env action is allowed.");
20633
20921
  }
20634
20922
  action = "delete";
20635
- key = requireValue4(rest, token);
20923
+ key = requireValue5(rest, token);
20636
20924
  break;
20637
20925
  case "--value":
20638
- value = requireValue4(rest, token);
20926
+ value = requireValue5(rest, token);
20639
20927
  break;
20640
20928
  case "--verbose":
20641
20929
  case "-v":
20642
20930
  verbose = true;
20643
20931
  break;
20644
20932
  case "--cwd":
20645
- cwd = requireValue4(rest, token);
20933
+ cwd = requireValue5(rest, token);
20646
20934
  break;
20647
20935
  default:
20648
20936
  throw new Error(`Unknown env option: ${token}`);
@@ -20700,7 +20988,7 @@ function parseCommitArgs(tokens) {
20700
20988
  push = true;
20701
20989
  break;
20702
20990
  case "--cwd":
20703
- cwd = requireValue4(rest, token);
20991
+ cwd = requireValue5(rest, token);
20704
20992
  break;
20705
20993
  default:
20706
20994
  throw new Error(`Unknown commit option: ${token}`);
@@ -20716,10 +21004,10 @@ function parseSummaryArgs(tokens) {
20716
21004
  const token = rest.shift();
20717
21005
  switch (token) {
20718
21006
  case "--pr":
20719
- prRef = requireValue4(rest, token);
21007
+ prRef = requireValue5(rest, token);
20720
21008
  break;
20721
21009
  case "--cwd":
20722
- cwd = requireValue4(rest, token);
21010
+ cwd = requireValue5(rest, token);
20723
21011
  break;
20724
21012
  default:
20725
21013
  throw new Error(`Unknown summary option: ${token}`);
@@ -20788,10 +21076,10 @@ function parseLinearPrArgs(tokens) {
20788
21076
  const token = rest.shift();
20789
21077
  switch (token) {
20790
21078
  case "--account":
20791
- account = requireValue4(rest, token);
21079
+ account = requireValue5(rest, token);
20792
21080
  break;
20793
21081
  case "--cwd":
20794
- cwd = requireValue4(rest, token);
21082
+ cwd = requireValue5(rest, token);
20795
21083
  break;
20796
21084
  default:
20797
21085
  throw new Error(`Unknown linear option: ${token}`);
@@ -20820,35 +21108,35 @@ function parseLinearCreateArgs(tokens) {
20820
21108
  const token = rest.shift();
20821
21109
  switch (token) {
20822
21110
  case "--account":
20823
- account = requireValue4(rest, token);
21111
+ account = requireValue5(rest, token);
20824
21112
  break;
20825
21113
  case "--repl":
20826
21114
  useRepl = true;
20827
21115
  break;
20828
21116
  case "--title":
20829
- title = requireValue4(rest, token);
21117
+ title = requireValue5(rest, token);
20830
21118
  break;
20831
21119
  case "--desc":
20832
21120
  case "--description":
20833
- description = decodeEscapedNewlines(requireValue4(rest, token));
21121
+ description = decodeEscapedNewlines(requireValue5(rest, token));
20834
21122
  break;
20835
21123
  case "--team-id":
20836
- teamId = requireValue4(rest, token);
21124
+ teamId = requireValue5(rest, token);
20837
21125
  break;
20838
21126
  case "--team-key":
20839
- teamKey = requireValue4(rest, token);
21127
+ teamKey = requireValue5(rest, token);
20840
21128
  break;
20841
21129
  case "--priority":
20842
- priority = parseLinearPriority(requireValue4(rest, token));
21130
+ priority = parseLinearPriority(requireValue5(rest, token));
20843
21131
  break;
20844
21132
  case "--parent-id":
20845
- parentId = requireValue4(rest, token);
21133
+ parentId = requireValue5(rest, token);
20846
21134
  break;
20847
21135
  case "--state-id":
20848
- stateId = requireValue4(rest, token);
21136
+ stateId = requireValue5(rest, token);
20849
21137
  break;
20850
21138
  case "--cwd":
20851
- cwd = requireValue4(rest, token);
21139
+ cwd = requireValue5(rest, token);
20852
21140
  break;
20853
21141
  default:
20854
21142
  throw new Error(`Unknown linear option: ${token}`);
@@ -20883,10 +21171,10 @@ function parseLinearWhoamiArgs(tokens) {
20883
21171
  const token = rest.shift();
20884
21172
  switch (token) {
20885
21173
  case "--account":
20886
- account = requireValue4(rest, token);
21174
+ account = requireValue5(rest, token);
20887
21175
  break;
20888
21176
  case "--cwd":
20889
- cwd = requireValue4(rest, token);
21177
+ cwd = requireValue5(rest, token);
20890
21178
  break;
20891
21179
  default:
20892
21180
  throw new Error(`Unknown linear option: ${token}`);
@@ -20911,10 +21199,10 @@ function parseLinearViewArgs(tokens) {
20911
21199
  const token = rest.shift();
20912
21200
  switch (token) {
20913
21201
  case "--account":
20914
- account = requireValue4(rest, token);
21202
+ account = requireValue5(rest, token);
20915
21203
  break;
20916
21204
  case "--cwd":
20917
- cwd = requireValue4(rest, token);
21205
+ cwd = requireValue5(rest, token);
20918
21206
  break;
20919
21207
  default:
20920
21208
  throw new Error(`Unknown linear option: ${token}`);
@@ -20949,32 +21237,32 @@ function parseLinearUpdateArgs(tokens) {
20949
21237
  const token = rest.shift();
20950
21238
  switch (token) {
20951
21239
  case "--account":
20952
- account = requireValue4(rest, token);
21240
+ account = requireValue5(rest, token);
20953
21241
  break;
20954
21242
  case "--title":
20955
- title = requireValue4(rest, token);
21243
+ title = requireValue5(rest, token);
20956
21244
  break;
20957
21245
  case "--desc":
20958
21246
  case "--description":
20959
- description = decodeEscapedNewlines(requireValue4(rest, token));
21247
+ description = decodeEscapedNewlines(requireValue5(rest, token));
20960
21248
  break;
20961
21249
  case "--team-id":
20962
- teamId = requireValue4(rest, token);
21250
+ teamId = requireValue5(rest, token);
20963
21251
  break;
20964
21252
  case "--team-key":
20965
- teamKey = requireValue4(rest, token);
21253
+ teamKey = requireValue5(rest, token);
20966
21254
  break;
20967
21255
  case "--priority":
20968
- priority = parseLinearPriority(requireValue4(rest, token));
21256
+ priority = parseLinearPriority(requireValue5(rest, token));
20969
21257
  break;
20970
21258
  case "--parent-id":
20971
- parentId = requireValue4(rest, token);
21259
+ parentId = requireValue5(rest, token);
20972
21260
  break;
20973
21261
  case "--state-id":
20974
- stateId = requireValue4(rest, token);
21262
+ stateId = requireValue5(rest, token);
20975
21263
  break;
20976
21264
  case "--cwd":
20977
- cwd = requireValue4(rest, token);
21265
+ cwd = requireValue5(rest, token);
20978
21266
  break;
20979
21267
  default:
20980
21268
  throw new Error(`Unknown linear option: ${token}`);
@@ -21012,10 +21300,10 @@ function parseLinearSubIssuesArgs(tokens) {
21012
21300
  const token = rest.shift();
21013
21301
  switch (token) {
21014
21302
  case "--account":
21015
- account = requireValue4(rest, token);
21303
+ account = requireValue5(rest, token);
21016
21304
  break;
21017
21305
  case "--cwd":
21018
- cwd = requireValue4(rest, token);
21306
+ cwd = requireValue5(rest, token);
21019
21307
  break;
21020
21308
  default:
21021
21309
  throw new Error(`Unknown linear option: ${token}`);
@@ -21042,15 +21330,15 @@ function parseLinearCommentArgs(tokens) {
21042
21330
  const token = rest.shift();
21043
21331
  switch (token) {
21044
21332
  case "--account":
21045
- account = requireValue4(rest, token);
21333
+ account = requireValue5(rest, token);
21046
21334
  break;
21047
21335
  case "--body":
21048
21336
  case "--desc":
21049
21337
  case "--description":
21050
- body = decodeEscapedNewlines(requireValue4(rest, token));
21338
+ body = decodeEscapedNewlines(requireValue5(rest, token));
21051
21339
  break;
21052
21340
  case "--cwd":
21053
- cwd = requireValue4(rest, token);
21341
+ cwd = requireValue5(rest, token);
21054
21342
  break;
21055
21343
  default:
21056
21344
  throw new Error(`Unknown linear option: ${token}`);
@@ -21080,10 +21368,10 @@ function parseLinearCommentsArgs(tokens) {
21080
21368
  const token = rest.shift();
21081
21369
  switch (token) {
21082
21370
  case "--account":
21083
- account = requireValue4(rest, token);
21371
+ account = requireValue5(rest, token);
21084
21372
  break;
21085
21373
  case "--cwd":
21086
- cwd = requireValue4(rest, token);
21374
+ cwd = requireValue5(rest, token);
21087
21375
  break;
21088
21376
  default:
21089
21377
  throw new Error(`Unknown linear option: ${token}`);
@@ -21107,16 +21395,16 @@ function parseLinearCycleArgs(tokens) {
21107
21395
  const token = rest.shift();
21108
21396
  switch (token) {
21109
21397
  case "--account":
21110
- account = requireValue4(rest, token);
21398
+ account = requireValue5(rest, token);
21111
21399
  break;
21112
21400
  case "--team-id":
21113
- teamId = requireValue4(rest, token);
21401
+ teamId = requireValue5(rest, token);
21114
21402
  break;
21115
21403
  case "--team-key":
21116
- teamKey = requireValue4(rest, token);
21404
+ teamKey = requireValue5(rest, token);
21117
21405
  break;
21118
21406
  case "--cwd":
21119
- cwd = requireValue4(rest, token);
21407
+ cwd = requireValue5(rest, token);
21120
21408
  break;
21121
21409
  default:
21122
21410
  throw new Error(`Unknown linear option: ${token}`);
@@ -21139,10 +21427,10 @@ function parseLinearTeamsArgs(tokens) {
21139
21427
  const token = rest.shift();
21140
21428
  switch (token) {
21141
21429
  case "--account":
21142
- account = requireValue4(rest, token);
21430
+ account = requireValue5(rest, token);
21143
21431
  break;
21144
21432
  case "--cwd":
21145
- cwd = requireValue4(rest, token);
21433
+ cwd = requireValue5(rest, token);
21146
21434
  break;
21147
21435
  default:
21148
21436
  throw new Error(`Unknown linear option: ${token}`);
@@ -21169,16 +21457,16 @@ function parseLinearUserIssuesArgs(tokens) {
21169
21457
  const token = rest.shift();
21170
21458
  switch (token) {
21171
21459
  case "--account":
21172
- account = requireValue4(rest, token);
21460
+ account = requireValue5(rest, token);
21173
21461
  break;
21174
21462
  case "--cycle":
21175
- cycle = parseLinearCycle(requireValue4(rest, token));
21463
+ cycle = parseLinearCycle(requireValue5(rest, token));
21176
21464
  break;
21177
21465
  case "--status":
21178
- status = parseLinearStatus(requireValue4(rest, token));
21466
+ status = parseLinearStatus(requireValue5(rest, token));
21179
21467
  break;
21180
21468
  case "--cwd":
21181
- cwd = requireValue4(rest, token);
21469
+ cwd = requireValue5(rest, token);
21182
21470
  break;
21183
21471
  default:
21184
21472
  throw new Error(`Unknown linear option: ${token}`);
@@ -21212,28 +21500,28 @@ function parseLinearIssuesArgs(tokens) {
21212
21500
  const token = rest.shift();
21213
21501
  switch (token) {
21214
21502
  case "--account":
21215
- account = requireValue4(rest, token);
21503
+ account = requireValue5(rest, token);
21216
21504
  break;
21217
21505
  case "--team-id":
21218
- teamId = requireValue4(rest, token);
21506
+ teamId = requireValue5(rest, token);
21219
21507
  break;
21220
21508
  case "--team-key":
21221
- teamKey = requireValue4(rest, token);
21509
+ teamKey = requireValue5(rest, token);
21222
21510
  break;
21223
21511
  case "--user":
21224
- user = requireValue4(rest, token);
21512
+ user = requireValue5(rest, token);
21225
21513
  break;
21226
21514
  case "--cycle":
21227
- cycle = parseLinearCycle(requireValue4(rest, token));
21515
+ cycle = parseLinearCycle(requireValue5(rest, token));
21228
21516
  break;
21229
21517
  case "--status":
21230
- status = parseLinearStatus(requireValue4(rest, token));
21518
+ status = parseLinearStatus(requireValue5(rest, token));
21231
21519
  break;
21232
21520
  case "--query":
21233
- query = requireValue4(rest, token).trim();
21521
+ query = requireValue5(rest, token).trim();
21234
21522
  break;
21235
21523
  case "--limit": {
21236
- const value = Number.parseInt(requireValue4(rest, token), 10);
21524
+ const value = Number.parseInt(requireValue5(rest, token), 10);
21237
21525
  if (!Number.isInteger(value) || value < 1 || value > 250) {
21238
21526
  throw new Error("Invalid --limit. Expected an integer between 1 and 250.");
21239
21527
  }
@@ -21241,7 +21529,7 @@ function parseLinearIssuesArgs(tokens) {
21241
21529
  break;
21242
21530
  }
21243
21531
  case "--cwd":
21244
- cwd = requireValue4(rest, token);
21532
+ cwd = requireValue5(rest, token);
21245
21533
  break;
21246
21534
  default:
21247
21535
  throw new Error(`Unknown linear option: ${token}`);
@@ -21282,10 +21570,10 @@ function parseLinearLegacyArgs(tokens) {
21282
21570
  useScreenshot = true;
21283
21571
  break;
21284
21572
  case "--account":
21285
- account = requireValue4(rest, token);
21573
+ account = requireValue5(rest, token);
21286
21574
  break;
21287
21575
  case "--cwd":
21288
- cwd = requireValue4(rest, token);
21576
+ cwd = requireValue5(rest, token);
21289
21577
  break;
21290
21578
  default:
21291
21579
  throw new Error(`Unknown linear option: ${token}`);
@@ -21379,19 +21667,19 @@ function parseNotionArgs(tokens) {
21379
21667
  const token = rest.shift();
21380
21668
  switch (token) {
21381
21669
  case "--parent":
21382
- parentPageId = requireValue4(rest, token);
21670
+ parentPageId = requireValue5(rest, token);
21383
21671
  break;
21384
21672
  case "--title":
21385
- title = requireValue4(rest, token);
21673
+ title = requireValue5(rest, token);
21386
21674
  break;
21387
21675
  case "--private":
21388
21676
  isPrivate = true;
21389
21677
  break;
21390
21678
  case "--content":
21391
- content2 = requireValue4(rest, token);
21679
+ content2 = requireValue5(rest, token);
21392
21680
  break;
21393
21681
  case "--file":
21394
- filePath2 = requireValue4(rest, token);
21682
+ filePath2 = requireValue5(rest, token);
21395
21683
  break;
21396
21684
  default:
21397
21685
  throw new Error(`Unknown notion option: ${token}`);
@@ -21435,10 +21723,10 @@ function parseNotionArgs(tokens) {
21435
21723
  const token = rest.shift();
21436
21724
  switch (token) {
21437
21725
  case "--content":
21438
- content = requireValue4(rest, token);
21726
+ content = requireValue5(rest, token);
21439
21727
  break;
21440
21728
  case "--file":
21441
- filePath = requireValue4(rest, token);
21729
+ filePath = requireValue5(rest, token);
21442
21730
  break;
21443
21731
  case "--append":
21444
21732
  append = true;
@@ -21483,11 +21771,11 @@ function parseRandomArgs(tokens) {
21483
21771
  mode = "easy";
21484
21772
  break;
21485
21773
  case "--length":
21486
- length = parsePositiveInt(requireValue4(rest, token), token);
21774
+ length = parsePositiveInt(requireValue5(rest, token), token);
21487
21775
  seenLength = true;
21488
21776
  break;
21489
21777
  case "--charset": {
21490
- const value = requireValue4(rest, token);
21778
+ const value = requireValue5(rest, token);
21491
21779
  if (!["base64url", "hex", "alnum", "ascii"].includes(value)) {
21492
21780
  throw new Error(
21493
21781
  `Invalid --charset value: ${value}. Use base64url|hex|alnum|ascii.`
@@ -21498,18 +21786,18 @@ function parseRandomArgs(tokens) {
21498
21786
  break;
21499
21787
  }
21500
21788
  case "--count":
21501
- count = parsePositiveInt(requireValue4(rest, token), token);
21789
+ count = parsePositiveInt(requireValue5(rest, token), token);
21502
21790
  break;
21503
21791
  case "--words":
21504
- words = parsePositiveInt(requireValue4(rest, token), token);
21792
+ words = parsePositiveInt(requireValue5(rest, token), token);
21505
21793
  seenWords = true;
21506
21794
  break;
21507
21795
  case "--digits":
21508
- digits = parseNonNegativeInt(requireValue4(rest, token), token);
21796
+ digits = parseNonNegativeInt(requireValue5(rest, token), token);
21509
21797
  seenDigits = true;
21510
21798
  break;
21511
21799
  case "--separator":
21512
- separator = requireValue4(rest, token);
21800
+ separator = requireValue5(rest, token);
21513
21801
  seenSeparator = true;
21514
21802
  break;
21515
21803
  default:
@@ -21552,7 +21840,7 @@ function parseCollectArgs(tokens) {
21552
21840
  const token = rest.shift();
21553
21841
  switch (token) {
21554
21842
  case "--endpoint":
21555
- options.endpoint = requireValue4(rest, token);
21843
+ options.endpoint = requireValue5(rest, token);
21556
21844
  break;
21557
21845
  case "--json":
21558
21846
  options.json = true;
@@ -21562,7 +21850,7 @@ function parseCollectArgs(tokens) {
21562
21850
  break;
21563
21851
  case "--thread":
21564
21852
  options.mode = "thread";
21565
- options.threadName = requireValue4(rest, token);
21853
+ options.threadName = requireValue5(rest, token);
21566
21854
  break;
21567
21855
  default:
21568
21856
  throw new Error(`Unknown collect option: ${token}`);
@@ -21573,7 +21861,7 @@ function parseCollectArgs(tokens) {
21573
21861
  }
21574
21862
  return { type: "collect" /* Collect */, ...options };
21575
21863
  }
21576
- function requireValue4(tokens, optionName) {
21864
+ function requireValue5(tokens, optionName) {
21577
21865
  const value = tokens.shift();
21578
21866
  if (!value) {
21579
21867
  throw new Error(`Missing value for ${optionName}`);
@@ -21714,6 +22002,11 @@ async function main() {
21714
22002
  await handler.handle(commandArgs);
21715
22003
  return;
21716
22004
  }
22005
+ case "ns" /* Ns */: {
22006
+ const handler = new NsCommandHandler();
22007
+ await handler.handle(commandArgs);
22008
+ return;
22009
+ }
21717
22010
  case "store" /* Store */: {
21718
22011
  const handler = new StoreCommandHandler();
21719
22012
  await handler.handle(commandArgs);