@wirecat/cli-template 0.15.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.
Files changed (149) hide show
  1. package/.github/workflows/ci.yml +17 -0
  2. package/AGENTS.md +56 -2
  3. package/CHANGELOG.md +36 -0
  4. package/README.md +12 -4
  5. package/biome.json +2 -2
  6. package/contracts/mcp-tools.json +2 -2
  7. package/dist/bin/clidev.js +2 -2
  8. package/dist/bundle/{chunk-LU4A2T7Y.js → all-profiles-FS7AEOE7.js} +8 -5
  9. package/dist/bundle/{anthropic-ICTW7CNQ.js → anthropic-5RN7BGDI.js} +3 -3
  10. package/dist/bundle/{app-server-OW5LT5XV.js → app-server-WGTKZQKJ.js} +28 -29
  11. package/dist/bundle/{bun-sqlite-JE6FJFQT.js → bun-sqlite-WK2IGBGD.js} +2 -2
  12. package/dist/bundle/{chunk-AS2PJNQ2.js → chunk-2MWNE4L3.js} +1 -1
  13. package/dist/bundle/{chunk-2DAXUNTS.js → chunk-5HHIPDNW.js} +1 -1
  14. package/dist/bundle/{chunk-YOJLIVGO.js → chunk-5KAYQKBK.js} +1 -1
  15. package/dist/bundle/{chunk-62JRF2JA.js → chunk-6WOJIAYA.js} +1 -1
  16. package/dist/bundle/chunk-7EUX7AZV.js +141 -0
  17. package/dist/bundle/{chunk-7F5VMLVK.js → chunk-ADFSSIV4.js} +1 -1
  18. package/dist/bundle/{chunk-U6QD3J3F.js → chunk-ATHZEV2Z.js} +2 -2
  19. package/dist/bundle/{chunk-7UPBPE3Z.js → chunk-BPMKAZSS.js} +8 -8
  20. package/dist/bundle/{chunk-DZLHY4IA.js → chunk-C3GNOEJP.js} +1 -1
  21. package/dist/bundle/{chunk-PIJUGF5F.js → chunk-CTBHQRX6.js} +1 -1
  22. package/dist/bundle/{chunk-LFLSV353.js → chunk-DEHBTFIC.js} +1 -1
  23. package/dist/bundle/{chunk-NVNUUHT5.js → chunk-EA3TMI4A.js} +8 -8
  24. package/dist/bundle/{chunk-5GTMQTQH.js → chunk-EILS4BTQ.js} +16 -18
  25. package/dist/bundle/{chunk-EX2FV7YJ.js → chunk-ENDBOYQR.js} +14 -14
  26. package/dist/bundle/{chunk-6AW4DDK4.js → chunk-ETJXPB6A.js} +1 -1
  27. package/dist/bundle/{chunk-LATYBJ4T.js → chunk-FMO6F5Q2.js} +1 -1
  28. package/dist/bundle/{chunk-VVGPAHUN.js → chunk-HTYLT6ME.js} +23 -7
  29. package/dist/bundle/{chunk-F34HGYWF.js → chunk-JFXWLQ2L.js} +1 -1
  30. package/dist/bundle/{chunk-KLFYY7KC.js → chunk-JJZCPBH3.js} +6 -6
  31. package/dist/bundle/{chunk-G7W53MQP.js → chunk-LRHX62ZF.js} +2 -2
  32. package/dist/bundle/{chunk-SOYOOU2D.js → chunk-MBBOINK4.js} +2 -2
  33. package/dist/bundle/{chunk-NRZV7K4M.js → chunk-MEXT6XDP.js} +2 -2
  34. package/dist/bundle/{chunk-R2JKPHH5.js → chunk-NVPWZF67.js} +1 -1
  35. package/dist/bundle/{chunk-45244QQ6.js → chunk-OF56L2JU.js} +2 -2
  36. package/dist/bundle/{chunk-4MU2UM4C.js → chunk-OGTRPW2K.js} +3 -3
  37. package/dist/bundle/{chunk-VXOR76ZL.js → chunk-ORV4EGNC.js} +1 -1
  38. package/dist/bundle/{chunk-TJJ2XSJP.js → chunk-QGOOPPEW.js} +2 -2
  39. package/dist/bundle/{chunk-NH6LZ3H3.js → chunk-RFJKNFVF.js} +3 -3
  40. package/dist/bundle/{chunk-R5RYPD23.js → chunk-RYOAQCVJ.js} +1 -1
  41. package/dist/bundle/{chunk-66VMJGV6.js → chunk-SKBRW5U3.js} +1 -1
  42. package/dist/bundle/{chunk-NG7MOJBT.js → chunk-TXHCL75B.js} +43 -6
  43. package/dist/bundle/{chunk-FC53WQHG.js → chunk-VPCXYY46.js} +1 -1
  44. package/dist/bundle/{chunk-IOJ2DTCY.js → chunk-WDWP5N6M.js} +2 -0
  45. package/dist/bundle/{chunk-NVGOHYTE.js → chunk-WM5AMTRY.js} +4 -4
  46. package/dist/bundle/{chunk-MWUHBEDN.js → chunk-YNROUY3R.js} +10 -10
  47. package/dist/bundle/{chunk-DQIBGCF3.js → chunk-Z5NL6YNU.js} +2 -2
  48. package/dist/bundle/{chunk-GHF72SHT.js → chunk-ZSY4WAGI.js} +28 -21
  49. package/dist/bundle/clidev.js +3 -3
  50. package/dist/bundle/{command-contract-3MPKXBVL.js → command-contract-ZDU73EPH.js} +9 -9
  51. package/dist/bundle/{decode-NXB5UKMO.js → decode-QMLOGZ6R.js} +2 -2
  52. package/dist/bundle/{embed-IKZ24BMC.js → embed-PIR2LJR2.js} +4 -4
  53. package/dist/bundle/{embedder-GMQ24DOQ.js → embedder-6KBRPAEQ.js} +4 -4
  54. package/dist/bundle/{first-run-PURIGDLD.js → first-run-JO3CMY3Z.js} +7 -7
  55. package/dist/bundle/{first-screen-B2CF2CET.js → first-screen-3T5IXTFL.js} +10 -10
  56. package/dist/bundle/{node-sqlite-73Z4SFOA.js → node-sqlite-LIK6OYNF.js} +2 -2
  57. package/dist/bundle/{oauth-EVTPAMZP.js → oauth-7FVF7HQQ.js} +4 -4
  58. package/dist/bundle/{open-46WZAPJ3.js → open-CRZDEATN.js} +2 -2
  59. package/dist/bundle/{openai-GWRDAHDU.js → openai-WAJ6WREQ.js} +11 -32
  60. package/dist/bundle/{program-37NVH5YJ.js → program-ZFFFPBRS.js} +2251 -291
  61. package/dist/bundle/{prompt-IVEYRLS5.js → prompt-QQIVHO3M.js} +3 -3
  62. package/dist/bundle/{recognize-WVEKHODM.js → recognize-4KLBZDEC.js} +2 -2
  63. package/dist/bundle/{remote-4K5VPMC7.js → remote-BABMZTHA.js} +5 -5
  64. package/dist/bundle/{rerank-V24UJZYJ.js → rerank-P3IQQJIL.js} +4 -4
  65. package/dist/bundle/{chunk-EMHCXXNJ.js → serve-25SSAKRZ.js} +6 -4
  66. package/dist/bundle/server-G4GCDMYI.js +52 -0
  67. package/dist/bundle/{chunk-KJ3UADR3.js → server-P4XUYY5A.js} +27 -7
  68. package/dist/bundle/{state-ZPYGECVP.js → state-QCQALQBJ.js} +3 -3
  69. package/dist/bundle/{store-6JQCLPQF.js → store-ZECPRGGH.js} +7 -7
  70. package/dist/bundle/store-maintenance-command-ECUO5G6L.js +42 -0
  71. package/dist/commands/comments.d.ts +3 -0
  72. package/dist/commands/comments.d.ts.map +1 -0
  73. package/dist/commands/comments.js +114 -0
  74. package/dist/commands/comments.js.map +1 -0
  75. package/dist/commands/session.d.ts +3 -0
  76. package/dist/commands/session.d.ts.map +1 -0
  77. package/dist/commands/session.js +96 -0
  78. package/dist/commands/session.js.map +1 -0
  79. package/dist/context.d.ts +83 -0
  80. package/dist/context.d.ts.map +1 -0
  81. package/dist/context.js +58 -0
  82. package/dist/context.js.map +1 -0
  83. package/dist/program.d.ts.map +1 -1
  84. package/dist/program.js +24 -4
  85. package/dist/program.js.map +1 -1
  86. package/dist/sample/comments.d.ts +61 -0
  87. package/dist/sample/comments.d.ts.map +1 -0
  88. package/dist/sample/comments.js +39 -0
  89. package/dist/sample/comments.js.map +1 -0
  90. package/dist/sample/transport.d.ts +42 -0
  91. package/dist/sample/transport.d.ts.map +1 -0
  92. package/dist/sample/transport.js +152 -0
  93. package/dist/sample/transport.js.map +1 -0
  94. package/dist/token.d.ts +16 -0
  95. package/dist/token.d.ts.map +1 -0
  96. package/dist/token.js +32 -0
  97. package/dist/token.js.map +1 -0
  98. package/dist/version.d.ts +1 -1
  99. package/dist/version.js +1 -1
  100. package/docs/commands.md +234 -12
  101. package/docs/configuration.md +1 -1
  102. package/docs/dev/reference-clis.md +3 -2
  103. package/docs/dev/test-matrix.md +36 -5
  104. package/docs/index.md +4 -3
  105. package/docs/security.md +4 -2
  106. package/kit/dist/new.js +6 -3
  107. package/lint/overrides.json +9 -1
  108. package/package.json +3 -4
  109. package/scripts/test-matrix-untested.ts +19 -0
  110. package/skills/clidev-cli/SKILL.md +1 -1
  111. package/src/commands/comments.ts +167 -0
  112. package/src/commands/session.ts +144 -0
  113. package/src/comments.test.ts +258 -0
  114. package/src/context.ts +78 -0
  115. package/src/mcp.test.ts +71 -76
  116. package/src/program.test.ts +9 -16
  117. package/src/program.ts +28 -4
  118. package/src/sample/comments.ts +51 -0
  119. package/src/sample/transport.test.ts +117 -0
  120. package/src/sample/transport.ts +184 -0
  121. package/src/testing/fake-comments.ts +167 -0
  122. package/src/testing/harness.ts +51 -0
  123. package/src/token.ts +42 -0
  124. package/src/version.ts +1 -1
  125. package/dist/bundle/all-profiles-NVB2HT2S.js +0 -24
  126. package/dist/bundle/chunk-GUFPQZUA.js +0 -48
  127. package/dist/bundle/chunk-NL2DQPT7.js +0 -2
  128. package/dist/bundle/mcp-ASNYBQ5B.js +0 -152
  129. package/dist/bundle/mcp-EY2NUYDQ.js +0 -82
  130. package/dist/bundle/serve-PJWSOV7F.js +0 -19
  131. package/dist/bundle/server-3TPCEZ6P.js +0 -40
  132. package/dist/bundle/server-GQX5MZTT.js +0 -53
  133. package/dist/bundle/store-maintenance-command-ND4ADMGC.js +0 -42
  134. package/dist/commands/doctor.d.ts +0 -77
  135. package/dist/commands/doctor.d.ts.map +0 -1
  136. package/dist/commands/doctor.js +0 -74
  137. package/dist/commands/doctor.js.map +0 -1
  138. package/dist/commands/mcp.d.ts +0 -3
  139. package/dist/commands/mcp.d.ts.map +0 -1
  140. package/dist/commands/mcp.js +0 -97
  141. package/dist/commands/mcp.js.map +0 -1
  142. package/dist/mcp.d.ts +0 -29
  143. package/dist/mcp.d.ts.map +0 -1
  144. package/dist/mcp.js +0 -98
  145. package/dist/mcp.js.map +0 -1
  146. package/src/commands/doctor.ts +0 -86
  147. package/src/commands/mcp.ts +0 -130
  148. package/src/mcp-http.test.ts +0 -172
  149. package/src/mcp.ts +0 -140
@@ -1,5 +1,10 @@
1
1
  import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ providerWaitMs,
5
+ readJsonResponse,
6
+ statusToCode
7
+ } from "./chunk-7EUX7AZV.js";
3
8
  import {
4
9
  listen
5
10
  } from "./chunk-NENYWEXF.js";
@@ -25,11 +30,14 @@ import {
25
30
  historyLimitGaps,
26
31
  historySkipsOf,
27
32
  keepRefreshedRefs,
33
+ mcpUrlOf,
28
34
  meaningNote,
29
35
  messagesAnswer,
30
36
  notesAnswer,
31
37
  officialAnswer,
32
38
  offsetOf,
39
+ portOf,
40
+ publicUrlOf,
33
41
  rankingAnswer,
34
42
  readsStdin,
35
43
  refreshAnswer,
@@ -44,12 +52,7 @@ import {
44
52
  syncsFirst,
45
53
  taskStatsAnswer,
46
54
  waitingAnswer
47
- } from "./chunk-NG7MOJBT.js";
48
- import {
49
- mcpUrlOf,
50
- portOf,
51
- publicUrlOf
52
- } from "./chunk-GUFPQZUA.js";
55
+ } from "./chunk-TXHCL75B.js";
53
56
  import "./chunk-YIVY2WI3.js";
54
57
  import {
55
58
  INPUT_FIELD_REASONS,
@@ -63,7 +66,7 @@ import {
63
66
  skillStatus,
64
67
  skillVersion,
65
68
  withVersion
66
- } from "./chunk-NVGOHYTE.js";
69
+ } from "./chunk-WM5AMTRY.js";
67
70
  import {
68
71
  DAY_MS,
69
72
  DRY_RUN_DAYS,
@@ -103,7 +106,7 @@ import {
103
106
  writeRepliesFile,
104
107
  writeRepliesState,
105
108
  writeReplyConsent
106
- } from "./chunk-EX2FV7YJ.js";
109
+ } from "./chunk-ENDBOYQR.js";
107
110
  import {
108
111
  DEFAULT_PACE,
109
112
  FloodMemory,
@@ -113,6 +116,7 @@ import {
113
116
  answerOf,
114
117
  commandPermissions,
115
118
  floodPathFor,
119
+ guardFor,
116
120
  holdEnd,
117
121
  knownBeside,
118
122
  knownPermissionKeys,
@@ -125,7 +129,7 @@ import {
125
129
  sendsPathFor,
126
130
  terminalAsker,
127
131
  unknownPermissionIssues
128
- } from "./chunk-KLFYY7KC.js";
132
+ } from "./chunk-JJZCPBH3.js";
129
133
  import {
130
134
  ADMIN_RIGHTS,
131
135
  AGENDA_QUERY,
@@ -190,6 +194,7 @@ import {
190
194
  chatShown,
191
195
  checkMediaArchive,
192
196
  closedStateOf,
197
+ commandPath,
193
198
  communicationFields,
194
199
  contactAnswer,
195
200
  contactShown,
@@ -299,36 +304,36 @@ import {
299
304
  withQuery,
300
305
  withoutPhone,
301
306
  wrongAccount
302
- } from "./chunk-GHF72SHT.js";
307
+ } from "./chunk-ZSY4WAGI.js";
303
308
  import {
304
309
  acquireLock,
305
310
  readBoundedUtf8File,
306
311
  syncDirectory,
307
312
  writeFileAtomic
308
- } from "./chunk-PIJUGF5F.js";
313
+ } from "./chunk-CTBHQRX6.js";
309
314
  import {
310
315
  readSecret
311
- } from "./chunk-G7W53MQP.js";
316
+ } from "./chunk-LRHX62ZF.js";
312
317
  import {
313
318
  MAX_BUFFERED_INPUT,
314
319
  bufferedInput,
315
320
  provideInputPolicy
316
- } from "./chunk-2DAXUNTS.js";
321
+ } from "./chunk-5HHIPDNW.js";
317
322
  import {
318
323
  commandsText,
319
324
  installHelp
320
- } from "./chunk-4MU2UM4C.js";
325
+ } from "./chunk-OGTRPW2K.js";
321
326
  import "./chunk-HTQTIKWP.js";
322
327
  import {
323
328
  setupAtStart
324
- } from "./chunk-MWUHBEDN.js";
329
+ } from "./chunk-YNROUY3R.js";
325
330
  import {
326
331
  installerOf,
327
332
  isNewer,
328
333
  latestVersion,
329
334
  runUpdate,
330
335
  updateNotice
331
- } from "./chunk-AS2PJNQ2.js";
336
+ } from "./chunk-2MWNE4L3.js";
332
337
  import "./chunk-7Z4HR6GO.js";
333
338
  import {
334
339
  httpLaunchFile,
@@ -338,23 +343,23 @@ import {
338
343
  readHttpLaunch,
339
344
  readHttpLock,
340
345
  signedInClients
341
- } from "./chunk-6AW4DDK4.js";
346
+ } from "./chunk-ETJXPB6A.js";
342
347
  import {
343
348
  lockPath,
344
349
  readLock
345
- } from "./chunk-DZLHY4IA.js";
350
+ } from "./chunk-C3GNOEJP.js";
346
351
  import {
347
352
  isLocal,
348
353
  remoteModel
349
- } from "./chunk-SOYOOU2D.js";
350
- import "./chunk-R5RYPD23.js";
351
- import "./chunk-LATYBJ4T.js";
354
+ } from "./chunk-MBBOINK4.js";
355
+ import "./chunk-RYOAQCVJ.js";
356
+ import "./chunk-FMO6F5Q2.js";
352
357
  import {
353
358
  SCHEMA_DIALECT,
354
359
  commandContract,
355
360
  commandPathOf,
356
361
  findCommand
357
- } from "./chunk-NRZV7K4M.js";
362
+ } from "./chunk-MEXT6XDP.js";
358
363
  import {
359
364
  AUTHORITY_KEY,
360
365
  Argument,
@@ -423,6 +428,7 @@ import {
423
428
  commandWords,
424
429
  contact,
425
430
  contactNote,
431
+ currentAttempt,
426
432
  describeOptions,
427
433
  describeProgram,
428
434
  destroysNothing,
@@ -466,6 +472,7 @@ import {
466
472
  listJobs,
467
473
  listOf,
468
474
  listRuns,
475
+ logsInOrOut,
469
476
  mailHolderVariable,
470
477
  meetingPreparation,
471
478
  meetingProjectCandidates,
@@ -486,6 +493,7 @@ import {
486
493
  printItem,
487
494
  processRun,
488
495
  profileFree,
496
+ profilesHere,
489
497
  provide,
490
498
  reachesOtherService,
491
499
  reaction,
@@ -500,15 +508,18 @@ import {
500
508
  recordLogFor,
501
509
  recorded,
502
510
  recordedRun,
511
+ refuseCommandName,
503
512
  refuseJoinedPath,
504
513
  refuseUnderReadOnly,
505
514
  registryProfiles,
515
+ rememberAccount,
506
516
  removeJob,
507
517
  renderAnswer,
508
518
  renderDocument,
509
519
  repairConfigText,
510
520
  rootOf,
511
521
  rootOf2,
522
+ runEvent,
512
523
  runnable,
513
524
  runsDirFor,
514
525
  runtime,
@@ -545,7 +556,7 @@ import {
545
556
  wasSettled,
546
557
  withLines,
547
558
  withoutProviderRefs
548
- } from "./chunk-VVGPAHUN.js";
559
+ } from "./chunk-HTYLT6ME.js";
549
560
  import {
550
561
  agentOf,
551
562
  isCliFailure,
@@ -554,8 +565,8 @@ import {
554
565
  providerErrorKey,
555
566
  runContextOf,
556
567
  secretInput
557
- } from "./chunk-VXOR76ZL.js";
558
- import "./chunk-U6QD3J3F.js";
568
+ } from "./chunk-ORV4EGNC.js";
569
+ import "./chunk-ATHZEV2Z.js";
559
570
  import {
560
571
  alive,
561
572
  carries
@@ -564,7 +575,7 @@ import {
564
575
  IDENTITY,
565
576
  PACKAGE,
566
577
  SKILL
567
- } from "./chunk-FC53WQHG.js";
578
+ } from "./chunk-VPCXYY46.js";
568
579
  import {
569
580
  ACCOUNT_GROUPS_SETTING,
570
581
  ATTACHMENT_LIMIT_ENV,
@@ -599,11 +610,11 @@ import {
599
610
  savedTaskCategories,
600
611
  stemmersOrigin,
601
612
  titlePart
602
- } from "./chunk-NVNUUHT5.js";
613
+ } from "./chunk-EA3TMI4A.js";
603
614
  import {
604
615
  DEFAULT_STEMMERS,
605
616
  parseStemmers
606
- } from "./chunk-R2JKPHH5.js";
617
+ } from "./chunk-NVPWZF67.js";
607
618
  import {
608
619
  PRIORITY_LABELS,
609
620
  SAVE_HELP,
@@ -626,7 +637,7 @@ import {
626
637
  validateQuery,
627
638
  walkQuery,
628
639
  zonedTime
629
- } from "./chunk-YOJLIVGO.js";
640
+ } from "./chunk-5KAYQKBK.js";
630
641
  import "./chunk-3WDYHOAF.js";
631
642
  import {
632
643
  DEFAULT_TASK_CATEGORIES,
@@ -638,16 +649,16 @@ import {
638
649
  unlistedNote,
639
650
  withTaskCategory,
640
651
  writeTaskCategoryEdits
641
- } from "./chunk-TJJ2XSJP.js";
652
+ } from "./chunk-QGOOPPEW.js";
642
653
  import {
643
654
  openCache
644
- } from "./chunk-NH6LZ3H3.js";
655
+ } from "./chunk-RFJKNFVF.js";
645
656
  import "./chunk-3MDNAYQA.js";
646
657
  import "./chunk-CGFQT3LQ.js";
647
658
  import {
648
659
  isTextModelInstalled,
649
660
  textModelsDirectory
650
- } from "./chunk-DQIBGCF3.js";
661
+ } from "./chunk-Z5NL6YNU.js";
651
662
  import {
652
663
  DEFAULT_ORDER,
653
664
  OPENAI_TRANSCRIBE_MODEL,
@@ -661,10 +672,10 @@ import {
661
672
  orderedModels,
662
673
  speechModel,
663
674
  vadPath
664
- } from "./chunk-45244QQ6.js";
675
+ } from "./chunk-OF56L2JU.js";
665
676
  import {
666
677
  storePath
667
- } from "./chunk-62JRF2JA.js";
678
+ } from "./chunk-6WOJIAYA.js";
668
679
  import {
669
680
  BATCH_LIMITS,
670
681
  COMPACT_FLAG,
@@ -706,6 +717,7 @@ import {
706
717
  pipe,
707
718
  prepareBatch,
708
719
  processStreams,
720
+ realSleep,
709
721
  record,
710
722
  regex,
711
723
  renderError,
@@ -719,9 +731,10 @@ import {
719
731
  union,
720
732
  unknown,
721
733
  visibleControls,
734
+ wallClock,
722
735
  writeSecurely,
723
736
  writes
724
- } from "./chunk-IOJ2DTCY.js";
737
+ } from "./chunk-WDWP5N6M.js";
725
738
  import "./chunk-Y5E2WNWB.js";
726
739
  import {
727
740
  __name
@@ -1367,16 +1380,16 @@ var guardedApp = /* @__PURE__ */ __name(async (guard, connection, { chat: chat2,
1367
1380
  }, "guardedApp");
1368
1381
 
1369
1382
  // node_modules/.pnpm/@wirecat+cli-core@0.584.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_ab8c0b68b8b4768d5b87d6e249ef10da/node_modules/@wirecat/cli-core/dist/sends/polls.js
1370
- var pollVoters = /* @__PURE__ */ __name(async (connection, { chat: chat2, message: message2, answer: answer2, limit }) => {
1383
+ var pollVoters = /* @__PURE__ */ __name(async (connection, { chat: chat2, message: message2, answer: answer3, limit }) => {
1371
1384
  const voters = capability(connection, "pollVoters", "list who voted");
1372
1385
  const read3 = capability(connection, "poll", "read a poll");
1373
1386
  const { id: chatId } = await connection.resolve(chat2);
1374
1387
  const poll = await read3(chatId, message2);
1375
1388
  if (poll.anonymous)
1376
1389
  throw new CliError("validation_error", "nobody can see who voted in an anonymous poll");
1377
- if (answer2 !== void 0 && !poll.answers.some((one) => one.id === answer2))
1378
- throw new CliError("validation_error", `the poll has no answer ${answer2}; \`polls show\` prints their ids`);
1379
- const page = await voters(chatId, message2, { limit, ...answer2 === void 0 ? {} : { answerId: answer2 } });
1390
+ if (answer3 !== void 0 && !poll.answers.some((one) => one.id === answer3))
1391
+ throw new CliError("validation_error", `the poll has no answer ${answer3}; \`polls show\` prints their ids`);
1392
+ const page = await voters(chatId, message2, { limit, ...answer3 === void 0 ? {} : { answerId: answer3 } });
1380
1393
  return { chatId, messageId: message2, ...page };
1381
1394
  }, "pollVoters");
1382
1395
  var guardedVote = /* @__PURE__ */ __name(async (guard, connection, { chat: chat2, message: message2, answers }) => {
@@ -1525,12 +1538,12 @@ var priced = /* @__PURE__ */ __name((argv) => {
1525
1538
  }, "priced");
1526
1539
  var reportOf = /* @__PURE__ */ __name((stdout) => {
1527
1540
  try {
1528
- const answer2 = JSON.parse(stdout.toString("utf8"));
1529
- if (answer2?.type !== "result")
1541
+ const answer3 = JSON.parse(stdout.toString("utf8"));
1542
+ if (answer3?.type !== "result")
1530
1543
  return { text: stdout };
1531
1544
  return {
1532
- text: typeof answer2.result === "string" ? Buffer.from(answer2.result) : stdout,
1533
- ...typeof answer2.total_cost_usd === "number" ? { costUsd: answer2.total_cost_usd } : {}
1545
+ text: typeof answer3.result === "string" ? Buffer.from(answer3.result) : stdout,
1546
+ ...typeof answer3.total_cost_usd === "number" ? { costUsd: answer3.total_cost_usd } : {}
1534
1547
  };
1535
1548
  } catch {
1536
1549
  return { text: stdout };
@@ -1583,9 +1596,9 @@ var shortTime = /* @__PURE__ */ __name((iso) => {
1583
1596
  const two = /* @__PURE__ */ __name((n2) => String(n2).padStart(2, "0"), "two");
1584
1597
  return `${at2.getFullYear()}-${two(at2.getMonth() + 1)}-${two(at2.getDate())} ${two(at2.getHours())}:${two(at2.getMinutes())}`;
1585
1598
  }, "shortTime");
1586
- var failingNotice = /* @__PURE__ */ __name((command, runs, statusCommand3) => {
1599
+ var failingNotice = /* @__PURE__ */ __name((command, runs, statusCommand4) => {
1587
1600
  const lines2 = runs.flatMap(({ job: job2, last }) => last && last.exitCode !== 0 ? [
1588
- `${command}: scheduled ${job2} failing since ${shortTime(last.failingSince ?? last.at)} (${last.failures ?? 1} run${(last.failures ?? 1) === 1 ? "" : "s"})${last.reason ? `: ${last.reason}` : ""} \u2014 ${statusCommand3}`
1601
+ `${command}: scheduled ${job2} failing since ${shortTime(last.failingSince ?? last.at)} (${last.failures ?? 1} run${(last.failures ?? 1) === 1 ? "" : "s"})${last.reason ? `: ${last.reason}` : ""} \u2014 ${statusCommand4}`
1589
1602
  ] : []);
1590
1603
  return lines2.length ? lines2.join("\n") : void 0;
1591
1604
  }, "failingNotice");
@@ -2618,7 +2631,7 @@ var runOnce = /* @__PURE__ */ __name(async (argv, definition2, options) => {
2618
2631
  forEachCommand(program, (child) => child.exitOverride());
2619
2632
  const profiled = liftProfile(argv, commandWords(program), valuedOptions(program));
2620
2633
  const { profile } = profiled;
2621
- const lifted = options.agent ? profiled.rest : liftOptionsAfterDashes(profiled.rest, (words3) => commandAt(program, commandPath(program, words3)));
2634
+ const lifted = options.agent ? profiled.rest : liftOptionsAfterDashes(profiled.rest, (words3) => commandAt(program, commandPath2(program, words3)));
2622
2635
  const liftedEnd = lifted.indexOf("--");
2623
2636
  const liftedFlags = lifted.slice(0, liftedEnd < 0 ? void 0 : liftedEnd);
2624
2637
  machine ||= isMachine(liftedFlags);
@@ -2627,22 +2640,22 @@ var runOnce = /* @__PURE__ */ __name(async (argv, definition2, options) => {
2627
2640
  try {
2628
2641
  for (const words3 of [flags, liftedFlags])
2629
2642
  refuseJoinedPath(program, words3.filter((word) => !word.startsWith("-")), profile !== void 0 && !/\s/.test(profile) ? [profile] : []);
2630
- } catch (failure3) {
2631
- const settled = await settleFailure(failure3, { definition: definition2, program, rest: lifted, argv, profile, options });
2632
- return report(streams, reporting, failed(definition2, program, lifted, failure3, settled, debug));
2643
+ } catch (failure2) {
2644
+ const settled = await settleFailure(failure2, { definition: definition2, program, rest: lifted, argv, profile, options });
2645
+ return report(streams, reporting, failed(definition2, program, lifted, failure2, settled, debug));
2633
2646
  }
2634
2647
  if (profile !== void 0)
2635
2648
  program.setOptionValue("profile", profile);
2636
- const requested = liftJson(lifted, (words3) => commandAt(program, commandPath(program, words3)));
2649
+ const requested = liftJson(lifted, (words3) => commandAt(program, commandPath2(program, words3)));
2637
2650
  const rest = requested.argv;
2638
2651
  if (requested.fields !== void 0)
2639
2652
  program.setOptionValue("fields", requested.fields);
2640
2653
  if (profile !== void 0 && rest.length === 0) {
2641
2654
  const asProfile = commandAt(program, "account show") && isProfileName(profile) ? `, or \`${command} ${profile} account show\` if "${profile}" is your profile` : "";
2642
2655
  const message2 = `"${profile}" is not a command, so it was read as a profile name \u2014 and no command followed it. Run \`${command} --help\` for the commands${asProfile}.`;
2643
- const failure3 = new CliError("validation_error", message2, { param: "profile" });
2644
- const settled = await settleFailure(failure3, { definition: definition2, program, rest, argv, profile, options });
2645
- return report(streams, reporting, failed(definition2, program, rest, failure3, settled, debug));
2656
+ const failure2 = new CliError("validation_error", message2, { param: "profile" });
2657
+ const settled = await settleFailure(failure2, { definition: definition2, program, rest, argv, profile, options });
2658
+ return report(streams, reporting, failed(definition2, program, rest, failure2, settled, debug));
2646
2659
  }
2647
2660
  try {
2648
2661
  await control.race(() => program.parseAsync(rest, { from: "user" }));
@@ -2674,16 +2687,16 @@ var runOnce = /* @__PURE__ */ __name(async (argv, definition2, options) => {
2674
2687
  streams.diagnostic(help.replace(/\n$/, ""));
2675
2688
  return exitCodeFor("validation_error");
2676
2689
  }
2677
- const group = commandPath(program, rest);
2690
+ const group = commandPath2(program, rest);
2678
2691
  message2 = `give a command \u2014 run \`${[command, group, "--help"].filter(Boolean).join(" ")}\` for the commands`;
2679
2692
  }
2680
2693
  if (profile !== void 0 && error.code === "commander.unknownCommand" && rest[0] !== void 0 && !commandWords(program).has(rest[0])) {
2681
2694
  message2 = message2.trimEnd();
2682
2695
  message2 += ` \u2014 "${profile}" is not a command, so it was read as a profile name \u2014 which left "${rest[0]}" to be one.`;
2683
2696
  }
2684
- const failure3 = new CliError("validation_error", message2);
2685
- const settled2 = await settleFailure(failure3, { definition: definition2, program, rest, argv, profile, options });
2686
- return report(streams, reporting, failed(definition2, program, rest, failure3, settled2, debug));
2697
+ const failure2 = new CliError("validation_error", message2);
2698
+ const settled2 = await settleFailure(failure2, { definition: definition2, program, rest, argv, profile, options });
2699
+ return report(streams, reporting, failed(definition2, program, rest, failure2, settled2, debug));
2687
2700
  }
2688
2701
  const settled = await settleFailure(error, { definition: definition2, program, rest, argv, profile, options });
2689
2702
  const exit2 = report(streams, reporting, failed(definition2, program, rest, error, settled, debug));
@@ -2747,17 +2760,17 @@ var hintFor = /* @__PURE__ */ __name(({ app, configuration: configuration2 }, ar
2747
2760
  const statePath = join3(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "update-check.json");
2748
2761
  return skillHint({ app, argv, env, statePath, enabled });
2749
2762
  }, "hintFor");
2750
- var settleFailure = /* @__PURE__ */ __name(async (failure3, state) => {
2763
+ var settleFailure = /* @__PURE__ */ __name(async (failure2, state) => {
2751
2764
  let timer;
2752
2765
  let settlementFailed;
2753
2766
  try {
2754
2767
  const settle = (async () => {
2755
2768
  try {
2756
- await state.definition.onFailure?.(failure3, state.program);
2769
+ await state.definition.onFailure?.(failure2, state.program);
2757
2770
  } catch {
2758
2771
  settlementFailed = true;
2759
2772
  }
2760
- await keepFailure(failure3, state);
2773
+ await keepFailure(failure2, state);
2761
2774
  })();
2762
2775
  await Promise.race([
2763
2776
  settle,
@@ -2773,11 +2786,11 @@ var settleFailure = /* @__PURE__ */ __name(async (failure3, state) => {
2773
2786
  clearTimeout(timer);
2774
2787
  }
2775
2788
  }, "settleFailure");
2776
- var keepFailure = /* @__PURE__ */ __name(async (failure3, { definition: definition2, program, rest, argv, profile, options }) => {
2777
- if (wasSettled(failure3))
2789
+ var keepFailure = /* @__PURE__ */ __name(async (failure2, { definition: definition2, program, rest, argv, profile, options }) => {
2790
+ if (wasSettled(failure2))
2778
2791
  return;
2779
2792
  const env = options.env ?? process.env;
2780
- const path = commandPath(program, program.args.length > 0 ? program.args : rest);
2793
+ const path = commandPath2(program, program.args.length > 0 ? program.args : rest);
2781
2794
  const { resolveSettings } = definition2.configuration ?? settingsFor(definition2.app);
2782
2795
  let settings;
2783
2796
  try {
@@ -2808,11 +2821,11 @@ var keepFailure = /* @__PURE__ */ __name(async (failure3, { definition: definiti
2808
2821
  ...settings ? { keepDays: settings.keepRunsForDays } : {},
2809
2822
  ...settings?.keepSuccessfulRunsForDays === void 0 ? {} : { keepSuccessDays: settings.keepSuccessfulRunsForDays }
2810
2823
  }, async () => {
2811
- throw failure3;
2824
+ throw failure2;
2812
2825
  }).catch(() => {
2813
2826
  });
2814
2827
  }, "keepFailure");
2815
- var commandPath = /* @__PURE__ */ __name((program, rest) => {
2828
+ var commandPath2 = /* @__PURE__ */ __name((program, rest) => {
2816
2829
  const words3 = [];
2817
2830
  let current = program;
2818
2831
  for (const token of rest) {
@@ -2826,19 +2839,19 @@ var commandPath = /* @__PURE__ */ __name((program, rest) => {
2826
2839
  }
2827
2840
  return words3.join(" ");
2828
2841
  }, "commandPath");
2829
- var budgetSteps = /* @__PURE__ */ __name((program, path, failure3) => {
2842
+ var budgetSteps = /* @__PURE__ */ __name((program, path, failure2) => {
2830
2843
  const command = path ? commandAt(program, path) : void 0;
2831
- if (!command || !(failure3 instanceof CliError) || failure3.details?.reason !== "output.too-large")
2844
+ if (!command || !(failure2 instanceof CliError) || failure2.details?.reason !== "output.too-large")
2832
2845
  return [];
2833
- const { max_bytes: maxBytes, needed_bytes: neededBytes } = failure3.details;
2846
+ const { max_bytes: maxBytes, needed_bytes: neededBytes } = failure2.details;
2834
2847
  return typeof maxBytes === "number" && typeof neededBytes === "number" ? tooLargeSteps(command, { maxBytes, neededBytes }) : [];
2835
2848
  }, "budgetSteps");
2836
2849
  var failed = /* @__PURE__ */ __name(({ app }, program, rest, error, settled, debug) => {
2837
- const path = commandPath(program, program.args.length > 0 ? program.args : rest);
2850
+ const path = commandPath2(program, program.args.length > 0 ? program.args : rest);
2838
2851
  const told = error instanceof NoProfileHere && !commandAt(program, "setup") ? error.withoutSetup(path) : error;
2839
- const failure3 = settled.settlementFailed && isCliFailure(told) ? new CliError(told.code, told.message, { ...told.details, settlement_failed: true }) : told;
2852
+ const failure2 = settled.settlementFailed && isCliFailure(told) ? new CliError(told.code, told.message, { ...told.details, settlement_failed: true }) : told;
2840
2853
  const effects = judgedEffects(path ? metaOf(commandAt(program, path) ?? program).effects : void 0);
2841
- const built = errorObjectOf(failure3, {
2854
+ const built = errorObjectOf(failure2, {
2842
2855
  ...failureContext(app.errors),
2843
2856
  targets: judgedTargets(program),
2844
2857
  ...effects ? { effects } : {}
@@ -2846,7 +2859,7 @@ var failed = /* @__PURE__ */ __name(({ app }, program, rest, error, settled, deb
2846
2859
  const { next: _named, ...said } = built.error;
2847
2860
  const steps = failureSteps(program, {
2848
2861
  ...built.error,
2849
- next: [...built.error.next ?? [], ...budgetSteps(program, path, failure3)]
2862
+ next: [...built.error.next ?? [], ...budgetSteps(program, path, failure2)]
2850
2863
  });
2851
2864
  const object2 = { ...built, error: { ...said, ...steps.length > 0 ? { next: steps } : {} } };
2852
2865
  showInputFields(object2, path && commandAt(program, path) || program);
@@ -2855,7 +2868,7 @@ var failed = /* @__PURE__ */ __name(({ app }, program, rest, error, settled, deb
2855
2868
  object: object2,
2856
2869
  cli: app.command,
2857
2870
  program,
2858
- ...debug ? { record: errorRecordOf(failure3, object2, { command, service: app.command, version: app.version }) } : {}
2871
+ ...debug ? { record: errorRecordOf(failure2, object2, { command, service: app.command, version: app.version }) } : {}
2859
2872
  };
2860
2873
  }, "failed");
2861
2874
  var report = /* @__PURE__ */ __name((streams, options, { object: object2, record: record2, cli, program }) => {
@@ -3257,11 +3270,11 @@ var reasonOf = /* @__PURE__ */ __name((error) => {
3257
3270
  return code;
3258
3271
  return error instanceof Error ? error.name : "an unknown problem";
3259
3272
  }, "reasonOf");
3260
- var quietly = /* @__PURE__ */ __name(async (write, warn) => {
3273
+ var quietly = /* @__PURE__ */ __name(async (write2, warn) => {
3261
3274
  let store;
3262
3275
  try {
3263
3276
  store = await openStore();
3264
- await write(store);
3277
+ await write2(store);
3265
3278
  return true;
3266
3279
  } catch (error) {
3267
3280
  warn(`the local copy was not updated: ${reasonOf(error)}`);
@@ -3888,6 +3901,35 @@ var PressLog = class {
3888
3901
  // node_modules/.pnpm/@wirecat+cli-core@0.584.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_ab8c0b68b8b4768d5b87d6e249ef10da/node_modules/@wirecat/cli-core/dist/cli/command-runs.js
3889
3902
  import { AsyncLocalStorage } from "node:async_hooks";
3890
3903
  var parses = new AsyncLocalStorage();
3904
+ var providerEvent = /* @__PURE__ */ __name((event) => {
3905
+ const parse3 = parses.getStore();
3906
+ if (parse3)
3907
+ parse3.runs.events(event);
3908
+ else
3909
+ runEvent(event);
3910
+ }, "providerEvent");
3911
+ var providerRequest = /* @__PURE__ */ __name((operation, sink = providerEvent, call = {}) => {
3912
+ const { bytes: sent, ...shape } = call;
3913
+ const wire = { operation, level: "wire", ...call.attempt === void 0 ? currentAttempt() : {}, ...shape };
3914
+ sink({ event: "request", ...wire, ...sent === void 0 ? {} : { bytes: sent } });
3915
+ const started = performance.now();
3916
+ return ({ status, error, errorCode, providerError, bytes, counts, ids } = {}) => {
3917
+ const failed2 = error !== void 0 || errorCode !== void 0;
3918
+ const key = providerErrorKey(providerError);
3919
+ sink({
3920
+ event: "response",
3921
+ ...wire,
3922
+ ...status === void 0 ? {} : { status },
3923
+ durationMs: Math.round(performance.now() - started),
3924
+ outcome: failed2 ? "error" : "ok",
3925
+ ...failed2 ? { errorCode: errorCode ?? (isCliError(error) ? error.code : "provider_error") } : {},
3926
+ ...key ? { providerError: key } : {},
3927
+ ...bytes === void 0 ? {} : { bytes },
3928
+ ...counts ? { counts } : {},
3929
+ ...ids ? { ids } : {}
3930
+ });
3931
+ };
3932
+ }, "providerRequest");
3891
3933
 
3892
3934
  // node_modules/.pnpm/@wirecat+cli-core@0.584.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_ab8c0b68b8b4768d5b87d6e249ef10da/node_modules/@wirecat/cli-core/dist/cli/discovery-descriptions.js
3893
3935
  var DISCOVERY_DESCRIPTIONS = Object.freeze({
@@ -4427,15 +4469,15 @@ var repairCommand = /* @__PURE__ */ __name((app, config2) => profileFree(grantsA
4427
4469
  const context = baseContext(this, (flags, options) => config2.resolveSettings(flags, { ...options, readOnly: true, needsProfile: false, withIssues: true }));
4428
4470
  const { settings, renderer, env } = context;
4429
4471
  const file = settings.configPath;
4430
- const answer2 = /* @__PURE__ */ __name((fields) => renderAnswer(this, context, itemOf({ file, found: existsSync7(file), dry_run: dryRun2, changes: [], backup: null, ...fields })), "answer");
4472
+ const answer3 = /* @__PURE__ */ __name((fields) => renderAnswer(this, context, itemOf({ file, found: existsSync7(file), dry_run: dryRun2, changes: [], backup: null, ...fields })), "answer");
4431
4473
  if (!existsSync7(file)) {
4432
- answer2({ repaired: false, reason: "no settings file" });
4474
+ answer3({ repaired: false, reason: "no settings file" });
4433
4475
  return;
4434
4476
  }
4435
4477
  const bytes = readFileSync6(file);
4436
4478
  const result = repairConfigText(bytes.toString("utf8"));
4437
4479
  if (result.state === "valid") {
4438
- answer2({ repaired: false, reason: "nothing to repair" });
4480
+ answer3({ repaired: false, reason: "nothing to repair" });
4439
4481
  return;
4440
4482
  }
4441
4483
  if (result.state === "refused")
@@ -4449,7 +4491,7 @@ var repairCommand = /* @__PURE__ */ __name((app, config2) => profileFree(grantsA
4449
4491
  writeSecurely(backup, bytes, statSync3(file).mode & 511);
4450
4492
  writeSecurely(file, result.text, 384);
4451
4493
  }
4452
- answer2({ repaired: !dryRun2, changes: result.fixes, backup });
4494
+ answer3({ repaired: !dryRun2, changes: result.fixes, backup });
4453
4495
  for (const one of result.fixes)
4454
4496
  renderer.note(`line ${one.line}: ${dryRun2 ? "would fix" : "fixed"} ${REPAIR_WORDS[one.kind]}`);
4455
4497
  if (backup)
@@ -4607,7 +4649,7 @@ var maskedRun = /* @__PURE__ */ __name((metadata, label, program = new Command()
4607
4649
  }
4608
4650
  } : {},
4609
4651
  ...partial2 ? {
4610
- partial: { ...partial2, failures: partial2.failures.map((failure3) => ({ ...failure3, id: label(failure3.id) })) }
4652
+ partial: { ...partial2, failures: partial2.failures.map((failure2) => ({ ...failure2, id: label(failure2.id) })) }
4611
4653
  } : {}
4612
4654
  };
4613
4655
  }, "maskedRun");
@@ -5235,7 +5277,7 @@ var serving = /* @__PURE__ */ __name((target, lock, now) => ({
5235
5277
  var clientLines = /* @__PURE__ */ __name((clients) => clients.length === 0 ? ["No browser app is logged in."] : [
5236
5278
  `Logged-in apps (names are what each app calls itself): ${clients.map((one) => `${one.claimedName === null ? "no name" : JSON.stringify(one.claimedName)} (${clock(one.lastLoginAt)}${one.lastTool && one.lastToolAt ? `; last call ${one.lastTool} at ${clock(one.lastToolAt)}, ${one.toolCallsToday} today` : ""})`).join(", ")}.`
5237
5279
  ], "clientLines");
5238
- var mcpServerCommand = /* @__PURE__ */ __name(({ example, defaultPort = MCP_HTTP_DEFAULT_PORT, permission = false, profiles = false, target, answer: answer2, system }) => {
5280
+ var mcpServerCommand = /* @__PURE__ */ __name(({ example, defaultPort = MCP_HTTP_DEFAULT_PORT, permission = false, profiles = false, target, answer: answer3, system }) => {
5239
5281
  const command = annotate(new Command("server"), { effects: LOCAL_READ, mcp: false }).summary("run the HTTP MCP server in the background").description("start, stop and check `mcp serve --http` in the background; status shows the login code for a browser app");
5240
5282
  const machine = /* @__PURE__ */ __name((self) => system?.(self) ?? thisMachine(), "machine");
5241
5283
  const start = destroysNothing(annotate(command.command("start"), {
@@ -5257,7 +5299,7 @@ var mcpServerCommand = /* @__PURE__ */ __name(({ example, defaultPort = MCP_HTTP
5257
5299
  const lockFile = httpLockFile(one.tokenFile);
5258
5300
  const before = readHttpLock(lockFile);
5259
5301
  if (before && alive(before.pid)) {
5260
- answer2(this, { ...named(one), started: false, running: true, ...serving(one, before, Date.now()) }, [
5302
+ answer3(this, { ...named(one), started: false, running: true, ...serving(one, before, Date.now()) }, [
5261
5303
  `Already serving ${shown(one)} over HTTP since ${clock(before.startedAt)} (PID ${before.pid}, port ${before.port}).`
5262
5304
  ]);
5263
5305
  return;
@@ -5284,7 +5326,7 @@ var mcpServerCommand = /* @__PURE__ */ __name(({ example, defaultPort = MCP_HTTP
5284
5326
  const now = readHttpLock(lockFile);
5285
5327
  if (now?.pid === pid && now.listeningAt) {
5286
5328
  const code = liveCode(now, Date.now());
5287
- answer2(this, { ...named(one), started: true, running: true, ...serving(one, now, Date.now()), log }, [
5329
+ answer3(this, { ...named(one), started: true, running: true, ...serving(one, now, Date.now()), log }, [
5288
5330
  `Started: serving ${shown(one)} over HTTP (PID ${pid}) on 127.0.0.1:${now.port}.`,
5289
5331
  `Browser apps connect to ${connectorUrl(now)}`,
5290
5332
  ...code ? [`Login code for a new browser app: ${code.code} (until ${clock(code.expires_at)}).`] : []
@@ -5304,7 +5346,7 @@ ${last}` : ""}`, { retryable: false });
5304
5346
  const one = target(this);
5305
5347
  const lock = readHttpLock(httpLockFile(one.tokenFile));
5306
5348
  if (!lock || !alive(lock.pid)) {
5307
- answer2(this, { ...named(one), stopped: false }, [
5349
+ answer3(this, { ...named(one), stopped: false }, [
5308
5350
  `Nothing to stop: ${shown(one)} is not serving MCP over HTTP.`
5309
5351
  ]);
5310
5352
  return;
@@ -5318,7 +5360,7 @@ ${last}` : ""}`, { retryable: false });
5318
5360
  await sys.pause();
5319
5361
  if (alive(lock.pid))
5320
5362
  throw new CliError("timeout", `mcp serve --http (PID ${lock.pid}) has not stopped yet`);
5321
- answer2(this, { ...named(one), stopped: true, pid: lock.pid }, [
5363
+ answer3(this, { ...named(one), stopped: true, pid: lock.pid }, [
5322
5364
  `Stopped serving ${shown(one)} over HTTP (PID ${lock.pid}).`
5323
5365
  ]);
5324
5366
  });
@@ -5333,7 +5375,7 @@ ${last}` : ""}`, { retryable: false });
5333
5375
  const running = lock !== void 0 && alive(lock.pid);
5334
5376
  const clients = signedInClients(one.tokenFile, now);
5335
5377
  const live = running ? serving(one, lock, now) : void 0;
5336
- answer2(this, {
5378
+ answer3(this, {
5337
5379
  ...named(one),
5338
5380
  running,
5339
5381
  ...live ?? {},
@@ -5417,11 +5459,11 @@ var messengerHost = /* @__PURE__ */ __name((messenger) => ({
5417
5459
  context: /* @__PURE__ */ __name((self, options) => messengerContext(self, messenger, options), "context"),
5418
5460
  permissionExample: "messages.send=deny",
5419
5461
  serveStdio: /* @__PURE__ */ __name(async (self, context) => {
5420
- const { serveOverStdio } = await import("./server-GQX5MZTT.js");
5462
+ const { serveOverStdio } = await import("./server-G4GCDMYI.js");
5421
5463
  await serveOverStdio(self, context, messenger, {});
5422
5464
  }, "serveStdio"),
5423
5465
  serveHttp: /* @__PURE__ */ __name(async (self, context, http) => {
5424
- const { serveOverHttpUntilStopped } = await import("./server-GQX5MZTT.js");
5466
+ const { serveOverHttpUntilStopped } = await import("./server-G4GCDMYI.js");
5425
5467
  await serveOverHttpUntilStopped(self, context, messenger, {}, http);
5426
5468
  }, "serveHttp"),
5427
5469
  instructions: /* @__PURE__ */ __name(async (profiles) => {
@@ -5481,7 +5523,7 @@ var mcpGroup = /* @__PURE__ */ __name((host) => {
5481
5523
  }).summary("forget every login given to a browser app").description("forget every login `mcp serve --http` gave a browser app, of this profile or of the server `--profiles` names; each app must log in again")).action(async function() {
5482
5524
  const context = host.context(this, { needsProfile: false });
5483
5525
  const served = servedProfiles(this, host, context, this.opts().profiles, "mcp revoke", "whose browser logins to forget");
5484
- const { revokeAll } = await import("./oauth-EVTPAMZP.js");
5526
+ const { revokeAll } = await import("./oauth-7FVF7HQQ.js");
5485
5527
  revokeAll(httpTokenFile(app, "set" in served ? served.set.key : served.profile, context.env));
5486
5528
  renderAnswer(this, context, itemOf("set" in served ? { revoked: true, profile: null, profiles: served.set.option } : { revoked: true, profile: served.profile }));
5487
5529
  }));
@@ -5651,8 +5693,8 @@ var serveProfiles = /* @__PURE__ */ __name(async (self, context, host, flags, se
5651
5693
  reaches: `the browser apps reach ${app.command}`,
5652
5694
  path: true
5653
5695
  });
5654
- const { serveAllProfilesOverHttp } = await import("./all-profiles-NVB2HT2S.js");
5655
- const { mcpHttpMarker: mcpHttpMarker2 } = await import("./state-ZPYGECVP.js");
5696
+ const { serveAllProfilesOverHttp } = await import("./all-profiles-FS7AEOE7.js");
5697
+ const { mcpHttpMarker: mcpHttpMarker2 } = await import("./state-QCQALQBJ.js");
5656
5698
  const port = portOf(flags.port, DEFAULT_PORT);
5657
5699
  const listening = await serveAllProfilesOverHttp(options, {
5658
5700
  publicUrl,
@@ -5675,7 +5717,7 @@ var serveProfiles = /* @__PURE__ */ __name(async (self, context, host, flags, se
5675
5717
  await listening.close();
5676
5718
  return;
5677
5719
  }
5678
- const { serveAllProfilesOverStdio } = await import("./all-profiles-NVB2HT2S.js");
5720
+ const { serveAllProfilesOverStdio } = await import("./all-profiles-FS7AEOE7.js");
5679
5721
  context.renderer.note(`serving ${profileSetLabel(set)} over MCP on stdin and stdout`);
5680
5722
  const { stdin, stdout, signal } = environmentOf(self);
5681
5723
  await serveAllProfilesOverStdio(options, {
@@ -5818,7 +5860,7 @@ var searchRuns = /* @__PURE__ */ __name((dir, { query = "", terms = [], status,
5818
5860
  for (const run3 of listRuns(dir, from === void 0 ? {} : { since: from })) {
5819
5861
  if (profile !== void 0 && run3.profile !== profile || status !== void 0 && run3.status !== status || from !== void 0 && Date.parse(run3.startedAt) < from || window2.until !== void 0 && Date.parse(run3.startedAt) > window2.until)
5820
5862
  continue;
5821
- const metadataMatch = (!errorCode || run3.errorCode === errorCode || run3.partial?.failures.some((failure3) => failure3.errorCode === errorCode)) && !operation && needles.every((needle) => JSON.stringify(run3).toLowerCase().includes(needle));
5863
+ const metadataMatch = (!errorCode || run3.errorCode === errorCode || run3.partial?.failures.some((failure2) => failure2.errorCode === errorCode)) && !operation && needles.every((needle) => JSON.stringify(run3).toLowerCase().includes(needle));
5822
5864
  const ruledOut = !metadataMatch && needles.length === 0 && (operation !== void 0 && run3.operations !== void 0 && !run3.operations.includes(operation) || errorCode !== void 0 && run3.codes !== void 0 && !run3.codes.includes(errorCode));
5823
5865
  if (ruledOut)
5824
5866
  continue;
@@ -6011,10 +6053,10 @@ You are the configured analysis provider. Do not execute CLI commands or ask for
6011
6053
  `, "analysisPrompt");
6012
6054
  var analysisAnswer = /* @__PURE__ */ __name((text2, model2) => {
6013
6055
  try {
6014
- const answer2 = JSON.parse(text2);
6015
- if (!answer2 || answer2.model !== model2 || answer2.skill !== "1" || !Array.isArray(answer2.answers) || !answer2.answers.length || answer2.answers.some((item) => !item || typeof item.message !== "string" || !(item.parent === null || typeof item.parent === "string") || typeof item.confidence !== "number" || !Number.isFinite(item.confidence) || item.confidence < 0 || item.confidence > 1))
6056
+ const answer3 = JSON.parse(text2);
6057
+ if (!answer3 || answer3.model !== model2 || answer3.skill !== "1" || !Array.isArray(answer3.answers) || !answer3.answers.length || answer3.answers.some((item) => !item || typeof item.message !== "string" || !(item.parent === null || typeof item.parent === "string") || typeof item.confidence !== "number" || !Number.isFinite(item.confidence) || item.confidence < 0 || item.confidence > 1))
6016
6058
  throw new Error("invalid");
6017
- return answer2;
6059
+ return answer3;
6018
6060
  } catch {
6019
6061
  throw new CliError("invalid_response", "analysis returned invalid linking JSON; this batch was not stored");
6020
6062
  }
@@ -6046,10 +6088,10 @@ var runAnalysis = /* @__PURE__ */ __name(async (conversations, chat2, request, {
6046
6088
  if (!Number.isInteger(response.tokens) || response.tokens < 1 || response.tokens > inputBound + outputBound)
6047
6089
  throw new CliError("invalid_response", "analysis token usage exceeded the reserved budget; this batch was not stored");
6048
6090
  tokens += response.tokens;
6049
- const answer2 = analysisAnswer(response.text, model2);
6091
+ const answer3 = analysisAnswer(response.text, model2);
6050
6092
  let saved;
6051
6093
  try {
6052
- saved = await conversations.addAnswers(batch.batch, answer2);
6094
+ saved = await conversations.addAnswers(batch.batch, answer3);
6053
6095
  } catch {
6054
6096
  throw new CliError("invalid_response", "analysis named invalid batch messages or parents; this batch was not stored");
6055
6097
  }
@@ -6286,10 +6328,10 @@ var conversationBuildCommand = /* @__PURE__ */ __name((messenger) => boundOption
6286
6328
  if (status.messages && !await consents.has(status.chat, identity)) {
6287
6329
  const what = `${status.messages} messages, ${status.characters} characters (about ${status.tokensEstimate} message tokens, plus prompt and batch context), go to ${target.model} at ${target.baseUrl}; this run reserves at most ${maxTokens} input/output tokens. Consent is remembered for this chat and provider until revoked`;
6288
6330
  if (!options.yes) {
6289
- const answer2 = await answerOf(this, `${what}. Allow analysis? [y/N] `);
6290
- if (answer2 === null)
6331
+ const answer3 = await answerOf(this, `${what}. Allow analysis? [y/N] `);
6332
+ if (answer3 === null)
6291
6333
  throw new CliError("confirmation_required", `${what} \u2014 add --yes`);
6292
- if (!/^y(es)?$/i.test(answer2.trim()))
6334
+ if (!/^y(es)?$/i.test(answer3.trim()))
6293
6335
  throw new CliError("cancelled", "cancelled \u2014 nothing was sent");
6294
6336
  }
6295
6337
  await consents.remember(status.chat, identity);
@@ -6443,8 +6485,8 @@ ${batch.messages.map((one) => `${one.answer ? "?" : " "} ${one.id} ${one.at.sli
6443
6485
  const { batch } = this.opts();
6444
6486
  const context = messengerContext(this, messenger);
6445
6487
  refuseLocalWrite(context, messenger.app.command, LINKS_KEY);
6446
- const answer2 = answerOf2(await readAll(context.stdin));
6447
- const stored2 = await context.withServices((services) => services.conversations.addAnswers(batch, answer2));
6488
+ const answer3 = answerOf2(await readAll(context.stdin));
6489
+ const stored2 = await context.withServices((services) => services.conversations.addAnswers(batch, answer3));
6448
6490
  renderAnswer(this, context, itemOf(stored2, { next: [nextStep("conversations.build", { args: { chat: stored2.chat } })] }), () => `${stored2.stored} answers stored
6449
6491
  `);
6450
6492
  });
@@ -6606,10 +6648,10 @@ var consent = /* @__PURE__ */ __name(async (command, status, baseUrl, { yes: yes
6606
6648
  const what = `${status.left} chunks of chat ${status.chat}, up to ${status.tokensAtMost} tokens${price}, go to ${status.model} (${new URL(baseUrl).host})`;
6607
6649
  if (yes2)
6608
6650
  return;
6609
- const answer2 = await answerOf(command, `${what}. Send them? [y/N] `);
6610
- if (answer2 === null)
6651
+ const answer3 = await answerOf(command, `${what}. Send them? [y/N] `);
6652
+ if (answer3 === null)
6611
6653
  throw new CliError("confirmation_required", `${what} \u2014 add --yes to send them`);
6612
- if (!/^y(es)?$/i.test(answer2.trim()))
6654
+ if (!/^y(es)?$/i.test(answer3.trim()))
6613
6655
  throw new CliError("cancelled", "cancelled \u2014 nothing was sent");
6614
6656
  }, "consent");
6615
6657
  var LINKS_KEY = "conversations.links";
@@ -6623,11 +6665,11 @@ var answerOf2 = /* @__PURE__ */ __name((text2) => {
6623
6665
  } catch {
6624
6666
  throw new CliError("validation_error", "the answer on stdin is not JSON \u2014 see `conversations links add --help`");
6625
6667
  }
6626
- const answer2 = parsed;
6627
- if (!answer2 || typeof answer2 !== "object" || !Array.isArray(answer2.answers)) {
6668
+ const answer3 = parsed;
6669
+ if (!answer3 || typeof answer3 !== "object" || !Array.isArray(answer3.answers)) {
6628
6670
  throw new CliError("validation_error", 'the answer needs "answers": a list of { "message", "parent", "confidence" }');
6629
6671
  }
6630
- return answer2;
6672
+ return answer3;
6631
6673
  }, "answerOf");
6632
6674
  var linksCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("links"), {
6633
6675
  output: { entity: "message_links" },
@@ -7412,7 +7454,7 @@ var handlers = /* @__PURE__ */ __name((reader, meta) => {
7412
7454
  if (index.remaining > 0)
7413
7455
  found.coverage = { ...found.coverage, indexing: "pending" };
7414
7456
  const complete = found.coverage.indexing === "ready";
7415
- const answer2 = {
7457
+ const answer3 = {
7416
7458
  ...meetingHitsList(found, request.limit ?? 100, "search meetings", meetingSearchArguments(query, flags)),
7417
7459
  meta: {
7418
7460
  ...meta(),
@@ -7421,7 +7463,7 @@ var handlers = /* @__PURE__ */ __name((reader, meta) => {
7421
7463
  ...!complete ? { issues: [{ code: "invalid_response", source: "meeting-index" }] } : {}
7422
7464
  }
7423
7465
  };
7424
- return { answer: answer2, complete };
7466
+ return { answer: answer3, complete };
7425
7467
  }, "run")
7426
7468
  };
7427
7469
  }
@@ -9007,11 +9049,11 @@ var runCapOf = /* @__PURE__ */ __name((argv) => {
9007
9049
  const cap = at2 < 0 ? Number.NaN : Number(argv[at2 + 1]);
9008
9050
  return Number.isFinite(cap) ? cap : null;
9009
9051
  }, "runCapOf");
9010
- var scheduleCommandFor = /* @__PURE__ */ __name(({ app, context: contextOf, newMail, limits: configured, agentRuns = [] }) => {
9052
+ var scheduleCommandFor = /* @__PURE__ */ __name(({ app, context: contextOf2, newMail, limits: configured, agentRuns = [] }) => {
9011
9053
  const agentClis = [app, ...agentRuns];
9012
9054
  const command = new Command("schedule").description(`run a ${app.command} command or an agent later or on a timer (systemd, launchd, Task Scheduler); an agent cannot send`);
9013
9055
  const prepare = /* @__PURE__ */ __name((self, resolving = {}) => {
9014
- const context = contextOf(self, resolving);
9056
+ const context = contextOf2(self, resolving);
9015
9057
  const system = environmentOf(self).system ?? thisMachine();
9016
9058
  const state = resolvePaths({ appName: app.appName, prefix: app.envPrefix, env: context.env }).state;
9017
9059
  const say = /* @__PURE__ */ __name((value2, lines2) => renderAnswer(self, context, itemOf(value2), () => lines2.join("\n")), "say");
@@ -9190,12 +9232,12 @@ var scheduleCommandFor = /* @__PURE__ */ __name(({ app, context: contextOf, newM
9190
9232
  maxCostPerDayUsd: limitsOf(this, schedule).maxCostPerDay
9191
9233
  } : {}
9192
9234
  }));
9193
- const answer2 = listOf("schedule list", {
9235
+ const answer3 = listOf("schedule list", {
9194
9236
  items: rows2.map((row2) => snakeKeys(row2)),
9195
9237
  limit: Math.max(1, rows2.length),
9196
9238
  has_more: false
9197
9239
  });
9198
- renderAnswer(this, context, answer2, () => {
9240
+ renderAnswer(this, context, answer3, () => {
9199
9241
  if (rows2.length === 0) {
9200
9242
  context.renderer.note(`no schedules \u2014 \`${lineOf(this, "schedule command|agent")}\` adds one`);
9201
9243
  return "";
@@ -9278,12 +9320,12 @@ var appMcpCommand = /* @__PURE__ */ __name((app, configuration2, options) => {
9278
9320
  permissionExample: options.permissionExample,
9279
9321
  serveStdio: /* @__PURE__ */ __name(async (self, context) => {
9280
9322
  checked2(self, context);
9281
- const { serveAppOverStdio } = await import("./app-server-OW5LT5XV.js");
9323
+ const { serveAppOverStdio } = await import("./app-server-WGTKZQKJ.js");
9282
9324
  await serveAppOverStdio(self, context, server());
9283
9325
  }, "serveStdio"),
9284
9326
  serveHttp: /* @__PURE__ */ __name(async (self, context, http) => {
9285
9327
  checked2(self, context);
9286
- const { serveAppOverHttp } = await import("./app-server-OW5LT5XV.js");
9328
+ const { serveAppOverHttp } = await import("./app-server-WGTKZQKJ.js");
9287
9329
  await serveAppOverHttp(self, context, server(), http);
9288
9330
  }, "serveHttp"),
9289
9331
  instructions: /* @__PURE__ */ __name(async (profiles) => {
@@ -9601,15 +9643,15 @@ var requestsCommand = /* @__PURE__ */ __name((messenger) => {
9601
9643
  [true, "let them in; the group sees them join"],
9602
9644
  [false, "turn the request away"]
9603
9645
  ]) {
9604
- const answer2 = annotate(new Command(accept ? "confirm" : "reject"), {
9646
+ const answer3 = annotate(new Command(accept ? "confirm" : "reject"), {
9605
9647
  output: { entity: "chat_request_change" },
9606
9648
  effects: REMOTE_WRITE
9607
9649
  }).description(help).argument("<chat>", messenger.chatArgument).argument(everyone ? "[person]" : "<person>", "who asked: an id from `chats requests list`");
9608
9650
  if (everyone)
9609
- answer2.option("--all", "every pending request, counted against the hourly limit first");
9651
+ answer3.option("--all", "every pending request, counted against the hourly limit first");
9610
9652
  if (byLink)
9611
- answer2.option("--link <link>", "with --all: only the requests made by this invite link");
9612
- requests.addCommand(answer2.action(async function(chat2, person) {
9653
+ answer3.option("--link <link>", "with --all: only the requests made by this invite link");
9654
+ requests.addCommand(answer3.action(async function(chat2, person) {
9613
9655
  const context = messengerContext(this, messenger);
9614
9656
  const { all, link } = this.opts();
9615
9657
  if (person === void 0 === (all !== true))
@@ -9863,7 +9905,7 @@ var botMcpCommand = /* @__PURE__ */ __name((bot) => {
9863
9905
  const mcp = bot.mcp;
9864
9906
  if (!mcp)
9865
9907
  throw new Error("bot mcp is mounted only with BotMessenger.mcp");
9866
- const [{ serveBotOverStdio }, run3] = await Promise.all([import("./server-3TPCEZ6P.js"), mcp.program()]);
9908
+ const [{ serveBotOverStdio }, run3] = await Promise.all([import("./server-P4XUYY5A.js"), mcp.program()]);
9867
9909
  await serveBotOverStdio({
9868
9910
  bot,
9869
9911
  program: { run: run3, commands: describeProgram(rootOf2(this)) },
@@ -10086,7 +10128,7 @@ var moderatorOf = /* @__PURE__ */ __name((context, bot, adapter, botId, ban) =>
10086
10128
  }, () => remove(chatId, personId, { block: ban }));
10087
10129
  }, "removePerson")
10088
10130
  }), "moderatorOf");
10089
- var yes = /* @__PURE__ */ __name((answer2) => /^\s*y(es)?\s*$/i.test(answer2), "yes");
10131
+ var yes = /* @__PURE__ */ __name((answer3) => /^\s*y(es)?\s*$/i.test(answer3), "yes");
10090
10132
  var botModerateCommand = /* @__PURE__ */ __name((bot) => annotate(new Command("moderate"), {
10091
10133
  effects: REMOTE_WRITE,
10092
10134
  examples: botExamples(bot, "chats moderate Team --dry-run")
@@ -10118,8 +10160,8 @@ var botModerateCommand = /* @__PURE__ */ __name((bot) => annotate(new Command("m
10118
10160
  allowDangerous: options.allowDangerous === true,
10119
10161
  maxActions,
10120
10162
  confirm: /* @__PURE__ */ __name(async (finding) => {
10121
- const answer2 = await ask(`${describe(finding)}? [y/N] `);
10122
- return answer2 === null ? void 0 : yes(answer2);
10163
+ const answer3 = await ask(`${describe(finding)}? [y/N] `);
10164
+ return answer3 === null ? void 0 : yes(answer3);
10123
10165
  }, "confirm")
10124
10166
  });
10125
10167
  if (context.format === "pretty")
@@ -10203,8 +10245,8 @@ var cardOf = /* @__PURE__ */ __name(async (store, context, bot, who3, across, li
10203
10245
  const [person] = await resolve6(store, bot, [who3], people2);
10204
10246
  const rows2 = (await store.messages.find({ ...filter, senders: [person.id], perChat: true, limit: 1 })).items;
10205
10247
  const latest = rows2.filter((hit, index) => rows2.findIndex((other) => other.chatId === hit.chatId) === index);
10206
- const kindOf = bot.chatKindOf ?? kindByNumber;
10207
- const dialogs = latest.filter((hit) => kindOf(hit) === "dialog");
10248
+ const kindOf2 = bot.chatKindOf ?? kindByNumber;
10249
+ const dialogs = latest.filter((hit) => kindOf2(hit) === "dialog");
10208
10250
  const pages = await Promise.all(dialogs.map(async (hit) => {
10209
10251
  const { account } = parseLocator(hit.locator);
10210
10252
  const page = await store.messages.messages({ provider: bot.provider, account }, hit.chatId, { limit });
@@ -10219,7 +10261,7 @@ var cardOf = /* @__PURE__ */ __name(async (store, context, bot, who3, across, li
10219
10261
  chats: latest.map((hit) => ({
10220
10262
  id: hit.chatId,
10221
10263
  title: hit.chatTitle,
10222
- kind: kindOf(hit),
10264
+ kind: kindOf2(hit),
10223
10265
  lastMessageAt: hit.timestamp
10224
10266
  })),
10225
10267
  messages: messages.slice(-limit)
@@ -10363,7 +10405,7 @@ var typesOf = /* @__PURE__ */ __name((typed2) => {
10363
10405
  const types = typed2?.split(",").map((one) => one.trim()).filter(Boolean);
10364
10406
  return types && types.length > 0 ? types : void 0;
10365
10407
  }, "typesOf");
10366
- var botWrite = /* @__PURE__ */ __name((context, key, write) => guardedWrite(context.guard(), { operationId: newOperationId(), chatId: null, kind: "account", key }, write), "botWrite");
10408
+ var botWrite = /* @__PURE__ */ __name((context, key, write2) => guardedWrite(context.guard(), { operationId: newOperationId(), chatId: null, kind: "account", key }, write2), "botWrite");
10367
10409
  var botMenuCommand = /* @__PURE__ */ __name((bot) => {
10368
10410
  const command = new Command("commands").description("the bot's command menu \u2014 what people see after /");
10369
10411
  withQuery(annotate(command.command("list"), { effects: REMOTE_READ, examples: botExamples(bot, "commands list") }), BOT_MENU_QUERY).description("the commands in the menu now").action(async function(words3) {
@@ -10410,7 +10452,7 @@ var botCallbacksCommand = /* @__PURE__ */ __name((bot) => new Command("callbacks
10410
10452
  const press = text2 === void 0 ? void 0 : new PressLog(botFiles(bot.app, context.profile, context.env).presses).find(callbackId);
10411
10453
  await context.run(async (events) => {
10412
10454
  const adapter = await context.authenticated({ events });
10413
- const answer2 = botCan(adapter, "answer", bot, "answer a button");
10455
+ const answer3 = botCan(adapter, "answer", bot, "answer a button");
10414
10456
  const operationId = newOperationId();
10415
10457
  await guardedWrite(context.guard(), {
10416
10458
  operationId,
@@ -10418,7 +10460,7 @@ var botCallbacksCommand = /* @__PURE__ */ __name((bot) => new Command("callbacks
10418
10460
  kind: "message",
10419
10461
  key: "bot.callbacks.answer",
10420
10462
  ...text2 === void 0 ? {} : { length: text2.length }
10421
- }, () => answer2(callbackId, {
10463
+ }, () => answer3(callbackId, {
10422
10464
  ...text2 === void 0 ? {} : { text: text2 },
10423
10465
  ...notification === void 0 ? {} : { notification },
10424
10466
  ...press ? { press } : {}
@@ -10964,9 +11006,9 @@ var chatsCommand = /* @__PURE__ */ __name((bot) => {
10964
11006
  const ref = context.chatRef(chat2);
10965
11007
  await context.run(async (events) => {
10966
11008
  const adapter = await context.authenticated({ events });
10967
- const act = botCan(adapter, "action", bot, "show an action");
11009
+ const act2 = botCan(adapter, "action", bot, "show an action");
10968
11010
  const operationId = newOperationId();
10969
- await guardedWrite(context.guard(), { operationId, chatId: ref, kind: "chat", key: "bot.chats.action" }, () => act(ref, action));
11011
+ await guardedWrite(context.guard(), { operationId, chatId: ref, kind: "chat", key: "bot.chats.action" }, () => act2(ref, action));
10970
11012
  renderAnswer(this, context, itemOf({ operation_id: operationId, chat_id: ref, action }));
10971
11013
  });
10972
11014
  });
@@ -11593,11 +11635,11 @@ var syncCommand = /* @__PURE__ */ __name((messenger) => {
11593
11635
  throw new CliError("validation_error", "--dry-run prices a full fetch; --since-time and --last do not narrow it");
11594
11636
  }
11595
11637
  const named2 = chat2;
11596
- const answer2 = await context.withServices((services) => services.archive.estimate(named2, { limit, pageSize, pauseMs }));
11597
- renderAnswer(this, context, itemOf(snakeKeys(answer2)));
11598
- if (answer2.missing === null) {
11638
+ const answer3 = await context.withServices((services) => services.archive.estimate(named2, { limit, pageSize, pauseMs }));
11639
+ renderAnswer(this, context, itemOf(snakeKeys(answer3)));
11640
+ if (answer3.missing === null) {
11599
11641
  context.renderer.note(`nothing held of this chat to measure by \u2014 \`${lineOf(this, `messages sync ${chat2} --limit ${pageSize}`)}\` gives the estimate something to go on`);
11600
- } else if (answer2.missing > 0)
11642
+ } else if (answer3.missing > 0)
11601
11643
  context.renderer.note("an estimate: provider waits (FloodWait) come on top");
11602
11644
  return;
11603
11645
  }
@@ -12949,10 +12991,10 @@ var moderateCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command
12949
12991
  allowDangerous: options.allowDangerous === true,
12950
12992
  maxActions,
12951
12993
  confirm: /* @__PURE__ */ __name(async (finding) => {
12952
- const answer2 = await answerOf(this, `${describe(finding)}? [y/N] `);
12953
- if (answer2 === null)
12994
+ const answer3 = await answerOf(this, `${describe(finding)}? [y/N] `);
12995
+ if (answer3 === null)
12954
12996
  return void 0;
12955
- return /^\s*y(es)?\s*$/i.test(answer2);
12997
+ return /^\s*y(es)?\s*$/i.test(answer3);
12956
12998
  }, "confirm")
12957
12999
  }));
12958
13000
  renderAnswer(this, context, itemOf(snakeKeys({ chatId, rows: rows2 }), { meta: window2.meta }), () => rows2.map((row2) => [row2.kind, row2.personName ?? row2.personId, row2.rule, row2.action, row2.outcome, row2.reason ?? ""].join(" ").trimEnd()).map((line7) => `${line7}
@@ -14785,14 +14827,14 @@ var contactsCommand = /* @__PURE__ */ __name((messenger) => {
14785
14827
  const checked2 = await context.withServices((services) => services.botcheck.person(person, { registries: registries2, ...key ? { registry: { casKey: key } } : {} }));
14786
14828
  for (const note2 of checked2.notes)
14787
14829
  context.renderer.note(note2);
14788
- for (const { name, answer: answer3, detail } of checked2.registries) {
14789
- if (answer3 === "unknown")
14830
+ for (const { name, answer: answer4, detail } of checked2.registries) {
14831
+ if (answer4 === "unknown")
14790
14832
  context.renderer.note(`${name}: not known \u2014 ${detail ?? "no answer"}`);
14791
14833
  }
14792
14834
  if (checked2.unknown.length > 0)
14793
14835
  context.renderer.note(`not judged, nothing to judge by: ${checked2.unknown.join(", ")}`);
14794
- const { notes: _2, ...answer2 } = checked2;
14795
- renderAnswer(this, context, itemOf(snakeKeys(answer2)));
14836
+ const { notes: _2, ...answer3 } = checked2;
14837
+ renderAnswer(this, context, itemOf(snakeKeys(answer3)));
14796
14838
  });
14797
14839
  annotate(contacts.command("link"), { effects: LOCAL_WRITE, output: { entity: "linked_person" } }).summary("link identities that belong to one person").description("record that two people in the store are one person \u2014 the same name is never enough").argument("<person>", "their id, @username, or part of their name").argument("<other>", "the same in another messenger of the store, as <messenger>:<person> \u2014 max:Ana; me: it is you, as zoom:<id> me").action(async function(person, other) {
14798
14840
  const context = messengerContext(this, messenger);
@@ -15006,12 +15048,12 @@ var hearOnline = /* @__PURE__ */ __name(async (messenger, connection, chat2, mes
15006
15048
  }, "hearOnline");
15007
15049
  var hearLocally = /* @__PURE__ */ __name(async (bytes, messageId, choice) => {
15008
15050
  const { model: model2, directory, open, ffmpeg } = choice;
15009
- const { decodeAudio } = await import("./decode-NXB5UKMO.js");
15051
+ const { decodeAudio } = await import("./decode-QMLOGZ6R.js");
15010
15052
  const { samples, rate } = await decodeAudio(bytes, ffmpeg);
15011
15053
  if (choice.with === "openai") {
15012
15054
  if (choice.refusal)
15013
15055
  throw choice.refusal;
15014
- const { transcribeOpenAI } = await import("./openai-GWRDAHDU.js");
15056
+ const { transcribeOpenAI } = await import("./openai-WAJ6WREQ.js");
15015
15057
  const transcribeModel = choice.transcribeModel ?? OPENAI_TRANSCRIBE_MODEL;
15016
15058
  const pieces = await transcribeOpenAI({ samples, rate }, {
15017
15059
  apiKey: choice.apiKey ?? "",
@@ -15030,7 +15072,7 @@ var hearLocally = /* @__PURE__ */ __name(async (bytes, messageId, choice) => {
15030
15072
  model: transcribeModel
15031
15073
  };
15032
15074
  }
15033
- const { openRecognizer, toModelRate } = await import("./recognize-WVEKHODM.js");
15075
+ const { openRecognizer, toModelRate } = await import("./recognize-4KLBZDEC.js");
15034
15076
  const recognizer = (open ?? openRecognizer)(model2, modelPath(directory, model2), vadPath(directory));
15035
15077
  try {
15036
15078
  return {
@@ -15118,7 +15160,7 @@ var downloadAudioModel = /* @__PURE__ */ __name(async (command, messenger, id3)
15118
15160
  await install(model2, directory, { progress: /* @__PURE__ */ __name((line7) => context.renderer.note(line7), "progress") });
15119
15161
  }
15120
15162
  context.renderer.note(`${model2.id}: loading it once to check it works`);
15121
- const { openRecognizer, SAMPLE_RATE } = await import("./recognize-WVEKHODM.js");
15163
+ const { openRecognizer, SAMPLE_RATE } = await import("./recognize-4KLBZDEC.js");
15122
15164
  const recognizer = openRecognizer(model2, modelPath(directory, model2), vadPath(directory));
15123
15165
  try {
15124
15166
  recognizer.recognize(new Float32Array(SAMPLE_RATE));
@@ -15337,9 +15379,9 @@ var hearVoices = /* @__PURE__ */ __name(async (messenger, messages, kept, transc
15337
15379
  }
15338
15380
  return answers;
15339
15381
  });
15340
- for (const [voice, answer2] of fetched) {
15382
+ for (const [voice, answer3] of fetched) {
15341
15383
  try {
15342
- const heard2 = answer2 instanceof Uint8Array ? await hearLocally(answer2, voice.messageId, choice) : answer2;
15384
+ const heard2 = answer3 instanceof Uint8Array ? await hearLocally(answer3, voice.messageId, choice) : answer3;
15343
15385
  if (heard2.pending || heard2.text.trim() === "")
15344
15386
  continue;
15345
15387
  transcripts.set(keyOf2(voice), heard2.text);
@@ -15592,9 +15634,9 @@ var inboxCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("i
15592
15634
  });
15593
15635
  if (inbox.partial && format === "pretty")
15594
15636
  renderer.warn(PARTIAL_NOTE);
15595
- const answer2 = inboxAnswer(inbox, hearing, reader, transcribe === true, meta);
15596
- renderAnswer(this, context, answer2, () => {
15597
- if (answer2.items.length === 0) {
15637
+ const answer3 = inboxAnswer(inbox, hearing, reader, transcribe === true, meta);
15638
+ renderAnswer(this, context, answer3, () => {
15639
+ if (answer3.items.length === 0) {
15598
15640
  renderer.note(inbox.mode === "unread" ? "nothing unread" : `nothing new since ${inbox.since}`);
15599
15641
  return "";
15600
15642
  }
@@ -15897,7 +15939,7 @@ var downloadChat = /* @__PURE__ */ __name(async (command, context, messenger, ch
15897
15939
  stop.release();
15898
15940
  }
15899
15941
  }, "downloadChat");
15900
- var summary2 = /* @__PURE__ */ __name(({ saved, existing, complete, batch }) => `${saved} saved${existing > 0 ? `, ${existing} already there` : ""}${complete ? " \u2014 the whole chat" : batch?.failures.every((failure3) => failure3.stage === "extract") ? " \u2014 downloads retained; retry attachments extract for failed locators" : " \u2014 run it again to continue"}`, "summary");
15942
+ var summary2 = /* @__PURE__ */ __name(({ saved, existing, complete, batch }) => `${saved} saved${existing > 0 ? `, ${existing} already there` : ""}${complete ? " \u2014 the whole chat" : batch?.failures.every((failure2) => failure2.stage === "extract") ? " \u2014 downloads retained; retry attachments extract for failed locators" : " \u2014 run it again to continue"}`, "summary");
15901
15943
  var joined = /* @__PURE__ */ __name((a2, b) => {
15902
15944
  const from = Math.min(a2.from, b.from);
15903
15945
  const to = Math.max(a2.to, b.to);
@@ -16537,8 +16579,8 @@ var starCommands = /* @__PURE__ */ __name((messenger) => [true, false].map((star
16537
16579
  examples: [`${messenger.app.command} messages ${name} <chat> <message>`]
16538
16580
  }).description(starred ? "star a message, so it is easy to find again; only you see the star" : "take the star off a message").argument("<chat>", messenger.chatArgument).argument("<message>", "the message id").action(async function(chat2, message2) {
16539
16581
  const context = messengerContext(this, messenger);
16540
- const answer2 = await context.withServices((services) => services.messages.star({ chat: chat2, message: message2.trim(), starred }));
16541
- renderAnswer(this, context, itemOf(snakeKeys(answer2)));
16582
+ const answer3 = await context.withServices((services) => services.messages.star({ chat: chat2, message: message2.trim(), starred }));
16583
+ renderAnswer(this, context, itemOf(snakeKeys(answer3)));
16542
16584
  });
16543
16585
  }), "starCommands");
16544
16586
 
@@ -16828,14 +16870,14 @@ var pollsCommand = /* @__PURE__ */ __name((messenger) => {
16828
16870
  effects: REMOTE_READ,
16829
16871
  examples: [`${messenger.app.command} personal polls voters "Book club" 101 answers:0 --limit 10`]
16830
16872
  }).description(messenger.pollAnonymous === false ? "who voted for what, newest first" : "who voted for what, newest first; not in an anonymous poll").argument("<chat>", messenger.chatArgument).argument("<message>", "the id of the message that carries the poll").option("--limit <n>", "how many to show", positiveCount("--limit")).option("--page <n>", "which page, starting at 1", positiveCount("--page")), { output: { entity: "poll_vote" } }), VOTERS_QUERY).action(async function(chat2, message2, words3) {
16831
- const answer2 = nativeTerms(listQuery(typedQuery(words3), VOTERS_QUERY, "polls voters"), "polls voters").get("answers")?.value;
16873
+ const answer3 = nativeTerms(listQuery(typedQuery(words3), VOTERS_QUERY, "polls voters"), "polls voters").get("answers")?.value;
16832
16874
  const context = messengerContext(this, messenger);
16833
16875
  const { limit, page } = context.settings;
16834
16876
  const found = await context.withMessenger((connection) => pollVoters(connection, {
16835
16877
  chat: chat2,
16836
16878
  message: message2.trim(),
16837
16879
  limit: limit * page,
16838
- ...answer2 === void 0 ? {} : { answer: answer2.trim() }
16880
+ ...answer3 === void 0 ? {} : { answer: answer3.trim() }
16839
16881
  }));
16840
16882
  renderAnswer(this, context, listOf("polls voters", {
16841
16883
  items: found.items.slice((page - 1) * limit).map(pollVoteAnswer),
@@ -17341,11 +17383,11 @@ var addReplyEditors = /* @__PURE__ */ __name((replies, messenger) => {
17341
17383
  audience.action(function() {
17342
17384
  const context = messengerContext(this, messenger);
17343
17385
  const { settings, renderer, env } = context;
17344
- const answer2 = editAudience(repliesPathFor(messenger.app, settings.profile, env), messenger.provider, this.opts());
17386
+ const answer3 = editAudience(repliesPathFor(messenger.app, settings.profile, env), messenger.provider, this.opts());
17345
17387
  const warn = renderer.warn;
17346
- for (const { text: text2, warning } of audienceWarnings(answer2))
17388
+ for (const { text: text2, warning } of audienceWarnings(answer3))
17347
17389
  warn(text2, warning);
17348
- renderItem(this, context, answer2);
17390
+ renderItem(this, context, answer3);
17349
17391
  });
17350
17392
  replies.addCommand(audience);
17351
17393
  }, "addReplyEditors");
@@ -17389,7 +17431,7 @@ var repliesCommand = /* @__PURE__ */ __name((messenger) => {
17389
17431
  renderer.note(`${found.botUnknown} sender(s) not known as bot or person; taken as people`);
17390
17432
  }
17391
17433
  renderer.note(`only what this machine has stored from ${found.since} to ${found.until} was read`);
17392
- const answer2 = {
17434
+ const answer3 = {
17393
17435
  since: found.since,
17394
17436
  until: found.until,
17395
17437
  bot_unknown: found.botUnknown,
@@ -17410,7 +17452,7 @@ var repliesCommand = /* @__PURE__ */ __name((messenger) => {
17410
17452
  ].filter(Boolean).join(" + ")}`),
17411
17453
  ...Object.entries(skipped).sort(([, a2], [, b]) => b - a2).map(([why, count5]) => ` passed over ${count5}: ${why}`)
17412
17454
  ]);
17413
- renderAnswer(this, context, itemOf(answer2, { meta: window2.meta }), () => `${lines2.join("\n")}
17455
+ renderAnswer(this, context, itemOf(answer3, { meta: window2.meta }), () => `${lines2.join("\n")}
17414
17456
  `);
17415
17457
  });
17416
17458
  const switched = /* @__PURE__ */ __name((on) => async function() {
@@ -18886,150 +18928,2052 @@ var appUpdate = /* @__PURE__ */ __name((app) => {
18886
18928
  };
18887
18929
  }, "appUpdate");
18888
18930
 
18889
- // dist/commands/doctor.js
18890
- import { existsSync as existsSync18 } from "node:fs";
18891
- import { dirname as dirname8 } from "node:path";
18931
+ // node_modules/.pnpm/@wirecat+cli-core@0.584.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_ab8c0b68b8b4768d5b87d6e249ef10da/node_modules/@wirecat/cli-core/dist/sends/keyed-guard.js
18932
+ var keyedGuard = /* @__PURE__ */ __name((build, ask, levelOf, extra) => {
18933
+ let question;
18934
+ let answered = false;
18935
+ const guard = build(async (key, request) => {
18936
+ if (answered)
18937
+ return;
18938
+ await ask(question || key, request);
18939
+ answered = true;
18940
+ });
18941
+ const probes = /* @__PURE__ */ new WeakMap();
18942
+ const all = /* @__PURE__ */ __name((request) => {
18943
+ let found = probes.get(request);
18944
+ if (!found) {
18945
+ found = extra.map((key) => ({ chatId: null, kind: "read", key }));
18946
+ probes.set(request, found);
18947
+ }
18948
+ return [request, ...found];
18949
+ }, "all");
18950
+ const levelOfRequest = /* @__PURE__ */ __name(({ key }) => levelOf(key ?? ""), "levelOfRequest");
18951
+ const refuse = /* @__PURE__ */ __name((request) => {
18952
+ const refused = all(request).find((one) => ["deny", "readonly"].includes(levelOfRequest(one)));
18953
+ if (refused)
18954
+ guard.check(refused, { reserve: false });
18955
+ }, "refuse");
18956
+ return {
18957
+ refuse,
18958
+ ask: /* @__PURE__ */ __name(async (request) => {
18959
+ refuse(request);
18960
+ question = all(request).filter((one) => levelOfRequest(one) === "ask").map(({ key }) => key).join(" and ");
18961
+ for (const one of all(request))
18962
+ await guard.ask?.(one);
18963
+ }, "ask"),
18964
+ check: /* @__PURE__ */ __name((request, options) => {
18965
+ for (const one of all(request).slice(1))
18966
+ guard.check(one, { reserve: false });
18967
+ guard.check(request, options);
18968
+ }, "check"),
18969
+ ...guard.reserve ? { reserve: guard.reserve } : {},
18970
+ record: /* @__PURE__ */ __name((entry) => guard.record(entry), "record")
18971
+ };
18972
+ }, "keyedGuard");
18892
18973
 
18893
18974
  // dist/config.js
18894
18975
  var permissions = commandPermissions();
18895
18976
  var configuration = settingsFor(IDENTITY, { permissions });
18896
18977
 
18897
- // dist/commands/doctor.js
18898
- var failure2 = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "failure");
18899
- var configFiles3 = /* @__PURE__ */ __name((path) => {
18900
- const files = privateFiles({ files: [path], dirs: [dirname8(path)] });
18901
- if (!files.checked)
18902
- return { files, fixes: [] };
18978
+ // dist/sample/comments.js
18979
+ var wireComment = object({
18980
+ id: string(),
18981
+ body: string(),
18982
+ authorName: string(),
18983
+ createdAt: string()
18984
+ });
18985
+ var wirePage = object({ comments: array(wireComment), hasMore: boolean() });
18986
+ var wireUser = object({ id: string(), name: string() });
18987
+ var commentSchema = strictObject({
18988
+ id: string(),
18989
+ text: string(),
18990
+ author: string(),
18991
+ created_at: string()
18992
+ });
18993
+ var commentOf = /* @__PURE__ */ __name((wire) => ({
18994
+ id: wire.id,
18995
+ text: wire.body,
18996
+ author: wire.authorName,
18997
+ created_at: wire.createdAt
18998
+ }), "commentOf");
18999
+ var commentsService = /* @__PURE__ */ __name((api) => ({
19000
+ me: /* @__PURE__ */ __name(() => api.send({ method: "GET", path: "me" }, wireUser), "me"),
19001
+ list: /* @__PURE__ */ __name(async ({ limit, offset, author }) => {
19002
+ const page = await api.send({ method: "GET", path: "comments", query: { limit, offset, by: author } }, wirePage);
19003
+ return { items: page.comments.map(commentOf), has_more: page.hasMore };
19004
+ }, "list"),
19005
+ show: /* @__PURE__ */ __name(async (id3) => commentOf(await api.send({ method: "GET", path: "comments/{id}", ids: { id: id3 } }, wireComment)), "show"),
19006
+ create: /* @__PURE__ */ __name(async (text2) => commentOf(await api.send({ method: "POST", path: "comments", body: { body: text2 } }, wireComment)), "create"),
19007
+ update: /* @__PURE__ */ __name(async (id3, text2) => commentOf(await api.send({ method: "PATCH", path: "comments/{id}", ids: { id: id3 }, body: { body: text2 } }, wireComment)), "update")
19008
+ }), "commentsService");
19009
+
19010
+ // dist/sample/transport.js
19011
+ var SERVICE_URL = "https://comments.example.invalid/v1/";
19012
+ var SERVICE = "Example Comments";
19013
+ var TIMEOUT_MS = 3e4;
19014
+ var LARGEST_ANSWER = 8 * 1024 * 1024;
19015
+ var LONGEST_PACE_WAIT_MS = 6e4;
19016
+ var segment = /* @__PURE__ */ __name((name, value2) => {
19017
+ if (value2 === "" || value2 === "." || value2 === "..")
19018
+ throw new CliError("validation_error", `${name} must name one item; an empty, "." or ".." id is refused`);
19019
+ return encodeURIComponent(value2);
19020
+ }, "segment");
19021
+ var urlOf = /* @__PURE__ */ __name(({ path, ids = {}, query = {} }) => {
19022
+ const url = new URL(path.replace(/\{(\w+)\}/g, (_2, name) => segment(name, ids[name] ?? "")), SERVICE_URL);
19023
+ for (const [key, value2] of Object.entries(query))
19024
+ if (value2 !== void 0)
19025
+ url.searchParams.set(key, String(value2));
19026
+ return url;
19027
+ }, "urlOf");
19028
+ var failureOf2 = /* @__PURE__ */ __name((status, writes2, retryAfterMs) => {
19029
+ if (status === 401)
19030
+ return new CliError("authentication_error", `${SERVICE} refused the token; sign in again with session start`, {
19031
+ status
19032
+ });
19033
+ if (status === 429)
19034
+ return new CliError("rate_limited", `${SERVICE} asked to slow down; retry the command later`, {
19035
+ status,
19036
+ retryable: true,
19037
+ ...retryAfterMs === void 0 ? {} : { retry_after_ms: retryAfterMs }
19038
+ });
19039
+ if (status >= 500 && writes2)
19040
+ return new CliError("outcome_unknown", `${SERVICE} failed during a write; check it before repeating the write`, {
19041
+ status,
19042
+ retryable: false
19043
+ });
19044
+ if (status === 404)
19045
+ return new CliError("not_found", `${SERVICE} has no such item, or this token cannot see it`);
19046
+ return new CliError(statusToCode(status), `${SERVICE} refused the request (HTTP ${status})`, {
19047
+ status,
19048
+ retryable: status >= 500
19049
+ });
19050
+ }, "failureOf");
19051
+ var transport = /* @__PURE__ */ __name((options) => {
19052
+ const fetchOf = options.fetch ?? fetch;
19053
+ const sleep4 = options.sleep ?? realSleep;
19054
+ const now = options.now ?? Date.now;
19055
+ const turn = /* @__PURE__ */ __name(async () => {
19056
+ if (!options.pacer)
19057
+ return;
19058
+ const wait = await options.pacer.reserve() - now();
19059
+ if (wait <= 0)
19060
+ return;
19061
+ if (wait > LONGEST_PACE_WAIT_MS)
19062
+ throw new CliError("rate_limited", `this profile must wait ${Math.ceil(wait / 1e3)} s before its next request`, {
19063
+ retry_after_ms: wait
19064
+ });
19065
+ await sleep4(wait, options.signal, "retry");
19066
+ }, "turn");
19067
+ const unanswered2 = /* @__PURE__ */ __name((writes2, error) => {
19068
+ if (writes2)
19069
+ return new CliError("outcome_unknown", `${SERVICE} did not answer a write; check it before repeating the write`, {
19070
+ retryable: false
19071
+ });
19072
+ if (options.signal?.aborted)
19073
+ return new CliError("cancelled", `the ${SERVICE} request was stopped`);
19074
+ const timedOut = error?.name === "TimeoutError";
19075
+ return timedOut ? new CliError("timeout", `${SERVICE} did not answer in time`, { retryable: true }) : new CliError("network_error", `${SERVICE} could not be reached`, { retryable: true });
19076
+ }, "unanswered");
19077
+ const send = /* @__PURE__ */ __name(async (request, answer3) => {
19078
+ const writes2 = request.method !== "GET";
19079
+ const url = urlOf(request);
19080
+ await turn();
19081
+ const deadline = new AbortController();
19082
+ const timer = setTimeout(() => deadline.abort(new DOMException("timed out", "TimeoutError")), options.timeoutMs ?? TIMEOUT_MS);
19083
+ timer.unref();
19084
+ const signal = options.signal ? AbortSignal.any([options.signal, deadline.signal]) : deadline.signal;
19085
+ const end = providerRequest(`${request.method} /${request.path}`, options.events, {
19086
+ method: request.method,
19087
+ transport: "http"
19088
+ });
19089
+ try {
19090
+ let response;
19091
+ try {
19092
+ response = await fetchOf(url, {
19093
+ method: request.method,
19094
+ headers: {
19095
+ authorization: `Bearer ${options.token}`,
19096
+ accept: "application/json",
19097
+ ...request.body ? { "content-type": "application/json" } : {}
19098
+ },
19099
+ ...request.body ? { body: JSON.stringify(request.body) } : {},
19100
+ // A redirect would carry the Authorization header to an address we did not choose.
19101
+ redirect: "error",
19102
+ signal
19103
+ });
19104
+ } catch (error) {
19105
+ const failure2 = unanswered2(writes2, deadline.signal.reason ?? error);
19106
+ end({ errorCode: failure2.code });
19107
+ throw failure2;
19108
+ }
19109
+ if (!response.ok) {
19110
+ const failure2 = failureOf2(response.status, writes2, providerWaitMs(response.headers, wallClock));
19111
+ end({ status: response.status, errorCode: failure2.code });
19112
+ throw failure2;
19113
+ }
19114
+ let body;
19115
+ try {
19116
+ body = await readJsonResponse(response, { maxBytes: LARGEST_ANSWER, signal });
19117
+ } catch (error) {
19118
+ const failure2 = isCliError(error) && error.code !== "invalid_response" ? error : new CliError("invalid_response", `${SERVICE} answered with something other than bounded JSON`);
19119
+ end({ status: response.status, errorCode: failure2.code });
19120
+ throw failure2;
19121
+ }
19122
+ const parsed = safeParse(answer3, body);
19123
+ if (!parsed.success) {
19124
+ end({ status: response.status, errorCode: "invalid_response" });
19125
+ throw new CliError("invalid_response", `${SERVICE}'s answer does not have the documented shape`);
19126
+ }
19127
+ end({ status: response.status });
19128
+ return parsed.output;
19129
+ } finally {
19130
+ clearTimeout(timer);
19131
+ }
19132
+ }, "send");
19133
+ return { send };
19134
+ }, "transport");
19135
+
19136
+ // dist/token.js
19137
+ var TOKEN_VARIABLE = `${IDENTITY.envPrefix}_TOKEN`;
19138
+ var tokenStore = /* @__PURE__ */ __name((env, keyring, warn) => {
19139
+ const where = { appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env };
19140
+ const options = {
19141
+ configDir: resolvePaths(where).config,
19142
+ service: IDENTITY.appName,
19143
+ envVar: TOKEN_VARIABLE,
19144
+ isolated: isMovedRun(where),
19145
+ env,
19146
+ ...keyring ? { keyring } : {},
19147
+ warn
19148
+ };
19149
+ const credentials = new Credentials(options);
19150
+ const account = /* @__PURE__ */ __name((profile) => `token:${profile}`, "account");
18903
19151
  return {
18904
- files: { ...files, problems: files.problems.map(({ path: path2, mode, want }) => ({ path: path2, mode, want })) },
18905
- fixes: files.problems.map((problem) => problem.fix)
19152
+ read: /* @__PURE__ */ __name((profile) => credentials.read(account(profile)), "read"),
19153
+ write: /* @__PURE__ */ __name((profile, token, storage) => new Credentials({ ...options, storage: storage === "file" ? "file" : "auto" }).write(account(profile), token, {
19154
+ signIn: true
19155
+ }), "write"),
19156
+ remove: /* @__PURE__ */ __name((profile) => credentials.remove(account(profile)), "remove")
18906
19157
  };
18907
- }, "configFiles");
18908
- var doctorReport = /* @__PURE__ */ __name((env) => {
18909
- const paths = resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env });
18910
- const common = {
18911
- version: IDENTITY.version,
18912
- runtime: { node: process.versions.node, platform: process.platform },
18913
- paths: { config: paths.config, state: paths.state, cache: paths.cache }
19158
+ }, "tokenStore");
19159
+ var holdsToken = /* @__PURE__ */ __name((env, profile, keyring) => tokenStore(env, keyring, () => {
19160
+ }).read(profile) !== void 0, "holdsToken");
19161
+
19162
+ // dist/context.js
19163
+ var PACE = { perMinute: 120, burst: 20 };
19164
+ var contextOf = /* @__PURE__ */ __name((command) => {
19165
+ const base = baseContext(command, configuration.resolveSettings);
19166
+ return {
19167
+ ...base,
19168
+ environment: environmentOf(command),
19169
+ flags: command.optsWithGlobals(),
19170
+ profile: base.settings.profile,
19171
+ tokens: tokenStore(base.env, base.keyring, base.renderer.warn)
18914
19172
  };
18915
- const readOnly = readOnlyLockOf(IDENTITY, env) ?? null;
19173
+ }, "contextOf");
19174
+ var signInWords = /* @__PURE__ */ __name((profile) => `\`${IDENTITY.command} ${profile} session start\``, "signInWords");
19175
+ var refuseOffline = /* @__PURE__ */ __name((flags) => {
19176
+ if (flags.offline)
19177
+ throw new CliError("permission_error", `this needs ${SERVICE}; leave out --offline`, { reason: "offline.refused" });
19178
+ }, "refuseOffline");
19179
+ var serviceFor = /* @__PURE__ */ __name((command, token, events) => {
19180
+ const { environment, env, profile } = contextOf(command);
19181
+ return commentsService(transport({
19182
+ token,
19183
+ events,
19184
+ signal: environment.signal,
19185
+ ...environment.fetch ? { fetch: environment.fetch } : {},
19186
+ pacer: new Pacer(pacePathFor(IDENTITY, profile, env), PACE)
19187
+ }));
19188
+ }, "serviceFor");
19189
+ var tokenOf = /* @__PURE__ */ __name((command) => {
19190
+ const { flags, profile, tokens } = contextOf(command);
19191
+ refuseOffline(flags);
19192
+ const saved = tokens.read(profile);
19193
+ if (!saved)
19194
+ throw new CliError("authentication_error", `profile ${profile} is not signed in \u2014 run ${signInWords(profile)}`);
19195
+ return saved.secret;
19196
+ }, "tokenOf");
19197
+ var withService = /* @__PURE__ */ __name((command, body) => {
19198
+ const token = tokenOf(command);
19199
+ return contextOf(command).run((events) => body(serviceFor(command, token, events)));
19200
+ }, "withService");
19201
+
19202
+ // dist/commands/comments.js
19203
+ var CLI = IDENTITY.command;
19204
+ var COMMENTS_QUERY2 = {
19205
+ entity: "comment",
19206
+ backend: "native",
19207
+ fields: [termField("author", "kw", "author:u2")]
19208
+ };
19209
+ var ALL_PAGES = 20;
19210
+ var ALL_PAGE_SIZE = 100;
19211
+ var listAll = /* @__PURE__ */ __name(async (service, author) => {
19212
+ const items = [];
19213
+ for (let page = 0; page < ALL_PAGES; page++) {
19214
+ const found = await service.list({ limit: ALL_PAGE_SIZE, offset: page * ALL_PAGE_SIZE, author });
19215
+ for (const item of found.items)
19216
+ items.push(item);
19217
+ if (!found.has_more)
19218
+ return { items, has_more: false };
19219
+ }
19220
+ return { items, has_more: true };
19221
+ }, "listAll");
19222
+ var listCommand4 = /* @__PURE__ */ __name(() => withPaging(withQuery(answerEntity(annotate(new Command("list"), {
19223
+ effects: REMOTE_READ,
19224
+ offline: false,
19225
+ examples: [`${CLI} personal comments list`, `${CLI} personal comments list author:u2 --json=id,text`]
19226
+ }), "comment", commentSchema), COMMENTS_QUERY2)).description(`list the comments in ${SERVICE}, newest first`).action(async function(words3) {
19227
+ const path = commandPath(this);
19228
+ const author = queryTerms(words3, COMMENTS_QUERY2, path).get("author");
19229
+ const { settings } = contextOf(this);
19230
+ const found = await withService(this, (service) => settings.all ? listAll(service, author) : service.list({ ...pageOf(settings), author }));
19231
+ renderAnswer(this, outputFor(this), pagedList(path, settings, found));
19232
+ }), "listCommand");
19233
+ var showCommand3 = /* @__PURE__ */ __name(() => answerEntity(annotate(new Command("show"), {
19234
+ effects: REMOTE_READ,
19235
+ offline: false,
19236
+ examples: [`${CLI} personal comments show c1`, `${CLI} personal comments show c1 --json`]
19237
+ }), "comment", commentSchema).description(`show one comment in ${SERVICE}`).argument("<id>", "the comment's id, as list prints it").action(async function(id3) {
19238
+ renderAnswer(this, outputFor(this), itemOf(await withService(this, (service) => service.show(id3))));
19239
+ }), "showCommand");
19240
+ var write = /* @__PURE__ */ __name(async (command, act2) => {
19241
+ const { settings, env, renderer } = contextOf(command);
19242
+ const key = commandPath(command).replaceAll(" ", ".");
19243
+ const operationId = newOperationId();
19244
+ const levelOf = /* @__PURE__ */ __name((one) => levelFor(settings.permissions, one, permissions.defaults).level, "levelOf");
19245
+ const guard = keyedGuard((ask) => guardFor(
19246
+ IDENTITY,
19247
+ // SAMPLE: the service limits its own rate, so this guard keeps the levels and the journal, not a send cap.
19248
+ { ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: permissions.defaults },
19249
+ renderer.warn,
19250
+ env,
19251
+ ask
19252
+ ), terminalAsker(command), levelOf, []);
19253
+ const request = { chatId: null, kind: "edit", key, operationId };
19254
+ guard.refuse(request);
19255
+ let comment;
18916
19256
  try {
18917
- const settings = configuration.resolveSettings({}, { env, readOnly: true, needsProfile: false, withIssues: true });
18918
- const { files, fixes } = configFiles3(settings.configPath);
18919
- return {
18920
- report: {
18921
- ...common,
18922
- config: { path: settings.configPath, found: settings.configFound, issues: settings.configIssues ?? [] },
18923
- profiles: settings.configuredProfiles,
18924
- read_only: readOnly,
18925
- files
18926
- },
18927
- fixes
18928
- };
19257
+ comment = await guardedWrite(guard, request, () => withService(command, act2));
18929
19258
  } catch (error) {
18930
- const file = configFilePath(paths.config);
18931
- const { files, fixes } = configFiles3(file);
18932
- return {
18933
- report: {
18934
- ...common,
18935
- config: { path: file, found: existsSync18(file), issues: [] },
18936
- settings: { error: failure2(error) },
18937
- profiles: null,
18938
- read_only: readOnly,
18939
- files
18940
- },
18941
- fixes
18942
- };
19259
+ if (error instanceof CliError && error.code === "outcome_unknown")
19260
+ throw new CliError("outcome_unknown", error.message, { ...error.details, operation_id: operationId });
19261
+ throw error;
18943
19262
  }
18944
- }, "doctorReport");
18945
- var doctorCommand3 = /* @__PURE__ */ __name(() => profileFree(annotate(new Command("doctor"), {
18946
- effects: LOCAL_READ,
18947
- examples: [`${IDENTITY.command} doctor`, `${IDENTITY.command} doctor --json`]
18948
- })).description("check this installation: version, paths, config, profiles; no keyring or network").action(function() {
18949
- const env = environmentOf(this).env ?? process.env;
18950
- const { report: report2, fixes } = doctorReport(env);
18951
- const output = outputFor(this);
18952
- renderAnswer(this, output, itemOf(report2));
18953
- for (const fix of fixes)
18954
- output.renderer.note(`to make it private: ${fix}`);
18955
- }), "doctorCommand");
18956
-
18957
- // dist/commands/mcp.js
18958
- var SETUP = `claude mcp add ${IDENTITY.command} -- ${IDENTITY.command} personal mcp serve`;
18959
- var settingsOf2 = /* @__PURE__ */ __name((command) => {
18960
- const flags = command.optsWithGlobals();
18961
- const env = environmentOf(command).env ?? process.env;
18962
- const { profile } = configuration.resolveSettings(flags, { env });
18963
- return { flags, env, profile, tokenFile: httpTokenFile(IDENTITY, profile, env) };
18964
- }, "settingsOf");
18965
- var serveCommand3 = /* @__PURE__ */ __name(() => annotate(new Command("serve"), {
19263
+ renderAnswer(command, outputFor(command), itemOf({ operation_id: operationId, comment }));
19264
+ }, "write");
19265
+ var createCommand = /* @__PURE__ */ __name(() => annotate(new Command("create"), {
18966
19266
  effects: REMOTE_WRITE,
18967
- lifetime: "persistent",
18968
- mcp: false,
19267
+ offline: false,
18969
19268
  examples: [
18970
- `${IDENTITY.command} personal mcp serve`,
18971
- `${IDENTITY.command} personal mcp serve --http --public-url https://laptop.example.ts.net`
19269
+ `${CLI} personal comments create --text "Looks good to me"`,
19270
+ `${CLI} personal comments create --text "Looks good to me" --dry-run`
18972
19271
  ]
18973
- }).summary("serve this profile's commands to an AI agent").description(`serve this profile's commands to an agent over MCP, on stdin and stdout, writes included; the profile's permissions decide \u2014 \`${SETUP}\``).option("--http", "serve over HTTP on 127.0.0.1 for ChatGPT and Claude in the browser, behind your tunnel; the profile's permissions decide").option("--port <port>", `the local port for --http (default ${MCP_HTTP_DEFAULT_PORT})`).option("--public-url <url>", "the tunnel's https address the browser apps use, e.g. https://<name>.ts.net").action(async function() {
18974
- const { flags, env, profile, tokenFile } = settingsOf2(this);
18975
- if (!flags.http && (flags.json || flags.jsonl))
18976
- throw new CliError("validation_error", "MCP over stdio controls its own output; leave out --json and --jsonl");
18977
- const environment = environmentOf(this);
18978
- const run3 = environment.runCommand;
18979
- if (!run3)
18980
- throw new Error("mcp serve runs inside the program's run(), which provides runCommand");
18981
- const program = rootOf(this);
18982
- const options = {
18983
- profile,
18984
- commands: describeProgram(program),
18985
- levels: /* @__PURE__ */ __name(() => configuration.resolveSettings(flags, { env }).permissions, "levels"),
18986
- authority: changesAuthorityAt(program),
18987
- run: run3,
18988
- ...environment.signal ? { signal: environment.signal } : {}
19272
+ }).description(`post a comment in ${SERVICE}`).requiredOption("--text <text>", "the comment's text").action(async function(args) {
19273
+ await write(this, (service) => service.create(args.text));
19274
+ }), "createCommand");
19275
+ var updateCommand2 = /* @__PURE__ */ __name(() => annotate(new Command("update"), {
19276
+ effects: REMOTE_WRITE,
19277
+ offline: false,
19278
+ examples: [`${CLI} personal comments update c1 --text "Looks good now"`]
19279
+ }).description(`change the text of your comment in ${SERVICE}`).argument("<id>", "the comment's id, as list prints it").requiredOption("--text <text>", "the new text").action(async function(id3, args) {
19280
+ await write(this, (service) => service.update(id3, args.text));
19281
+ }), "updateCommand");
19282
+ var commentsCommand2 = /* @__PURE__ */ __name(() => annotate(new Command("comments"), { effects: REMOTE_READ }).description(`read and write comments in ${SERVICE}, the sample service`).addCommand(listCommand4()).addCommand(showCommand3()).addCommand(createCommand()).addCommand(updateCommand2()), "commentsCommand");
19283
+
19284
+ // node_modules/.pnpm/qrcode-generator@2.0.4/node_modules/qrcode-generator/dist/qrcode.mjs
19285
+ var qrcode = /* @__PURE__ */ __name(function(typeNumber, errorCorrectionLevel) {
19286
+ const PAD0 = 236;
19287
+ const PAD1 = 17;
19288
+ let _typeNumber = typeNumber;
19289
+ const _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
19290
+ let _modules = null;
19291
+ let _moduleCount = 0;
19292
+ let _dataCache = null;
19293
+ const _dataList = [];
19294
+ const _this = {};
19295
+ const makeImpl = /* @__PURE__ */ __name(function(test, maskPattern) {
19296
+ _moduleCount = _typeNumber * 4 + 17;
19297
+ _modules = (function(moduleCount) {
19298
+ const modules = new Array(moduleCount);
19299
+ for (let row2 = 0; row2 < moduleCount; row2 += 1) {
19300
+ modules[row2] = new Array(moduleCount);
19301
+ for (let col = 0; col < moduleCount; col += 1) {
19302
+ modules[row2][col] = null;
19303
+ }
19304
+ }
19305
+ return modules;
19306
+ })(_moduleCount);
19307
+ setupPositionProbePattern(0, 0);
19308
+ setupPositionProbePattern(_moduleCount - 7, 0);
19309
+ setupPositionProbePattern(0, _moduleCount - 7);
19310
+ setupPositionAdjustPattern();
19311
+ setupTimingPattern();
19312
+ setupTypeInfo(test, maskPattern);
19313
+ if (_typeNumber >= 7) {
19314
+ setupTypeNumber(test);
19315
+ }
19316
+ if (_dataCache == null) {
19317
+ _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
19318
+ }
19319
+ mapData(_dataCache, maskPattern);
19320
+ }, "makeImpl");
19321
+ const setupPositionProbePattern = /* @__PURE__ */ __name(function(row2, col) {
19322
+ for (let r2 = -1; r2 <= 7; r2 += 1) {
19323
+ if (row2 + r2 <= -1 || _moduleCount <= row2 + r2) continue;
19324
+ for (let c2 = -1; c2 <= 7; c2 += 1) {
19325
+ if (col + c2 <= -1 || _moduleCount <= col + c2) continue;
19326
+ if (0 <= r2 && r2 <= 6 && (c2 == 0 || c2 == 6) || 0 <= c2 && c2 <= 6 && (r2 == 0 || r2 == 6) || 2 <= r2 && r2 <= 4 && 2 <= c2 && c2 <= 4) {
19327
+ _modules[row2 + r2][col + c2] = true;
19328
+ } else {
19329
+ _modules[row2 + r2][col + c2] = false;
19330
+ }
19331
+ }
19332
+ }
19333
+ }, "setupPositionProbePattern");
19334
+ const getBestMaskPattern = /* @__PURE__ */ __name(function() {
19335
+ let minLostPoint = 0;
19336
+ let pattern = 0;
19337
+ for (let i3 = 0; i3 < 8; i3 += 1) {
19338
+ makeImpl(true, i3);
19339
+ const lostPoint = QRUtil.getLostPoint(_this);
19340
+ if (i3 == 0 || minLostPoint > lostPoint) {
19341
+ minLostPoint = lostPoint;
19342
+ pattern = i3;
19343
+ }
19344
+ }
19345
+ return pattern;
19346
+ }, "getBestMaskPattern");
19347
+ const setupTimingPattern = /* @__PURE__ */ __name(function() {
19348
+ for (let r2 = 8; r2 < _moduleCount - 8; r2 += 1) {
19349
+ if (_modules[r2][6] != null) {
19350
+ continue;
19351
+ }
19352
+ _modules[r2][6] = r2 % 2 == 0;
19353
+ }
19354
+ for (let c2 = 8; c2 < _moduleCount - 8; c2 += 1) {
19355
+ if (_modules[6][c2] != null) {
19356
+ continue;
19357
+ }
19358
+ _modules[6][c2] = c2 % 2 == 0;
19359
+ }
19360
+ }, "setupTimingPattern");
19361
+ const setupPositionAdjustPattern = /* @__PURE__ */ __name(function() {
19362
+ const pos = QRUtil.getPatternPosition(_typeNumber);
19363
+ for (let i3 = 0; i3 < pos.length; i3 += 1) {
19364
+ for (let j = 0; j < pos.length; j += 1) {
19365
+ const row2 = pos[i3];
19366
+ const col = pos[j];
19367
+ if (_modules[row2][col] != null) {
19368
+ continue;
19369
+ }
19370
+ for (let r2 = -2; r2 <= 2; r2 += 1) {
19371
+ for (let c2 = -2; c2 <= 2; c2 += 1) {
19372
+ if (r2 == -2 || r2 == 2 || c2 == -2 || c2 == 2 || r2 == 0 && c2 == 0) {
19373
+ _modules[row2 + r2][col + c2] = true;
19374
+ } else {
19375
+ _modules[row2 + r2][col + c2] = false;
19376
+ }
19377
+ }
19378
+ }
19379
+ }
19380
+ }
19381
+ }, "setupPositionAdjustPattern");
19382
+ const setupTypeNumber = /* @__PURE__ */ __name(function(test) {
19383
+ const bits = QRUtil.getBCHTypeNumber(_typeNumber);
19384
+ for (let i3 = 0; i3 < 18; i3 += 1) {
19385
+ const mod = !test && (bits >> i3 & 1) == 1;
19386
+ _modules[Math.floor(i3 / 3)][i3 % 3 + _moduleCount - 8 - 3] = mod;
19387
+ }
19388
+ for (let i3 = 0; i3 < 18; i3 += 1) {
19389
+ const mod = !test && (bits >> i3 & 1) == 1;
19390
+ _modules[i3 % 3 + _moduleCount - 8 - 3][Math.floor(i3 / 3)] = mod;
19391
+ }
19392
+ }, "setupTypeNumber");
19393
+ const setupTypeInfo = /* @__PURE__ */ __name(function(test, maskPattern) {
19394
+ const data = _errorCorrectionLevel << 3 | maskPattern;
19395
+ const bits = QRUtil.getBCHTypeInfo(data);
19396
+ for (let i3 = 0; i3 < 15; i3 += 1) {
19397
+ const mod = !test && (bits >> i3 & 1) == 1;
19398
+ if (i3 < 6) {
19399
+ _modules[i3][8] = mod;
19400
+ } else if (i3 < 8) {
19401
+ _modules[i3 + 1][8] = mod;
19402
+ } else {
19403
+ _modules[_moduleCount - 15 + i3][8] = mod;
19404
+ }
19405
+ }
19406
+ for (let i3 = 0; i3 < 15; i3 += 1) {
19407
+ const mod = !test && (bits >> i3 & 1) == 1;
19408
+ if (i3 < 8) {
19409
+ _modules[8][_moduleCount - i3 - 1] = mod;
19410
+ } else if (i3 < 9) {
19411
+ _modules[8][15 - i3 - 1 + 1] = mod;
19412
+ } else {
19413
+ _modules[8][15 - i3 - 1] = mod;
19414
+ }
19415
+ }
19416
+ _modules[_moduleCount - 8][8] = !test;
19417
+ }, "setupTypeInfo");
19418
+ const mapData = /* @__PURE__ */ __name(function(data, maskPattern) {
19419
+ let inc = -1;
19420
+ let row2 = _moduleCount - 1;
19421
+ let bitIndex = 7;
19422
+ let byteIndex = 0;
19423
+ const maskFunc = QRUtil.getMaskFunction(maskPattern);
19424
+ for (let col = _moduleCount - 1; col > 0; col -= 2) {
19425
+ if (col == 6) col -= 1;
19426
+ while (true) {
19427
+ for (let c2 = 0; c2 < 2; c2 += 1) {
19428
+ if (_modules[row2][col - c2] == null) {
19429
+ let dark = false;
19430
+ if (byteIndex < data.length) {
19431
+ dark = (data[byteIndex] >>> bitIndex & 1) == 1;
19432
+ }
19433
+ const mask = maskFunc(row2, col - c2);
19434
+ if (mask) {
19435
+ dark = !dark;
19436
+ }
19437
+ _modules[row2][col - c2] = dark;
19438
+ bitIndex -= 1;
19439
+ if (bitIndex == -1) {
19440
+ byteIndex += 1;
19441
+ bitIndex = 7;
19442
+ }
19443
+ }
19444
+ }
19445
+ row2 += inc;
19446
+ if (row2 < 0 || _moduleCount <= row2) {
19447
+ row2 -= inc;
19448
+ inc = -inc;
19449
+ break;
19450
+ }
19451
+ }
19452
+ }
19453
+ }, "mapData");
19454
+ const createBytes = /* @__PURE__ */ __name(function(buffer, rsBlocks) {
19455
+ let offset = 0;
19456
+ let maxDcCount = 0;
19457
+ let maxEcCount = 0;
19458
+ const dcdata = new Array(rsBlocks.length);
19459
+ const ecdata = new Array(rsBlocks.length);
19460
+ for (let r2 = 0; r2 < rsBlocks.length; r2 += 1) {
19461
+ const dcCount = rsBlocks[r2].dataCount;
19462
+ const ecCount = rsBlocks[r2].totalCount - dcCount;
19463
+ maxDcCount = Math.max(maxDcCount, dcCount);
19464
+ maxEcCount = Math.max(maxEcCount, ecCount);
19465
+ dcdata[r2] = new Array(dcCount);
19466
+ for (let i3 = 0; i3 < dcdata[r2].length; i3 += 1) {
19467
+ dcdata[r2][i3] = 255 & buffer.getBuffer()[i3 + offset];
19468
+ }
19469
+ offset += dcCount;
19470
+ const rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
19471
+ const rawPoly = qrPolynomial(dcdata[r2], rsPoly.getLength() - 1);
19472
+ const modPoly = rawPoly.mod(rsPoly);
19473
+ ecdata[r2] = new Array(rsPoly.getLength() - 1);
19474
+ for (let i3 = 0; i3 < ecdata[r2].length; i3 += 1) {
19475
+ const modIndex = i3 + modPoly.getLength() - ecdata[r2].length;
19476
+ ecdata[r2][i3] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
19477
+ }
19478
+ }
19479
+ let totalCodeCount = 0;
19480
+ for (let i3 = 0; i3 < rsBlocks.length; i3 += 1) {
19481
+ totalCodeCount += rsBlocks[i3].totalCount;
19482
+ }
19483
+ const data = new Array(totalCodeCount);
19484
+ let index = 0;
19485
+ for (let i3 = 0; i3 < maxDcCount; i3 += 1) {
19486
+ for (let r2 = 0; r2 < rsBlocks.length; r2 += 1) {
19487
+ if (i3 < dcdata[r2].length) {
19488
+ data[index] = dcdata[r2][i3];
19489
+ index += 1;
19490
+ }
19491
+ }
19492
+ }
19493
+ for (let i3 = 0; i3 < maxEcCount; i3 += 1) {
19494
+ for (let r2 = 0; r2 < rsBlocks.length; r2 += 1) {
19495
+ if (i3 < ecdata[r2].length) {
19496
+ data[index] = ecdata[r2][i3];
19497
+ index += 1;
19498
+ }
19499
+ }
19500
+ }
19501
+ return data;
19502
+ }, "createBytes");
19503
+ const createData = /* @__PURE__ */ __name(function(typeNumber2, errorCorrectionLevel2, dataList) {
19504
+ const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, errorCorrectionLevel2);
19505
+ const buffer = qrBitBuffer();
19506
+ for (let i3 = 0; i3 < dataList.length; i3 += 1) {
19507
+ const data = dataList[i3];
19508
+ buffer.put(data.getMode(), 4);
19509
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
19510
+ data.write(buffer);
19511
+ }
19512
+ let totalDataCount = 0;
19513
+ for (let i3 = 0; i3 < rsBlocks.length; i3 += 1) {
19514
+ totalDataCount += rsBlocks[i3].dataCount;
19515
+ }
19516
+ if (buffer.getLengthInBits() > totalDataCount * 8) {
19517
+ throw "code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")";
19518
+ }
19519
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
19520
+ buffer.put(0, 4);
19521
+ }
19522
+ while (buffer.getLengthInBits() % 8 != 0) {
19523
+ buffer.putBit(false);
19524
+ }
19525
+ while (true) {
19526
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
19527
+ break;
19528
+ }
19529
+ buffer.put(PAD0, 8);
19530
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
19531
+ break;
19532
+ }
19533
+ buffer.put(PAD1, 8);
19534
+ }
19535
+ return createBytes(buffer, rsBlocks);
19536
+ }, "createData");
19537
+ _this.addData = function(data, mode) {
19538
+ mode = mode || "Byte";
19539
+ let newData = null;
19540
+ switch (mode) {
19541
+ case "Numeric":
19542
+ newData = qrNumber(data);
19543
+ break;
19544
+ case "Alphanumeric":
19545
+ newData = qrAlphaNum(data);
19546
+ break;
19547
+ case "Byte":
19548
+ newData = qr8BitByte(data);
19549
+ break;
19550
+ case "Kanji":
19551
+ newData = qrKanji(data);
19552
+ break;
19553
+ default:
19554
+ throw "mode:" + mode;
19555
+ }
19556
+ _dataList.push(newData);
19557
+ _dataCache = null;
18989
19558
  };
18990
- const { serveMcp, serveMcpOverHttp } = await import("./mcp-ASNYBQ5B.js");
18991
- if (!flags.http)
18992
- return serveMcp(options);
18993
- const { portOf: portOf2, publicUrlOf: publicUrlOf2 } = await import("./mcp-EY2NUYDQ.js");
18994
- const { renderer } = outputFor(this);
18995
- await serveMcpOverHttp(options, {
18996
- publicUrl: publicUrlOf2(flags.publicUrl, {
18997
- missing: "--http",
18998
- reaches: `the browser apps reach ${IDENTITY.command}`
18999
- }),
19000
- port: portOf2(flags.port, MCP_HTTP_DEFAULT_PORT),
19001
- tokenFile,
19002
- background: env[`${IDENTITY.envPrefix}_MCP_HTTP`] !== void 0,
19003
- note: /* @__PURE__ */ __name((line7) => renderer.note(line7), "note")
19004
- });
19005
- }), "serveCommand");
19006
- var revokeCommand = /* @__PURE__ */ __name(() => annotate(new Command("revoke"), {
19559
+ _this.isDark = function(row2, col) {
19560
+ if (row2 < 0 || _moduleCount <= row2 || col < 0 || _moduleCount <= col) {
19561
+ throw row2 + "," + col;
19562
+ }
19563
+ return _modules[row2][col];
19564
+ };
19565
+ _this.getModuleCount = function() {
19566
+ return _moduleCount;
19567
+ };
19568
+ _this.make = function() {
19569
+ if (_typeNumber < 1) {
19570
+ let typeNumber2 = 1;
19571
+ for (; typeNumber2 < 40; typeNumber2++) {
19572
+ const rsBlocks = QRRSBlock.getRSBlocks(typeNumber2, _errorCorrectionLevel);
19573
+ const buffer = qrBitBuffer();
19574
+ for (let i3 = 0; i3 < _dataList.length; i3++) {
19575
+ const data = _dataList[i3];
19576
+ buffer.put(data.getMode(), 4);
19577
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber2));
19578
+ data.write(buffer);
19579
+ }
19580
+ let totalDataCount = 0;
19581
+ for (let i3 = 0; i3 < rsBlocks.length; i3++) {
19582
+ totalDataCount += rsBlocks[i3].dataCount;
19583
+ }
19584
+ if (buffer.getLengthInBits() <= totalDataCount * 8) {
19585
+ break;
19586
+ }
19587
+ }
19588
+ _typeNumber = typeNumber2;
19589
+ }
19590
+ makeImpl(false, getBestMaskPattern());
19591
+ };
19592
+ _this.createTableTag = function(cellSize, margin) {
19593
+ cellSize = cellSize || 2;
19594
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
19595
+ let qrHtml = "";
19596
+ qrHtml += '<table style="';
19597
+ qrHtml += " border-width: 0px; border-style: none;";
19598
+ qrHtml += " border-collapse: collapse;";
19599
+ qrHtml += " padding: 0px; margin: " + margin + "px;";
19600
+ qrHtml += '">';
19601
+ qrHtml += "<tbody>";
19602
+ for (let r2 = 0; r2 < _this.getModuleCount(); r2 += 1) {
19603
+ qrHtml += "<tr>";
19604
+ for (let c2 = 0; c2 < _this.getModuleCount(); c2 += 1) {
19605
+ qrHtml += '<td style="';
19606
+ qrHtml += " border-width: 0px; border-style: none;";
19607
+ qrHtml += " border-collapse: collapse;";
19608
+ qrHtml += " padding: 0px; margin: 0px;";
19609
+ qrHtml += " width: " + cellSize + "px;";
19610
+ qrHtml += " height: " + cellSize + "px;";
19611
+ qrHtml += " background-color: ";
19612
+ qrHtml += _this.isDark(r2, c2) ? "#000000" : "#ffffff";
19613
+ qrHtml += ";";
19614
+ qrHtml += '"/>';
19615
+ }
19616
+ qrHtml += "</tr>";
19617
+ }
19618
+ qrHtml += "</tbody>";
19619
+ qrHtml += "</table>";
19620
+ return qrHtml;
19621
+ };
19622
+ _this.createSvgTag = function(cellSize, margin, alt, title) {
19623
+ let opts = {};
19624
+ if (typeof arguments[0] == "object") {
19625
+ opts = arguments[0];
19626
+ cellSize = opts.cellSize;
19627
+ margin = opts.margin;
19628
+ alt = opts.alt;
19629
+ title = opts.title;
19630
+ }
19631
+ cellSize = cellSize || 2;
19632
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
19633
+ alt = typeof alt === "string" ? { text: alt } : alt || {};
19634
+ alt.text = alt.text || null;
19635
+ alt.id = alt.text ? alt.id || "qrcode-description" : null;
19636
+ title = typeof title === "string" ? { text: title } : title || {};
19637
+ title.text = title.text || null;
19638
+ title.id = title.text ? title.id || "qrcode-title" : null;
19639
+ const size = _this.getModuleCount() * cellSize + margin * 2;
19640
+ let c2, mc, r2, mr, qrSvg = "", rect;
19641
+ rect = "l" + cellSize + ",0 0," + cellSize + " -" + cellSize + ",0 0,-" + cellSize + "z ";
19642
+ qrSvg += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg"';
19643
+ qrSvg += !opts.scalable ? ' width="' + size + 'px" height="' + size + 'px"' : "";
19644
+ qrSvg += ' viewBox="0 0 ' + size + " " + size + '" ';
19645
+ qrSvg += ' preserveAspectRatio="xMinYMin meet"';
19646
+ qrSvg += title.text || alt.text ? ' role="img" aria-labelledby="' + escapeXml([title.id, alt.id].join(" ").trim()) + '"' : "";
19647
+ qrSvg += ">";
19648
+ qrSvg += title.text ? '<title id="' + escapeXml(title.id) + '">' + escapeXml(title.text) + "</title>" : "";
19649
+ qrSvg += alt.text ? '<description id="' + escapeXml(alt.id) + '">' + escapeXml(alt.text) + "</description>" : "";
19650
+ qrSvg += '<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>';
19651
+ qrSvg += '<path d="';
19652
+ for (r2 = 0; r2 < _this.getModuleCount(); r2 += 1) {
19653
+ mr = r2 * cellSize + margin;
19654
+ for (c2 = 0; c2 < _this.getModuleCount(); c2 += 1) {
19655
+ if (_this.isDark(r2, c2)) {
19656
+ mc = c2 * cellSize + margin;
19657
+ qrSvg += "M" + mc + "," + mr + rect;
19658
+ }
19659
+ }
19660
+ }
19661
+ qrSvg += '" stroke="transparent" fill="black"/>';
19662
+ qrSvg += "</svg>";
19663
+ return qrSvg;
19664
+ };
19665
+ _this.createDataURL = function(cellSize, margin) {
19666
+ cellSize = cellSize || 2;
19667
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
19668
+ const size = _this.getModuleCount() * cellSize + margin * 2;
19669
+ const min = margin;
19670
+ const max = size - margin;
19671
+ return createDataURL(size, size, function(x, y) {
19672
+ if (min <= x && x < max && min <= y && y < max) {
19673
+ const c2 = Math.floor((x - min) / cellSize);
19674
+ const r2 = Math.floor((y - min) / cellSize);
19675
+ return _this.isDark(r2, c2) ? 0 : 1;
19676
+ } else {
19677
+ return 1;
19678
+ }
19679
+ });
19680
+ };
19681
+ _this.createImgTag = function(cellSize, margin, alt) {
19682
+ cellSize = cellSize || 2;
19683
+ margin = typeof margin == "undefined" ? cellSize * 4 : margin;
19684
+ const size = _this.getModuleCount() * cellSize + margin * 2;
19685
+ let img = "";
19686
+ img += "<img";
19687
+ img += ' src="';
19688
+ img += _this.createDataURL(cellSize, margin);
19689
+ img += '"';
19690
+ img += ' width="';
19691
+ img += size;
19692
+ img += '"';
19693
+ img += ' height="';
19694
+ img += size;
19695
+ img += '"';
19696
+ if (alt) {
19697
+ img += ' alt="';
19698
+ img += escapeXml(alt);
19699
+ img += '"';
19700
+ }
19701
+ img += "/>";
19702
+ return img;
19703
+ };
19704
+ const escapeXml = /* @__PURE__ */ __name(function(s2) {
19705
+ let escaped = "";
19706
+ for (let i3 = 0; i3 < s2.length; i3 += 1) {
19707
+ const c2 = s2.charAt(i3);
19708
+ switch (c2) {
19709
+ case "<":
19710
+ escaped += "&lt;";
19711
+ break;
19712
+ case ">":
19713
+ escaped += "&gt;";
19714
+ break;
19715
+ case "&":
19716
+ escaped += "&amp;";
19717
+ break;
19718
+ case '"':
19719
+ escaped += "&quot;";
19720
+ break;
19721
+ default:
19722
+ escaped += c2;
19723
+ break;
19724
+ }
19725
+ }
19726
+ return escaped;
19727
+ }, "escapeXml");
19728
+ const _createHalfASCII = /* @__PURE__ */ __name(function(margin) {
19729
+ const cellSize = 1;
19730
+ margin = typeof margin == "undefined" ? cellSize * 2 : margin;
19731
+ const size = _this.getModuleCount() * cellSize + margin * 2;
19732
+ const min = margin;
19733
+ const max = size - margin;
19734
+ let y, x, r1, r2, p;
19735
+ const blocks = {
19736
+ "\u2588\u2588": "\u2588",
19737
+ "\u2588 ": "\u2580",
19738
+ " \u2588": "\u2584",
19739
+ " ": " "
19740
+ };
19741
+ const blocksLastLineNoMargin = {
19742
+ "\u2588\u2588": "\u2580",
19743
+ "\u2588 ": "\u2580",
19744
+ " \u2588": " ",
19745
+ " ": " "
19746
+ };
19747
+ let ascii = "";
19748
+ for (y = 0; y < size; y += 2) {
19749
+ r1 = Math.floor((y - min) / cellSize);
19750
+ r2 = Math.floor((y + 1 - min) / cellSize);
19751
+ for (x = 0; x < size; x += 1) {
19752
+ p = "\u2588";
19753
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
19754
+ p = " ";
19755
+ }
19756
+ if (min <= x && x < max && min <= y + 1 && y + 1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
19757
+ p += " ";
19758
+ } else {
19759
+ p += "\u2588";
19760
+ }
19761
+ ascii += margin < 1 && y + 1 >= max ? blocksLastLineNoMargin[p] : blocks[p];
19762
+ }
19763
+ ascii += "\n";
19764
+ }
19765
+ if (size % 2 && margin > 0) {
19766
+ return ascii.substring(0, ascii.length - size - 1) + Array(size + 1).join("\u2580");
19767
+ }
19768
+ return ascii.substring(0, ascii.length - 1);
19769
+ }, "_createHalfASCII");
19770
+ _this.createASCII = function(cellSize, margin) {
19771
+ cellSize = cellSize || 1;
19772
+ if (cellSize < 2) {
19773
+ return _createHalfASCII(margin);
19774
+ }
19775
+ cellSize -= 1;
19776
+ margin = typeof margin == "undefined" ? cellSize * 2 : margin;
19777
+ const size = _this.getModuleCount() * cellSize + margin * 2;
19778
+ const min = margin;
19779
+ const max = size - margin;
19780
+ let y, x, r2, p;
19781
+ const white = Array(cellSize + 1).join("\u2588\u2588");
19782
+ const black = Array(cellSize + 1).join(" ");
19783
+ let ascii = "";
19784
+ let line7 = "";
19785
+ for (y = 0; y < size; y += 1) {
19786
+ r2 = Math.floor((y - min) / cellSize);
19787
+ line7 = "";
19788
+ for (x = 0; x < size; x += 1) {
19789
+ p = 1;
19790
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
19791
+ p = 0;
19792
+ }
19793
+ line7 += p ? white : black;
19794
+ }
19795
+ for (r2 = 0; r2 < cellSize; r2 += 1) {
19796
+ ascii += line7 + "\n";
19797
+ }
19798
+ }
19799
+ return ascii.substring(0, ascii.length - 1);
19800
+ };
19801
+ _this.renderTo2dContext = function(context, cellSize) {
19802
+ cellSize = cellSize || 2;
19803
+ const length = _this.getModuleCount();
19804
+ for (let row2 = 0; row2 < length; row2++) {
19805
+ for (let col = 0; col < length; col++) {
19806
+ context.fillStyle = _this.isDark(row2, col) ? "black" : "white";
19807
+ context.fillRect(col * cellSize, row2 * cellSize, cellSize, cellSize);
19808
+ }
19809
+ }
19810
+ };
19811
+ return _this;
19812
+ }, "qrcode");
19813
+ qrcode.stringToBytes = function(s2) {
19814
+ const bytes = [];
19815
+ for (let i3 = 0; i3 < s2.length; i3 += 1) {
19816
+ const c2 = s2.charCodeAt(i3);
19817
+ bytes.push(c2 & 255);
19818
+ }
19819
+ return bytes;
19820
+ };
19821
+ qrcode.createStringToBytes = function(unicodeData, numChars) {
19822
+ const unicodeMap = (function() {
19823
+ const bin = base64DecodeInputStream(unicodeData);
19824
+ const read3 = /* @__PURE__ */ __name(function() {
19825
+ const b = bin.read();
19826
+ if (b == -1) throw "eof";
19827
+ return b;
19828
+ }, "read");
19829
+ let count5 = 0;
19830
+ const unicodeMap2 = {};
19831
+ while (true) {
19832
+ const b0 = bin.read();
19833
+ if (b0 == -1) break;
19834
+ const b1 = read3();
19835
+ const b2 = read3();
19836
+ const b3 = read3();
19837
+ const k = String.fromCharCode(b0 << 8 | b1);
19838
+ const v = b2 << 8 | b3;
19839
+ unicodeMap2[k] = v;
19840
+ count5 += 1;
19841
+ }
19842
+ if (count5 != numChars) {
19843
+ throw count5 + " != " + numChars;
19844
+ }
19845
+ return unicodeMap2;
19846
+ })();
19847
+ const unknownChar = "?".charCodeAt(0);
19848
+ return function(s2) {
19849
+ const bytes = [];
19850
+ for (let i3 = 0; i3 < s2.length; i3 += 1) {
19851
+ const c2 = s2.charCodeAt(i3);
19852
+ if (c2 < 128) {
19853
+ bytes.push(c2);
19854
+ } else {
19855
+ const b = unicodeMap[s2.charAt(i3)];
19856
+ if (typeof b == "number") {
19857
+ if ((b & 255) == b) {
19858
+ bytes.push(b);
19859
+ } else {
19860
+ bytes.push(b >>> 8);
19861
+ bytes.push(b & 255);
19862
+ }
19863
+ } else {
19864
+ bytes.push(unknownChar);
19865
+ }
19866
+ }
19867
+ }
19868
+ return bytes;
19869
+ };
19870
+ };
19871
+ var QRMode = {
19872
+ MODE_NUMBER: 1 << 0,
19873
+ MODE_ALPHA_NUM: 1 << 1,
19874
+ MODE_8BIT_BYTE: 1 << 2,
19875
+ MODE_KANJI: 1 << 3
19876
+ };
19877
+ var QRErrorCorrectionLevel = {
19878
+ L: 1,
19879
+ M: 0,
19880
+ Q: 3,
19881
+ H: 2
19882
+ };
19883
+ var QRMaskPattern = {
19884
+ PATTERN000: 0,
19885
+ PATTERN001: 1,
19886
+ PATTERN010: 2,
19887
+ PATTERN011: 3,
19888
+ PATTERN100: 4,
19889
+ PATTERN101: 5,
19890
+ PATTERN110: 6,
19891
+ PATTERN111: 7
19892
+ };
19893
+ var QRUtil = (function() {
19894
+ const PATTERN_POSITION_TABLE = [
19895
+ [],
19896
+ [6, 18],
19897
+ [6, 22],
19898
+ [6, 26],
19899
+ [6, 30],
19900
+ [6, 34],
19901
+ [6, 22, 38],
19902
+ [6, 24, 42],
19903
+ [6, 26, 46],
19904
+ [6, 28, 50],
19905
+ [6, 30, 54],
19906
+ [6, 32, 58],
19907
+ [6, 34, 62],
19908
+ [6, 26, 46, 66],
19909
+ [6, 26, 48, 70],
19910
+ [6, 26, 50, 74],
19911
+ [6, 30, 54, 78],
19912
+ [6, 30, 56, 82],
19913
+ [6, 30, 58, 86],
19914
+ [6, 34, 62, 90],
19915
+ [6, 28, 50, 72, 94],
19916
+ [6, 26, 50, 74, 98],
19917
+ [6, 30, 54, 78, 102],
19918
+ [6, 28, 54, 80, 106],
19919
+ [6, 32, 58, 84, 110],
19920
+ [6, 30, 58, 86, 114],
19921
+ [6, 34, 62, 90, 118],
19922
+ [6, 26, 50, 74, 98, 122],
19923
+ [6, 30, 54, 78, 102, 126],
19924
+ [6, 26, 52, 78, 104, 130],
19925
+ [6, 30, 56, 82, 108, 134],
19926
+ [6, 34, 60, 86, 112, 138],
19927
+ [6, 30, 58, 86, 114, 142],
19928
+ [6, 34, 62, 90, 118, 146],
19929
+ [6, 30, 54, 78, 102, 126, 150],
19930
+ [6, 24, 50, 76, 102, 128, 154],
19931
+ [6, 28, 54, 80, 106, 132, 158],
19932
+ [6, 32, 58, 84, 110, 136, 162],
19933
+ [6, 26, 54, 82, 110, 138, 166],
19934
+ [6, 30, 58, 86, 114, 142, 170]
19935
+ ];
19936
+ const G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
19937
+ const G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
19938
+ const G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
19939
+ const _this = {};
19940
+ const getBCHDigit = /* @__PURE__ */ __name(function(data) {
19941
+ let digit = 0;
19942
+ while (data != 0) {
19943
+ digit += 1;
19944
+ data >>>= 1;
19945
+ }
19946
+ return digit;
19947
+ }, "getBCHDigit");
19948
+ _this.getBCHTypeInfo = function(data) {
19949
+ let d2 = data << 10;
19950
+ while (getBCHDigit(d2) - getBCHDigit(G15) >= 0) {
19951
+ d2 ^= G15 << getBCHDigit(d2) - getBCHDigit(G15);
19952
+ }
19953
+ return (data << 10 | d2) ^ G15_MASK;
19954
+ };
19955
+ _this.getBCHTypeNumber = function(data) {
19956
+ let d2 = data << 12;
19957
+ while (getBCHDigit(d2) - getBCHDigit(G18) >= 0) {
19958
+ d2 ^= G18 << getBCHDigit(d2) - getBCHDigit(G18);
19959
+ }
19960
+ return data << 12 | d2;
19961
+ };
19962
+ _this.getPatternPosition = function(typeNumber) {
19963
+ return PATTERN_POSITION_TABLE[typeNumber - 1];
19964
+ };
19965
+ _this.getMaskFunction = function(maskPattern) {
19966
+ switch (maskPattern) {
19967
+ case QRMaskPattern.PATTERN000:
19968
+ return function(i3, j) {
19969
+ return (i3 + j) % 2 == 0;
19970
+ };
19971
+ case QRMaskPattern.PATTERN001:
19972
+ return function(i3, j) {
19973
+ return i3 % 2 == 0;
19974
+ };
19975
+ case QRMaskPattern.PATTERN010:
19976
+ return function(i3, j) {
19977
+ return j % 3 == 0;
19978
+ };
19979
+ case QRMaskPattern.PATTERN011:
19980
+ return function(i3, j) {
19981
+ return (i3 + j) % 3 == 0;
19982
+ };
19983
+ case QRMaskPattern.PATTERN100:
19984
+ return function(i3, j) {
19985
+ return (Math.floor(i3 / 2) + Math.floor(j / 3)) % 2 == 0;
19986
+ };
19987
+ case QRMaskPattern.PATTERN101:
19988
+ return function(i3, j) {
19989
+ return i3 * j % 2 + i3 * j % 3 == 0;
19990
+ };
19991
+ case QRMaskPattern.PATTERN110:
19992
+ return function(i3, j) {
19993
+ return (i3 * j % 2 + i3 * j % 3) % 2 == 0;
19994
+ };
19995
+ case QRMaskPattern.PATTERN111:
19996
+ return function(i3, j) {
19997
+ return (i3 * j % 3 + (i3 + j) % 2) % 2 == 0;
19998
+ };
19999
+ default:
20000
+ throw "bad maskPattern:" + maskPattern;
20001
+ }
20002
+ };
20003
+ _this.getErrorCorrectPolynomial = function(errorCorrectLength) {
20004
+ let a2 = qrPolynomial([1], 0);
20005
+ for (let i3 = 0; i3 < errorCorrectLength; i3 += 1) {
20006
+ a2 = a2.multiply(qrPolynomial([1, QRMath.gexp(i3)], 0));
20007
+ }
20008
+ return a2;
20009
+ };
20010
+ _this.getLengthInBits = function(mode, type) {
20011
+ if (1 <= type && type < 10) {
20012
+ switch (mode) {
20013
+ case QRMode.MODE_NUMBER:
20014
+ return 10;
20015
+ case QRMode.MODE_ALPHA_NUM:
20016
+ return 9;
20017
+ case QRMode.MODE_8BIT_BYTE:
20018
+ return 8;
20019
+ case QRMode.MODE_KANJI:
20020
+ return 8;
20021
+ default:
20022
+ throw "mode:" + mode;
20023
+ }
20024
+ } else if (type < 27) {
20025
+ switch (mode) {
20026
+ case QRMode.MODE_NUMBER:
20027
+ return 12;
20028
+ case QRMode.MODE_ALPHA_NUM:
20029
+ return 11;
20030
+ case QRMode.MODE_8BIT_BYTE:
20031
+ return 16;
20032
+ case QRMode.MODE_KANJI:
20033
+ return 10;
20034
+ default:
20035
+ throw "mode:" + mode;
20036
+ }
20037
+ } else if (type < 41) {
20038
+ switch (mode) {
20039
+ case QRMode.MODE_NUMBER:
20040
+ return 14;
20041
+ case QRMode.MODE_ALPHA_NUM:
20042
+ return 13;
20043
+ case QRMode.MODE_8BIT_BYTE:
20044
+ return 16;
20045
+ case QRMode.MODE_KANJI:
20046
+ return 12;
20047
+ default:
20048
+ throw "mode:" + mode;
20049
+ }
20050
+ } else {
20051
+ throw "type:" + type;
20052
+ }
20053
+ };
20054
+ _this.getLostPoint = function(qrcode2) {
20055
+ const moduleCount = qrcode2.getModuleCount();
20056
+ let lostPoint = 0;
20057
+ for (let row2 = 0; row2 < moduleCount; row2 += 1) {
20058
+ for (let col = 0; col < moduleCount; col += 1) {
20059
+ let sameCount = 0;
20060
+ const dark = qrcode2.isDark(row2, col);
20061
+ for (let r2 = -1; r2 <= 1; r2 += 1) {
20062
+ if (row2 + r2 < 0 || moduleCount <= row2 + r2) {
20063
+ continue;
20064
+ }
20065
+ for (let c2 = -1; c2 <= 1; c2 += 1) {
20066
+ if (col + c2 < 0 || moduleCount <= col + c2) {
20067
+ continue;
20068
+ }
20069
+ if (r2 == 0 && c2 == 0) {
20070
+ continue;
20071
+ }
20072
+ if (dark == qrcode2.isDark(row2 + r2, col + c2)) {
20073
+ sameCount += 1;
20074
+ }
20075
+ }
20076
+ }
20077
+ if (sameCount > 5) {
20078
+ lostPoint += 3 + sameCount - 5;
20079
+ }
20080
+ }
20081
+ }
20082
+ ;
20083
+ for (let row2 = 0; row2 < moduleCount - 1; row2 += 1) {
20084
+ for (let col = 0; col < moduleCount - 1; col += 1) {
20085
+ let count5 = 0;
20086
+ if (qrcode2.isDark(row2, col)) count5 += 1;
20087
+ if (qrcode2.isDark(row2 + 1, col)) count5 += 1;
20088
+ if (qrcode2.isDark(row2, col + 1)) count5 += 1;
20089
+ if (qrcode2.isDark(row2 + 1, col + 1)) count5 += 1;
20090
+ if (count5 == 0 || count5 == 4) {
20091
+ lostPoint += 3;
20092
+ }
20093
+ }
20094
+ }
20095
+ for (let row2 = 0; row2 < moduleCount; row2 += 1) {
20096
+ for (let col = 0; col < moduleCount - 6; col += 1) {
20097
+ if (qrcode2.isDark(row2, col) && !qrcode2.isDark(row2, col + 1) && qrcode2.isDark(row2, col + 2) && qrcode2.isDark(row2, col + 3) && qrcode2.isDark(row2, col + 4) && !qrcode2.isDark(row2, col + 5) && qrcode2.isDark(row2, col + 6)) {
20098
+ lostPoint += 40;
20099
+ }
20100
+ }
20101
+ }
20102
+ for (let col = 0; col < moduleCount; col += 1) {
20103
+ for (let row2 = 0; row2 < moduleCount - 6; row2 += 1) {
20104
+ if (qrcode2.isDark(row2, col) && !qrcode2.isDark(row2 + 1, col) && qrcode2.isDark(row2 + 2, col) && qrcode2.isDark(row2 + 3, col) && qrcode2.isDark(row2 + 4, col) && !qrcode2.isDark(row2 + 5, col) && qrcode2.isDark(row2 + 6, col)) {
20105
+ lostPoint += 40;
20106
+ }
20107
+ }
20108
+ }
20109
+ let darkCount = 0;
20110
+ for (let col = 0; col < moduleCount; col += 1) {
20111
+ for (let row2 = 0; row2 < moduleCount; row2 += 1) {
20112
+ if (qrcode2.isDark(row2, col)) {
20113
+ darkCount += 1;
20114
+ }
20115
+ }
20116
+ }
20117
+ const ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
20118
+ lostPoint += ratio * 10;
20119
+ return lostPoint;
20120
+ };
20121
+ return _this;
20122
+ })();
20123
+ var QRMath = (function() {
20124
+ const EXP_TABLE = new Array(256);
20125
+ const LOG_TABLE = new Array(256);
20126
+ for (let i3 = 0; i3 < 8; i3 += 1) {
20127
+ EXP_TABLE[i3] = 1 << i3;
20128
+ }
20129
+ for (let i3 = 8; i3 < 256; i3 += 1) {
20130
+ EXP_TABLE[i3] = EXP_TABLE[i3 - 4] ^ EXP_TABLE[i3 - 5] ^ EXP_TABLE[i3 - 6] ^ EXP_TABLE[i3 - 8];
20131
+ }
20132
+ for (let i3 = 0; i3 < 255; i3 += 1) {
20133
+ LOG_TABLE[EXP_TABLE[i3]] = i3;
20134
+ }
20135
+ const _this = {};
20136
+ _this.glog = function(n2) {
20137
+ if (n2 < 1) {
20138
+ throw "glog(" + n2 + ")";
20139
+ }
20140
+ return LOG_TABLE[n2];
20141
+ };
20142
+ _this.gexp = function(n2) {
20143
+ while (n2 < 0) {
20144
+ n2 += 255;
20145
+ }
20146
+ while (n2 >= 256) {
20147
+ n2 -= 255;
20148
+ }
20149
+ return EXP_TABLE[n2];
20150
+ };
20151
+ return _this;
20152
+ })();
20153
+ var qrPolynomial = /* @__PURE__ */ __name(function(num, shift) {
20154
+ if (typeof num.length == "undefined") {
20155
+ throw num.length + "/" + shift;
20156
+ }
20157
+ const _num = (function() {
20158
+ let offset = 0;
20159
+ while (offset < num.length && num[offset] == 0) {
20160
+ offset += 1;
20161
+ }
20162
+ const _num2 = new Array(num.length - offset + shift);
20163
+ for (let i3 = 0; i3 < num.length - offset; i3 += 1) {
20164
+ _num2[i3] = num[i3 + offset];
20165
+ }
20166
+ return _num2;
20167
+ })();
20168
+ const _this = {};
20169
+ _this.getAt = function(index) {
20170
+ return _num[index];
20171
+ };
20172
+ _this.getLength = function() {
20173
+ return _num.length;
20174
+ };
20175
+ _this.multiply = function(e) {
20176
+ const num2 = new Array(_this.getLength() + e.getLength() - 1);
20177
+ for (let i3 = 0; i3 < _this.getLength(); i3 += 1) {
20178
+ for (let j = 0; j < e.getLength(); j += 1) {
20179
+ num2[i3 + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i3)) + QRMath.glog(e.getAt(j)));
20180
+ }
20181
+ }
20182
+ return qrPolynomial(num2, 0);
20183
+ };
20184
+ _this.mod = function(e) {
20185
+ if (_this.getLength() - e.getLength() < 0) {
20186
+ return _this;
20187
+ }
20188
+ const ratio = QRMath.glog(_this.getAt(0)) - QRMath.glog(e.getAt(0));
20189
+ const num2 = new Array(_this.getLength());
20190
+ for (let i3 = 0; i3 < _this.getLength(); i3 += 1) {
20191
+ num2[i3] = _this.getAt(i3);
20192
+ }
20193
+ for (let i3 = 0; i3 < e.getLength(); i3 += 1) {
20194
+ num2[i3] ^= QRMath.gexp(QRMath.glog(e.getAt(i3)) + ratio);
20195
+ }
20196
+ return qrPolynomial(num2, 0).mod(e);
20197
+ };
20198
+ return _this;
20199
+ }, "qrPolynomial");
20200
+ var QRRSBlock = (function() {
20201
+ const RS_BLOCK_TABLE = [
20202
+ // L
20203
+ // M
20204
+ // Q
20205
+ // H
20206
+ // 1
20207
+ [1, 26, 19],
20208
+ [1, 26, 16],
20209
+ [1, 26, 13],
20210
+ [1, 26, 9],
20211
+ // 2
20212
+ [1, 44, 34],
20213
+ [1, 44, 28],
20214
+ [1, 44, 22],
20215
+ [1, 44, 16],
20216
+ // 3
20217
+ [1, 70, 55],
20218
+ [1, 70, 44],
20219
+ [2, 35, 17],
20220
+ [2, 35, 13],
20221
+ // 4
20222
+ [1, 100, 80],
20223
+ [2, 50, 32],
20224
+ [2, 50, 24],
20225
+ [4, 25, 9],
20226
+ // 5
20227
+ [1, 134, 108],
20228
+ [2, 67, 43],
20229
+ [2, 33, 15, 2, 34, 16],
20230
+ [2, 33, 11, 2, 34, 12],
20231
+ // 6
20232
+ [2, 86, 68],
20233
+ [4, 43, 27],
20234
+ [4, 43, 19],
20235
+ [4, 43, 15],
20236
+ // 7
20237
+ [2, 98, 78],
20238
+ [4, 49, 31],
20239
+ [2, 32, 14, 4, 33, 15],
20240
+ [4, 39, 13, 1, 40, 14],
20241
+ // 8
20242
+ [2, 121, 97],
20243
+ [2, 60, 38, 2, 61, 39],
20244
+ [4, 40, 18, 2, 41, 19],
20245
+ [4, 40, 14, 2, 41, 15],
20246
+ // 9
20247
+ [2, 146, 116],
20248
+ [3, 58, 36, 2, 59, 37],
20249
+ [4, 36, 16, 4, 37, 17],
20250
+ [4, 36, 12, 4, 37, 13],
20251
+ // 10
20252
+ [2, 86, 68, 2, 87, 69],
20253
+ [4, 69, 43, 1, 70, 44],
20254
+ [6, 43, 19, 2, 44, 20],
20255
+ [6, 43, 15, 2, 44, 16],
20256
+ // 11
20257
+ [4, 101, 81],
20258
+ [1, 80, 50, 4, 81, 51],
20259
+ [4, 50, 22, 4, 51, 23],
20260
+ [3, 36, 12, 8, 37, 13],
20261
+ // 12
20262
+ [2, 116, 92, 2, 117, 93],
20263
+ [6, 58, 36, 2, 59, 37],
20264
+ [4, 46, 20, 6, 47, 21],
20265
+ [7, 42, 14, 4, 43, 15],
20266
+ // 13
20267
+ [4, 133, 107],
20268
+ [8, 59, 37, 1, 60, 38],
20269
+ [8, 44, 20, 4, 45, 21],
20270
+ [12, 33, 11, 4, 34, 12],
20271
+ // 14
20272
+ [3, 145, 115, 1, 146, 116],
20273
+ [4, 64, 40, 5, 65, 41],
20274
+ [11, 36, 16, 5, 37, 17],
20275
+ [11, 36, 12, 5, 37, 13],
20276
+ // 15
20277
+ [5, 109, 87, 1, 110, 88],
20278
+ [5, 65, 41, 5, 66, 42],
20279
+ [5, 54, 24, 7, 55, 25],
20280
+ [11, 36, 12, 7, 37, 13],
20281
+ // 16
20282
+ [5, 122, 98, 1, 123, 99],
20283
+ [7, 73, 45, 3, 74, 46],
20284
+ [15, 43, 19, 2, 44, 20],
20285
+ [3, 45, 15, 13, 46, 16],
20286
+ // 17
20287
+ [1, 135, 107, 5, 136, 108],
20288
+ [10, 74, 46, 1, 75, 47],
20289
+ [1, 50, 22, 15, 51, 23],
20290
+ [2, 42, 14, 17, 43, 15],
20291
+ // 18
20292
+ [5, 150, 120, 1, 151, 121],
20293
+ [9, 69, 43, 4, 70, 44],
20294
+ [17, 50, 22, 1, 51, 23],
20295
+ [2, 42, 14, 19, 43, 15],
20296
+ // 19
20297
+ [3, 141, 113, 4, 142, 114],
20298
+ [3, 70, 44, 11, 71, 45],
20299
+ [17, 47, 21, 4, 48, 22],
20300
+ [9, 39, 13, 16, 40, 14],
20301
+ // 20
20302
+ [3, 135, 107, 5, 136, 108],
20303
+ [3, 67, 41, 13, 68, 42],
20304
+ [15, 54, 24, 5, 55, 25],
20305
+ [15, 43, 15, 10, 44, 16],
20306
+ // 21
20307
+ [4, 144, 116, 4, 145, 117],
20308
+ [17, 68, 42],
20309
+ [17, 50, 22, 6, 51, 23],
20310
+ [19, 46, 16, 6, 47, 17],
20311
+ // 22
20312
+ [2, 139, 111, 7, 140, 112],
20313
+ [17, 74, 46],
20314
+ [7, 54, 24, 16, 55, 25],
20315
+ [34, 37, 13],
20316
+ // 23
20317
+ [4, 151, 121, 5, 152, 122],
20318
+ [4, 75, 47, 14, 76, 48],
20319
+ [11, 54, 24, 14, 55, 25],
20320
+ [16, 45, 15, 14, 46, 16],
20321
+ // 24
20322
+ [6, 147, 117, 4, 148, 118],
20323
+ [6, 73, 45, 14, 74, 46],
20324
+ [11, 54, 24, 16, 55, 25],
20325
+ [30, 46, 16, 2, 47, 17],
20326
+ // 25
20327
+ [8, 132, 106, 4, 133, 107],
20328
+ [8, 75, 47, 13, 76, 48],
20329
+ [7, 54, 24, 22, 55, 25],
20330
+ [22, 45, 15, 13, 46, 16],
20331
+ // 26
20332
+ [10, 142, 114, 2, 143, 115],
20333
+ [19, 74, 46, 4, 75, 47],
20334
+ [28, 50, 22, 6, 51, 23],
20335
+ [33, 46, 16, 4, 47, 17],
20336
+ // 27
20337
+ [8, 152, 122, 4, 153, 123],
20338
+ [22, 73, 45, 3, 74, 46],
20339
+ [8, 53, 23, 26, 54, 24],
20340
+ [12, 45, 15, 28, 46, 16],
20341
+ // 28
20342
+ [3, 147, 117, 10, 148, 118],
20343
+ [3, 73, 45, 23, 74, 46],
20344
+ [4, 54, 24, 31, 55, 25],
20345
+ [11, 45, 15, 31, 46, 16],
20346
+ // 29
20347
+ [7, 146, 116, 7, 147, 117],
20348
+ [21, 73, 45, 7, 74, 46],
20349
+ [1, 53, 23, 37, 54, 24],
20350
+ [19, 45, 15, 26, 46, 16],
20351
+ // 30
20352
+ [5, 145, 115, 10, 146, 116],
20353
+ [19, 75, 47, 10, 76, 48],
20354
+ [15, 54, 24, 25, 55, 25],
20355
+ [23, 45, 15, 25, 46, 16],
20356
+ // 31
20357
+ [13, 145, 115, 3, 146, 116],
20358
+ [2, 74, 46, 29, 75, 47],
20359
+ [42, 54, 24, 1, 55, 25],
20360
+ [23, 45, 15, 28, 46, 16],
20361
+ // 32
20362
+ [17, 145, 115],
20363
+ [10, 74, 46, 23, 75, 47],
20364
+ [10, 54, 24, 35, 55, 25],
20365
+ [19, 45, 15, 35, 46, 16],
20366
+ // 33
20367
+ [17, 145, 115, 1, 146, 116],
20368
+ [14, 74, 46, 21, 75, 47],
20369
+ [29, 54, 24, 19, 55, 25],
20370
+ [11, 45, 15, 46, 46, 16],
20371
+ // 34
20372
+ [13, 145, 115, 6, 146, 116],
20373
+ [14, 74, 46, 23, 75, 47],
20374
+ [44, 54, 24, 7, 55, 25],
20375
+ [59, 46, 16, 1, 47, 17],
20376
+ // 35
20377
+ [12, 151, 121, 7, 152, 122],
20378
+ [12, 75, 47, 26, 76, 48],
20379
+ [39, 54, 24, 14, 55, 25],
20380
+ [22, 45, 15, 41, 46, 16],
20381
+ // 36
20382
+ [6, 151, 121, 14, 152, 122],
20383
+ [6, 75, 47, 34, 76, 48],
20384
+ [46, 54, 24, 10, 55, 25],
20385
+ [2, 45, 15, 64, 46, 16],
20386
+ // 37
20387
+ [17, 152, 122, 4, 153, 123],
20388
+ [29, 74, 46, 14, 75, 47],
20389
+ [49, 54, 24, 10, 55, 25],
20390
+ [24, 45, 15, 46, 46, 16],
20391
+ // 38
20392
+ [4, 152, 122, 18, 153, 123],
20393
+ [13, 74, 46, 32, 75, 47],
20394
+ [48, 54, 24, 14, 55, 25],
20395
+ [42, 45, 15, 32, 46, 16],
20396
+ // 39
20397
+ [20, 147, 117, 4, 148, 118],
20398
+ [40, 75, 47, 7, 76, 48],
20399
+ [43, 54, 24, 22, 55, 25],
20400
+ [10, 45, 15, 67, 46, 16],
20401
+ // 40
20402
+ [19, 148, 118, 6, 149, 119],
20403
+ [18, 75, 47, 31, 76, 48],
20404
+ [34, 54, 24, 34, 55, 25],
20405
+ [20, 45, 15, 61, 46, 16]
20406
+ ];
20407
+ const qrRSBlock = /* @__PURE__ */ __name(function(totalCount, dataCount) {
20408
+ const _this2 = {};
20409
+ _this2.totalCount = totalCount;
20410
+ _this2.dataCount = dataCount;
20411
+ return _this2;
20412
+ }, "qrRSBlock");
20413
+ const _this = {};
20414
+ const getRsBlockTable = /* @__PURE__ */ __name(function(typeNumber, errorCorrectionLevel) {
20415
+ switch (errorCorrectionLevel) {
20416
+ case QRErrorCorrectionLevel.L:
20417
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
20418
+ case QRErrorCorrectionLevel.M:
20419
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
20420
+ case QRErrorCorrectionLevel.Q:
20421
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
20422
+ case QRErrorCorrectionLevel.H:
20423
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
20424
+ default:
20425
+ return void 0;
20426
+ }
20427
+ }, "getRsBlockTable");
20428
+ _this.getRSBlocks = function(typeNumber, errorCorrectionLevel) {
20429
+ const rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
20430
+ if (typeof rsBlock == "undefined") {
20431
+ throw "bad rs block @ typeNumber:" + typeNumber + "/errorCorrectionLevel:" + errorCorrectionLevel;
20432
+ }
20433
+ const length = rsBlock.length / 3;
20434
+ const list2 = [];
20435
+ for (let i3 = 0; i3 < length; i3 += 1) {
20436
+ const count5 = rsBlock[i3 * 3 + 0];
20437
+ const totalCount = rsBlock[i3 * 3 + 1];
20438
+ const dataCount = rsBlock[i3 * 3 + 2];
20439
+ for (let j = 0; j < count5; j += 1) {
20440
+ list2.push(qrRSBlock(totalCount, dataCount));
20441
+ }
20442
+ }
20443
+ return list2;
20444
+ };
20445
+ return _this;
20446
+ })();
20447
+ var qrBitBuffer = /* @__PURE__ */ __name(function() {
20448
+ const _buffer = [];
20449
+ let _length = 0;
20450
+ const _this = {};
20451
+ _this.getBuffer = function() {
20452
+ return _buffer;
20453
+ };
20454
+ _this.getAt = function(index) {
20455
+ const bufIndex = Math.floor(index / 8);
20456
+ return (_buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
20457
+ };
20458
+ _this.put = function(num, length) {
20459
+ for (let i3 = 0; i3 < length; i3 += 1) {
20460
+ _this.putBit((num >>> length - i3 - 1 & 1) == 1);
20461
+ }
20462
+ };
20463
+ _this.getLengthInBits = function() {
20464
+ return _length;
20465
+ };
20466
+ _this.putBit = function(bit) {
20467
+ const bufIndex = Math.floor(_length / 8);
20468
+ if (_buffer.length <= bufIndex) {
20469
+ _buffer.push(0);
20470
+ }
20471
+ if (bit) {
20472
+ _buffer[bufIndex] |= 128 >>> _length % 8;
20473
+ }
20474
+ _length += 1;
20475
+ };
20476
+ return _this;
20477
+ }, "qrBitBuffer");
20478
+ var qrNumber = /* @__PURE__ */ __name(function(data) {
20479
+ const _mode = QRMode.MODE_NUMBER;
20480
+ const _data = data;
20481
+ const _this = {};
20482
+ _this.getMode = function() {
20483
+ return _mode;
20484
+ };
20485
+ _this.getLength = function(buffer) {
20486
+ return _data.length;
20487
+ };
20488
+ _this.write = function(buffer) {
20489
+ const data2 = _data;
20490
+ let i3 = 0;
20491
+ while (i3 + 2 < data2.length) {
20492
+ buffer.put(strToNum(data2.substring(i3, i3 + 3)), 10);
20493
+ i3 += 3;
20494
+ }
20495
+ if (i3 < data2.length) {
20496
+ if (data2.length - i3 == 1) {
20497
+ buffer.put(strToNum(data2.substring(i3, i3 + 1)), 4);
20498
+ } else if (data2.length - i3 == 2) {
20499
+ buffer.put(strToNum(data2.substring(i3, i3 + 2)), 7);
20500
+ }
20501
+ }
20502
+ };
20503
+ const strToNum = /* @__PURE__ */ __name(function(s2) {
20504
+ let num = 0;
20505
+ for (let i3 = 0; i3 < s2.length; i3 += 1) {
20506
+ num = num * 10 + chatToNum(s2.charAt(i3));
20507
+ }
20508
+ return num;
20509
+ }, "strToNum");
20510
+ const chatToNum = /* @__PURE__ */ __name(function(c2) {
20511
+ if ("0" <= c2 && c2 <= "9") {
20512
+ return c2.charCodeAt(0) - "0".charCodeAt(0);
20513
+ }
20514
+ throw "illegal char :" + c2;
20515
+ }, "chatToNum");
20516
+ return _this;
20517
+ }, "qrNumber");
20518
+ var qrAlphaNum = /* @__PURE__ */ __name(function(data) {
20519
+ const _mode = QRMode.MODE_ALPHA_NUM;
20520
+ const _data = data;
20521
+ const _this = {};
20522
+ _this.getMode = function() {
20523
+ return _mode;
20524
+ };
20525
+ _this.getLength = function(buffer) {
20526
+ return _data.length;
20527
+ };
20528
+ _this.write = function(buffer) {
20529
+ const s2 = _data;
20530
+ let i3 = 0;
20531
+ while (i3 + 1 < s2.length) {
20532
+ buffer.put(
20533
+ getCode(s2.charAt(i3)) * 45 + getCode(s2.charAt(i3 + 1)),
20534
+ 11
20535
+ );
20536
+ i3 += 2;
20537
+ }
20538
+ if (i3 < s2.length) {
20539
+ buffer.put(getCode(s2.charAt(i3)), 6);
20540
+ }
20541
+ };
20542
+ const getCode = /* @__PURE__ */ __name(function(c2) {
20543
+ if ("0" <= c2 && c2 <= "9") {
20544
+ return c2.charCodeAt(0) - "0".charCodeAt(0);
20545
+ } else if ("A" <= c2 && c2 <= "Z") {
20546
+ return c2.charCodeAt(0) - "A".charCodeAt(0) + 10;
20547
+ } else {
20548
+ switch (c2) {
20549
+ case " ":
20550
+ return 36;
20551
+ case "$":
20552
+ return 37;
20553
+ case "%":
20554
+ return 38;
20555
+ case "*":
20556
+ return 39;
20557
+ case "+":
20558
+ return 40;
20559
+ case "-":
20560
+ return 41;
20561
+ case ".":
20562
+ return 42;
20563
+ case "/":
20564
+ return 43;
20565
+ case ":":
20566
+ return 44;
20567
+ default:
20568
+ throw "illegal char :" + c2;
20569
+ }
20570
+ }
20571
+ }, "getCode");
20572
+ return _this;
20573
+ }, "qrAlphaNum");
20574
+ var qr8BitByte = /* @__PURE__ */ __name(function(data) {
20575
+ const _mode = QRMode.MODE_8BIT_BYTE;
20576
+ const _data = data;
20577
+ const _bytes = qrcode.stringToBytes(data);
20578
+ const _this = {};
20579
+ _this.getMode = function() {
20580
+ return _mode;
20581
+ };
20582
+ _this.getLength = function(buffer) {
20583
+ return _bytes.length;
20584
+ };
20585
+ _this.write = function(buffer) {
20586
+ for (let i3 = 0; i3 < _bytes.length; i3 += 1) {
20587
+ buffer.put(_bytes[i3], 8);
20588
+ }
20589
+ };
20590
+ return _this;
20591
+ }, "qr8BitByte");
20592
+ var qrKanji = /* @__PURE__ */ __name(function(data) {
20593
+ const _mode = QRMode.MODE_KANJI;
20594
+ const _data = data;
20595
+ const stringToBytes2 = qrcode.stringToBytes;
20596
+ !(function(c2, code) {
20597
+ const test = stringToBytes2(c2);
20598
+ if (test.length != 2 || (test[0] << 8 | test[1]) != code) {
20599
+ throw "sjis not supported.";
20600
+ }
20601
+ })("\u53CB", 38726);
20602
+ const _bytes = stringToBytes2(data);
20603
+ const _this = {};
20604
+ _this.getMode = function() {
20605
+ return _mode;
20606
+ };
20607
+ _this.getLength = function(buffer) {
20608
+ return ~~(_bytes.length / 2);
20609
+ };
20610
+ _this.write = function(buffer) {
20611
+ const data2 = _bytes;
20612
+ let i3 = 0;
20613
+ while (i3 + 1 < data2.length) {
20614
+ let c2 = (255 & data2[i3]) << 8 | 255 & data2[i3 + 1];
20615
+ if (33088 <= c2 && c2 <= 40956) {
20616
+ c2 -= 33088;
20617
+ } else if (57408 <= c2 && c2 <= 60351) {
20618
+ c2 -= 49472;
20619
+ } else {
20620
+ throw "illegal char at " + (i3 + 1) + "/" + c2;
20621
+ }
20622
+ c2 = (c2 >>> 8 & 255) * 192 + (c2 & 255);
20623
+ buffer.put(c2, 13);
20624
+ i3 += 2;
20625
+ }
20626
+ if (i3 < data2.length) {
20627
+ throw "illegal char at " + (i3 + 1);
20628
+ }
20629
+ };
20630
+ return _this;
20631
+ }, "qrKanji");
20632
+ var byteArrayOutputStream = /* @__PURE__ */ __name(function() {
20633
+ const _bytes = [];
20634
+ const _this = {};
20635
+ _this.writeByte = function(b) {
20636
+ _bytes.push(b & 255);
20637
+ };
20638
+ _this.writeShort = function(i3) {
20639
+ _this.writeByte(i3);
20640
+ _this.writeByte(i3 >>> 8);
20641
+ };
20642
+ _this.writeBytes = function(b, off, len) {
20643
+ off = off || 0;
20644
+ len = len || b.length;
20645
+ for (let i3 = 0; i3 < len; i3 += 1) {
20646
+ _this.writeByte(b[i3 + off]);
20647
+ }
20648
+ };
20649
+ _this.writeString = function(s2) {
20650
+ for (let i3 = 0; i3 < s2.length; i3 += 1) {
20651
+ _this.writeByte(s2.charCodeAt(i3));
20652
+ }
20653
+ };
20654
+ _this.toByteArray = function() {
20655
+ return _bytes;
20656
+ };
20657
+ _this.toString = function() {
20658
+ let s2 = "";
20659
+ s2 += "[";
20660
+ for (let i3 = 0; i3 < _bytes.length; i3 += 1) {
20661
+ if (i3 > 0) {
20662
+ s2 += ",";
20663
+ }
20664
+ s2 += _bytes[i3];
20665
+ }
20666
+ s2 += "]";
20667
+ return s2;
20668
+ };
20669
+ return _this;
20670
+ }, "byteArrayOutputStream");
20671
+ var base64EncodeOutputStream = /* @__PURE__ */ __name(function() {
20672
+ let _buffer = 0;
20673
+ let _buflen = 0;
20674
+ let _length = 0;
20675
+ let _base64 = "";
20676
+ const _this = {};
20677
+ const writeEncoded = /* @__PURE__ */ __name(function(b) {
20678
+ _base64 += String.fromCharCode(encode(b & 63));
20679
+ }, "writeEncoded");
20680
+ const encode = /* @__PURE__ */ __name(function(n2) {
20681
+ if (n2 < 0) {
20682
+ throw "n:" + n2;
20683
+ } else if (n2 < 26) {
20684
+ return 65 + n2;
20685
+ } else if (n2 < 52) {
20686
+ return 97 + (n2 - 26);
20687
+ } else if (n2 < 62) {
20688
+ return 48 + (n2 - 52);
20689
+ } else if (n2 == 62) {
20690
+ return 43;
20691
+ } else if (n2 == 63) {
20692
+ return 47;
20693
+ } else {
20694
+ throw "n:" + n2;
20695
+ }
20696
+ }, "encode");
20697
+ _this.writeByte = function(n2) {
20698
+ _buffer = _buffer << 8 | n2 & 255;
20699
+ _buflen += 8;
20700
+ _length += 1;
20701
+ while (_buflen >= 6) {
20702
+ writeEncoded(_buffer >>> _buflen - 6);
20703
+ _buflen -= 6;
20704
+ }
20705
+ };
20706
+ _this.flush = function() {
20707
+ if (_buflen > 0) {
20708
+ writeEncoded(_buffer << 6 - _buflen);
20709
+ _buffer = 0;
20710
+ _buflen = 0;
20711
+ }
20712
+ if (_length % 3 != 0) {
20713
+ const padlen = 3 - _length % 3;
20714
+ for (let i3 = 0; i3 < padlen; i3 += 1) {
20715
+ _base64 += "=";
20716
+ }
20717
+ }
20718
+ };
20719
+ _this.toString = function() {
20720
+ return _base64;
20721
+ };
20722
+ return _this;
20723
+ }, "base64EncodeOutputStream");
20724
+ var base64DecodeInputStream = /* @__PURE__ */ __name(function(str) {
20725
+ const _str = str;
20726
+ let _pos = 0;
20727
+ let _buffer = 0;
20728
+ let _buflen = 0;
20729
+ const _this = {};
20730
+ _this.read = function() {
20731
+ while (_buflen < 8) {
20732
+ if (_pos >= _str.length) {
20733
+ if (_buflen == 0) {
20734
+ return -1;
20735
+ }
20736
+ throw "unexpected end of file./" + _buflen;
20737
+ }
20738
+ const c2 = _str.charAt(_pos);
20739
+ _pos += 1;
20740
+ if (c2 == "=") {
20741
+ _buflen = 0;
20742
+ return -1;
20743
+ } else if (c2.match(/^\s$/)) {
20744
+ continue;
20745
+ }
20746
+ _buffer = _buffer << 6 | decode(c2.charCodeAt(0));
20747
+ _buflen += 6;
20748
+ }
20749
+ const n2 = _buffer >>> _buflen - 8 & 255;
20750
+ _buflen -= 8;
20751
+ return n2;
20752
+ };
20753
+ const decode = /* @__PURE__ */ __name(function(c2) {
20754
+ if (65 <= c2 && c2 <= 90) {
20755
+ return c2 - 65;
20756
+ } else if (97 <= c2 && c2 <= 122) {
20757
+ return c2 - 97 + 26;
20758
+ } else if (48 <= c2 && c2 <= 57) {
20759
+ return c2 - 48 + 52;
20760
+ } else if (c2 == 43) {
20761
+ return 62;
20762
+ } else if (c2 == 47) {
20763
+ return 63;
20764
+ } else {
20765
+ throw "c:" + c2;
20766
+ }
20767
+ }, "decode");
20768
+ return _this;
20769
+ }, "base64DecodeInputStream");
20770
+ var gifImage = /* @__PURE__ */ __name(function(width, height) {
20771
+ const _width = width;
20772
+ const _height = height;
20773
+ const _data = new Array(width * height);
20774
+ const _this = {};
20775
+ _this.setPixel = function(x, y, pixel) {
20776
+ _data[y * _width + x] = pixel;
20777
+ };
20778
+ _this.write = function(out) {
20779
+ out.writeString("GIF87a");
20780
+ out.writeShort(_width);
20781
+ out.writeShort(_height);
20782
+ out.writeByte(128);
20783
+ out.writeByte(0);
20784
+ out.writeByte(0);
20785
+ out.writeByte(0);
20786
+ out.writeByte(0);
20787
+ out.writeByte(0);
20788
+ out.writeByte(255);
20789
+ out.writeByte(255);
20790
+ out.writeByte(255);
20791
+ out.writeString(",");
20792
+ out.writeShort(0);
20793
+ out.writeShort(0);
20794
+ out.writeShort(_width);
20795
+ out.writeShort(_height);
20796
+ out.writeByte(0);
20797
+ const lzwMinCodeSize = 2;
20798
+ const raster = getLZWRaster(lzwMinCodeSize);
20799
+ out.writeByte(lzwMinCodeSize);
20800
+ let offset = 0;
20801
+ while (raster.length - offset > 255) {
20802
+ out.writeByte(255);
20803
+ out.writeBytes(raster, offset, 255);
20804
+ offset += 255;
20805
+ }
20806
+ out.writeByte(raster.length - offset);
20807
+ out.writeBytes(raster, offset, raster.length - offset);
20808
+ out.writeByte(0);
20809
+ out.writeString(";");
20810
+ };
20811
+ const bitOutputStream = /* @__PURE__ */ __name(function(out) {
20812
+ const _out = out;
20813
+ let _bitLength = 0;
20814
+ let _bitBuffer = 0;
20815
+ const _this2 = {};
20816
+ _this2.write = function(data, length) {
20817
+ if (data >>> length != 0) {
20818
+ throw "length over";
20819
+ }
20820
+ while (_bitLength + length >= 8) {
20821
+ _out.writeByte(255 & (data << _bitLength | _bitBuffer));
20822
+ length -= 8 - _bitLength;
20823
+ data >>>= 8 - _bitLength;
20824
+ _bitBuffer = 0;
20825
+ _bitLength = 0;
20826
+ }
20827
+ _bitBuffer = data << _bitLength | _bitBuffer;
20828
+ _bitLength = _bitLength + length;
20829
+ };
20830
+ _this2.flush = function() {
20831
+ if (_bitLength > 0) {
20832
+ _out.writeByte(_bitBuffer);
20833
+ }
20834
+ };
20835
+ return _this2;
20836
+ }, "bitOutputStream");
20837
+ const getLZWRaster = /* @__PURE__ */ __name(function(lzwMinCodeSize) {
20838
+ const clearCode = 1 << lzwMinCodeSize;
20839
+ const endCode = (1 << lzwMinCodeSize) + 1;
20840
+ let bitLength = lzwMinCodeSize + 1;
20841
+ const table = lzwTable();
20842
+ for (let i3 = 0; i3 < clearCode; i3 += 1) {
20843
+ table.add(String.fromCharCode(i3));
20844
+ }
20845
+ table.add(String.fromCharCode(clearCode));
20846
+ table.add(String.fromCharCode(endCode));
20847
+ const byteOut = byteArrayOutputStream();
20848
+ const bitOut = bitOutputStream(byteOut);
20849
+ bitOut.write(clearCode, bitLength);
20850
+ let dataIndex = 0;
20851
+ let s2 = String.fromCharCode(_data[dataIndex]);
20852
+ dataIndex += 1;
20853
+ while (dataIndex < _data.length) {
20854
+ const c2 = String.fromCharCode(_data[dataIndex]);
20855
+ dataIndex += 1;
20856
+ if (table.contains(s2 + c2)) {
20857
+ s2 = s2 + c2;
20858
+ } else {
20859
+ bitOut.write(table.indexOf(s2), bitLength);
20860
+ if (table.size() < 4095) {
20861
+ if (table.size() == 1 << bitLength) {
20862
+ bitLength += 1;
20863
+ }
20864
+ table.add(s2 + c2);
20865
+ }
20866
+ s2 = c2;
20867
+ }
20868
+ }
20869
+ bitOut.write(table.indexOf(s2), bitLength);
20870
+ bitOut.write(endCode, bitLength);
20871
+ bitOut.flush();
20872
+ return byteOut.toByteArray();
20873
+ }, "getLZWRaster");
20874
+ const lzwTable = /* @__PURE__ */ __name(function() {
20875
+ const _map = {};
20876
+ let _size = 0;
20877
+ const _this2 = {};
20878
+ _this2.add = function(key) {
20879
+ if (_this2.contains(key)) {
20880
+ throw "dup key:" + key;
20881
+ }
20882
+ _map[key] = _size;
20883
+ _size += 1;
20884
+ };
20885
+ _this2.size = function() {
20886
+ return _size;
20887
+ };
20888
+ _this2.indexOf = function(key) {
20889
+ return _map[key];
20890
+ };
20891
+ _this2.contains = function(key) {
20892
+ return typeof _map[key] != "undefined";
20893
+ };
20894
+ return _this2;
20895
+ }, "lzwTable");
20896
+ return _this;
20897
+ }, "gifImage");
20898
+ var createDataURL = /* @__PURE__ */ __name(function(width, height, getPixel) {
20899
+ const gif = gifImage(width, height);
20900
+ for (let y = 0; y < height; y += 1) {
20901
+ for (let x = 0; x < width; x += 1) {
20902
+ gif.setPixel(x, y, getPixel(x, y));
20903
+ }
20904
+ }
20905
+ const b = byteArrayOutputStream();
20906
+ gif.write(b);
20907
+ const base64 = base64EncodeOutputStream();
20908
+ const bytes = b.toByteArray();
20909
+ for (let i3 = 0; i3 < bytes.length; i3 += 1) {
20910
+ base64.writeByte(bytes[i3]);
20911
+ }
20912
+ base64.flush();
20913
+ return "data:image/gif;base64," + base64;
20914
+ }, "createDataURL");
20915
+ var stringToBytes = qrcode.stringToBytes;
20916
+
20917
+ // dist/commands/session.js
20918
+ var CLI2 = IDENTITY.command;
20919
+ var answer2 = /* @__PURE__ */ __name((command, item) => renderAnswer(command, outputFor(command), itemOf(item)), "answer");
20920
+ var storageOf = /* @__PURE__ */ __name((raw) => {
20921
+ if (raw === "keyring" || raw === "file")
20922
+ return raw;
20923
+ throw new CliError("validation_error", `--credential-storage takes keyring or file; got ${raw}`);
20924
+ }, "storageOf");
20925
+ var startCommand = /* @__PURE__ */ __name(() => logsInOrOut(annotate(new Command("start"), {
20926
+ effects: FETCH,
20927
+ lifetime: "interactive",
20928
+ mcp: false,
20929
+ examples: [`${CLI2} personal session start`, `${CLI2} personal session start --credential-storage file`]
20930
+ })).summary(`sign in to ${SERVICE} with an API token`).description(`sign this profile in: the ${SERVICE} API token is asked hidden or read from stdin, never taken as an argument, checked against the service, and only then kept in the keyring, or in a private file`).option("--credential-storage <storage>", "where the token is kept: keyring, which falls back to a private file by itself, or file", storageOf, "keyring").action(async function(args) {
20931
+ const { env, flags, profile, tokens, run: run3 } = contextOf(this);
20932
+ refuseCommandName(profile, commandWords(rootOf(this)), CLI2);
20933
+ refuseOffline(flags);
20934
+ const token = (await readSecret(`${SERVICE} API token: `, secretInputOf(this))).trim();
20935
+ if (!token)
20936
+ throw new CliError("validation_error", "no token was given");
20937
+ const user = await run3((events) => serviceFor(this, token, events).me());
20938
+ const storedIn = tokens.write(profile, token, args.credentialStorage);
20939
+ rememberAccount(IDENTITY, profile, user.id, env);
20940
+ answer2(this, { profile, state: "saved", stored_in: storedIn, verified: true, user });
20941
+ }), "startCommand");
20942
+ var statusCommand3 = /* @__PURE__ */ __name(() => annotate(new Command("status"), {
20943
+ effects: REMOTE_READ,
20944
+ examples: [`${CLI2} personal session status`, `${CLI2} personal session status --check --json`]
20945
+ }).summary("show where this profile's token comes from; never the token").description(`show where this profile's token comes from: ${TOKEN_VARIABLE}, the keyring or a file, never the token; --check asks ${SERVICE} whose token it is`).option("--check", `ask ${SERVICE} whether the token still works, and whose it is`).action(async function(args) {
20946
+ const { profile, tokens } = contextOf(this);
20947
+ const saved = tokens.read(profile);
20948
+ const status = { profile, state: saved ? "saved" : "missing", token_from: saved?.source ?? null };
20949
+ if (!args.check || !saved)
20950
+ return answer2(this, { ...status, verified: false });
20951
+ answer2(this, { ...status, verified: true, user: await withService(this, (service) => service.me()) });
20952
+ }), "statusCommand");
20953
+ var endCommand = /* @__PURE__ */ __name(() => logsInOrOut(annotate(new Command("end"), {
19007
20954
  effects: LOCAL_WRITE,
19008
20955
  mcp: false,
19009
- examples: [`${IDENTITY.command} personal mcp revoke`]
19010
- }).summary("forget every login given to a browser app").description("forget every login `mcp serve --http` gave a browser app; each must log in again").action(async function() {
19011
- refuseUnderReadOnly(this, "mcp revoke");
19012
- const { profile, tokenFile } = settingsOf2(this);
19013
- const { revokeAll } = await import("./mcp-EY2NUYDQ.js");
19014
- revokeAll(tokenFile);
19015
- renderAnswer(this, outputFor(this), itemOf({ revoked: true, profile }));
19016
- }), "revokeCommand");
19017
- var mcpCommand3 = /* @__PURE__ */ __name(() => annotate(new Command("mcp"), { effects: LOCAL_READ, mcp: false }).summary("serve this profile's commands to an AI agent").description(`serve this profile's commands to an agent over MCP \u2014 \`${SETUP}\``).addCommand(serveCommand3()).addCommand(revokeCommand()).addCommand(mcpServerCommand({
19018
- example: `${IDENTITY.command} personal`,
19019
- target: /* @__PURE__ */ __name((self) => {
19020
- const { env, profile, tokenFile } = settingsOf2(self);
19021
- return {
19022
- invocation: `${IDENTITY.command} ${profile}`,
19023
- profile,
19024
- envPrefix: IDENTITY.envPrefix,
19025
- env,
19026
- tokenFile,
19027
- argv: [profile, "mcp", "serve", "--http"],
19028
- version: IDENTITY.version
19029
- };
19030
- }, "target"),
19031
- answer: /* @__PURE__ */ __name((self, item, lines2) => renderAnswer(self, outputFor(self), itemOf(item), () => lines2.join("\n")), "answer")
19032
- })), "mcpCommand");
20956
+ examples: [`${CLI2} personal session end`]
20957
+ })).summary("forget this profile's token on this computer").description(`forget this profile's token on this computer; the token itself stays valid in ${SERVICE}`).action(function() {
20958
+ refuseUnderReadOnly(this, "session end");
20959
+ const { profile, tokens } = contextOf(this);
20960
+ answer2(this, { profile, ended: tokens.remove(profile) });
20961
+ }), "endCommand");
20962
+ var listCommand5 = /* @__PURE__ */ __name(() => profileFree(annotate(new Command("list"), {
20963
+ effects: LOCAL_READ,
20964
+ examples: [`${CLI2} session list`, `${CLI2} session list --json`]
20965
+ })).summary("list the profiles here and whether each is signed in").description("list the profiles on this computer and whether each has a token; picks none").action(function() {
20966
+ const environment = environmentOf(this);
20967
+ const env = environment.env ?? process.env;
20968
+ const { configuredProfiles } = configuration.resolveSettings({}, { env, needsProfile: false });
20969
+ const tokens = tokenStore(env, environment.keyring, outputFor(this).renderer.warn);
20970
+ const items = profilesHere(IDENTITY, configuredProfiles, env).map((profile) => {
20971
+ const saved = tokens.read(profile);
20972
+ return { profile, signed_in: saved !== void 0, token_from: saved?.source ?? null };
20973
+ });
20974
+ renderAnswer(this, outputFor(this), listOf("session list", { items, limit: Math.max(1, items.length), has_more: false }));
20975
+ }), "listCommand");
20976
+ var sessionCommand = /* @__PURE__ */ __name(() => annotate(new Command("session"), { effects: LOCAL_READ }).description(`keep this profile's ${SERVICE} token in the OS keyring`).addCommand(startCommand()).addCommand(statusCommand3()).addCommand(endCommand()).addCommand(listCommand5()), "sessionCommand");
19033
20977
 
19034
20978
  // dist/program.js
19035
20979
  var update = appUpdate({
@@ -19041,13 +20985,29 @@ var update = appUpdate({
19041
20985
  enabled: /* @__PURE__ */ __name((env) => configuration.resolveSettings({}, { env, needsProfile: false }).updateCheck, "enabled"),
19042
20986
  offVariables: [`${IDENTITY.envPrefix}_NO_UPDATE_CHECK`]
19043
20987
  });
20988
+ var mcpCommand3 = /* @__PURE__ */ __name(() => {
20989
+ let keyring;
20990
+ const mcp = appMcpCommand2(IDENTITY, configuration, {
20991
+ name: SERVICE,
20992
+ // SAMPLE: name the kinds of text other people wrote that your answers carry (WC-MCP-11).
20993
+ untrusted: ["comment text", "author names"],
20994
+ permissionExample: "comments.create=deny",
20995
+ skill: SKILL,
20996
+ signedIn: /* @__PURE__ */ __name((profile, env) => holdsToken(env, profile, keyring), "signedIn")
20997
+ });
20998
+ return mcp.hook("preAction", (_mcp, action) => {
20999
+ keyring = environmentOf(action).keyring;
21000
+ });
21001
+ }, "mcpCommand");
19044
21002
  var definition = /* @__PURE__ */ __name(() => ({
19045
21003
  app: IDENTITY,
19046
21004
  // The whole object: cli-core refuses a command by its key only when it gets the permission table too.
19047
21005
  configuration,
19048
21006
  commands: /* @__PURE__ */ __name(() => [
19049
21007
  commandsCommand2(IDENTITY),
19050
- doctorCommand3(),
21008
+ sessionCommand(),
21009
+ commentsCommand2(),
21010
+ appDoctorCommand2(IDENTITY, configuration, { packageName: PACKAGE }),
19051
21011
  skillCommand3(IDENTITY, SKILL),
19052
21012
  mcpCommand3(),
19053
21013
  upgradeCommand2(IDENTITY, PACKAGE, (command) => ({