lastlight-core 0.40.5 → 0.42.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 (99) hide show
  1. package/config/default.yaml +47 -0
  2. package/dist/admin/board-cache.d.ts +5 -0
  3. package/dist/admin/board-cache.js +14 -0
  4. package/dist/admin/board-cache.js.map +1 -1
  5. package/dist/admin/board-stream.d.ts +5 -7
  6. package/dist/admin/board-stream.js +2 -5
  7. package/dist/admin/board-stream.js.map +1 -1
  8. package/dist/admin/board.d.ts +12 -0
  9. package/dist/admin/board.js +19 -2
  10. package/dist/admin/board.js.map +1 -1
  11. package/dist/admin/change-stream.d.ts +33 -0
  12. package/dist/admin/change-stream.js +75 -0
  13. package/dist/admin/change-stream.js.map +1 -0
  14. package/dist/admin/chat-session-reader.d.ts +2 -2
  15. package/dist/admin/chat-session-reader.js +28 -28
  16. package/dist/admin/chat-session-reader.js.map +1 -1
  17. package/dist/admin/index.js +3 -3
  18. package/dist/admin/index.js.map +1 -1
  19. package/dist/admin/routes.js +89 -74
  20. package/dist/admin/routes.js.map +1 -1
  21. package/dist/admin/sessions.d.ts +52 -37
  22. package/dist/admin/sessions.js +101 -182
  23. package/dist/admin/sessions.js.map +1 -1
  24. package/dist/admin/transcript-index.d.ts +25 -0
  25. package/dist/admin/transcript-index.js +26 -0
  26. package/dist/admin/transcript-index.js.map +1 -0
  27. package/dist/config/config.d.ts +53 -0
  28. package/dist/config/config.js +154 -1
  29. package/dist/config/config.js.map +1 -1
  30. package/dist/config/provider-registry.d.ts +2 -1
  31. package/dist/config/provider-registry.js +1 -0
  32. package/dist/config/provider-registry.js.map +1 -1
  33. package/dist/engine/agent-executor.d.ts +2 -2
  34. package/dist/engine/agent-executor.js +8 -1
  35. package/dist/engine/agent-executor.js.map +1 -1
  36. package/dist/engine/chat/chat-runner.js +9 -2
  37. package/dist/engine/chat/chat-runner.js.map +1 -1
  38. package/dist/engine/executors/orchestrator.d.ts +4 -3
  39. package/dist/engine/executors/orchestrator.js +8 -6
  40. package/dist/engine/executors/orchestrator.js.map +1 -1
  41. package/dist/engine/executors/shared.d.ts +15 -1
  42. package/dist/engine/executors/shared.js +32 -5
  43. package/dist/engine/executors/shared.js.map +1 -1
  44. package/dist/engine/jira/adf.d.ts +27 -0
  45. package/dist/engine/jira/adf.js +225 -0
  46. package/dist/engine/jira/adf.js.map +1 -0
  47. package/dist/engine/jira/client.d.ts +99 -0
  48. package/dist/engine/jira/client.js +245 -0
  49. package/dist/engine/jira/client.js.map +1 -0
  50. package/dist/engine/llm.js +1 -0
  51. package/dist/engine/llm.js.map +1 -1
  52. package/dist/index.js +22 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/sandbox/docker.js +5 -0
  55. package/dist/sandbox/docker.js.map +1 -1
  56. package/dist/sandbox/egress-allowlist.d.ts +40 -3
  57. package/dist/sandbox/egress-allowlist.js +68 -3
  58. package/dist/sandbox/egress-allowlist.js.map +1 -1
  59. package/dist/sandbox/egress-firewall-config.d.ts +6 -0
  60. package/dist/sandbox/egress-firewall-config.js +9 -3
  61. package/dist/sandbox/egress-firewall-config.js.map +1 -1
  62. package/dist/sandbox/model-gateway.d.ts +40 -0
  63. package/dist/sandbox/model-gateway.js +235 -0
  64. package/dist/sandbox/model-gateway.js.map +1 -0
  65. package/dist/sandbox/sandbox.js +9 -2
  66. package/dist/sandbox/sandbox.js.map +1 -1
  67. package/dist/sandbox/smol.d.ts +1 -1
  68. package/dist/sandbox/smol.js +1 -1
  69. package/dist/session-log.d.ts +30 -0
  70. package/dist/session-log.js +67 -5
  71. package/dist/session-log.js.map +1 -1
  72. package/dist/state/change-signal.d.ts +17 -0
  73. package/dist/state/change-signal.js +62 -0
  74. package/dist/state/change-signal.js.map +1 -0
  75. package/dist/state/db.d.ts +6 -0
  76. package/dist/state/db.js +8 -2
  77. package/dist/state/db.js.map +1 -1
  78. package/dist/state/execution-store.d.ts +53 -13
  79. package/dist/state/execution-store.js +130 -22
  80. package/dist/state/execution-store.js.map +1 -1
  81. package/dist/state/schema/pg.d.ts +34 -0
  82. package/dist/state/schema/pg.js +9 -0
  83. package/dist/state/schema/pg.js.map +1 -1
  84. package/dist/state/schema/sqlite.d.ts +38 -0
  85. package/dist/state/schema/sqlite.js +9 -0
  86. package/dist/state/schema/sqlite.js.map +1 -1
  87. package/dist/state/workflow-run-store.d.ts +3 -0
  88. package/dist/state/workflow-run-store.js +26 -0
  89. package/dist/state/workflow-run-store.js.map +1 -1
  90. package/dist/workflows/handlers/survey-units.js +6 -3
  91. package/dist/workflows/handlers/survey-units.js.map +1 -1
  92. package/docker-compose.yml +36 -2
  93. package/drizzle/pg/0004_colorful_speed.sql +4 -0
  94. package/drizzle/pg/meta/0004_snapshot.json +1942 -0
  95. package/drizzle/pg/meta/_journal.json +7 -0
  96. package/drizzle/sqlite/0005_cynical_whistler.sql +4 -0
  97. package/drizzle/sqlite/meta/0005_snapshot.json +1767 -0
  98. package/drizzle/sqlite/meta/_journal.json +7 -0
  99. package/package.json +26 -26
@@ -1,4 +1,5 @@
1
1
  import { SessionLog, type JsonlMessage, type SessionLogScope } from "../session-log.js";
2
+ import type { ExecutionStore, SessionSummary } from "../state/execution-store.js";
2
3
  export type { JsonlMessage } from "../session-log.js";
3
4
  export interface SessionMeta {
4
5
  id: string;
@@ -26,7 +27,22 @@ export interface SessionMeta {
26
27
  * and null sessions are never filtered out.
27
28
  */
28
29
  repo?: string | null;
30
+ /**
31
+ * Whether the session's phase is still running, when the source knows —
32
+ * the ledger does (`finished_at` is null). Liveness uses it ahead of the
33
+ * recent-activity heuristic.
34
+ */
35
+ running?: boolean;
29
36
  }
37
+ /**
38
+ * The dashboard's session-type key (see `dashboard/src/sessionTypes.ts`) for a
39
+ * ledger `skill` — `<workflow>:<phase>`, or a bare name for non-workflow rows.
40
+ *
41
+ * Read off the ledger rather than sniffed from the transcript's first prompt,
42
+ * which is what this used to do: the skill is the authoritative name of what
43
+ * ran, and reading it costs nothing.
44
+ */
45
+ export declare function sessionTypeForSkill(skill: string): string;
30
46
  /**
31
47
  * Which on-disk slice of `<sessionsDir>/projects` a SessionReader exposes.
32
48
  *
@@ -47,7 +63,11 @@ export type SessionReaderScope = SessionLogScope;
47
63
  * caring where the data lives.
48
64
  */
49
65
  export interface SessionSource {
50
- listSessionIds(): Promise<string[]>;
66
+ /**
67
+ * The newest `limit` sessions, newest first, with their meta. One query —
68
+ * the list must never cost a directory walk or a transcript parse per row.
69
+ */
70
+ listSessions(limit: number): Promise<SessionMeta[]>;
51
71
  exists(sessionId: string): Promise<boolean>;
52
72
  getSessionMeta(sessionId: string): Promise<SessionMeta | null>;
53
73
  read(sessionId: string): Promise<Array<{
@@ -58,53 +78,48 @@ export interface SessionSource {
58
78
  normalizeRawLine(raw: Record<string, unknown>): JsonlMessage[];
59
79
  }
60
80
  /**
61
- * Resolve a session id to the `owner/repo` it ran against, or null.
81
+ * The slice of the `executions` ledger a {@link SessionReader} reads. A narrow
82
+ * port rather than the whole `StateDb`, so the reader is testable with a
83
+ * migrated test DB or a stub alike.
84
+ */
85
+ export type SessionLedger = Pick<ExecutionStore, "listSessions" | "sessionById" | "setTranscriptPath">;
86
+ /** Map a ledger {@link SessionSummary} to the dashboard's {@link SessionMeta}. */
87
+ export declare function metaFromSummary(s: SessionSummary): SessionMeta;
88
+ /**
89
+ * The workflow "Sessions" tab: sandbox-run transcripts, LISTED from the
90
+ * `executions` ledger and READ from disk.
62
91
  *
63
- * Injected as a function rather than handing {@link SessionReader} a `StateDb`
64
- * on purpose: the reader's whole job is the on-disk jsonl tree, and the repo is
65
- * a single scalar lookup from an unrelated table. A one-function seam keeps the
66
- * DB out of this module's type surface and makes the repo behaviour testable
67
- * with a closure instead of a migrated database.
92
+ * Every session the dashboard can show has a ledger row (each phase records its
93
+ * session id there), so the list, its ordering and every field it renders come
94
+ * from one indexed query. Only opening a session touches the filesystem — and
95
+ * then through the row's `transcript_path`, an O(1) lookup. This replaced a
96
+ * reader that walked the whole transcript tree and parsed hundreds of files on
97
+ * every 3 s stream tick, which pinned the agent's event loop on a host with
98
+ * tens of thousands of transcripts.
68
99
  */
69
- export type RepoForSession = (sessionId: string) => Promise<string | null>;
70
100
  export declare class SessionReader implements SessionSource {
71
- private sessionLog;
72
- private scope;
73
- private repoForSession?;
74
- private metaCache;
75
- private static CACHE_TTL_MS;
76
- constructor(sessionsHomeDir: string, scope?: SessionReaderScope, repoForSession?: RepoForSession);
77
- constructor(sessionLog: SessionLog, scope?: SessionReaderScope, repoForSession?: RepoForSession);
101
+ private readonly sessionLog;
102
+ private readonly ledger;
103
+ constructor(sessionLog: SessionLog, ledger: SessionLedger);
104
+ listSessions(limit: number): Promise<SessionMeta[]>;
78
105
  exists(sessionId: string): Promise<boolean>;
79
- /** Return all session IDs across all project directories, sorted
80
- * newest-first by file mtime.
81
- *
82
- * Filters out agent sub-sessions (agent-xxx) — those are included
83
- * in their parent session's view.
84
- *
85
- * The newest-first ordering matters: callers (the `/sessions` list +
86
- * SSE handlers) slice this to a `limit * 2` window BEFORE loading and
87
- * date-sorting each session's meta. With raw `readdir` order that window
88
- * could omit the most recent sessions entirely — e.g. today's runs living
89
- * in repo-suffixed project dirs read after a large generic dir — so the
90
- * list silently showed only older sessions. mtime is a cheap, reliable
91
- * recency proxy (it tracks the last appended message) that keeps the
92
- * freshest sessions inside the window; the handler then refines ordering
93
- * by parsed `started_at`. Mirrors the DB-backed chat reader, which
94
- * already returns threads newest-first. */
95
- listSessionIds(): Promise<string[]>;
96
106
  getSessionMeta(sessionId: string): Promise<SessionMeta | null>;
97
- private _readSessionMeta;
98
107
  /**
99
- * Read all messages from a session, unwrapping Claude Code envelope format.
100
- * Also includes messages from agent sub-sessions (agent-xxx.jsonl) that
101
- * belong to this session, interleaved by timestamp.
108
+ * Read all messages from a session, including legacy `agent-*` sidechains,
109
+ * interleaved by timestamp.
102
110
  */
103
111
  read(sessionId: string): Promise<Array<{
104
112
  index: number;
105
113
  msg: JsonlMessage;
106
114
  }>>;
107
- /** Get the file path for a session (needed by the tailer) */
115
+ /** Get the file path for a session (needed by the tailer). */
108
116
  getFilePath(sessionId: string): Promise<string | null>;
109
117
  normalizeRawLine(raw: Record<string, unknown>): JsonlMessage[];
118
+ /**
119
+ * Session id → its transcript. The ledger's `transcript_path` makes this one
120
+ * point lookup. A row written before that column existed (and not yet
121
+ * backfilled) falls back to ONE scan for this id, then records what it found
122
+ * so the next open is direct.
123
+ */
124
+ private resolve;
110
125
  }
@@ -1,210 +1,129 @@
1
- import { SessionLog, } from "../session-log.js";
1
+ import { transcriptRelativePath, } from "../session-log.js";
2
2
  /**
3
- * Detect session type from the first user message (prompt).
4
- * Matches against known orchestrator prompt patterns.
3
+ * The dashboard's session-type key (see `dashboard/src/sessionTypes.ts`) for a
4
+ * ledger `skill` — `<workflow>:<phase>`, or a bare name for non-workflow rows.
5
+ *
6
+ * Read off the ledger rather than sniffed from the transcript's first prompt,
7
+ * which is what this used to do: the skill is the authoritative name of what
8
+ * ran, and reading it costs nothing.
5
9
  */
6
- function detectSessionType(firstUserMessage) {
7
- if (!firstUserMessage)
8
- return "agent";
9
- const msg = firstUserMessage.slice(0, 500); // Only need the start
10
- // Build cycle phases
11
- if (msg.includes("PRE-FLIGHT GUARDRAILS CHECK"))
10
+ export function sessionTypeForSkill(skill) {
11
+ const [workflow = "", phase = ""] = skill.split(":");
12
+ if (workflow === "pr-review")
13
+ return "review";
14
+ if (workflow === "pr-fix")
15
+ return "pr-fix";
16
+ if (workflow.includes("triage"))
17
+ return "triage";
18
+ if (workflow.includes("health"))
19
+ return "health";
20
+ if (workflow === "chat")
21
+ return "chat";
22
+ const p = phase || workflow;
23
+ if (p.startsWith("guardrails"))
12
24
  return "guardrails";
13
- if (msg.includes("You are the ARCHITECT"))
25
+ if (p.startsWith("architect"))
14
26
  return "architect";
15
- if (msg.includes("You are the EXECUTOR (fix cycle"))
16
- return "fix";
17
- if (msg.includes("You are the EXECUTOR"))
27
+ if (p.startsWith("executor"))
18
28
  return "executor";
19
- if (msg.includes("You are the CODE REVIEWER"))
29
+ if (p.startsWith("reviewer"))
20
30
  return "reviewer";
21
- if (msg.includes("Create a pull request for the work on branch"))
31
+ if (p.startsWith("fix"))
32
+ return "fix";
33
+ if (p === "pr" || p.startsWith("pr_") || p.startsWith("pr-"))
22
34
  return "pr";
23
- if (msg.includes("You are fixing a PR based on"))
24
- return "pr-fix";
25
- if (msg.includes("Check if a build cycle already exists"))
35
+ if (p.startsWith("resume"))
26
36
  return "resume";
27
- // Skills
28
- if (msg.includes("issue-triage"))
29
- return "triage";
30
- if (msg.includes("pr-review"))
31
- return "review";
32
- if (msg.includes("repo-health"))
33
- return "health";
34
- // Chat (handled by chat.ts, not executor)
35
- if (msg.includes("You are Last Light") && msg.includes("chat"))
36
- return "chat";
37
37
  return "agent";
38
38
  }
39
+ /** Map a ledger {@link SessionSummary} to the dashboard's {@link SessionMeta}. */
40
+ export function metaFromSummary(s) {
41
+ const started = Date.parse(s.startedAt) / 1000;
42
+ const finished = s.finishedAt ? Date.parse(s.finishedAt) / 1000 : NaN;
43
+ return {
44
+ id: s.sessionId,
45
+ source: "agent",
46
+ sessionType: sessionTypeForSkill(s.skill),
47
+ model: s.model,
48
+ started_at: Number.isNaN(started) ? 0 : started,
49
+ last_message_at: Number.isNaN(finished) ? null : finished,
50
+ // The ledger counts turns, not messages. The list shows it as a size hint;
51
+ // nothing filters on it for this source (see `hasContent` in routes.ts).
52
+ message_count: s.turns ?? 0,
53
+ tool_call_count: 0,
54
+ conversation_message_count: s.turns ?? 0,
55
+ last_assistant_content: s.outputSnippet,
56
+ agentIds: [],
57
+ repo: s.repo,
58
+ running: s.finishedAt === null,
59
+ };
60
+ }
61
+ /**
62
+ * The workflow "Sessions" tab: sandbox-run transcripts, LISTED from the
63
+ * `executions` ledger and READ from disk.
64
+ *
65
+ * Every session the dashboard can show has a ledger row (each phase records its
66
+ * session id there), so the list, its ordering and every field it renders come
67
+ * from one indexed query. Only opening a session touches the filesystem — and
68
+ * then through the row's `transcript_path`, an O(1) lookup. This replaced a
69
+ * reader that walked the whole transcript tree and parsed hundreds of files on
70
+ * every 3 s stream tick, which pinned the agent's event loop on a host with
71
+ * tens of thousands of transcripts.
72
+ */
39
73
  export class SessionReader {
40
74
  sessionLog;
41
- scope;
42
- repoForSession;
43
- metaCache = new Map();
44
- static CACHE_TTL_MS = 10_000; // 10s cache for session metadata
45
- constructor(sessionsHomeDirOrLog, scope = "sandbox", repoForSession) {
46
- this.sessionLog = typeof sessionsHomeDirOrLog === "string"
47
- ? new SessionLog(sessionsHomeDirOrLog)
48
- : sessionsHomeDirOrLog;
49
- this.scope = scope;
50
- this.repoForSession = repoForSession;
75
+ ledger;
76
+ constructor(sessionLog, ledger) {
77
+ this.sessionLog = sessionLog;
78
+ this.ledger = ledger;
51
79
  }
52
- // `async` on a synchronous body: this reader is filesystem-backed, but its
53
- // DB-backed sibling is not, and both satisfy one SessionSource.
54
- async exists(sessionId) {
55
- return this.sessionLog.findSession(this.scope, sessionId) !== null;
80
+ async listSessions(limit) {
81
+ return (await this.ledger.listSessions(limit)).map(metaFromSummary);
56
82
  }
57
- /** Return all session IDs across all project directories, sorted
58
- * newest-first by file mtime.
59
- *
60
- * Filters out agent sub-sessions (agent-xxx) — those are included
61
- * in their parent session's view.
62
- *
63
- * The newest-first ordering matters: callers (the `/sessions` list +
64
- * SSE handlers) slice this to a `limit * 2` window BEFORE loading and
65
- * date-sorting each session's meta. With raw `readdir` order that window
66
- * could omit the most recent sessions entirely — e.g. today's runs living
67
- * in repo-suffixed project dirs read after a large generic dir — so the
68
- * list silently showed only older sessions. mtime is a cheap, reliable
69
- * recency proxy (it tracks the last appended message) that keeps the
70
- * freshest sessions inside the window; the handler then refines ordering
71
- * by parsed `started_at`. Mirrors the DB-backed chat reader, which
72
- * already returns threads newest-first. */
73
- async listSessionIds() {
74
- return this.sessionLog.listSessions(this.scope).map((e) => e.id);
83
+ async exists(sessionId) {
84
+ return (await this.resolve(sessionId)) !== null;
75
85
  }
76
86
  async getSessionMeta(sessionId) {
77
- const cached = this.metaCache.get(sessionId);
78
- if (cached && Date.now() - cached.cachedAt < SessionReader.CACHE_TTL_MS) {
79
- return cached.meta;
80
- }
81
- const meta = await this._readSessionMeta(sessionId);
82
- if (meta) {
83
- this.metaCache.set(sessionId, { meta, cachedAt: Date.now() });
84
- }
85
- return meta;
86
- }
87
- async _readSessionMeta(sessionId) {
88
- const entry = this.sessionLog.findSession(this.scope, sessionId);
89
- if (!entry)
90
- return null;
91
- const filesToScan = this.sessionLog.relatedFilesForSession(this.scope, sessionId, { includeAgents: true });
92
- let source = "agent";
93
- let model = null;
94
- let startedAt = null;
95
- let lastMessageAt = null;
96
- let messageCount = 0;
97
- let toolCallCount = 0;
98
- let conversationMessageCount = 0;
99
- let lastAssistantContent = null;
100
- let firstUserMessage = null;
101
- const agentIds = [];
102
- for (const scanFile of filesToScan) {
103
- const records = await this.sessionLog.readNormalizedFile(scanFile);
104
- for (const { raw, msg } of records) {
105
- // Track agent sub-sessions
106
- const agentId = raw.agentId;
107
- if (agentId && !agentIds.includes(agentId)) {
108
- agentIds.push(agentId);
109
- }
110
- // Extract source from userType field
111
- if (raw.userType === "external")
112
- source = "agent";
113
- // Extract model from first assistant message
114
- if (msg.role === "assistant" && msg.model && !model) {
115
- model = msg.model;
116
- }
117
- // Handle session_meta (Hermes format)
118
- if (msg.role === "session_meta") {
119
- source = msg.platform ?? msg.source ?? source;
120
- model = msg.model ?? model;
121
- if (msg.timestamp) {
122
- startedAt = new Date(msg.timestamp).getTime() / 1000;
123
- }
124
- continue;
125
- }
126
- if (msg.timestamp) {
127
- const ts = new Date(msg.timestamp).getTime() / 1000;
128
- if (!Number.isNaN(ts)) {
129
- // True min/max across the main session AND every agent sub-
130
- // session file. The previous "first / last seen" logic broke
131
- // when multiple files were scanned in non-chronological
132
- // readdir order — `lastMessageAt` ended up being the final
133
- // timestamp of whichever file was scanned last, which could
134
- // easily be older than the real most recent message.
135
- if (startedAt === null || ts < startedAt)
136
- startedAt = ts;
137
- if (lastMessageAt === null || ts > lastMessageAt)
138
- lastMessageAt = ts;
139
- }
140
- }
141
- if (msg.role === "user" || msg.role === "assistant" || msg.role === "tool") {
142
- messageCount++;
143
- conversationMessageCount++;
144
- }
145
- // Capture first user message for type detection
146
- if (msg.role === "user" && firstUserMessage === null && msg.content) {
147
- firstUserMessage = typeof msg.content === "string"
148
- ? msg.content
149
- : Array.isArray(msg.content)
150
- ? msg.content
151
- .filter((b) => b.type === "text")
152
- .map((b) => b.text)
153
- .join(" ")
154
- : JSON.stringify(msg.content);
155
- }
156
- if (msg.role === "assistant") {
157
- if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
158
- toolCallCount += msg.tool_calls.length;
159
- }
160
- if (typeof msg.content === "string" && msg.content) {
161
- lastAssistantContent = msg.content;
162
- }
163
- }
164
- }
165
- }
166
- if (startedAt === null) {
167
- // No parseable timestamps (empty or malformed file). Fall back to the
168
- // file's mtime — its real last-write time — NOT Date.now(). Using "now"
169
- // made a zero-byte/timestamp-less session masquerade as freshly active:
170
- // it sorted to the top of the list and tripped the 5-minute liveness
171
- // check, surfacing dead runs as live sessions.
172
- startedAt = entry.mtimeMs > 0 ? entry.mtimeMs / 1000 : Date.now() / 1000;
173
- }
174
- const sessionType = detectSessionType(firstUserMessage ?? "");
175
- return {
176
- id: sessionId,
177
- source,
178
- sessionType,
179
- model,
180
- started_at: startedAt,
181
- last_message_at: lastMessageAt,
182
- message_count: messageCount,
183
- tool_call_count: toolCallCount,
184
- conversation_message_count: conversationMessageCount,
185
- last_assistant_content: lastAssistantContent,
186
- agentIds,
187
- // Best-effort: a session whose repo we can't resolve stays visible.
188
- repo: (await this.repoForSession?.(sessionId)) ?? null,
189
- };
87
+ const summary = await this.ledger.sessionById(sessionId);
88
+ return summary ? metaFromSummary(summary) : null;
190
89
  }
191
90
  /**
192
- * Read all messages from a session, unwrapping Claude Code envelope format.
193
- * Also includes messages from agent sub-sessions (agent-xxx.jsonl) that
194
- * belong to this session, interleaved by timestamp.
91
+ * Read all messages from a session, including legacy `agent-*` sidechains,
92
+ * interleaved by timestamp.
195
93
  */
196
94
  async read(sessionId) {
197
- return this.sessionLog.readNormalizedSession(this.scope, sessionId, {
198
- includeAgents: true,
199
- skipEmptySystem: true,
200
- });
95
+ const entry = await this.resolve(sessionId);
96
+ return entry
97
+ ? this.sessionLog.readNormalizedEntry(entry, { includeAgents: true, skipEmptySystem: true })
98
+ : [];
201
99
  }
202
- /** Get the file path for a session (needed by the tailer) */
100
+ /** Get the file path for a session (needed by the tailer). */
203
101
  async getFilePath(sessionId) {
204
- return this.sessionLog.findSession(this.scope, sessionId)?.filePath ?? null;
102
+ return (await this.resolve(sessionId))?.filePath ?? null;
205
103
  }
206
104
  normalizeRawLine(raw) {
207
105
  return this.sessionLog.normalizeLine(raw);
208
106
  }
107
+ /**
108
+ * Session id → its transcript. The ledger's `transcript_path` makes this one
109
+ * point lookup. A row written before that column existed (and not yet
110
+ * backfilled) falls back to ONE scan for this id, then records what it found
111
+ * so the next open is direct.
112
+ */
113
+ async resolve(sessionId) {
114
+ const summary = await this.ledger.sessionById(sessionId);
115
+ if (!summary)
116
+ return null;
117
+ if (summary.transcriptPath) {
118
+ const entry = this.sessionLog.entryForRelativePath(summary.transcriptPath);
119
+ if (entry)
120
+ return entry;
121
+ }
122
+ const found = this.sessionLog.findSession("sandbox", sessionId);
123
+ if (found) {
124
+ await this.ledger.setTranscriptPath(sessionId, transcriptRelativePath(found.projectSlug, found.id));
125
+ }
126
+ return found;
127
+ }
209
128
  }
210
129
  //# sourceMappingURL=sessions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sessions.js","sourceRoot":"","sources":["../../src/admin/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAGX,MAAM,mBAAmB,CAAC;AAgC3B;;;GAGG;AACH,SAAS,iBAAiB,CAAC,gBAAwB;IACjD,IAAI,CAAC,gBAAgB;QAAE,OAAO,OAAO,CAAC;IACtC,MAA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AO,CAAC,cAAc,CAAC,CAAC;YAC3E,IAAI,KAAK;gBAAE,OAAO,KAAK,CAAC;QAC1B,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAChE,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,SAAS,EAAE,sBAAsB,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;QACtG,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Boot backfill for `executions.transcript_path`.
3
+ *
4
+ * The dashboard opens a workflow session's transcript through the path recorded
5
+ * on its ledger row, so no request ever walks the transcript tree. Rows written
6
+ * before that column existed (and any transcript moved back from an archive)
7
+ * have no path yet. This pass records one for every such session whose file is
8
+ * on disk, once, in the background after the server is listening.
9
+ *
10
+ * Cost: one async directory listing (names only, no stat) of `projects/*` —
11
+ * about 0.2 s for 39k transcripts — and one UPDATE per matched session, in
12
+ * batches that yield to the event loop. A boot with nothing missing costs one
13
+ * indexed query and returns. Rows with no file stay null, so a later boot
14
+ * re-checks them cheaply; that is how un-archiving works: move the files back
15
+ * and restart.
16
+ */
17
+ import type { LoggerPort } from "lastlight-workflow-engine";
18
+ import type { ExecutionStore } from "../state/execution-store.js";
19
+ import type { SessionLog } from "../session-log.js";
20
+ export declare const TRANSCRIPT_INDEX_BATCH = 500;
21
+ export interface TranscriptIndexResult {
22
+ indexed: number;
23
+ unmatched: number;
24
+ }
25
+ export declare function indexTranscripts(executions: Pick<ExecutionStore, "sessionIdsMissingTranscriptPath" | "setTranscriptPath">, sessionLog: Pick<SessionLog, "indexSandboxTranscripts">, log?: LoggerPort): Promise<TranscriptIndexResult>;
@@ -0,0 +1,26 @@
1
+ export const TRANSCRIPT_INDEX_BATCH = 500;
2
+ export async function indexTranscripts(executions, sessionLog, log) {
3
+ const missing = await executions.sessionIdsMissingTranscriptPath();
4
+ if (missing.length === 0)
5
+ return { indexed: 0, unmatched: 0 };
6
+ const onDisk = await sessionLog.indexSandboxTranscripts();
7
+ let indexed = 0;
8
+ let unmatched = 0;
9
+ for (let i = 0; i < missing.length; i++) {
10
+ const sessionId = missing[i];
11
+ const rel = onDisk.get(sessionId);
12
+ if (rel) {
13
+ await executions.setTranscriptPath(sessionId, rel);
14
+ indexed++;
15
+ }
16
+ else {
17
+ unmatched++;
18
+ }
19
+ // Yield between batches so the dashboard and webhooks stay responsive.
20
+ if ((i + 1) % TRANSCRIPT_INDEX_BATCH === 0)
21
+ await new Promise((r) => setImmediate(r));
22
+ }
23
+ log?.info("Indexed transcript paths", { indexed, unmatched });
24
+ return { indexed, unmatched };
25
+ }
26
+ //# sourceMappingURL=transcript-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript-index.js","sourceRoot":"","sources":["../../src/admin/transcript-index.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAO1C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,UAAyF,EACzF,UAAuD,EACvD,GAAgB;IAEhB,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,+BAA+B,EAAE,CAAC;IACnE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAE9D,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,uBAAuB,EAAE,CAAC;IAC1D,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,UAAU,CAAC,iBAAiB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;YACnD,OAAO,EAAE,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,SAAS,EAAE,CAAC;QACd,CAAC;QACD,uEAAuE;QACvE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,sBAAsB,KAAK,CAAC;YAAE,MAAM,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9F,CAAC;IACD,GAAG,EAAE,IAAI,CAAC,0BAA0B,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAC9D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC"}
@@ -31,6 +31,47 @@ export interface SlackConfig {
31
31
  */
32
32
  repoChannels: Record<string, string>;
33
33
  }
34
+ /** A Jira project's mapping to a GitHub repo, with optional per-component overrides. */
35
+ export interface JiraProjectMapping {
36
+ /** Project default repo, `owner/repo`. */
37
+ repo: string;
38
+ /** Optional component-name → `owner/repo` overrides, resolved before the default. */
39
+ components?: Record<string, string>;
40
+ }
41
+ /**
42
+ * The live Jira connector config (issue #501). Credentials + the site come from
43
+ * env (secret); behaviour comes from the YAML `jira:` block. Present only when
44
+ * enabled with the secrets set — otherwise the feature is inert.
45
+ */
46
+ export interface JiraConfig {
47
+ /** `JIRA_SITE_URL`, e.g. `https://acme.atlassian.net` (no trailing slash). */
48
+ siteUrl: string;
49
+ /**
50
+ * `JIRA_CLOUD_ID` — only a SCOPED token needs it (gateway base); a classic
51
+ * token leaves it unset and uses `siteUrl`. Supplied from config, not resolved
52
+ * at boot (`tenantInfo` 404s on some sites; `accessible-resources` is OAuth-only).
53
+ */
54
+ cloudId?: string;
55
+ /** `JIRA_EMAIL` / `JIRA_API_TOKEN` — basic auth for the bot account. */
56
+ email: string;
57
+ apiToken: string;
58
+ /** `JIRA_WEBHOOK_SECRET` — HMAC secret the inbound webhook is signed with. */
59
+ webhookSecret: string;
60
+ /** Jira label that opts a ticket in. */
61
+ triggerLabel: string;
62
+ /** Jira accountIds allowed to trigger / comment / approve. EMPTY = nobody. */
63
+ allowedAccountIds: string[];
64
+ projects: Record<string, JiraProjectMapping>;
65
+ transitions: {
66
+ started?: string;
67
+ prOpened?: string;
68
+ merged?: string;
69
+ };
70
+ webhook: {
71
+ url: string | null;
72
+ autoSync: boolean;
73
+ };
74
+ }
34
75
  /** The weekly Slack repo digest. Operator-only — see {@link RuntimeConfig.digest}. */
35
76
  export interface DigestConfig {
36
77
  /** How far back a digest looks, in days. */
@@ -177,6 +218,8 @@ export interface LastLightConfig {
177
218
  */
178
219
  githubToken?: string;
179
220
  slack?: SlackConfig;
221
+ /** Jira connector (issue #501) — present only when enabled with `JIRA_*` set. */
222
+ jira?: JiraConfig;
180
223
  approval?: Record<string, boolean>;
181
224
  bootstrapLabel: string;
182
225
  /**
@@ -584,6 +627,16 @@ export declare function getHoldLabel(): string;
584
627
  * rather than mirrored by hand.
585
628
  */
586
629
  export declare const SENSITIVE_KEY_RE: RegExp;
630
+ /**
631
+ * A WHOLE key that names a count of tokens (`maxTokens`, `max_tokens`,
632
+ * `maxOutputTokens`, `contextTokens`). `SENSITIVE_KEY_RE` matches it for the
633
+ * `token` in it, but its value is a number the operator tunes and needs to read
634
+ * back, so `redactPublic` shows it — when, and only when, the value IS a finite
635
+ * number. Anchored at both ends, so `adminToken` or `maxTokensSecret` never
636
+ * qualifies, and the value check keeps a credential pasted under a count key
637
+ * (repo YAML is redacted before validation) masked.
638
+ */
639
+ export declare const TOKEN_COUNT_KEY_RE: RegExp;
587
640
  /**
588
641
  * Recursively redact secret-looking keys from a public (non-secret) config tree.
589
642
  * Exported alongside {@link SENSITIVE_KEY_RE} for the admin routes — same rule,