@sayknow-cli/coding-agent 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/bin/skc.js +4 -0
  2. package/dist/types/cli/mcp-cli.d.ts +25 -0
  3. package/dist/types/cli/plugin-cli.d.ts +2 -0
  4. package/dist/types/cli.d.ts +6 -0
  5. package/dist/types/commands/mcp.d.ts +70 -0
  6. package/dist/types/commands/plugin.d.ts +6 -0
  7. package/dist/types/commands/session.d.ts +6 -0
  8. package/dist/types/config/keybindings.d.ts +2 -2
  9. package/dist/types/config/model-profile-activation.d.ts +8 -1
  10. package/dist/types/config/settings-schema.d.ts +1 -59
  11. package/dist/types/deep-interview/plaintext-gate-guard.d.ts +11 -0
  12. package/dist/types/extensibility/skc-plugins/compiler.d.ts +19 -0
  13. package/dist/types/extensibility/skc-plugins/constrained-hooks.d.ts +29 -0
  14. package/dist/types/extensibility/skc-plugins/index.d.ts +9 -0
  15. package/dist/types/extensibility/skc-plugins/injection.d.ts +9 -0
  16. package/dist/types/extensibility/skc-plugins/installer.d.ts +13 -0
  17. package/dist/types/extensibility/skc-plugins/mcp-policy.d.ts +26 -0
  18. package/dist/types/extensibility/skc-plugins/observability.d.ts +27 -0
  19. package/dist/types/extensibility/skc-plugins/prompt-appendix.d.ts +16 -0
  20. package/dist/types/extensibility/skc-plugins/registry.d.ts +32 -0
  21. package/dist/types/extensibility/skc-plugins/runtime-adapters.d.ts +64 -0
  22. package/dist/types/extensibility/skc-plugins/session-validation.d.ts +42 -0
  23. package/dist/types/extensibility/skc-plugins/types.d.ts +158 -2
  24. package/dist/types/extensibility/skc-plugins/validation.d.ts +8 -1
  25. package/dist/types/i18n/messages/en.d.ts +0 -1
  26. package/dist/types/main.d.ts +2 -0
  27. package/dist/types/modes/components/custom-editor.d.ts +1 -1
  28. package/dist/types/modes/components/model-selector.d.ts +8 -0
  29. package/dist/types/modes/components/settings-defs.d.ts +0 -1
  30. package/dist/types/modes/components/status-line/git-utils.d.ts +6 -0
  31. package/dist/types/modes/theme/defaults/index.d.ts +99 -0
  32. package/dist/types/modes/theme/theme.d.ts +1 -1
  33. package/dist/types/notifications/html-format.d.ts +11 -0
  34. package/dist/types/notifications/index.d.ts +149 -1
  35. package/dist/types/notifications/lifecycle-commands.d.ts +60 -0
  36. package/dist/types/notifications/lifecycle-control-runtime.d.ts +98 -0
  37. package/dist/types/notifications/lifecycle-orchestrator.d.ts +144 -0
  38. package/dist/types/notifications/operator-runtime.d.ts +52 -0
  39. package/dist/types/notifications/rate-limit-pool.d.ts +2 -0
  40. package/dist/types/notifications/recent-activity.d.ts +35 -0
  41. package/dist/types/notifications/telegram-daemon.d.ts +114 -16
  42. package/dist/types/notifications/telegram-reference.d.ts +3 -1
  43. package/dist/types/notifications/topic-registry.d.ts +12 -9
  44. package/dist/types/runtime-mcp/types.d.ts +7 -0
  45. package/dist/types/sdk.d.ts +2 -0
  46. package/dist/types/session/agent-session.d.ts +14 -4
  47. package/dist/types/session/blob-store.d.ts +25 -0
  48. package/dist/types/session/session-manager.d.ts +57 -0
  49. package/dist/types/skc-runtime/launch-tmux.d.ts +1 -0
  50. package/dist/types/skc-runtime/psmux-detect.d.ts +78 -0
  51. package/dist/types/skc-runtime/team-runtime.d.ts +2 -0
  52. package/dist/types/skc-runtime/tmux-common.d.ts +30 -2
  53. package/dist/types/skc-runtime/tmux-sessions.d.ts +18 -0
  54. package/dist/types/slash-commands/helpers/fast-status-report.d.ts +6 -0
  55. package/dist/types/system-prompt.d.ts +2 -0
  56. package/dist/types/task/executor.d.ts +9 -1
  57. package/dist/types/tools/composer-bash-policy.d.ts +14 -0
  58. package/dist/types/tools/index.d.ts +3 -1
  59. package/dist/types/utils/changelog.d.ts +1 -0
  60. package/dist/types/web/insane/url-guard.d.ts +6 -3
  61. package/dist/types/web/scrapers/types.d.ts +5 -0
  62. package/dist/types/web/scrapers/utils.d.ts +7 -1
  63. package/package.json +11 -9
  64. package/scripts/g004-tmux-smoke.ts +100 -0
  65. package/scripts/g005-daemon-smoke.ts +180 -0
  66. package/scripts/g011-daemon-path-smoke.ts +153 -0
  67. package/src/cli/fast-help.ts +29 -1
  68. package/src/cli/mcp-cli.ts +272 -0
  69. package/src/cli/plugin-cli.ts +66 -3
  70. package/src/cli.ts +30 -12
  71. package/src/commands/mcp.ts +117 -0
  72. package/src/commands/plugin.ts +4 -0
  73. package/src/commands/session.ts +18 -0
  74. package/src/config/keybindings.ts +2 -2
  75. package/src/config/model-profile-activation.ts +55 -7
  76. package/src/config/settings-schema.ts +8 -93
  77. package/src/deep-interview/plaintext-gate-guard.ts +94 -0
  78. package/src/defaults/skc/extensions/grok-cli-vendor/biome.json +1 -1
  79. package/src/defaults/skc/skills/deep-interview/SKILL.md +7 -6
  80. package/src/defaults/skc/skills/team/SKILL.md +5 -3
  81. package/src/defaults/skc/skills/ultragoal/SKILL.md +41 -13
  82. package/src/export/html/index.ts +2 -2
  83. package/src/extensibility/extensions/runner.ts +1 -0
  84. package/src/extensibility/skc-plugins/compiler.ts +351 -0
  85. package/src/extensibility/skc-plugins/constrained-hooks.ts +170 -0
  86. package/src/extensibility/skc-plugins/index.ts +9 -0
  87. package/src/extensibility/skc-plugins/injection.ts +109 -0
  88. package/src/extensibility/skc-plugins/installer.ts +434 -0
  89. package/src/extensibility/skc-plugins/loader.ts +3 -1
  90. package/src/extensibility/skc-plugins/mcp-policy.ts +239 -0
  91. package/src/extensibility/skc-plugins/observability.ts +84 -0
  92. package/src/extensibility/skc-plugins/paths.ts +1 -1
  93. package/src/extensibility/skc-plugins/prompt-appendix.ts +109 -0
  94. package/src/extensibility/skc-plugins/registry.ts +180 -0
  95. package/src/extensibility/skc-plugins/runtime-adapters.ts +234 -0
  96. package/src/extensibility/skc-plugins/schema.ts +250 -20
  97. package/src/extensibility/skc-plugins/session-validation.ts +147 -0
  98. package/src/extensibility/skc-plugins/types.ts +199 -3
  99. package/src/extensibility/skc-plugins/validation.ts +80 -0
  100. package/src/extensibility/skills.ts +15 -0
  101. package/src/hooks/skill-state.ts +57 -0
  102. package/src/i18n/messages/de.ts +0 -1
  103. package/src/i18n/messages/en.ts +0 -1
  104. package/src/i18n/messages/es.ts +0 -1
  105. package/src/i18n/messages/fr.ts +0 -1
  106. package/src/i18n/messages/ja.ts +0 -1
  107. package/src/i18n/messages/ko.ts +0 -1
  108. package/src/i18n/messages/zh.ts +0 -1
  109. package/src/internal-urls/docs-index.generated.ts +12 -8
  110. package/src/main.ts +14 -3
  111. package/src/modes/bridge/bridge-mode.ts +11 -0
  112. package/src/modes/components/assistant-message.ts +49 -1
  113. package/src/modes/components/custom-editor.ts +2 -0
  114. package/src/modes/components/footer.ts +2 -3
  115. package/src/modes/components/hook-editor.ts +1 -1
  116. package/src/modes/components/hook-selector.ts +67 -43
  117. package/src/modes/components/model-selector.ts +56 -11
  118. package/src/modes/components/settings-defs.ts +1 -2
  119. package/src/modes/components/settings-selector.ts +2 -7
  120. package/src/modes/components/status-line/git-utils.ts +25 -0
  121. package/src/modes/components/status-line.ts +10 -11
  122. package/src/modes/components/welcome.ts +2 -3
  123. package/src/modes/controllers/extension-ui-controller.ts +0 -27
  124. package/src/modes/controllers/selector-controller.ts +53 -11
  125. package/src/modes/interactive-mode.ts +4 -1
  126. package/src/modes/shared/agent-wire/scopes.ts +1 -1
  127. package/src/modes/theme/defaults/gruvbox-dark.json +99 -0
  128. package/src/modes/theme/defaults/index.ts +2 -0
  129. package/src/modes/theme/theme.ts +0 -4
  130. package/src/modes/utils/hotkeys-markdown.ts +1 -1
  131. package/src/notifications/html-format.ts +38 -0
  132. package/src/notifications/index.ts +242 -12
  133. package/src/notifications/lifecycle-commands.ts +238 -0
  134. package/src/notifications/lifecycle-control-runtime.ts +405 -0
  135. package/src/notifications/lifecycle-orchestrator.ts +358 -0
  136. package/src/notifications/operator-runtime.ts +171 -0
  137. package/src/notifications/rate-limit-pool.ts +19 -0
  138. package/src/notifications/recent-activity.ts +132 -0
  139. package/src/notifications/telegram-daemon.ts +778 -257
  140. package/src/notifications/telegram-reference.ts +25 -7
  141. package/src/notifications/topic-registry.ts +23 -9
  142. package/src/prompts/agents/executor.md +2 -2
  143. package/src/runtime-mcp/transports/stdio.ts +38 -4
  144. package/src/runtime-mcp/types.ts +7 -0
  145. package/src/sdk.ts +157 -10
  146. package/src/session/agent-session.ts +166 -74
  147. package/src/session/blob-store.ts +196 -8
  148. package/src/session/session-manager.ts +762 -12
  149. package/src/skc-runtime/launch-tmux.ts +68 -19
  150. package/src/skc-runtime/psmux-detect.ts +239 -0
  151. package/src/skc-runtime/team-runtime.ts +56 -23
  152. package/src/skc-runtime/tmux-common.ts +88 -4
  153. package/src/skc-runtime/tmux-sessions.ts +111 -9
  154. package/src/skc-runtime/ultragoal-guard.ts +25 -8
  155. package/src/skc-runtime/ultragoal-runtime.ts +75 -15
  156. package/src/slash-commands/builtin-registry.ts +23 -3
  157. package/src/slash-commands/helpers/fast-status-report.ts +13 -3
  158. package/src/slash-commands/helpers/parse.ts +2 -1
  159. package/src/system-prompt.ts +9 -0
  160. package/src/task/executor.ts +31 -7
  161. package/src/task/index.ts +2 -0
  162. package/src/tools/ask.ts +5 -1
  163. package/src/tools/bash.ts +9 -0
  164. package/src/tools/composer-bash-policy.ts +96 -0
  165. package/src/tools/fetch.ts +18 -2
  166. package/src/tools/index.ts +3 -1
  167. package/src/utils/changelog.ts +8 -0
  168. package/src/web/insane/url-guard.ts +18 -14
  169. package/src/web/scrapers/types.ts +143 -45
  170. package/src/web/scrapers/utils.ts +70 -19
@@ -0,0 +1,98 @@
1
+ import type { ResumeCandidate, SessionCreateFrame, SessionLifecycleRequest, SessionLifecycleResponse } from "./index";
2
+ import { type AuditEvent, type CreateEffectResult, type LedgerStore, type LifecycleOutcome, type OrchestratorDeps, type ResumeEffectResult } from "./lifecycle-orchestrator";
3
+ /** Minimal view of the native control server this runtime depends on. */
4
+ export interface ControlServerLike {
5
+ onLifecycleRequest(cb: (err: Error | null, req: {
6
+ kind: string;
7
+ requestId: string;
8
+ payloadJson: string;
9
+ }) => void): void;
10
+ respond(responseJson: string): void;
11
+ }
12
+ /**
13
+ * A startable control server (the native NotificationControlServer, or a fake in
14
+ * tests). Extends {@link ControlServerLike} with the start/stop lifecycle the
15
+ * daemon owns.
16
+ */
17
+ export interface LifecycleControlServer extends ControlServerLike {
18
+ start(): Promise<unknown>;
19
+ stop(): void;
20
+ }
21
+ /** Factory the daemon uses to construct a control server bound to its ownership. */
22
+ export type LifecycleControlServerFactory = (input: {
23
+ token: string;
24
+ ownerId: string;
25
+ agentDir: string;
26
+ }) => LifecycleControlServer;
27
+ /** Atomic + fsynced file-backed idempotency ledger store. */
28
+ export declare function fileLedgerStore(idempotencyFile: string): LedgerStore;
29
+ /** Append-only JSONL audit sink (0600). Never receives tokens or raw prompts. */
30
+ export declare function fileAudit(auditPath: string): (e: AuditEvent) => void;
31
+ /** Simple per-chat sliding-window create rate limiter. */
32
+ export declare function createRateLimiter(maxPerWindow: number, windowMs: number): (chatId: string, nowMs: number) => boolean;
33
+ /** Build the `skc` argv for a create target (existing path / worktree / dir).
34
+ *
35
+ * The launched session id is carried via `SKC_SESSION_ID` in the child env (see
36
+ * {@link daemonSpawnCreate}); the root `skc` launcher has no `--session-id`
37
+ * flag, so it must never appear in argv. Only flags the launch parser actually
38
+ * supports are emitted (`--worktree <branch>` for worktree targets). */
39
+ export declare function buildCreateArgv(frame: SessionCreateFrame, _ids: {
40
+ intendedSessionId: string;
41
+ startupPromptRef?: string;
42
+ }): {
43
+ cwd: string;
44
+ args: string[];
45
+ };
46
+ /** Real daemon-safe tmux launcher: detached `tmux new-session -d` + SKC tags. */
47
+ export declare function daemonSpawnCreate(env?: NodeJS.ProcessEnv): (frame: SessionCreateFrame, ids: {
48
+ lifecycleRequestId: string;
49
+ intendedSessionId: string;
50
+ startupPromptRef?: string;
51
+ }) => Promise<CreateEffectResult>;
52
+ /** Real force-close effect (SKC-managed only, id-matched). */
53
+ export declare function daemonCloseSession(env?: NodeJS.ProcessEnv): (target: {
54
+ sessionId: string;
55
+ tmuxSession?: string;
56
+ sessionStateFile?: string;
57
+ }) => Promise<{
58
+ processGone: boolean;
59
+ }>;
60
+ /** Real resume effect: reattach if a live SKC session matches; else resolve the
61
+ * prefix against saved history and fail closed (`ambiguous`/`notFound`) before
62
+ * cold-restarting exactly one resolved session via the daemon-safe launcher. */
63
+ export declare function daemonResumeSession(env?: NodeJS.ProcessEnv, opts?: {
64
+ sessionsRoot?: string;
65
+ }): (target: {
66
+ sessionIdOrPrefix: string;
67
+ path?: string;
68
+ }) => Promise<ResumeEffectResult | {
69
+ ambiguous: ResumeCandidate[];
70
+ } | {
71
+ notFound: true;
72
+ }>;
73
+ /** Translate an orchestrator outcome into a wire response frame. */
74
+ export declare function outcomeToResponse(frame: SessionLifecycleRequest, outcome: LifecycleOutcome): SessionLifecycleResponse;
75
+ /**
76
+ * Wire a control server's lifecycle requests through the orchestrator.
77
+ *
78
+ * Handlers run on a single serial queue (a promise chain): the daemon owns the
79
+ * one control endpoint, so serializing here makes each request's ledger
80
+ * read -> classify -> write atomic with respect to every other request. Two
81
+ * identical updates that arrive nearly simultaneously can no longer both
82
+ * classify as `new` and both spawn — the second sees the first's persisted
83
+ * `in_progress`/`success` entry and re-acks instead.
84
+ */
85
+ export declare function attachLifecycleControl(server: ControlServerLike, deps: OrchestratorDeps): void;
86
+ /** Assemble real orchestrator deps for the daemon (ledger/audit under agentDir). */
87
+ export declare function buildOrchestratorDeps(input: {
88
+ pairedChatId: string;
89
+ agentNotificationsDir: string;
90
+ /** Root of saved session histories (`<agentDir>/sessions`), for resume resolution. */
91
+ sessionsRoot?: string;
92
+ env?: NodeJS.ProcessEnv;
93
+ }): OrchestratorDeps;
94
+ /**
95
+ * Default production factory: a real native NotificationControlServer bound to
96
+ * the daemon's control token, owner id, and agent dir.
97
+ */
98
+ export declare const createNativeControlServer: LifecycleControlServerFactory;
@@ -0,0 +1,144 @@
1
+ import type { LifecycleErrorReason, ResumeCandidate, SessionCreateFrame, SessionLifecycleRequest } from "./index";
2
+ /** Durable idempotency state for a single lifecycle request. */
3
+ export type LedgerState = "in_progress" | "success" | "failure" | "terminal_uncertain";
4
+ /** One persisted idempotency entry, keyed by `chatId:updateId`. */
5
+ export interface LedgerEntry {
6
+ requestHash: string;
7
+ state: LedgerState;
8
+ requestId: string;
9
+ verb: SessionLifecycleRequest["type"];
10
+ intendedSessionId?: string;
11
+ startupPromptRef?: string;
12
+ createdAt: number;
13
+ updatedAt: number;
14
+ targetSummary: Record<string, unknown>;
15
+ sessionId?: string;
16
+ tmuxSession?: string;
17
+ sessionStateFile?: string;
18
+ endpointUrl?: string;
19
+ /** Close effect outcome: whether the tmux process is confirmed gone. */
20
+ processGone?: boolean;
21
+ reason?: LifecycleErrorReason;
22
+ }
23
+ /** The full on-disk ledger document. */
24
+ export interface LedgerDoc {
25
+ version: 1;
26
+ entries: Record<string, LedgerEntry>;
27
+ }
28
+ /** Persistence boundary: atomic + fsynced read/write of the ledger document. */
29
+ export interface LedgerStore {
30
+ read(): Promise<LedgerDoc>;
31
+ /** Write atomically (temp + fsync + rename) under a per-ledger lock. */
32
+ write(doc: LedgerDoc): Promise<void>;
33
+ }
34
+ /** One audit line. Tokens and raw prompts are NEVER included. */
35
+ export interface AuditEvent {
36
+ ts: string;
37
+ event: "accepted" | "rejected" | "duplicate_reack" | "rate_limited" | "spawn_started" | "recovered_in_progress" | "success" | "failure" | "terminal_uncertain";
38
+ chatId: string;
39
+ updateId: number;
40
+ requestId: string;
41
+ requestHash: string;
42
+ verb: SessionLifecycleRequest["type"];
43
+ targetSummary: Record<string, unknown>;
44
+ sessionId?: string;
45
+ tmuxSession?: string;
46
+ reason?: LifecycleErrorReason;
47
+ /** Prompt byte length only (never the prompt text). */
48
+ promptBytes?: number;
49
+ /** Prompt content hash only (never the prompt text). */
50
+ promptHash?: string;
51
+ }
52
+ export interface CreateEffectResult {
53
+ sessionId: string;
54
+ tmuxSession: string;
55
+ sessionStateFile?: string;
56
+ endpointUrl: string;
57
+ topicThreadId: string;
58
+ }
59
+ export interface ResumeEffectResult extends CreateEffectResult {
60
+ mode: "reattached" | "cold_restarted";
61
+ }
62
+ /** Injected effects + policy. Pure orchestration calls into these. */
63
+ export interface OrchestratorDeps {
64
+ /** The single paired chat id. Anything else is rejected before parsing. */
65
+ pairedChatId: string;
66
+ now: () => number;
67
+ store: LedgerStore;
68
+ audit: (event: AuditEvent) => Promise<void> | void;
69
+ /** Per-chat create rate limiter: returns true when allowed. */
70
+ allowCreate: (chatId: string, nowMs: number) => boolean;
71
+ /** Persist the once-consumed 0600 startup-prompt file; returns its ref. */
72
+ writeStartupPrompt: (requestId: string, prompt: string | undefined) => Promise<string | undefined>;
73
+ /** Spawn a session for a create/cold-restart. */
74
+ spawnCreate: (frame: SessionCreateFrame, ids: {
75
+ lifecycleRequestId: string;
76
+ intendedSessionId: string;
77
+ startupPromptRef?: string;
78
+ }) => Promise<CreateEffectResult>;
79
+ closeSession: (target: {
80
+ sessionId: string;
81
+ tmuxSession?: string;
82
+ sessionStateFile?: string;
83
+ }) => Promise<{
84
+ processGone: boolean;
85
+ }>;
86
+ resumeSession: (target: {
87
+ sessionIdOrPrefix: string;
88
+ path?: string;
89
+ }) => Promise<ResumeEffectResult | {
90
+ ambiguous: ResumeCandidate[];
91
+ } | {
92
+ notFound: true;
93
+ }>;
94
+ newLifecycleRequestId: () => string;
95
+ newSessionId: () => string;
96
+ }
97
+ /** A redaction-safe summary of a request target (never includes the token). */
98
+ export declare function summarizeTarget(frame: SessionLifecycleRequest): Record<string, unknown>;
99
+ /**
100
+ * Stable request hash over the meaningful (non-token) request content. Used to
101
+ * detect a duplicate update id reused with a DIFFERENT body (conflict).
102
+ */
103
+ export declare function requestHash(frame: SessionLifecycleRequest): string;
104
+ export declare function ledgerKey(chatId: string, updateId: number): string;
105
+ /** How a freshly-arrived request relates to the durable ledger. */
106
+ export type DuplicateClass = {
107
+ kind: "new";
108
+ } | {
109
+ kind: "reack_success";
110
+ entry: LedgerEntry;
111
+ } | {
112
+ kind: "reack_failure";
113
+ entry: LedgerEntry;
114
+ } | {
115
+ kind: "in_progress";
116
+ entry: LedgerEntry;
117
+ } | {
118
+ kind: "terminal_uncertain";
119
+ entry: LedgerEntry;
120
+ } | {
121
+ kind: "conflict";
122
+ entry: LedgerEntry;
123
+ };
124
+ /** Classify a request against an existing ledger entry (pure). */
125
+ export declare function classifyDuplicate(existing: LedgerEntry | undefined, hash: string): DuplicateClass;
126
+ /** The structured outcome the daemon translates into a wire response frame. */
127
+ export type LifecycleOutcome = {
128
+ status: "ok";
129
+ entry: LedgerEntry;
130
+ mode?: "reattached" | "cold_restarted";
131
+ } | {
132
+ status: "error";
133
+ reason: LifecycleErrorReason;
134
+ message: string;
135
+ candidates?: ResumeCandidate[];
136
+ } | {
137
+ status: "pending";
138
+ entry: LedgerEntry;
139
+ };
140
+ /**
141
+ * Handle one authenticated lifecycle request. Enforces paired-chat gating,
142
+ * idempotency, and rate limiting BEFORE any side effect, then dispatches.
143
+ */
144
+ export declare function handleLifecycleRequest(frame: SessionLifecycleRequest, deps: OrchestratorDeps): Promise<LifecycleOutcome>;
@@ -0,0 +1,52 @@
1
+ export interface NotificationOperatorTimerDeps {
2
+ now?: () => number;
3
+ setTimeoutImpl?: typeof setTimeout;
4
+ clearTimeoutImpl?: typeof clearTimeout;
5
+ setIntervalImpl?: typeof setInterval;
6
+ clearIntervalImpl?: typeof clearInterval;
7
+ }
8
+ export interface NotificationOperatorRuntimeState {
9
+ running: boolean;
10
+ stopRequested: boolean;
11
+ activeAbort: boolean;
12
+ }
13
+ export interface OperatorBackoffOptions {
14
+ initialMs: number;
15
+ maxMs: number;
16
+ factor?: number;
17
+ }
18
+ export declare class OperatorBackoffPolicy {
19
+ #private;
20
+ constructor(opts: OperatorBackoffOptions);
21
+ next(): number;
22
+ reset(): void;
23
+ get currentMs(): number;
24
+ }
25
+ export interface OperatorRoute<TContext> {
26
+ name: string;
27
+ matches(event: Record<string, unknown>): boolean;
28
+ handle(context: TContext, event: Record<string, unknown>): Promise<void> | void;
29
+ }
30
+ export declare class OperatorEventRouter<TContext> {
31
+ readonly routes: OperatorRoute<TContext>[];
32
+ add(input: OperatorRoute<TContext>): this;
33
+ dispatch(context: TContext, event: Record<string, unknown>): Promise<boolean>;
34
+ }
35
+ export declare class NotificationOperatorRuntime {
36
+ #private;
37
+ constructor(deps?: NotificationOperatorTimerDeps);
38
+ get state(): NotificationOperatorRuntimeState;
39
+ start(): void;
40
+ stop(): void;
41
+ requestStop(): void;
42
+ get running(): boolean;
43
+ get stopRequested(): boolean;
44
+ createAbortController(): AbortController;
45
+ clearAbortController(controller: AbortController): void;
46
+ startInterval(name: string, intervalMs: number, tick: () => void): void;
47
+ stopInterval(name: string): void;
48
+ stopAllIntervals(): void;
49
+ runExclusive(name: string, fn: () => Promise<void>): Promise<void>;
50
+ sleep(ms: number, signal?: AbortSignal): Promise<void>;
51
+ now(): number;
52
+ }
@@ -81,6 +81,8 @@ export declare class RateLimitPool<T = unknown> {
81
81
  * single session monopolises a lane), consuming one token each.
82
82
  */
83
83
  drain(nowMs?: number): RateLimitItem<T>[];
84
+ /** Remove queued items matching `predicate` without consuming tokens. Returns removed items in lane/FIFO order. */
85
+ removeWhere(predicate: (item: RateLimitItem<T>) => boolean): RateLimitItem<T>[];
84
86
  private refill;
85
87
  /** Pop the next item by lane priority + per-session round-robin fairness. */
86
88
  private takeNext;
@@ -0,0 +1,35 @@
1
+ /** One ranked recent-session entry surfaced to the picker. */
2
+ export interface RecentSessionEntry {
3
+ /** Session id (the `.jsonl` file stem). */
4
+ sessionId: string;
5
+ /** Working directory / repo path, when recoverable from the header. */
6
+ path?: string;
7
+ /** Branch, when recoverable from the header. */
8
+ branch?: string;
9
+ /** A short title (first user message), when recoverable. */
10
+ title?: string;
11
+ /** Absolute path of the session history (state) file. */
12
+ sessionStateFile: string;
13
+ /** Last-activity epoch-millis (history file mtime). */
14
+ mtimeMs: number;
15
+ /** True when a terminal breadcrumb points at this session file. */
16
+ currentTerminal?: boolean;
17
+ }
18
+ export interface RecentActivityDeps {
19
+ /** Root holding `<encoded-cwd>/<sessionId>.jsonl` history files. */
20
+ sessionsRoot: string;
21
+ /** Optional breadcrumb session-file paths (current terminals). */
22
+ breadcrumbPaths?: string[];
23
+ /** Max entries to return (default 20). */
24
+ limit?: number;
25
+ /** Injection seam for tests. */
26
+ readFirstLine?: (file: string) => string | undefined;
27
+ }
28
+ /**
29
+ * List recent sessions ranked by history-file mtime (newest first).
30
+ *
31
+ * Scans `<sessionsRoot>/<encoded-cwd>/<sessionId>.jsonl`, stats each file, and
32
+ * returns up to `limit` entries enriched with header metadata and a
33
+ * `currentTerminal` flag for any breadcrumb-referenced session file.
34
+ */
35
+ export declare function listRecentSessions(deps: RecentActivityDeps): RecentSessionEntry[];
@@ -1,6 +1,8 @@
1
1
  import * as fs from "node:fs";
2
2
  import type { Settings } from "../config/settings";
3
3
  import type { DaemonRuntimeInfo } from "../daemon/control-types";
4
+ import { type ControlServerLike, type LifecycleControlServerFactory } from "./lifecycle-control-runtime";
5
+ import { NotificationOperatorRuntime, OperatorBackoffPolicy } from "./operator-runtime";
4
6
  import { type AliasTable, type CallbackRoute, type PendingAsk } from "./telegram-reference";
5
7
  export type EnsureDaemonResult = "owner_spawned" | "attached" | "disabled";
6
8
  export interface DaemonState {
@@ -58,6 +60,22 @@ export declare const CLIENT_PING_PONG_CAPABILITY = "client_ping_pong";
58
60
  /** Protocol version the daemon advertises in its ClientHello. */
59
61
  export declare const NOTIFICATION_PROTOCOL_VERSION = 2;
60
62
  export declare function daemonPaths(agentDir: string): DaemonPaths;
63
+ /**
64
+ * Attach session-lifecycle control (create/close/resume) to the running daemon.
65
+ *
66
+ * Wires an already-started, authenticated control server to the lifecycle
67
+ * orchestrator with real daemon-side effects (tmux launcher / force-close /
68
+ * resume), a durable fsynced idempotency ledger + audit JSONL under the agent
69
+ * notifications dir, and strict paired-chat gating. The control server itself
70
+ * (NotificationControlServer) is owned/started by the daemon process; this
71
+ * function only connects it to policy. Returns the orchestrator deps for tests.
72
+ */
73
+ export declare function startDaemonLifecycleControl(input: {
74
+ controlServer: ControlServerLike;
75
+ pairedChatId: string;
76
+ agentDir: string;
77
+ env?: NodeJS.ProcessEnv;
78
+ }): void;
61
79
  export declare function registerNotificationRoot(input: {
62
80
  settings: Settings;
63
81
  cwd: string;
@@ -146,6 +164,40 @@ export interface BotApi {
146
164
  signal?: AbortSignal;
147
165
  }): Promise<unknown>;
148
166
  }
167
+ export interface TelegramTransportOptions {
168
+ botToken: string;
169
+ apiBase?: string;
170
+ fetchImpl?: typeof fetch;
171
+ setTimeoutImpl?: typeof setTimeout;
172
+ }
173
+ /** Telegram Bot API transport: HTTP JSON/multipart details stay out of daemon orchestration. */
174
+ export declare class TelegramBotTransport implements BotApi {
175
+ #private;
176
+ constructor(opts: TelegramTransportOptions);
177
+ call(method: string, body: unknown, opts?: {
178
+ signal?: AbortSignal;
179
+ }): Promise<unknown>;
180
+ }
181
+ export interface TelegramUpdatePollerOptions {
182
+ botApi: BotApi;
183
+ runtime: NotificationOperatorRuntime;
184
+ backoff: OperatorBackoffPolicy;
185
+ processUpdate: (update: unknown) => Promise<void>;
186
+ }
187
+ /** Owns getUpdates offset, conflict backoff, and per-update error isolation. */
188
+ export declare class TelegramUpdatePoller {
189
+ #private;
190
+ constructor(opts: TelegramUpdatePollerOptions);
191
+ pollOnce(signal?: AbortSignal): Promise<number>;
192
+ }
193
+ /** Mutable dispatch state shared by session frames and inbound Telegram updates. */
194
+ export declare class TelegramEventDispatchState {
195
+ readonly busy: Set<string>;
196
+ readonly inboundReactions: Map<number, {
197
+ messageId: number;
198
+ }>;
199
+ readonly seenUpdateIds: Set<number>;
200
+ }
149
201
  /**
150
202
  * Cooperative control seam for the daemon run loop. Implemented by the
151
203
  * daemon-internal CLI / controller against the owner-scoped control-request
@@ -174,8 +226,17 @@ export interface TelegramDaemonOptions {
174
226
  idleTimeoutMs?: number;
175
227
  scanIntervalMs?: number;
176
228
  pid?: number;
229
+ /** Liveness probe for skipping dead-PID endpoint records in {@link TelegramNotificationDaemon.scanRoots}. */
230
+ pidAlive?: (pid: number) => boolean;
177
231
  botApi?: BotApi;
178
232
  control?: DaemonControlHooks;
233
+ /**
234
+ * Factory for the session-lifecycle control server. Defaults to the real
235
+ * native NotificationControlServer; tests inject a fake to verify the
236
+ * owner-bound start/stop lifecycle without a socket. When `undefined` AND no
237
+ * default applies (e.g. lifecycle control disabled), no control server starts.
238
+ */
239
+ createLifecycleControlServer?: LifecycleControlServerFactory | null;
179
240
  }
180
241
  interface SessionSocket {
181
242
  sessionId: string;
@@ -199,40 +260,72 @@ export declare class TelegramNotificationDaemon {
199
260
  readonly aliasTable: AliasTable;
200
261
  readonly messageRoutes: Map<string | number, CallbackRoute | Omit<CallbackRoute, "answer">>;
201
262
  readonly sessions: Map<string, SessionSocket>;
263
+ private readonly runtime;
264
+ private readonly sessionRouter;
265
+ private readonly pollConflictBackoff;
266
+ private readonly loopBackoff;
202
267
  private running;
203
- private offset;
204
268
  private readonly fsImpl;
205
269
  private readonly botApi;
206
270
  private readonly topics;
207
271
  private readonly pool;
208
- private readonly seenUpdateIds;
272
+ private readonly poller;
273
+ private readonly dispatchState;
274
+ /** Identity-bearing sessions by repo/branch surface, used to avoid transient duplicate topics. */
275
+ private readonly topicOwnerByIdentity;
276
+ /** Non-identity frames held until identity creates the correct thread. */
277
+ private readonly pendingThreadedFrames;
209
278
  /** True once the daemon has nudged the user to enable Threaded Mode. */
210
279
  private threadedFallbackNoticeSent;
211
280
  /** Sessions whose identity header was already sent flat (Threaded Mode off). */
212
281
  private readonly flatIdentitySent;
213
282
  /** Cached result of whether the paired chat is a private chat (flat-fallback gate). */
214
283
  private pairedChatPrivate;
215
- private flushTimer;
216
- private scanTimer;
217
- private scanning;
218
- private typingTimer;
219
284
  /** Sessions whose agent loop is currently busy (drives the typing indicator). */
220
- private readonly busy;
285
+ private get busy();
221
286
  /** Inbound update id → originating Telegram message, for delivery reactions. */
222
- private readonly inboundReactions;
223
- /** AbortController for the in-flight long poll; aborted by requestStop() to wake the loop. */
224
- private activePoll;
225
- /** Set when a cooperative stop has been requested (signal or control request). */
226
- private stopRequested;
227
- /** Current bounded backoff after a Telegram getUpdates 409 conflict (0 when healthy). */
228
- private pollConflictBackoffMs;
287
+ private get inboundReactions();
288
+ /**
289
+ * The owner-bound session-lifecycle control server (create/close/resume).
290
+ * Started in {@link run} after ownership is confirmed (so exactly one owner
291
+ * ever runs one), stopped in run()'s finally on any exit path.
292
+ */
293
+ private controlServer;
294
+ /** True while lifecycle control is active, so the loop keeps polling at idle. */
295
+ private lifecycleControlActive;
296
+ /** Control token (in-memory) the loopback client presents; never persisted/logged. */
297
+ private controlToken;
298
+ /** Loopback WS client to the daemon's own control endpoint (Option A real wire path). */
299
+ private controlClient;
300
+ /** Pending lifecycle responses awaiting a control-endpoint reply, by requestId. */
301
+ private readonly pendingLifecycle;
302
+ /** Monotonic counter for unique lifecycle request ids. */
303
+ private lifecycleSeq;
229
304
  /**
230
305
  * Cooperatively stop the daemon: set the stop flag and abort the in-flight
231
306
  * long poll so the run loop wakes immediately instead of waiting out the
232
307
  * ~25s getUpdates timeout. Safe to call from a signal handler.
233
308
  */
234
309
  requestStop(_reason?: "reload" | "stop" | "signal"): void;
310
+ private startLifecycleControl;
311
+ /** Stop the lifecycle control server (idempotent); called from run()'s finally. */
312
+ private stopLifecycleControl;
313
+ /**
314
+ * Connect the loopback control client and resolve responses by requestId.
315
+ * Resolves true once the socket is OPEN (bounded), false on error/timeout, so
316
+ * the caller only marks lifecycle control active when commands can be sent.
317
+ */
318
+ private connectControlClient;
319
+ /** Send a lifecycle frame over the loopback client and await the response. */
320
+ private submitLifecycleFrame;
321
+ private nextLifecycleRequestId;
322
+ /** Build an authenticated lifecycle frame from a parsed command + identity. */
323
+ private buildLifecycleFrame;
324
+ private handleLifecycleCommand;
325
+ /** Map a lifecycle response/error to a user-facing message (G010 surfacing). */
326
+ private formatLifecycleResponse;
235
327
  constructor(opts: TelegramDaemonOptions);
328
+ private createSessionRouter;
236
329
  loadAliases(): Promise<void>;
237
330
  persistAliases(): Promise<void>;
238
331
  scanRoots(): Promise<void>;
@@ -254,7 +347,14 @@ export declare class TelegramNotificationDaemon {
254
347
  private dropSession;
255
348
  private static readonly THREADED_FRAMES;
256
349
  private topicNameFor;
350
+ private topicIdentityKey;
351
+ private topicIdentityBase;
352
+ private topicOwnerForIdentity;
353
+ private submitThreadedFrame;
354
+ private rememberPendingThreadedFrame;
355
+ private flushPendingThreadedFrames;
257
356
  private ensureTopic;
357
+ private deleteTopic;
258
358
  private persistTopics;
259
359
  loadTopics(): Promise<void>;
260
360
  private downloadTelegramFile;
@@ -285,8 +385,6 @@ export declare class TelegramNotificationDaemon {
285
385
  private sendStaleGuidance;
286
386
  handleTelegramUpdate(update: unknown): Promise<void>;
287
387
  pollOnce(signal?: AbortSignal): Promise<number>;
288
- /** Abortable sleep honoring the injected timer; resolves early on abort. */
289
- private sleep;
290
388
  /** Sync the bot's Telegram command menu to what the daemon actually handles. */
291
389
  registerBotCommands(): Promise<void>;
292
390
  run(): Promise<void>;
@@ -90,10 +90,12 @@ export interface RouteInboundContext {
90
90
  }
91
91
  /** Route a Telegram update to a session/action without I/O. Fail closed under ambiguity. */
92
92
  export declare function routeInboundUpdate(update: unknown, ctx: RouteInboundContext): RouteDecision;
93
- /** Read `{url, token}` from an endpoint discovery file. */
93
+ /** Read `{url, token, pid?, stale?}` from an endpoint discovery file. */
94
94
  export declare function readEndpoint(path: string): {
95
95
  url: string;
96
96
  token: string;
97
+ pid?: number;
98
+ stale?: boolean;
97
99
  };
98
100
  /** Options for {@link runTelegramReferenceClient}. */
99
101
  export interface TelegramReferenceOptions {
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Per-session forum-topic registry for the threaded session surface.
3
3
  *
4
- * Each SKC session owns exactly one Telegram forum topic in the paired private
5
- * DM. The topic is created once (via `createForumTopic`) and REUSED on resume,
6
- * keyed by session id, so a resumed session streams back into its existing
7
- * thread/history. The registry also tracks whether the one-time identity header
8
- * has already been pinned, so it is sent exactly once per topic even across
4
+ * Each SKC session owns one active Telegram forum topic in the paired private
5
+ * DM. The topic is created via `createForumTopic`, reused while the session
6
+ * remains active, and removed from the registry when the daemon deletes it on
7
+ * shutdown. The registry also tracks whether the one-time identity header has
8
+ * already been pinned, so it is sent exactly once per active topic, even across
9
9
  * reconnects.
10
10
  *
11
11
  * State is a plain serialisable map persisted beside the daemon state files;
@@ -45,14 +45,15 @@ export declare class TopicRegistry {
45
45
  load(state: TopicRegistryState): void;
46
46
  /** Resolve the owning session for a topic id (for fail-closed inbound routing). */
47
47
  sessionForTopic(topicId: string): string | undefined;
48
+ /** All session ids with a persisted topic record. */
49
+ sessionIds(): string[];
48
50
  /** The existing topic record for a session, if any. */
49
51
  get(sessionId: string): TopicRecord | undefined;
50
52
  /**
51
- * Return the existing topic for `sessionId`, or create one via `create`
52
- * (called only on first use). Reuse-on-resume: an existing record is
53
- * returned without invoking `create`.
53
+ * Return the existing active topic for `sessionId`, or create one via
54
+ * `create` (called only on first use).
54
55
  */
55
- getOrCreateTopic(sessionId: string, create: () => Promise<string>, now?: () => number): Promise<TopicRecord>;
56
+ getOrCreateTopic(sessionId: string, create: () => Promise<string>, now?: () => number, name?: string): Promise<TopicRecord>;
56
57
  /** Mark the identity header as sent for a session. Idempotent. */
57
58
  markIdentitySent(sessionId: string): void;
58
59
  /** Whether the identity header still needs sending for this session. */
@@ -62,6 +63,8 @@ export declare class TopicRegistry {
62
63
  * caller should `editForumTopic`), `false` when already current or unknown.
63
64
  */
64
65
  applyName(sessionId: string, name: string): boolean;
66
+ /** Remove a session topic record after Telegram deletes the topic. */
67
+ delete(sessionId: string): boolean;
65
68
  /** Serialise for atomic persistence beside the daemon state. */
66
69
  serialize(): TopicRegistryState;
67
70
  }
@@ -64,6 +64,13 @@ export interface MCPStdioServerConfig extends MCPServerConfigBase {
64
64
  command: string;
65
65
  args?: string[];
66
66
  env?: Record<string, string>;
67
+ /**
68
+ * When true, the child process is NOT given the host environment. Only a
69
+ * minimal OS allowlist (PATH/HOME/temp/locale) plus any explicit `env` keys
70
+ * are passed. Used for third-party plugin-bundle MCP servers so they cannot
71
+ * read host secrets from the inherited environment.
72
+ */
73
+ noInheritEnv?: boolean;
67
74
  cwd?: string;
68
75
  }
69
76
  /** HTTP server configuration (Streamable HTTP transport) */
@@ -10,6 +10,7 @@ import "./discovery";
10
10
  import type { CustomCommandsLoadResult } from "./extensibility/custom-commands";
11
11
  import type { CustomTool } from "./extensibility/custom-tools/types";
12
12
  import { type ExtensionFactory, type ExtensionUIContext, type LoadExtensionsResult, type ToolDefinition } from "./extensibility/extensions";
13
+ import { type ConstrainedPluginHook } from "./extensibility/skc-plugins/constrained-hooks";
13
14
  import { type Skill, type SkillWarning } from "./extensibility/skills";
14
15
  import type { FileSlashCommand } from "./extensibility/slash-commands";
15
16
  import type { HindsightSessionState } from "./hindsight/state";
@@ -240,4 +241,5 @@ export interface BuildSystemPromptOptions {
240
241
  * as separate entries so providers can cache prompt prefixes without concatenating blocks.
241
242
  */
242
243
  export declare function buildSystemPrompt(options?: BuildSystemPromptOptions): Promise<BuildSystemPromptResult>;
244
+ export declare function createPluginHooksExtension(hooks: ConstrainedPluginHook[]): ExtensionFactory;
243
245
  export declare function createAgentSession(options?: CreateAgentSessionOptions): Promise<CreateAgentSessionResult>;