@pmate/cli 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -12612,8 +12612,8 @@ __export(index_exports, {
12612
12612
  parseCommandArgs: () => parseCommandArgs
12613
12613
  });
12614
12614
  module.exports = __toCommonJS(index_exports);
12615
- var import_node_fs14 = require("fs");
12616
- var import_node_path19 = __toESM(require("path"));
12615
+ var import_node_fs15 = require("fs");
12616
+ var import_node_path20 = __toESM(require("path"));
12617
12617
  var import_chalk3 = __toESM(require("chalk"));
12618
12618
 
12619
12619
  // src/cli.ts
@@ -13827,12 +13827,107 @@ var StsCommandHandler = class {
13827
13827
  }
13828
13828
  };
13829
13829
 
13830
+ // src/staticSiteSetup.ts
13831
+ async function setupStaticSiteBucket(input) {
13832
+ const bucketName = input.bucketName.trim();
13833
+ const domainName = input.domainName.trim();
13834
+ const subdomain = input.subdomain?.trim();
13835
+ const dnsRr = subdomain || "@";
13836
+ const cdnDomain = subdomain ? `${subdomain}.${domainName}` : domainName;
13837
+ await AliyunService.ensureBucket(bucketName);
13838
+ await sleep(2e3);
13839
+ await AliyunService.ensureCdnDomain(cdnDomain, bucketName);
13840
+ await sleep(2e3);
13841
+ await AliyunService.enableOssPrivateBucketOrigin(cdnDomain);
13842
+ await sleep(2e3);
13843
+ ui.success(`Enabled OSS private bucket origin for ${cdnDomain}`);
13844
+ await AliyunService.setDefaultCacheRules(cdnDomain);
13845
+ await sleep(2e3);
13846
+ ui.success(`Set default cache rules for ${cdnDomain}`);
13847
+ const cname = await AliyunService.getCdnCname(cdnDomain);
13848
+ if (!cname) {
13849
+ throw new Error(`No CNAME found for ${cdnDomain}. Try again in a minute.`);
13850
+ }
13851
+ ui.info(`CNAME for ${cdnDomain}:`, cname);
13852
+ const existingCname = await AliyunService.getCnameRecordValue(domainName, dnsRr);
13853
+ if (existingCname) {
13854
+ if (existingCname !== cname) {
13855
+ throw new Error(
13856
+ `Existing CNAME record for ${cdnDomain} points to ${existingCname}, not ${cname}.`
13857
+ );
13858
+ }
13859
+ ui.success(`CNAME record already exists for ${cdnDomain}`);
13860
+ } else {
13861
+ await AliyunService.addRecord({
13862
+ domainName,
13863
+ rr: dnsRr,
13864
+ type: "CNAME",
13865
+ value: cname,
13866
+ ttl: 600
13867
+ });
13868
+ await sleep(2e3);
13869
+ ui.success(`Added CNAME record ${cdnDomain} -> ${cname}`);
13870
+ }
13871
+ if (!subdomain) {
13872
+ const wwwCname = await AliyunService.getCnameRecordValue(domainName, "www");
13873
+ if (wwwCname) {
13874
+ if (wwwCname !== domainName) {
13875
+ throw new Error(
13876
+ `Existing CNAME record for www.${domainName} points to ${wwwCname}, not ${domainName}.`
13877
+ );
13878
+ }
13879
+ ui.success(`CNAME record already exists for www.${domainName}`);
13880
+ } else {
13881
+ await AliyunService.addRecord({
13882
+ domainName,
13883
+ rr: "www",
13884
+ type: "CNAME",
13885
+ value: domainName,
13886
+ ttl: 600
13887
+ });
13888
+ await sleep(2e3);
13889
+ ui.success(`Added CNAME record www.${domainName} -> ${domainName}`);
13890
+ }
13891
+ }
13892
+ await AliyunService.enableHttpsCertificate(cdnDomain);
13893
+ await sleep(2e3);
13894
+ ui.success(`Enabled HTTPS certificate for ${cdnDomain}`);
13895
+ if (input.routeType === "ssg") {
13896
+ await AliyunService.enableSsgRewriteRule(cdnDomain);
13897
+ await sleep(2e3);
13898
+ ui.success(`Enabled SSG rewrite rule for ${cdnDomain}`);
13899
+ return;
13900
+ }
13901
+ await AliyunService.enableSpaRewriteRule(cdnDomain);
13902
+ await sleep(2e3);
13903
+ ui.success(`Enabled SPA rewrite rule for ${cdnDomain}`);
13904
+ }
13905
+ function sleep(ms) {
13906
+ return new Promise((resolve) => {
13907
+ setTimeout(resolve, ms);
13908
+ });
13909
+ }
13910
+
13830
13911
  // src/commands/BucketCommandHandler.ts
13831
13912
  var BucketCommandHandler = class {
13832
13913
  async handle(args) {
13833
13914
  const bucketName = args.bucketName.trim();
13834
- await AliyunService.createBucket(bucketName);
13835
- ui.success(`Bucket created: ${bucketName}`);
13915
+ const subdomain = args.bucketSubdomain?.trim();
13916
+ if (!subdomain) {
13917
+ await AliyunService.createBucket(bucketName);
13918
+ ui.success(`Bucket created: ${bucketName}`);
13919
+ return;
13920
+ }
13921
+ const domainName = args.bucketDomain?.trim();
13922
+ if (!domainName) {
13923
+ throw new Error("Missing domain name. Use --domain <name> when --subdomain is set.");
13924
+ }
13925
+ await setupStaticSiteBucket({
13926
+ bucketName,
13927
+ domainName,
13928
+ subdomain,
13929
+ routeType: "spa"
13930
+ });
13836
13931
  }
13837
13932
  };
13838
13933
 
@@ -14301,82 +14396,12 @@ var InitCommandHandler = class {
14301
14396
  if (!baseDomain) {
14302
14397
  throw new Error(`Missing domain in ${import_node_path8.default.join(cwd, ".pmate.yaml")}`);
14303
14398
  }
14304
- const subdomain = appConfig.subdomain?.trim();
14305
- const dnsRr = subdomain || "@";
14306
- const cdnDomain = subdomain ? `${subdomain}.${baseDomain}` : baseDomain;
14307
- await AliyunService.ensureBucket(bucketName);
14308
- await this.sleep(2e3);
14309
- await AliyunService.ensureCdnDomain(cdnDomain, bucketName);
14310
- await this.sleep(2e3);
14311
- await AliyunService.enableOssPrivateBucketOrigin(cdnDomain);
14312
- await this.sleep(2e3);
14313
- ui.success(`Enabled OSS private bucket origin for ${cdnDomain}`);
14314
- await AliyunService.setDefaultCacheRules(cdnDomain);
14315
- await this.sleep(2e3);
14316
- ui.success(`Set default cache rules for ${cdnDomain}`);
14317
- const cname = await AliyunService.getCdnCname(cdnDomain);
14318
- if (!cname) {
14319
- throw new Error(`No CNAME found for ${cdnDomain}. Try again in a minute.`);
14320
- }
14321
- ui.info(`CNAME for ${cdnDomain}:`, cname);
14322
- const existingCname = await AliyunService.getCnameRecordValue(
14323
- baseDomain,
14324
- dnsRr
14325
- );
14326
- if (existingCname) {
14327
- if (existingCname !== cname) {
14328
- throw new Error(
14329
- `Existing CNAME record for ${cdnDomain} points to ${existingCname}, not ${cname}.`
14330
- );
14331
- }
14332
- ui.success(`CNAME record already exists for ${cdnDomain}`);
14333
- } else {
14334
- await AliyunService.addRecord({
14335
- domainName: baseDomain,
14336
- rr: dnsRr,
14337
- type: "CNAME",
14338
- value: cname,
14339
- ttl: 600
14340
- });
14341
- await this.sleep(2e3);
14342
- ui.success(`Added CNAME record ${cdnDomain} -> ${cname}`);
14343
- }
14344
- if (!subdomain) {
14345
- const wwwCname = await AliyunService.getCnameRecordValue(
14346
- baseDomain,
14347
- "www"
14348
- );
14349
- if (wwwCname) {
14350
- if (wwwCname !== baseDomain) {
14351
- throw new Error(
14352
- `Existing CNAME record for www.${baseDomain} points to ${wwwCname}, not ${baseDomain}.`
14353
- );
14354
- }
14355
- ui.success(`CNAME record already exists for www.${baseDomain}`);
14356
- } else {
14357
- await AliyunService.addRecord({
14358
- domainName: baseDomain,
14359
- rr: "www",
14360
- type: "CNAME",
14361
- value: baseDomain,
14362
- ttl: 600
14363
- });
14364
- await this.sleep(2e3);
14365
- ui.success(`Added CNAME record www.${baseDomain} -> ${baseDomain}`);
14366
- }
14367
- }
14368
- await AliyunService.enableHttpsCertificate(cdnDomain);
14369
- await this.sleep(2e3);
14370
- ui.success(`Enabled HTTPS certificate for ${cdnDomain}`);
14371
- if (appConfig.type === "vite" && appConfig.routeType === "ssg") {
14372
- await AliyunService.enableSsgRewriteRule(cdnDomain);
14373
- await this.sleep(2e3);
14374
- ui.success(`Enabled SSG rewrite rule for ${cdnDomain}`);
14375
- } else {
14376
- await AliyunService.enableSpaRewriteRule(cdnDomain);
14377
- await this.sleep(2e3);
14378
- ui.success(`Enabled SPA rewrite rule for ${cdnDomain}`);
14379
- }
14399
+ await setupStaticSiteBucket({
14400
+ bucketName,
14401
+ domainName: baseDomain,
14402
+ subdomain: appConfig.subdomain,
14403
+ routeType: appConfig.type === "vite" && appConfig.routeType === "ssg" ? "ssg" : "spa"
14404
+ });
14380
14405
  }
14381
14406
  async initNode(appConfig, cwd) {
14382
14407
  console.log("Initializing node app...");
@@ -17194,7 +17219,7 @@ var LinearCommandHandler = class {
17194
17219
  for (let attempt = 0; attempt < 12; attempt++) {
17195
17220
  buffer = await this.captureClipboardImageAsPng();
17196
17221
  if (buffer.length > 0) break;
17197
- await sleep(150);
17222
+ await sleep2(150);
17198
17223
  }
17199
17224
  if (buffer.length === 0) {
17200
17225
  const info = await this.getClipboardDebugInfo();
@@ -17645,7 +17670,7 @@ function parseJson(raw) {
17645
17670
  return JSON.parse(match[0]);
17646
17671
  }
17647
17672
  }
17648
- function sleep(ms) {
17673
+ function sleep2(ms) {
17649
17674
  return new Promise((resolve) => setTimeout(resolve, ms));
17650
17675
  }
17651
17676
 
@@ -17890,9 +17915,9 @@ ${indent}\`\`\``;
17890
17915
  static richTextToPlain(richText) {
17891
17916
  return richText.map((item) => item.plain_text ?? item.text?.content ?? "").join("").trim();
17892
17917
  }
17893
- static async requestJson(path20, init) {
17918
+ static async requestJson(path21, init) {
17894
17919
  const token = this.getToken();
17895
- const response = await fetch(`${this.baseUrl}${path20}`, {
17920
+ const response = await fetch(`${this.baseUrl}${path21}`, {
17896
17921
  method: init.method,
17897
17922
  headers: {
17898
17923
  Authorization: `Bearer ${token}`,
@@ -18940,9 +18965,406 @@ var AgentCommandHandler = class {
18940
18965
  }
18941
18966
  };
18942
18967
 
18943
- // src/commands/AppCommandHandler.ts
18968
+ // src/commands/StoreCommandHandler.ts
18944
18969
  var import_node_fs13 = require("fs");
18945
18970
  var import_node_path18 = __toESM(require("path"));
18971
+
18972
+ // src/storeClient.ts
18973
+ var STORE_LOG_VERSION = 1;
18974
+ var LOG_KIND_TABLE = 1e4;
18975
+ var LOG_KIND_MAPPING = 6003;
18976
+ function createHash3() {
18977
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
18978
+ }
18979
+ function createDescriptor(input) {
18980
+ for (const [label, value] of Object.entries({
18981
+ chain: input.chain,
18982
+ namespace: input.ns,
18983
+ kind: input.kind,
18984
+ name: input.name
18985
+ })) {
18986
+ if (!value || value.includes("/")) {
18987
+ throw new Error(`Invalid ${label} "${value}". ${label} must be non-empty and cannot contain "/".`);
18988
+ }
18989
+ }
18990
+ return { ...input };
18991
+ }
18992
+ function descriptorToTopic(descriptor) {
18993
+ const normalized = createDescriptor(descriptor);
18994
+ return `@${normalized.ns}/${normalized.name}`;
18995
+ }
18996
+ function descriptorPathSegments(descriptor) {
18997
+ const normalized = createDescriptor(descriptor);
18998
+ return ["chains", normalized.chain, "namespaces", normalized.ns, normalized.kind, normalized.name];
18999
+ }
19000
+ function buildPathUrl(baseUrl, pathSegments, query) {
19001
+ const path21 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
19002
+ const url = new URL(path21, baseUrl);
19003
+ if (query) {
19004
+ for (const [key, value] of Object.entries(query)) {
19005
+ url.searchParams.set(key, String(value));
19006
+ }
19007
+ }
19008
+ return url.toString();
19009
+ }
19010
+ async function requestJson(url, init, fallbackMessage) {
19011
+ const response = await fetch(url, init);
19012
+ const payload = await response.json();
19013
+ if (!response.ok || !payload?.success) {
19014
+ throw new Error(payload?.message || `${fallbackMessage}: ${response.status}`);
19015
+ }
19016
+ return payload;
19017
+ }
19018
+ var IndexerClient = class {
19019
+ constructor(baseUrl) {
19020
+ this.baseUrl = baseUrl;
19021
+ }
19022
+ async requestByPath(pathSegments, options = {}) {
19023
+ const method = options.method ?? "GET";
19024
+ const url = buildPathUrl(this.baseUrl, pathSegments, method === "GET" ? options.query : void 0);
19025
+ const payload = await requestJson(
19026
+ url,
19027
+ {
19028
+ method,
19029
+ headers: {
19030
+ Accept: "application/json",
19031
+ ...method === "POST" ? { "Content-Type": "application/json" } : {}
19032
+ },
19033
+ ...method === "POST" ? { body: JSON.stringify(options.query ?? {}) } : {}
19034
+ },
19035
+ "Indexer request failed"
19036
+ );
19037
+ return payload.data;
19038
+ }
19039
+ };
19040
+ var BlockLogAppender = class {
19041
+ constructor(chainId, baseUrl) {
19042
+ this.chainId = chainId;
19043
+ this.baseUrl = baseUrl;
19044
+ }
19045
+ async append(logs) {
19046
+ if (!logs.length) return;
19047
+ const url = `${this.baseUrl.replace(/\/+$/, "")}/chains/${encodeURIComponent(this.chainId)}/logs`;
19048
+ await fetch(url, {
19049
+ method: "POST",
19050
+ headers: {
19051
+ "Content-Type": "application/json",
19052
+ ...process.env.TSDB_BEARER_TOKEN ? { authorization: `Bearer ${process.env.TSDB_BEARER_TOKEN}` } : {}
19053
+ },
19054
+ body: JSON.stringify({ logs })
19055
+ }).then(async (response) => {
19056
+ if (!response.ok) {
19057
+ throw new Error(`TSDB request failed: ${response.status} ${response.statusText}`);
19058
+ }
19059
+ });
19060
+ }
19061
+ };
19062
+ var Namespace = class {
19063
+ constructor(options) {
19064
+ this.options = options;
19065
+ this.appender = new BlockLogAppender(options.chain, options.baseUrl.replace(/\/+$/, ""));
19066
+ this.indexerClient = new IndexerClient(options.indexerBaseUrl.replace(/\/+$/, ""));
19067
+ }
19068
+ table(name) {
19069
+ const descriptor = createDescriptor({
19070
+ chain: this.options.chain,
19071
+ ns: this.options.ns,
19072
+ kind: "table",
19073
+ name
19074
+ });
19075
+ return {
19076
+ list: async (pageNo = 0) => {
19077
+ const data = await this.indexerClient.requestByPath(
19078
+ [...descriptorPathSegments(descriptor), "page"],
19079
+ { query: { page_id: pageNo } }
19080
+ );
19081
+ if (!data) return [];
19082
+ if (Array.isArray(data)) return data;
19083
+ return Array.isArray(data.data) ? data.data : [];
19084
+ },
19085
+ getById: async (id) => {
19086
+ const data = await this.indexerClient.requestByPath(
19087
+ [...descriptorPathSegments(descriptor), "get_by_id"],
19088
+ { query: { id } }
19089
+ );
19090
+ return data ?? void 0;
19091
+ },
19092
+ exists: async (id) => {
19093
+ const data = await this.indexerClient.requestByPath(
19094
+ [...descriptorPathSegments(descriptor), "exists"],
19095
+ { query: { id } }
19096
+ );
19097
+ return Boolean(data);
19098
+ },
19099
+ appendRow: async (data) => {
19100
+ const log = {
19101
+ hash: createHash3(),
19102
+ t: Date.now(),
19103
+ kind: LOG_KIND_TABLE,
19104
+ topic: descriptorToTopic(descriptor),
19105
+ v: STORE_LOG_VERSION,
19106
+ data: { type: "create", after: data }
19107
+ };
19108
+ await this.appender.append([log]);
19109
+ },
19110
+ updateRow: async (data) => {
19111
+ const { id, ...value } = data;
19112
+ const log = {
19113
+ hash: createHash3(),
19114
+ t: Date.now(),
19115
+ kind: LOG_KIND_TABLE,
19116
+ topic: descriptorToTopic(descriptor),
19117
+ v: STORE_LOG_VERSION,
19118
+ data: { type: "update", id, value }
19119
+ };
19120
+ await this.appender.append([log]);
19121
+ },
19122
+ deleteRow: async (id) => {
19123
+ const log = {
19124
+ hash: createHash3(),
19125
+ t: Date.now(),
19126
+ kind: LOG_KIND_TABLE,
19127
+ topic: descriptorToTopic(descriptor),
19128
+ v: STORE_LOG_VERSION,
19129
+ data: { type: "delete", id }
19130
+ };
19131
+ await this.appender.append([log]);
19132
+ }
19133
+ };
19134
+ }
19135
+ kv(name) {
19136
+ const descriptor = createDescriptor({
19137
+ chain: this.options.chain,
19138
+ ns: this.options.ns,
19139
+ kind: "kv",
19140
+ name
19141
+ });
19142
+ return {
19143
+ list: async (pageNo = 0) => {
19144
+ const data = await this.indexerClient.requestByPath([...descriptorPathSegments(descriptor), "page"], {
19145
+ query: { page_id: pageNo }
19146
+ });
19147
+ if (!data) return [];
19148
+ if (Array.isArray(data)) return data;
19149
+ return Array.isArray(data.data) ? data.data : [];
19150
+ },
19151
+ get: async (key) => {
19152
+ const data = await this.indexerClient.requestByPath(
19153
+ [...descriptorPathSegments(descriptor), "get"],
19154
+ { query: { key } }
19155
+ );
19156
+ return data ?? void 0;
19157
+ },
19158
+ exists: async (key) => {
19159
+ const data = await this.indexerClient.requestByPath(
19160
+ [...descriptorPathSegments(descriptor), "exists"],
19161
+ { query: { key } }
19162
+ );
19163
+ return Boolean(data);
19164
+ },
19165
+ set: async (key, value) => {
19166
+ const log = {
19167
+ hash: createHash3(),
19168
+ t: Date.now(),
19169
+ kind: LOG_KIND_MAPPING,
19170
+ topic: descriptorToTopic(descriptor),
19171
+ v: STORE_LOG_VERSION,
19172
+ data: { key, value }
19173
+ };
19174
+ await this.appender.append([log]);
19175
+ },
19176
+ delete: async (key) => {
19177
+ const log = {
19178
+ hash: createHash3(),
19179
+ t: Date.now(),
19180
+ kind: LOG_KIND_MAPPING,
19181
+ topic: descriptorToTopic(descriptor),
19182
+ v: STORE_LOG_VERSION,
19183
+ data: { key, value: null }
19184
+ };
19185
+ await this.appender.append([log]);
19186
+ }
19187
+ };
19188
+ }
19189
+ };
19190
+
19191
+ // src/commands/StoreCommandHandler.ts
19192
+ var StoreCommandHandler = class {
19193
+ async handle(args) {
19194
+ if (args.scope === "namespace") {
19195
+ const items = await this.listNamespaces(args);
19196
+ this.renderNamespaceList(items, args.json);
19197
+ return;
19198
+ }
19199
+ const namespace = this.createNamespace(args);
19200
+ if (args.scope === "table") {
19201
+ const table = namespace.table(args.name);
19202
+ switch (args.action) {
19203
+ case "list": {
19204
+ const rows = await table.list(args.page);
19205
+ this.renderJsonOrSummary(
19206
+ rows,
19207
+ args.json,
19208
+ "No rows found.",
19209
+ (row) => row.id ?? "<missing-id>"
19210
+ );
19211
+ return;
19212
+ }
19213
+ case "get": {
19214
+ const row = await table.getById(args.id);
19215
+ this.renderValue(row, args.json);
19216
+ return;
19217
+ }
19218
+ case "exists": {
19219
+ const exists = await table.exists(args.id);
19220
+ this.renderValue(exists, args.json);
19221
+ return;
19222
+ }
19223
+ case "delete": {
19224
+ await table.deleteRow(args.id);
19225
+ ui.success(`Deleted row ${args.name}/${args.id}`);
19226
+ return;
19227
+ }
19228
+ case "create": {
19229
+ const payload = this.readJsonFile(args.filePath);
19230
+ await table.appendRow(payload);
19231
+ ui.success(`Created row in ${args.name}`, { filePath: args.filePath });
19232
+ return;
19233
+ }
19234
+ case "update": {
19235
+ const payload = this.readJsonFile(args.filePath);
19236
+ await table.updateRow(payload);
19237
+ ui.success(`Updated row in ${args.name}`, { filePath: args.filePath });
19238
+ return;
19239
+ }
19240
+ }
19241
+ }
19242
+ const kv = namespace.kv(args.name);
19243
+ switch (args.action) {
19244
+ case "list": {
19245
+ const rows = await kv.list(args.page);
19246
+ this.renderJsonOrSummary(
19247
+ rows,
19248
+ args.json,
19249
+ "No kv entries found.",
19250
+ (row) => row.key
19251
+ );
19252
+ return;
19253
+ }
19254
+ case "get": {
19255
+ const value = await kv.get(args.key);
19256
+ this.renderValue(value, args.json);
19257
+ return;
19258
+ }
19259
+ case "exists": {
19260
+ const exists = await kv.exists(args.key);
19261
+ this.renderValue(exists, args.json);
19262
+ return;
19263
+ }
19264
+ case "delete": {
19265
+ await kv.delete(args.key);
19266
+ ui.success(`Deleted key ${args.name}/${args.key}`);
19267
+ return;
19268
+ }
19269
+ case "set": {
19270
+ const value = args.filePath ? this.readJsonFile(args.filePath) : JSON.parse(args.value);
19271
+ await kv.set(args.key, value);
19272
+ ui.success(`Set key ${args.name}/${args.key}`);
19273
+ return;
19274
+ }
19275
+ }
19276
+ }
19277
+ createNamespace(args) {
19278
+ return new Namespace({
19279
+ chain: args.chain,
19280
+ ns: args.namespace,
19281
+ baseUrl: this.resolveBaseUrl(args.baseUrl),
19282
+ indexerBaseUrl: this.resolveIndexerBaseUrl(args.indexerBaseUrl)
19283
+ });
19284
+ }
19285
+ resolveBaseUrl(baseUrl) {
19286
+ const resolved = baseUrl || process.env.PMATE_STORE_BASE_URL || process.env.BLOCKCHAIN_BASE_URL;
19287
+ if (!resolved) {
19288
+ throw new Error(
19289
+ "Missing store base URL. Provide --base-url or set PMATE_STORE_BASE_URL / BLOCKCHAIN_BASE_URL."
19290
+ );
19291
+ }
19292
+ return resolved.replace(/\/+$/, "");
19293
+ }
19294
+ resolveIndexerBaseUrl(indexerBaseUrl) {
19295
+ return (indexerBaseUrl || process.env.PMATE_STORE_INDEXER_BASE_URL || process.env.INDEXER_BASE_URL || "https://indexer.pmate.chat").replace(/\/+$/, "");
19296
+ }
19297
+ async listNamespaces(args) {
19298
+ const baseUrl = this.resolveIndexerBaseUrl(args.indexerBaseUrl);
19299
+ const url = new URL(`/chains/${encodeURIComponent(args.chain)}/namespaces`, `${baseUrl}/`);
19300
+ const response = await fetch(url.toString(), {
19301
+ headers: { Accept: "application/json" }
19302
+ });
19303
+ const payload = await response.json();
19304
+ if (!response.ok || !payload?.success) {
19305
+ throw new Error(payload?.message || `Namespace list request failed with status ${response.status}`);
19306
+ }
19307
+ return payload.data ?? [];
19308
+ }
19309
+ readJsonFile(filePath) {
19310
+ const absolutePath = import_node_path18.default.resolve(process.cwd(), filePath);
19311
+ if (!(0, import_node_fs13.existsSync)(absolutePath)) {
19312
+ throw new Error(`JSON file not found: ${absolutePath}`);
19313
+ }
19314
+ const raw = (0, import_node_fs13.readFileSync)(absolutePath, "utf8");
19315
+ try {
19316
+ return JSON.parse(raw);
19317
+ } catch (error) {
19318
+ const message = error instanceof Error ? error.message : String(error);
19319
+ throw new Error(`Invalid JSON in ${absolutePath}: ${message}`);
19320
+ }
19321
+ }
19322
+ renderNamespaceList(items, asJson) {
19323
+ if (asJson) {
19324
+ ui.plain(JSON.stringify(items, null, 2));
19325
+ return;
19326
+ }
19327
+ if (items.length === 0) {
19328
+ ui.warn("No namespaces found.");
19329
+ return;
19330
+ }
19331
+ for (const item of items) {
19332
+ ui.info(`${item.chain}/${item.namespace}`);
19333
+ }
19334
+ }
19335
+ renderJsonOrSummary(items, asJson, emptyText, label) {
19336
+ if (asJson) {
19337
+ ui.plain(JSON.stringify(items, null, 2));
19338
+ return;
19339
+ }
19340
+ if (items.length === 0) {
19341
+ ui.warn(emptyText);
19342
+ return;
19343
+ }
19344
+ for (const item of items) {
19345
+ ui.info(label(item), item);
19346
+ }
19347
+ }
19348
+ renderValue(value, asJson) {
19349
+ if (asJson) {
19350
+ ui.plain(JSON.stringify(value ?? null, null, 2));
19351
+ return;
19352
+ }
19353
+ if (typeof value === "boolean") {
19354
+ ui.plain(String(value));
19355
+ return;
19356
+ }
19357
+ if (value == null) {
19358
+ ui.warn("Not found.");
19359
+ return;
19360
+ }
19361
+ ui.plain(JSON.stringify(value, null, 2));
19362
+ }
19363
+ };
19364
+
19365
+ // src/commands/AppCommandHandler.ts
19366
+ var import_node_fs14 = require("fs");
19367
+ var import_node_path19 = __toESM(require("path"));
18946
19368
  init_sessionStore();
18947
19369
  var AppCommandHandler = class {
18948
19370
  async handle(args) {
@@ -19017,11 +19439,11 @@ var AppCommandHandler = class {
19017
19439
  }).token;
19018
19440
  }
19019
19441
  readJsonFile(filePath) {
19020
- const absolutePath = import_node_path18.default.resolve(process.cwd(), filePath);
19021
- if (!(0, import_node_fs13.existsSync)(absolutePath)) {
19442
+ const absolutePath = import_node_path19.default.resolve(process.cwd(), filePath);
19443
+ if (!(0, import_node_fs14.existsSync)(absolutePath)) {
19022
19444
  throw new Error(`JSON file not found: ${absolutePath}`);
19023
19445
  }
19024
- const raw = (0, import_node_fs13.readFileSync)(absolutePath, "utf8");
19446
+ const raw = (0, import_node_fs14.readFileSync)(absolutePath, "utf8");
19025
19447
  try {
19026
19448
  return JSON.parse(raw);
19027
19449
  } catch (error) {
@@ -19189,7 +19611,7 @@ function parseAgentArgs(tokens) {
19189
19611
  }
19190
19612
  let baseUrl;
19191
19613
  let json = false;
19192
- const takeSharedOptions = () => {
19614
+ const takeSharedOptions2 = () => {
19193
19615
  while (rest.length > 0) {
19194
19616
  const token = rest[0];
19195
19617
  if (token === "--base-url") {
@@ -19206,7 +19628,7 @@ function parseAgentArgs(tokens) {
19206
19628
  }
19207
19629
  };
19208
19630
  if (action === "namespaces") {
19209
- takeSharedOptions();
19631
+ takeSharedOptions2();
19210
19632
  if (rest.length > 0) {
19211
19633
  throw new Error(`Unknown agent namespaces option: ${rest[0]}`);
19212
19634
  }
@@ -19248,7 +19670,7 @@ function parseAgentArgs(tokens) {
19248
19670
  `Usage: agent ${action} [<namespace>] <name> [--base-url <url>] [--json]`
19249
19671
  );
19250
19672
  }
19251
- takeSharedOptions();
19673
+ takeSharedOptions2();
19252
19674
  if (rest.length > 0) {
19253
19675
  throw new Error(`Unknown agent ${action} option: ${rest[0]}`);
19254
19676
  }
@@ -19329,6 +19751,213 @@ function requireValue(tokens, optionName) {
19329
19751
  return value;
19330
19752
  }
19331
19753
 
19754
+ // src/storeCommandParser.ts
19755
+ var DEFAULT_CHAIN = "pmate";
19756
+ var DEFAULT_NAMESPACE2 = "pmate";
19757
+ function parseStoreArgs(tokens) {
19758
+ const rest = [...tokens];
19759
+ const scope = rest.shift();
19760
+ if (!scope) {
19761
+ throw new Error("Missing store scope. Use: store namespace|table|kv");
19762
+ }
19763
+ const action = rest.shift();
19764
+ if (!action) {
19765
+ throw new Error(`Missing store ${scope} action.`);
19766
+ }
19767
+ const shared = {
19768
+ chain: DEFAULT_CHAIN,
19769
+ namespace: DEFAULT_NAMESPACE2,
19770
+ baseUrl: void 0,
19771
+ indexerBaseUrl: void 0,
19772
+ json: false
19773
+ };
19774
+ if (scope === "namespace") {
19775
+ if (action !== "list") {
19776
+ throw new Error(`Unknown store namespace action: ${action}`);
19777
+ }
19778
+ takeSharedOptions(rest, shared);
19779
+ if (rest.length > 0) {
19780
+ throw new Error(`Unknown store namespace option: ${rest[0]}`);
19781
+ }
19782
+ return {
19783
+ type: "store" /* Store */,
19784
+ scope,
19785
+ action,
19786
+ ...shared
19787
+ };
19788
+ }
19789
+ if (scope === "table") {
19790
+ return parseTableArgs(action, rest, shared);
19791
+ }
19792
+ if (scope === "kv") {
19793
+ return parseKvArgs(action, rest, shared);
19794
+ }
19795
+ throw new Error(`Unknown store scope: ${scope}`);
19796
+ }
19797
+ function parseTableArgs(action, rest, shared) {
19798
+ const name = rest.shift();
19799
+ if (!name || name.startsWith("-")) {
19800
+ throw new Error(`Missing table name. Usage: store table ${action} <name> ...`);
19801
+ }
19802
+ if (action === "list") {
19803
+ let page = 0;
19804
+ while (rest.length > 0) {
19805
+ const token = rest.shift();
19806
+ switch (token) {
19807
+ case "--page":
19808
+ page = parsePage(requireValue2(rest, token));
19809
+ break;
19810
+ default:
19811
+ pushSharedOption(token, rest, shared);
19812
+ }
19813
+ }
19814
+ return { type: "store" /* Store */, scope: "table", action, name, page, ...shared };
19815
+ }
19816
+ if (action === "get" || action === "exists" || action === "delete") {
19817
+ let id;
19818
+ while (rest.length > 0) {
19819
+ const token = rest.shift();
19820
+ switch (token) {
19821
+ case "--id":
19822
+ id = requireValue2(rest, token);
19823
+ break;
19824
+ default:
19825
+ pushSharedOption(token, rest, shared);
19826
+ }
19827
+ }
19828
+ if (!id) {
19829
+ throw new Error(`Missing required option --id for store table ${action}`);
19830
+ }
19831
+ return { type: "store" /* Store */, scope: "table", action, name, id, ...shared };
19832
+ }
19833
+ if (action === "create" || action === "update") {
19834
+ let filePath;
19835
+ while (rest.length > 0) {
19836
+ const token = rest.shift();
19837
+ switch (token) {
19838
+ case "--file":
19839
+ filePath = requireValue2(rest, token);
19840
+ break;
19841
+ default:
19842
+ pushSharedOption(token, rest, shared);
19843
+ }
19844
+ }
19845
+ if (!filePath) {
19846
+ throw new Error(`Missing required option --file for store table ${action}`);
19847
+ }
19848
+ return { type: "store" /* Store */, scope: "table", action, name, filePath, ...shared };
19849
+ }
19850
+ throw new Error(`Unknown store table action: ${action}`);
19851
+ }
19852
+ function parseKvArgs(action, rest, shared) {
19853
+ const name = rest.shift();
19854
+ if (!name || name.startsWith("-")) {
19855
+ throw new Error(`Missing kv name. Usage: store kv ${action} <name> ...`);
19856
+ }
19857
+ if (action === "list") {
19858
+ let page = 0;
19859
+ while (rest.length > 0) {
19860
+ const token = rest.shift();
19861
+ switch (token) {
19862
+ case "--page":
19863
+ page = parsePage(requireValue2(rest, token));
19864
+ break;
19865
+ default:
19866
+ pushSharedOption(token, rest, shared);
19867
+ }
19868
+ }
19869
+ return { type: "store" /* Store */, scope: "kv", action, name, page, ...shared };
19870
+ }
19871
+ if (action === "get" || action === "exists" || action === "delete") {
19872
+ let key;
19873
+ while (rest.length > 0) {
19874
+ const token = rest.shift();
19875
+ switch (token) {
19876
+ case "--key":
19877
+ key = requireValue2(rest, token);
19878
+ break;
19879
+ default:
19880
+ pushSharedOption(token, rest, shared);
19881
+ }
19882
+ }
19883
+ if (!key) {
19884
+ throw new Error(`Missing required option --key for store kv ${action}`);
19885
+ }
19886
+ return { type: "store" /* Store */, scope: "kv", action, name, key, ...shared };
19887
+ }
19888
+ if (action === "set") {
19889
+ let key;
19890
+ let value;
19891
+ let filePath;
19892
+ while (rest.length > 0) {
19893
+ const token = rest.shift();
19894
+ switch (token) {
19895
+ case "--key":
19896
+ key = requireValue2(rest, token);
19897
+ break;
19898
+ case "--value":
19899
+ value = requireValue2(rest, token);
19900
+ break;
19901
+ case "--file":
19902
+ filePath = requireValue2(rest, token);
19903
+ break;
19904
+ default:
19905
+ pushSharedOption(token, rest, shared);
19906
+ }
19907
+ }
19908
+ if (!key) {
19909
+ throw new Error("Missing required option --key for store kv set");
19910
+ }
19911
+ if (!value && !filePath || value && filePath) {
19912
+ throw new Error("Provide exactly one of --value or --file for store kv set");
19913
+ }
19914
+ return { type: "store" /* Store */, scope: "kv", action, name, key, value, filePath, ...shared };
19915
+ }
19916
+ throw new Error(`Unknown store kv action: ${action}`);
19917
+ }
19918
+ function takeSharedOptions(rest, shared) {
19919
+ while (rest.length > 0) {
19920
+ const token = rest.shift();
19921
+ pushSharedOption(token, rest, shared);
19922
+ }
19923
+ }
19924
+ function pushSharedOption(token, rest, shared) {
19925
+ switch (token) {
19926
+ case "--chain":
19927
+ shared.chain = requireValue2(rest, token);
19928
+ break;
19929
+ case "--ns":
19930
+ case "--namespace":
19931
+ shared.namespace = requireValue2(rest, token);
19932
+ break;
19933
+ case "--base-url":
19934
+ shared.baseUrl = requireValue2(rest, token);
19935
+ break;
19936
+ case "--indexer-base-url":
19937
+ shared.indexerBaseUrl = requireValue2(rest, token);
19938
+ break;
19939
+ case "--json":
19940
+ shared.json = true;
19941
+ break;
19942
+ default:
19943
+ throw new Error(`Unknown store option: ${token}`);
19944
+ }
19945
+ }
19946
+ function requireValue2(tokens, optionName) {
19947
+ const value = tokens.shift();
19948
+ if (!value || value.startsWith("-")) {
19949
+ throw new Error(`Missing value for ${optionName}`);
19950
+ }
19951
+ return value;
19952
+ }
19953
+ function parsePage(value) {
19954
+ const page = Number.parseInt(value, 10);
19955
+ if (!Number.isInteger(page) || page < 0) {
19956
+ throw new Error(`Invalid --page value: ${value}`);
19957
+ }
19958
+ return page;
19959
+ }
19960
+
19332
19961
  // src/appCommandParser.ts
19333
19962
  function parseAppArgs(tokens) {
19334
19963
  const rest = [...tokens];
@@ -19338,12 +19967,12 @@ function parseAppArgs(tokens) {
19338
19967
  }
19339
19968
  let baseUrl;
19340
19969
  let json = false;
19341
- const takeSharedOptions = () => {
19970
+ const takeSharedOptions2 = () => {
19342
19971
  while (rest.length > 0) {
19343
19972
  const token = rest[0];
19344
19973
  if (token === "--base-url") {
19345
19974
  rest.shift();
19346
- baseUrl = requireValue2(rest, token);
19975
+ baseUrl = requireValue3(rest, token);
19347
19976
  continue;
19348
19977
  }
19349
19978
  if (token === "--json") {
@@ -19355,7 +19984,7 @@ function parseAppArgs(tokens) {
19355
19984
  }
19356
19985
  };
19357
19986
  if (action === "list") {
19358
- takeSharedOptions();
19987
+ takeSharedOptions2();
19359
19988
  if (rest.length > 0) {
19360
19989
  throw new Error(`Unknown app list option: ${rest[0]}`);
19361
19990
  }
@@ -19368,7 +19997,7 @@ function parseAppArgs(tokens) {
19368
19997
  `Usage: app ${action} <id> [--base-url <url>] [--json]`
19369
19998
  );
19370
19999
  }
19371
- takeSharedOptions();
20000
+ takeSharedOptions2();
19372
20001
  if (rest.length > 0) {
19373
20002
  throw new Error(`Unknown app ${action} option: ${rest[0]}`);
19374
20003
  }
@@ -19380,10 +20009,10 @@ function parseAppArgs(tokens) {
19380
20009
  const token = rest.shift();
19381
20010
  switch (token) {
19382
20011
  case "--file":
19383
- filePath = requireValue2(rest, token);
20012
+ filePath = requireValue3(rest, token);
19384
20013
  break;
19385
20014
  case "--base-url":
19386
- baseUrl = requireValue2(rest, token);
20015
+ baseUrl = requireValue3(rest, token);
19387
20016
  break;
19388
20017
  case "--json":
19389
20018
  json = true;
@@ -19409,10 +20038,10 @@ function parseAppArgs(tokens) {
19409
20038
  const token = rest.shift();
19410
20039
  switch (token) {
19411
20040
  case "--file":
19412
- filePath = requireValue2(rest, token);
20041
+ filePath = requireValue3(rest, token);
19413
20042
  break;
19414
20043
  case "--base-url":
19415
- baseUrl = requireValue2(rest, token);
20044
+ baseUrl = requireValue3(rest, token);
19416
20045
  break;
19417
20046
  case "--json":
19418
20047
  json = true;
@@ -19428,7 +20057,7 @@ function parseAppArgs(tokens) {
19428
20057
  }
19429
20058
  throw new Error(`Unknown app action: ${action}`);
19430
20059
  }
19431
- function requireValue2(tokens, optionName) {
20060
+ function requireValue3(tokens, optionName) {
19432
20061
  const value = tokens.shift();
19433
20062
  if (!value || value.startsWith("-")) {
19434
20063
  throw new Error(`Missing value for ${optionName}`);
@@ -19438,7 +20067,7 @@ function requireValue2(tokens, optionName) {
19438
20067
 
19439
20068
  // src/index.ts
19440
20069
  var pkg = JSON.parse(
19441
- (0, import_node_fs14.readFileSync)(import_node_path19.default.resolve(__dirname, "..", "package.json"), "utf8")
20070
+ (0, import_node_fs15.readFileSync)(import_node_path20.default.resolve(__dirname, "..", "package.json"), "utf8")
19442
20071
  );
19443
20072
  var HELP_TEXT = [
19444
20073
  import_chalk3.default.bold(`pmate v${pkg.version}`),
@@ -19459,7 +20088,7 @@ var HELP_TEXT = [
19459
20088
  ` ${import_chalk3.default.gray(" --type <t> --value <v> --rr <rr> [--ttl <n>] [--domain <name>]")}`,
19460
20089
  ` ${import_chalk3.default.cyan("sts")} Request an OSS STS token from the CI server`,
19461
20090
  ` ${import_chalk3.default.cyan("bucket")} Manage OSS buckets`,
19462
- ` ${import_chalk3.default.gray(" --create --name <bucket>")}`,
20091
+ ` ${import_chalk3.default.gray(" --create --name <bucket> [--subdomain <name> --domain <name>]")}`,
19463
20092
  ` ${import_chalk3.default.cyan("deploy")} Deploy or view logs for app dir from .pmate.yaml`,
19464
20093
  ` ${import_chalk3.default.gray(" <app-name> [deploy|logs] [--cwd <dir>]")}`,
19465
20094
  ` ${import_chalk3.default.cyan("log")} Query app logs from the log indexer API`,
@@ -19522,6 +20151,11 @@ var HELP_TEXT = [
19522
20151
  ` ${import_chalk3.default.gray(" update [<namespace>] <name> --file <path> [--base-url <url>] [--json]")}`,
19523
20152
  ` ${import_chalk3.default.gray(" delete [<namespace>] <name> [--base-url <url>] [--json]")}`,
19524
20153
  ` ${import_chalk3.default.gray(" default namespace: pmate; default base URL: https://agent-api.pmate.chat")}`,
20154
+ ` ${import_chalk3.default.cyan("store")} Manage @pmate/store namespaces, tables, and kv stores`,
20155
+ ` ${import_chalk3.default.gray(" namespace list [--chain <chain>] [--indexer-base-url <url>] [--json]")}`,
20156
+ ` ${import_chalk3.default.gray(" table list|get|exists|create|update|delete <name> [options]")}`,
20157
+ ` ${import_chalk3.default.gray(" kv list|get|exists|set|delete <name> [options]")}`,
20158
+ ` ${import_chalk3.default.gray(" defaults: chain=pmate namespace=pmate env base URLs from BLOCKCHAIN_BASE_URL / INDEXER_BASE_URL")}`,
19525
20159
  ` ${import_chalk3.default.cyan("app")} Manage app registry entries via apps-api`,
19526
20160
  ` ${import_chalk3.default.gray(" list [--base-url <url>] [--json]")}`,
19527
20161
  ` ${import_chalk3.default.gray(" get <id> [--base-url <url>] [--json]")}`,
@@ -19589,7 +20223,7 @@ function parseCommandArgs(args) {
19589
20223
  const token = rest.shift();
19590
20224
  switch (token) {
19591
20225
  case "--app":
19592
- app = requireValue3(rest, token);
20226
+ app = requireValue4(rest, token);
19593
20227
  break;
19594
20228
  default:
19595
20229
  throw new Error(`Unknown login option: ${token}`);
@@ -19654,6 +20288,9 @@ function parseCommandArgs(args) {
19654
20288
  if (args.rest[0] === "agent") {
19655
20289
  return parseAgentArgs(args.rest.slice(1));
19656
20290
  }
20291
+ if (args.rest[0] === "store") {
20292
+ return parseStoreArgs(args.rest.slice(1));
20293
+ }
19657
20294
  if (args.rest[0] === "app") {
19658
20295
  return parseAppArgs(args.rest.slice(1));
19659
20296
  }
@@ -19674,7 +20311,7 @@ function parseVercelArgs(tokens) {
19674
20311
  const token = rest.shift();
19675
20312
  switch (token) {
19676
20313
  case "--scope":
19677
- scope = requireValue3(rest, token);
20314
+ scope = requireValue4(rest, token);
19678
20315
  break;
19679
20316
  default:
19680
20317
  throw new Error(`Unknown vercel option: ${token}`);
@@ -19694,10 +20331,10 @@ function parseVercelArgs(tokens) {
19694
20331
  const token = rest.shift();
19695
20332
  switch (token) {
19696
20333
  case "--scope":
19697
- scope = requireValue3(rest, token);
20334
+ scope = requireValue4(rest, token);
19698
20335
  break;
19699
20336
  case "--project":
19700
- project = requireValue3(rest, token);
20337
+ project = requireValue4(rest, token);
19701
20338
  break;
19702
20339
  case "--last-week":
19703
20340
  lastWeek = true;
@@ -19728,16 +20365,16 @@ function parseAddDnsArgs(tokens) {
19728
20365
  const token = rest.shift();
19729
20366
  switch (token) {
19730
20367
  case "--type":
19731
- options.dnsType = requireValue3(rest, token);
20368
+ options.dnsType = requireValue4(rest, token);
19732
20369
  break;
19733
20370
  case "--value":
19734
- options.dnsValue = requireValue3(rest, token);
20371
+ options.dnsValue = requireValue4(rest, token);
19735
20372
  break;
19736
20373
  case "--rr":
19737
- options.dnsRr = requireValue3(rest, token);
20374
+ options.dnsRr = requireValue4(rest, token);
19738
20375
  break;
19739
20376
  case "--ttl": {
19740
- const ttlValue = requireValue3(rest, token);
20377
+ const ttlValue = requireValue4(rest, token);
19741
20378
  const ttl = Number.parseInt(ttlValue, 10);
19742
20379
  if (!Number.isFinite(ttl) || ttl <= 0) {
19743
20380
  throw new Error(`Invalid --ttl value: ${ttlValue}`);
@@ -19746,7 +20383,7 @@ function parseAddDnsArgs(tokens) {
19746
20383
  break;
19747
20384
  }
19748
20385
  case "--domain":
19749
- options.dnsDomain = requireValue3(rest, token);
20386
+ options.dnsDomain = requireValue4(rest, token);
19750
20387
  break;
19751
20388
  default:
19752
20389
  throw new Error(`Unknown add-dns option: ${token}`);
@@ -19767,7 +20404,9 @@ function parseAddDnsArgs(tokens) {
19767
20404
  function parseBucketArgs(tokens) {
19768
20405
  const options = {
19769
20406
  bucketCreate: false,
19770
- bucketName: ""
20407
+ bucketName: "",
20408
+ bucketSubdomain: void 0,
20409
+ bucketDomain: void 0
19771
20410
  };
19772
20411
  const rest = [...tokens];
19773
20412
  while (rest.length > 0) {
@@ -19777,7 +20416,13 @@ function parseBucketArgs(tokens) {
19777
20416
  options.bucketCreate = true;
19778
20417
  break;
19779
20418
  case "--name":
19780
- options.bucketName = requireValue3(rest, token);
20419
+ options.bucketName = requireValue4(rest, token);
20420
+ break;
20421
+ case "--subdomain":
20422
+ options.bucketSubdomain = requireValue4(rest, token);
20423
+ break;
20424
+ case "--domain":
20425
+ options.bucketDomain = requireValue4(rest, token);
19781
20426
  break;
19782
20427
  default:
19783
20428
  throw new Error(`Unknown bucket option: ${token}`);
@@ -19789,6 +20434,9 @@ function parseBucketArgs(tokens) {
19789
20434
  if (!options.bucketName.trim()) {
19790
20435
  throw new Error("Missing bucket name. Use --name <bucket>.");
19791
20436
  }
20437
+ if (options.bucketSubdomain && !options.bucketDomain?.trim()) {
20438
+ throw new Error("Missing domain name. Use --domain <name> when --subdomain is set.");
20439
+ }
19792
20440
  return { type: "bucket" /* Bucket */, ...options };
19793
20441
  }
19794
20442
  function parseDeployArgs(tokens) {
@@ -19813,7 +20461,7 @@ function parseDeployArgs(tokens) {
19813
20461
  options.deployAction = "logs";
19814
20462
  break;
19815
20463
  case "--cwd":
19816
- options.deployCwd = requireValue3(rest, token);
20464
+ options.deployCwd = requireValue4(rest, token);
19817
20465
  break;
19818
20466
  default:
19819
20467
  throw new Error(`Unknown deploy option: ${token}`);
@@ -19838,13 +20486,13 @@ function parseLogArgs(tokens) {
19838
20486
  const token = rest.shift();
19839
20487
  switch (token) {
19840
20488
  case "--cwd":
19841
- options.logCwd = requireValue3(rest, token);
20489
+ options.logCwd = requireValue4(rest, token);
19842
20490
  break;
19843
20491
  case "--ns":
19844
- options.logNamespace = requireValue3(rest, token);
20492
+ options.logNamespace = requireValue4(rest, token);
19845
20493
  break;
19846
20494
  case "--page": {
19847
- const value = requireValue3(rest, token);
20495
+ const value = requireValue4(rest, token);
19848
20496
  const page = Number.parseInt(value, 10);
19849
20497
  if (!Number.isFinite(page) || page < 0) {
19850
20498
  throw new Error(`Invalid log page: ${value}`);
@@ -19856,7 +20504,7 @@ function parseLogArgs(tokens) {
19856
20504
  options.logHistory = true;
19857
20505
  break;
19858
20506
  case "--search":
19859
- options.logSearch = requireValue3(rest, token);
20507
+ options.logSearch = requireValue4(rest, token);
19860
20508
  break;
19861
20509
  default:
19862
20510
  throw new Error(`Unknown log option: ${token}`);
@@ -19879,7 +20527,7 @@ function parseInitArgs(tokens) {
19879
20527
  const token = rest.shift();
19880
20528
  switch (token) {
19881
20529
  case "--cwd":
19882
- options.initCwd = requireValue3(rest, token);
20530
+ options.initCwd = requireValue4(rest, token);
19883
20531
  break;
19884
20532
  default:
19885
20533
  throw new Error(`Unknown init option: ${token}`);
@@ -19902,7 +20550,7 @@ function parseDevArgs(tokens) {
19902
20550
  const token = rest.shift();
19903
20551
  switch (token) {
19904
20552
  case "--cwd":
19905
- options.devCwd = requireValue3(rest, token);
20553
+ options.devCwd = requireValue4(rest, token);
19906
20554
  break;
19907
20555
  default:
19908
20556
  throw new Error(`Unknown dev option: ${token}`);
@@ -19932,13 +20580,13 @@ function parseOssArgs(tokens) {
19932
20580
  const token = rest.shift();
19933
20581
  switch (token) {
19934
20582
  case "--bucket":
19935
- bucket = requireValue3(rest, token);
20583
+ bucket = requireValue4(rest, token);
19936
20584
  break;
19937
20585
  case "--file":
19938
- filePath = requireValue3(rest, token);
20586
+ filePath = requireValue4(rest, token);
19939
20587
  break;
19940
20588
  case "--key":
19941
- objectKey = requireValue3(rest, token);
20589
+ objectKey = requireValue4(rest, token);
19942
20590
  break;
19943
20591
  default:
19944
20592
  throw new Error(`Unknown oss option: ${token}`);
@@ -19971,7 +20619,7 @@ function parseEnvArgs(tokens) {
19971
20619
  throw new Error("Only one env action is allowed.");
19972
20620
  }
19973
20621
  action = "set";
19974
- key = requireValue3(rest, token);
20622
+ key = requireValue4(rest, token);
19975
20623
  break;
19976
20624
  case "--list":
19977
20625
  if (action) {
@@ -19984,17 +20632,17 @@ function parseEnvArgs(tokens) {
19984
20632
  throw new Error("Only one env action is allowed.");
19985
20633
  }
19986
20634
  action = "delete";
19987
- key = requireValue3(rest, token);
20635
+ key = requireValue4(rest, token);
19988
20636
  break;
19989
20637
  case "--value":
19990
- value = requireValue3(rest, token);
20638
+ value = requireValue4(rest, token);
19991
20639
  break;
19992
20640
  case "--verbose":
19993
20641
  case "-v":
19994
20642
  verbose = true;
19995
20643
  break;
19996
20644
  case "--cwd":
19997
- cwd = requireValue3(rest, token);
20645
+ cwd = requireValue4(rest, token);
19998
20646
  break;
19999
20647
  default:
20000
20648
  throw new Error(`Unknown env option: ${token}`);
@@ -20052,7 +20700,7 @@ function parseCommitArgs(tokens) {
20052
20700
  push = true;
20053
20701
  break;
20054
20702
  case "--cwd":
20055
- cwd = requireValue3(rest, token);
20703
+ cwd = requireValue4(rest, token);
20056
20704
  break;
20057
20705
  default:
20058
20706
  throw new Error(`Unknown commit option: ${token}`);
@@ -20068,10 +20716,10 @@ function parseSummaryArgs(tokens) {
20068
20716
  const token = rest.shift();
20069
20717
  switch (token) {
20070
20718
  case "--pr":
20071
- prRef = requireValue3(rest, token);
20719
+ prRef = requireValue4(rest, token);
20072
20720
  break;
20073
20721
  case "--cwd":
20074
- cwd = requireValue3(rest, token);
20722
+ cwd = requireValue4(rest, token);
20075
20723
  break;
20076
20724
  default:
20077
20725
  throw new Error(`Unknown summary option: ${token}`);
@@ -20140,10 +20788,10 @@ function parseLinearPrArgs(tokens) {
20140
20788
  const token = rest.shift();
20141
20789
  switch (token) {
20142
20790
  case "--account":
20143
- account = requireValue3(rest, token);
20791
+ account = requireValue4(rest, token);
20144
20792
  break;
20145
20793
  case "--cwd":
20146
- cwd = requireValue3(rest, token);
20794
+ cwd = requireValue4(rest, token);
20147
20795
  break;
20148
20796
  default:
20149
20797
  throw new Error(`Unknown linear option: ${token}`);
@@ -20172,35 +20820,35 @@ function parseLinearCreateArgs(tokens) {
20172
20820
  const token = rest.shift();
20173
20821
  switch (token) {
20174
20822
  case "--account":
20175
- account = requireValue3(rest, token);
20823
+ account = requireValue4(rest, token);
20176
20824
  break;
20177
20825
  case "--repl":
20178
20826
  useRepl = true;
20179
20827
  break;
20180
20828
  case "--title":
20181
- title = requireValue3(rest, token);
20829
+ title = requireValue4(rest, token);
20182
20830
  break;
20183
20831
  case "--desc":
20184
20832
  case "--description":
20185
- description = decodeEscapedNewlines(requireValue3(rest, token));
20833
+ description = decodeEscapedNewlines(requireValue4(rest, token));
20186
20834
  break;
20187
20835
  case "--team-id":
20188
- teamId = requireValue3(rest, token);
20836
+ teamId = requireValue4(rest, token);
20189
20837
  break;
20190
20838
  case "--team-key":
20191
- teamKey = requireValue3(rest, token);
20839
+ teamKey = requireValue4(rest, token);
20192
20840
  break;
20193
20841
  case "--priority":
20194
- priority = parseLinearPriority(requireValue3(rest, token));
20842
+ priority = parseLinearPriority(requireValue4(rest, token));
20195
20843
  break;
20196
20844
  case "--parent-id":
20197
- parentId = requireValue3(rest, token);
20845
+ parentId = requireValue4(rest, token);
20198
20846
  break;
20199
20847
  case "--state-id":
20200
- stateId = requireValue3(rest, token);
20848
+ stateId = requireValue4(rest, token);
20201
20849
  break;
20202
20850
  case "--cwd":
20203
- cwd = requireValue3(rest, token);
20851
+ cwd = requireValue4(rest, token);
20204
20852
  break;
20205
20853
  default:
20206
20854
  throw new Error(`Unknown linear option: ${token}`);
@@ -20235,10 +20883,10 @@ function parseLinearWhoamiArgs(tokens) {
20235
20883
  const token = rest.shift();
20236
20884
  switch (token) {
20237
20885
  case "--account":
20238
- account = requireValue3(rest, token);
20886
+ account = requireValue4(rest, token);
20239
20887
  break;
20240
20888
  case "--cwd":
20241
- cwd = requireValue3(rest, token);
20889
+ cwd = requireValue4(rest, token);
20242
20890
  break;
20243
20891
  default:
20244
20892
  throw new Error(`Unknown linear option: ${token}`);
@@ -20263,10 +20911,10 @@ function parseLinearViewArgs(tokens) {
20263
20911
  const token = rest.shift();
20264
20912
  switch (token) {
20265
20913
  case "--account":
20266
- account = requireValue3(rest, token);
20914
+ account = requireValue4(rest, token);
20267
20915
  break;
20268
20916
  case "--cwd":
20269
- cwd = requireValue3(rest, token);
20917
+ cwd = requireValue4(rest, token);
20270
20918
  break;
20271
20919
  default:
20272
20920
  throw new Error(`Unknown linear option: ${token}`);
@@ -20301,32 +20949,32 @@ function parseLinearUpdateArgs(tokens) {
20301
20949
  const token = rest.shift();
20302
20950
  switch (token) {
20303
20951
  case "--account":
20304
- account = requireValue3(rest, token);
20952
+ account = requireValue4(rest, token);
20305
20953
  break;
20306
20954
  case "--title":
20307
- title = requireValue3(rest, token);
20955
+ title = requireValue4(rest, token);
20308
20956
  break;
20309
20957
  case "--desc":
20310
20958
  case "--description":
20311
- description = decodeEscapedNewlines(requireValue3(rest, token));
20959
+ description = decodeEscapedNewlines(requireValue4(rest, token));
20312
20960
  break;
20313
20961
  case "--team-id":
20314
- teamId = requireValue3(rest, token);
20962
+ teamId = requireValue4(rest, token);
20315
20963
  break;
20316
20964
  case "--team-key":
20317
- teamKey = requireValue3(rest, token);
20965
+ teamKey = requireValue4(rest, token);
20318
20966
  break;
20319
20967
  case "--priority":
20320
- priority = parseLinearPriority(requireValue3(rest, token));
20968
+ priority = parseLinearPriority(requireValue4(rest, token));
20321
20969
  break;
20322
20970
  case "--parent-id":
20323
- parentId = requireValue3(rest, token);
20971
+ parentId = requireValue4(rest, token);
20324
20972
  break;
20325
20973
  case "--state-id":
20326
- stateId = requireValue3(rest, token);
20974
+ stateId = requireValue4(rest, token);
20327
20975
  break;
20328
20976
  case "--cwd":
20329
- cwd = requireValue3(rest, token);
20977
+ cwd = requireValue4(rest, token);
20330
20978
  break;
20331
20979
  default:
20332
20980
  throw new Error(`Unknown linear option: ${token}`);
@@ -20364,10 +21012,10 @@ function parseLinearSubIssuesArgs(tokens) {
20364
21012
  const token = rest.shift();
20365
21013
  switch (token) {
20366
21014
  case "--account":
20367
- account = requireValue3(rest, token);
21015
+ account = requireValue4(rest, token);
20368
21016
  break;
20369
21017
  case "--cwd":
20370
- cwd = requireValue3(rest, token);
21018
+ cwd = requireValue4(rest, token);
20371
21019
  break;
20372
21020
  default:
20373
21021
  throw new Error(`Unknown linear option: ${token}`);
@@ -20394,15 +21042,15 @@ function parseLinearCommentArgs(tokens) {
20394
21042
  const token = rest.shift();
20395
21043
  switch (token) {
20396
21044
  case "--account":
20397
- account = requireValue3(rest, token);
21045
+ account = requireValue4(rest, token);
20398
21046
  break;
20399
21047
  case "--body":
20400
21048
  case "--desc":
20401
21049
  case "--description":
20402
- body = decodeEscapedNewlines(requireValue3(rest, token));
21050
+ body = decodeEscapedNewlines(requireValue4(rest, token));
20403
21051
  break;
20404
21052
  case "--cwd":
20405
- cwd = requireValue3(rest, token);
21053
+ cwd = requireValue4(rest, token);
20406
21054
  break;
20407
21055
  default:
20408
21056
  throw new Error(`Unknown linear option: ${token}`);
@@ -20432,10 +21080,10 @@ function parseLinearCommentsArgs(tokens) {
20432
21080
  const token = rest.shift();
20433
21081
  switch (token) {
20434
21082
  case "--account":
20435
- account = requireValue3(rest, token);
21083
+ account = requireValue4(rest, token);
20436
21084
  break;
20437
21085
  case "--cwd":
20438
- cwd = requireValue3(rest, token);
21086
+ cwd = requireValue4(rest, token);
20439
21087
  break;
20440
21088
  default:
20441
21089
  throw new Error(`Unknown linear option: ${token}`);
@@ -20459,16 +21107,16 @@ function parseLinearCycleArgs(tokens) {
20459
21107
  const token = rest.shift();
20460
21108
  switch (token) {
20461
21109
  case "--account":
20462
- account = requireValue3(rest, token);
21110
+ account = requireValue4(rest, token);
20463
21111
  break;
20464
21112
  case "--team-id":
20465
- teamId = requireValue3(rest, token);
21113
+ teamId = requireValue4(rest, token);
20466
21114
  break;
20467
21115
  case "--team-key":
20468
- teamKey = requireValue3(rest, token);
21116
+ teamKey = requireValue4(rest, token);
20469
21117
  break;
20470
21118
  case "--cwd":
20471
- cwd = requireValue3(rest, token);
21119
+ cwd = requireValue4(rest, token);
20472
21120
  break;
20473
21121
  default:
20474
21122
  throw new Error(`Unknown linear option: ${token}`);
@@ -20491,10 +21139,10 @@ function parseLinearTeamsArgs(tokens) {
20491
21139
  const token = rest.shift();
20492
21140
  switch (token) {
20493
21141
  case "--account":
20494
- account = requireValue3(rest, token);
21142
+ account = requireValue4(rest, token);
20495
21143
  break;
20496
21144
  case "--cwd":
20497
- cwd = requireValue3(rest, token);
21145
+ cwd = requireValue4(rest, token);
20498
21146
  break;
20499
21147
  default:
20500
21148
  throw new Error(`Unknown linear option: ${token}`);
@@ -20521,16 +21169,16 @@ function parseLinearUserIssuesArgs(tokens) {
20521
21169
  const token = rest.shift();
20522
21170
  switch (token) {
20523
21171
  case "--account":
20524
- account = requireValue3(rest, token);
21172
+ account = requireValue4(rest, token);
20525
21173
  break;
20526
21174
  case "--cycle":
20527
- cycle = parseLinearCycle(requireValue3(rest, token));
21175
+ cycle = parseLinearCycle(requireValue4(rest, token));
20528
21176
  break;
20529
21177
  case "--status":
20530
- status = parseLinearStatus(requireValue3(rest, token));
21178
+ status = parseLinearStatus(requireValue4(rest, token));
20531
21179
  break;
20532
21180
  case "--cwd":
20533
- cwd = requireValue3(rest, token);
21181
+ cwd = requireValue4(rest, token);
20534
21182
  break;
20535
21183
  default:
20536
21184
  throw new Error(`Unknown linear option: ${token}`);
@@ -20564,28 +21212,28 @@ function parseLinearIssuesArgs(tokens) {
20564
21212
  const token = rest.shift();
20565
21213
  switch (token) {
20566
21214
  case "--account":
20567
- account = requireValue3(rest, token);
21215
+ account = requireValue4(rest, token);
20568
21216
  break;
20569
21217
  case "--team-id":
20570
- teamId = requireValue3(rest, token);
21218
+ teamId = requireValue4(rest, token);
20571
21219
  break;
20572
21220
  case "--team-key":
20573
- teamKey = requireValue3(rest, token);
21221
+ teamKey = requireValue4(rest, token);
20574
21222
  break;
20575
21223
  case "--user":
20576
- user = requireValue3(rest, token);
21224
+ user = requireValue4(rest, token);
20577
21225
  break;
20578
21226
  case "--cycle":
20579
- cycle = parseLinearCycle(requireValue3(rest, token));
21227
+ cycle = parseLinearCycle(requireValue4(rest, token));
20580
21228
  break;
20581
21229
  case "--status":
20582
- status = parseLinearStatus(requireValue3(rest, token));
21230
+ status = parseLinearStatus(requireValue4(rest, token));
20583
21231
  break;
20584
21232
  case "--query":
20585
- query = requireValue3(rest, token).trim();
21233
+ query = requireValue4(rest, token).trim();
20586
21234
  break;
20587
21235
  case "--limit": {
20588
- const value = Number.parseInt(requireValue3(rest, token), 10);
21236
+ const value = Number.parseInt(requireValue4(rest, token), 10);
20589
21237
  if (!Number.isInteger(value) || value < 1 || value > 250) {
20590
21238
  throw new Error("Invalid --limit. Expected an integer between 1 and 250.");
20591
21239
  }
@@ -20593,7 +21241,7 @@ function parseLinearIssuesArgs(tokens) {
20593
21241
  break;
20594
21242
  }
20595
21243
  case "--cwd":
20596
- cwd = requireValue3(rest, token);
21244
+ cwd = requireValue4(rest, token);
20597
21245
  break;
20598
21246
  default:
20599
21247
  throw new Error(`Unknown linear option: ${token}`);
@@ -20634,10 +21282,10 @@ function parseLinearLegacyArgs(tokens) {
20634
21282
  useScreenshot = true;
20635
21283
  break;
20636
21284
  case "--account":
20637
- account = requireValue3(rest, token);
21285
+ account = requireValue4(rest, token);
20638
21286
  break;
20639
21287
  case "--cwd":
20640
- cwd = requireValue3(rest, token);
21288
+ cwd = requireValue4(rest, token);
20641
21289
  break;
20642
21290
  default:
20643
21291
  throw new Error(`Unknown linear option: ${token}`);
@@ -20731,19 +21379,19 @@ function parseNotionArgs(tokens) {
20731
21379
  const token = rest.shift();
20732
21380
  switch (token) {
20733
21381
  case "--parent":
20734
- parentPageId = requireValue3(rest, token);
21382
+ parentPageId = requireValue4(rest, token);
20735
21383
  break;
20736
21384
  case "--title":
20737
- title = requireValue3(rest, token);
21385
+ title = requireValue4(rest, token);
20738
21386
  break;
20739
21387
  case "--private":
20740
21388
  isPrivate = true;
20741
21389
  break;
20742
21390
  case "--content":
20743
- content2 = requireValue3(rest, token);
21391
+ content2 = requireValue4(rest, token);
20744
21392
  break;
20745
21393
  case "--file":
20746
- filePath2 = requireValue3(rest, token);
21394
+ filePath2 = requireValue4(rest, token);
20747
21395
  break;
20748
21396
  default:
20749
21397
  throw new Error(`Unknown notion option: ${token}`);
@@ -20787,10 +21435,10 @@ function parseNotionArgs(tokens) {
20787
21435
  const token = rest.shift();
20788
21436
  switch (token) {
20789
21437
  case "--content":
20790
- content = requireValue3(rest, token);
21438
+ content = requireValue4(rest, token);
20791
21439
  break;
20792
21440
  case "--file":
20793
- filePath = requireValue3(rest, token);
21441
+ filePath = requireValue4(rest, token);
20794
21442
  break;
20795
21443
  case "--append":
20796
21444
  append = true;
@@ -20835,11 +21483,11 @@ function parseRandomArgs(tokens) {
20835
21483
  mode = "easy";
20836
21484
  break;
20837
21485
  case "--length":
20838
- length = parsePositiveInt(requireValue3(rest, token), token);
21486
+ length = parsePositiveInt(requireValue4(rest, token), token);
20839
21487
  seenLength = true;
20840
21488
  break;
20841
21489
  case "--charset": {
20842
- const value = requireValue3(rest, token);
21490
+ const value = requireValue4(rest, token);
20843
21491
  if (!["base64url", "hex", "alnum", "ascii"].includes(value)) {
20844
21492
  throw new Error(
20845
21493
  `Invalid --charset value: ${value}. Use base64url|hex|alnum|ascii.`
@@ -20850,18 +21498,18 @@ function parseRandomArgs(tokens) {
20850
21498
  break;
20851
21499
  }
20852
21500
  case "--count":
20853
- count = parsePositiveInt(requireValue3(rest, token), token);
21501
+ count = parsePositiveInt(requireValue4(rest, token), token);
20854
21502
  break;
20855
21503
  case "--words":
20856
- words = parsePositiveInt(requireValue3(rest, token), token);
21504
+ words = parsePositiveInt(requireValue4(rest, token), token);
20857
21505
  seenWords = true;
20858
21506
  break;
20859
21507
  case "--digits":
20860
- digits = parseNonNegativeInt(requireValue3(rest, token), token);
21508
+ digits = parseNonNegativeInt(requireValue4(rest, token), token);
20861
21509
  seenDigits = true;
20862
21510
  break;
20863
21511
  case "--separator":
20864
- separator = requireValue3(rest, token);
21512
+ separator = requireValue4(rest, token);
20865
21513
  seenSeparator = true;
20866
21514
  break;
20867
21515
  default:
@@ -20904,7 +21552,7 @@ function parseCollectArgs(tokens) {
20904
21552
  const token = rest.shift();
20905
21553
  switch (token) {
20906
21554
  case "--endpoint":
20907
- options.endpoint = requireValue3(rest, token);
21555
+ options.endpoint = requireValue4(rest, token);
20908
21556
  break;
20909
21557
  case "--json":
20910
21558
  options.json = true;
@@ -20914,7 +21562,7 @@ function parseCollectArgs(tokens) {
20914
21562
  break;
20915
21563
  case "--thread":
20916
21564
  options.mode = "thread";
20917
- options.threadName = requireValue3(rest, token);
21565
+ options.threadName = requireValue4(rest, token);
20918
21566
  break;
20919
21567
  default:
20920
21568
  throw new Error(`Unknown collect option: ${token}`);
@@ -20925,7 +21573,7 @@ function parseCollectArgs(tokens) {
20925
21573
  }
20926
21574
  return { type: "collect" /* Collect */, ...options };
20927
21575
  }
20928
- function requireValue3(tokens, optionName) {
21576
+ function requireValue4(tokens, optionName) {
20929
21577
  const value = tokens.shift();
20930
21578
  if (!value) {
20931
21579
  throw new Error(`Missing value for ${optionName}`);
@@ -21066,6 +21714,11 @@ async function main() {
21066
21714
  await handler.handle(commandArgs);
21067
21715
  return;
21068
21716
  }
21717
+ case "store" /* Store */: {
21718
+ const handler = new StoreCommandHandler();
21719
+ await handler.handle(commandArgs);
21720
+ return;
21721
+ }
21069
21722
  case "app" /* App */: {
21070
21723
  const handler = new AppCommandHandler();
21071
21724
  await handler.handle(commandArgs);