@songsid/agend 2.1.4 → 2.1.5-beta.10

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 (82) hide show
  1. package/dist/backend/claude-code.js +2 -2
  2. package/dist/backend/claude-code.js.map +1 -1
  3. package/dist/backend/types.d.ts +22 -0
  4. package/dist/backend/types.js +23 -1
  5. package/dist/backend/types.js.map +1 -1
  6. package/dist/channel/adapters/discord.d.ts +2 -0
  7. package/dist/channel/adapters/discord.js +25 -3
  8. package/dist/channel/adapters/discord.js.map +1 -1
  9. package/dist/channel/adapters/telegram.d.ts +5 -0
  10. package/dist/channel/adapters/telegram.js +11 -0
  11. package/dist/channel/adapters/telegram.js.map +1 -1
  12. package/dist/channel/types.d.ts +7 -0
  13. package/dist/cli.js +37 -37
  14. package/dist/cli.js.map +1 -1
  15. package/dist/config.js +38 -0
  16. package/dist/config.js.map +1 -1
  17. package/dist/daemon.d.ts +38 -0
  18. package/dist/daemon.js +95 -43
  19. package/dist/daemon.js.map +1 -1
  20. package/dist/fleet-context.d.ts +5 -0
  21. package/dist/fleet-manager.d.ts +126 -0
  22. package/dist/fleet-manager.js +688 -95
  23. package/dist/fleet-manager.js.map +1 -1
  24. package/dist/full-restart.d.ts +20 -0
  25. package/dist/full-restart.js +39 -0
  26. package/dist/full-restart.js.map +1 -0
  27. package/dist/locale.js +72 -2
  28. package/dist/locale.js.map +1 -1
  29. package/dist/login-controller.d.ts +127 -0
  30. package/dist/login-controller.js +450 -0
  31. package/dist/login-controller.js.map +1 -0
  32. package/dist/login-flows.d.ts +41 -3
  33. package/dist/login-flows.js +37 -5
  34. package/dist/login-flows.js.map +1 -1
  35. package/dist/login-manager.d.ts +12 -1
  36. package/dist/login-manager.js +64 -7
  37. package/dist/login-manager.js.map +1 -1
  38. package/dist/login-window-lock.d.ts +26 -0
  39. package/dist/login-window-lock.js +64 -0
  40. package/dist/login-window-lock.js.map +1 -0
  41. package/dist/restart-progress.d.ts +35 -5
  42. package/dist/restart-progress.js +195 -34
  43. package/dist/restart-progress.js.map +1 -1
  44. package/dist/service-restart-selection.d.ts +27 -0
  45. package/dist/service-restart-selection.js +25 -0
  46. package/dist/service-restart-selection.js.map +1 -0
  47. package/dist/tmux-manager.d.ts +19 -0
  48. package/dist/tmux-manager.js +79 -12
  49. package/dist/tmux-manager.js.map +1 -1
  50. package/dist/topic-commands.js +23 -7
  51. package/dist/topic-commands.js.map +1 -1
  52. package/dist/types.d.ts +18 -0
  53. package/dist/ui/web-terminal/terminal.css +17 -0
  54. package/dist/ui/web-terminal/terminal.html +44 -0
  55. package/dist/ui/web-terminal/terminal.js +148 -0
  56. package/dist/ui/web-terminal/vendor/LICENSE.addon-fit +19 -0
  57. package/dist/ui/web-terminal/vendor/LICENSE.addon-web-links +19 -0
  58. package/dist/ui/web-terminal/vendor/LICENSE.xterm +21 -0
  59. package/dist/ui/web-terminal/vendor/VENDORED.md +22 -0
  60. package/dist/ui/web-terminal/vendor/addon-fit.js +1 -0
  61. package/dist/ui/web-terminal/vendor/addon-web-links.js +1 -0
  62. package/dist/ui/web-terminal/vendor/xterm.css +285 -0
  63. package/dist/ui/web-terminal/vendor/xterm.js +1 -0
  64. package/dist/update-marker.d.ts +11 -1
  65. package/dist/update-marker.js +19 -4
  66. package/dist/update-marker.js.map +1 -1
  67. package/dist/update-progress.d.ts +1 -1
  68. package/dist/update-progress.js +12 -0
  69. package/dist/update-progress.js.map +1 -1
  70. package/dist/usage/providers.d.ts +39 -0
  71. package/dist/usage/providers.js +69 -3
  72. package/dist/usage/providers.js.map +1 -1
  73. package/dist/web-terminal-http.d.ts +61 -0
  74. package/dist/web-terminal-http.js +422 -0
  75. package/dist/web-terminal-http.js.map +1 -0
  76. package/dist/web-terminal.d.ts +336 -0
  77. package/dist/web-terminal.js +888 -0
  78. package/dist/web-terminal.js.map +1 -0
  79. package/dist/ws-server.d.ts +69 -0
  80. package/dist/ws-server.js +392 -0
  81. package/dist/ws-server.js.map +1 -0
  82. package/package.json +1 -1
@@ -103,6 +103,8 @@ export interface FleetContext {
103
103
  /** Persist and edit one `/update` message across the fleet process restart. */
104
104
  beginUpdateProgress?(adapter: import("./channel/types.js").ChannelAdapter, chatId: string, threadId: string | undefined, messageId: string): void;
105
105
  failUpdateProgress?(message: string): void;
106
+ /** Persist `/restart full`, wait for idle, then launch the environment-aware service restart. */
107
+ requestFullRestart?(adapter: import("./channel/types.js").ChannelAdapter, chatId: string, threadId: string | undefined, messageId: string): Promise<boolean>;
106
108
  /** Post one random, not-yet-dismissed tip with a dismiss button. */
107
109
  promptTip?(generalName: string, adapter: import("./channel/types.js").ChannelAdapter, chatId: string, threadId?: string): Promise<"posted" | "empty" | "unavailable">;
108
110
  /** Persistently enable advanced tips without waiting for the dismissal threshold. */
@@ -130,8 +132,11 @@ export interface FleetContext {
130
132
  adapterId: string;
131
133
  chatId: string;
132
134
  threadId?: string;
135
+ /** The requesting human — required by web mode (admin re-check, private token delivery). */
136
+ userId?: string;
133
137
  }, opts?: {
134
138
  skipAuthCheck?: boolean;
139
+ tokenPresent?: boolean;
135
140
  }): Promise<string | null>;
136
141
  /** Paste admin-supplied text (auth code / start URL) into the login window. */
137
142
  loginSubmitInput?(text: string): Promise<string>;
@@ -66,6 +66,28 @@ export interface DeliveryOptions {
66
66
  /** Test/operational override; normal deliveries use the 60 second backstop. */
67
67
  idleTimeoutMs?: number;
68
68
  }
69
+ /**
70
+ * Upper bound on a live probe driven by `/model`.
71
+ *
72
+ * A probe chains bounded leaves but is not itself bounded: claude-code runs
73
+ * `--version` (5s) then listModels then listApiModels (an 8s AbortController
74
+ * against api.anthropic.com), and several backends' probes carry no explicit
75
+ * timeout at all. Awaiting that inline would make `/model` the next thing to
76
+ * hang, so it races this deadline and falls back to the cached list.
77
+ *
78
+ * Must stay above CLI_PROBE_LONGEST_CHAIN_MS — the probe's bounded steps run
79
+ * back to back, so clearing only the longest single leaf would be false
80
+ * confidence: a deadline above 8s but below the 13s chain still truncates a
81
+ * probe that would have succeeded. Bounding the chain rather than the leaf is
82
+ * the lesson from the usage hang, and the tests assert against the derived
83
+ * chain constant so raising either step cannot silently break it.
84
+ *
85
+ * The deadline exists to stop a probe hanging forever, not to cut short one that
86
+ * would have finished: truncating a legitimate probe serves the previous list
87
+ * and hides exactly the newly released model the user opened `/model` to find.
88
+ * The wait is announced before it starts, so it reads as progress, not a stall.
89
+ */
90
+ export declare const CLI_ENV_PROBE_DEADLINE_MS = 16000;
69
91
  export declare class FleetManager implements FleetContext, LifecycleContext, ArchiverContext, StatuslineWatcherContext, OutboundContext, AgentEndpointContext {
70
92
  dataDir: string;
71
93
  private static signalTarget;
@@ -199,6 +221,8 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
199
221
  private updateProgressEditRunning;
200
222
  private lastUpdateProgressText;
201
223
  private updateCompletionTipText;
224
+ /** Injectable only to keep the chat→CLI reload hand-off deterministic in tests. */
225
+ private fullRestartLauncher;
202
226
  private eventLogPruneTimer;
203
227
  private logRotateTimer;
204
228
  /** Days of event/activity history to keep. */
@@ -287,6 +311,7 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
287
311
  private isModelAdmin;
288
312
  private handlePauseWakeSlash;
289
313
  private handleUpdateSlash;
314
+ private handleRestartSlash;
290
315
  private handleTipsSlash;
291
316
  /** Admin-only full conversation reset for fleet-topic and Classic instances. */
292
317
  private handleClearSlash;
@@ -448,6 +473,13 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
448
473
  */
449
474
  private startClassicInstanceUnattended;
450
475
  private backendNameOf;
476
+ /**
477
+ * Every configured instance whose backend may share credentials. ClassicBot
478
+ * rows live only in classicBot.yaml, so backend-wide operations must not use
479
+ * fleetConfig.instances as their roster. Set keeps a malformed name collision
480
+ * from restarting the same process twice; backendNameOf defines ownership.
481
+ */
482
+ private configuredBackendInstanceNames;
451
483
  /**
452
484
  * One fleet-level notice per burst, not one per instance: a post-update herd
453
485
  * fails many instances within the same second. Two notices per incident at
@@ -457,6 +489,13 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
457
489
  private runnableStartupCount;
458
490
  private configuredStartupInstanceNames;
459
491
  private restartProgressTarget;
492
+ /** Resolve only an adapter generation that can accept progress delivery.
493
+ * Discord exposes direct gateway readiness; adapters without a health
494
+ * snapshot use the fleet startup/retry state. */
495
+ private readyProgressAdapter;
496
+ /** Last-resort completion after RestartProgress could not deliver to its
497
+ * adopted target. It stays bounded and never wakes a not-ready gateway. */
498
+ private sendFleetStartCompletionFallback;
460
499
  stopInstance(name: string): Promise<void>;
461
500
  /** Restart a single instance, reloading fleet.yaml first to pick up config changes. */
462
501
  restartSingleInstance(name: string, opts?: {
@@ -479,6 +518,12 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
479
518
  token: string | null;
480
519
  };
481
520
  beginUpdateProgress(adapter: ChannelAdapter, chatId: string, threadId: string | undefined, messageId: string): void;
521
+ /** Persist the public response, wait for idle, then start the canonical service restart. */
522
+ requestFullRestart(adapter: ChannelAdapter, chatId: string, threadId: string | undefined, messageId: string): Promise<boolean>;
523
+ private isOwnedFullRestartMarker;
524
+ /** Give current work the same bounded idle grace used by graceful reload. */
525
+ private waitForFullRestartIdleGrace;
526
+ private reportFullRestartFailure;
482
527
  failUpdateProgress(message: string): void;
483
528
  /** The old fleet edits CLI install stages; the new fleet adopts the same message below. */
484
529
  private startUpdateProgressMonitor;
@@ -629,6 +674,35 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
629
674
  /** Side effects of a routed reply: cancel-button lifecycle, logs, SSE, chat log. */
630
675
  private afterReplyRouted;
631
676
  private handleScheduleTrigger;
677
+ /**
678
+ * The adapter that can actually post into a chat, found by its group.
679
+ *
680
+ * A schedule records where it was created (reply_chat_id) separately from
681
+ * what it triggers (target). Those need not share a platform: a Telegram
682
+ * group can schedule a Discord-topic instance. Picking the adapter from the
683
+ * target then sends a Telegram chat id through the Discord bot, which fails
684
+ * with Unknown Channel — the source topic never hears that its schedule ran.
685
+ *
686
+ * When several bots share one guild, the primary wins: a persona should not
687
+ * be the voice announcing fleet scheduling.
688
+ */
689
+ private adapterForChat;
690
+ /**
691
+ * The adapter that can answer a schedule in the chat it was created from.
692
+ *
693
+ * A schedule records its creator (source) and its trigger (target) separately,
694
+ * and they need not share a platform — the live fleet has a Telegram group
695
+ * scheduling a Discord-topic instance. Routing by target sends a Telegram chat
696
+ * id through the Discord bot, which is one half of the Unknown Channel errors.
697
+ *
698
+ * The creator's own adapter comes first, and only when its world actually owns
699
+ * that chat. Classic keeps its own identity, so a schedule made from a
700
+ * persona-bound Classic channel is answered by that persona: the primary bot
701
+ * may not even have access there, and would be the wrong voice if it did.
702
+ * Falling back to the target's adapter is deliberately NOT an option — that is
703
+ * the misroute itself; callers say why they stayed silent instead.
704
+ */
705
+ private scheduleSourceAdapter;
632
706
  private notifySourceTopic;
633
707
  private notifyScheduleFailure;
634
708
  private handleScheduleCrud;
@@ -744,6 +818,31 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
744
818
  * poll cannot flood the topic and a down General does not swallow it.
745
819
  */
746
820
  private reportClassicUnrecoverableIds;
821
+ /**
822
+ * Where a fleet-wide notice can actually be posted, or null if nowhere.
823
+ *
824
+ * On Telegram a group id is itself a chat, so posting straight to it is
825
+ * right. On Discord it is a *guild* id, and sending there makes the adapter
826
+ * fetch a channel that does not exist — DiscordAPIError 10003 Unknown
827
+ * Channel. That is why the daily summary never arrived on a Discord fleet:
828
+ * it had been posting to the guild every night and only the catch handler
829
+ * ever saw it.
830
+ *
831
+ * Discord therefore needs a real channel: the General topic (resolved from
832
+ * config rather than findGeneralInstance, so a fleet-level fault can still be
833
+ * reported while the General daemon is down), else the adapter's configured
834
+ * general_channel_id. With neither, there is no safe target and the caller
835
+ * should say so rather than send into a guaranteed failure.
836
+ */
837
+ private fleetNoticeTarget;
838
+ /**
839
+ * Post the daily summary where fleet-wide notices go.
840
+ *
841
+ * A named method rather than an inline closure so a test can drive the real
842
+ * thing: asserting on fleetNoticeTarget alone leaves the call site free to go
843
+ * back to posting at the bare group id, which is the defect this replaced.
844
+ */
845
+ private postDailySummary;
747
846
  notifyFleetError(text: string): void;
748
847
  private static readonly FLEET_ERROR_THROTTLE_MS;
749
848
  private fleetErrorNotices;
@@ -976,6 +1075,18 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
976
1075
  /** Invalidate work queued before a user cancel and wake idle-gate waiters. */
977
1076
  private cancelPendingDeliveries;
978
1077
  private activeLogin;
1078
+ /**
1079
+ * Web-terminal login (v2.1.5 default, `login.mode: web`). The relay code
1080
+ * below (activeLogin/LoginSession) is `login.mode: relay`, kept for one
1081
+ * release as the rollback lever and removed in 2.1.6.
1082
+ */
1083
+ private loginController;
1084
+ /**
1085
+ * One login/install window fleet-wide. Claimed synchronously before the
1086
+ * first await by web login, relay login and install alike (sol B1).
1087
+ */
1088
+ private readonly loginWindow;
1089
+ private get webLogin();
979
1090
  /** Post the backend chooser for a bare `/login`. Caller enforces admin. */
980
1091
  promptLoginBackends(chat: {
981
1092
  adapter: ChannelAdapter;
@@ -1042,11 +1153,16 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
1042
1153
  adapterId: string;
1043
1154
  chatId: string;
1044
1155
  threadId?: string;
1156
+ userId?: string;
1045
1157
  }, opts?: {
1046
1158
  skipAuthCheck?: boolean;
1159
+ tokenPresent?: boolean;
1047
1160
  }): Promise<string | null>;
1161
+ private startRelayClaimed;
1048
1162
  /** Create the login window and session (pre-check already settled). */
1049
1163
  private launchLoginSession;
1164
+ /** Fleet shutdown: end any web/relay login or install window and wait for its confirmed teardown. */
1165
+ private shutdownLoginWindows;
1050
1166
  /** `/login code <text>` — paste admin-supplied text into the login window. */
1051
1167
  loginSubmitInput(text: string): Promise<string>;
1052
1168
  /** `/login cancel` — abort the active session and remove its window. */
@@ -1068,6 +1184,8 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
1068
1184
  private handleLoginBackendSelect;
1069
1185
  /** Re-login confirmation (auth pre-check said credentials still work). */
1070
1186
  private handleLoginConfirm;
1187
+ /** "Resend token" button (web login): only the requester may press it; the token never enters the channel. */
1188
+ private handleLoginTokenResend;
1071
1189
  /** Kiro provider button → drive the CLI's arrow-key selector. */
1072
1190
  private handleLoginMenuSelect;
1073
1191
  private activeInstall;
@@ -1168,6 +1286,14 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
1168
1286
  private cliEnvPath;
1169
1287
  /** Read the cached CLI env for a backend, or null if missing/stale/unparseable. */
1170
1288
  private readCliEnv;
1289
+ /** True when a cached CLI env is old enough that `/model` should re-probe. */
1290
+ private cliEnvNeedsRefresh;
1291
+ /**
1292
+ * Run a live probe under a deadline, falling back to whatever the cache holds.
1293
+ * A model list is an aid: a vendor that stops answering must degrade to the
1294
+ * previous list, never stall the command that asked for it.
1295
+ */
1296
+ private probeBackendBounded;
1171
1297
  /**
1172
1298
  * Resolve the effective model for a fleet or ClassicBot instance, plus where it
1173
1299
  * came from. Single source of truth for `/model` and `/ctx` — precedence: