@xfey/tutti 0.1.60 → 0.1.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collaboration-state/clarification-records.d.ts +0 -9
- package/dist/collaboration-state/clarification-records.js +0 -57
- package/dist/collaboration-state/index.d.ts +6 -5
- package/dist/collaboration-state/index.js +5 -4
- package/dist/collaboration-state/messages.d.ts +4 -6
- package/dist/collaboration-state/messages.js +22 -29
- package/dist/collaboration-state/scratchpad-source-state.d.ts +4 -12
- package/dist/collaboration-state/scratchpad-source-state.js +24 -58
- package/dist/collaboration-state/scratchpad.d.ts +1 -2
- package/dist/collaboration-state/scratchpad.js +0 -59
- package/dist/collaboration-state/storage-types.d.ts +25 -5
- package/dist/collaboration-state/task-compile-context.d.ts +40 -0
- package/dist/collaboration-state/task-compile-context.js +273 -0
- package/dist/collaboration-state/types.d.ts +39 -9
- package/dist/control-plane/clarification-commands.d.ts +0 -1
- package/dist/control-plane/clarification-commands.js +0 -1
- package/dist/control-plane/index.js +16 -3
- package/dist/control-plane/project-context-bootstrap.d.ts +4 -4
- package/dist/control-plane/project-context-bootstrap.js +7 -12
- package/dist/control-plane/scratchpad-auto-refresh.js +12 -1
- package/dist/control-plane/scratchpad-refresh-start.js +77 -94
- package/dist/control-plane/scratchpad-refresh.js +3 -1
- package/dist/control-plane/scratchpad-source-messages.d.ts +15 -7
- package/dist/control-plane/scratchpad-source-messages.js +53 -69
- package/dist/control-plane/task-compile-clarification-context.d.ts +9 -0
- package/dist/control-plane/task-compile-clarification-context.js +70 -0
- package/dist/control-plane/task-compile-continuation.js +28 -56
- package/dist/control-plane/task-compile-output.js +50 -14
- package/dist/control-plane/task-compile-start.js +119 -55
- package/dist/control-plane/workflows/openai.d.ts +2 -1
- package/dist/control-plane/workflows/openai.js +13 -27
- package/dist/control-plane/workflows/types.d.ts +27 -17
- package/migrations/0014_scratchpad_task_compile_context.sql +147 -0
- package/migrations/README.md +2 -1
- package/package.json +1 -1
- package/prompts/procedures/README.md +3 -3
- package/prompts/procedures/scratchpad-refresh.md +17 -9
- package/prompts/procedures/task-compile.md +6 -3
- package/prompts/prompt-flow-map.md +21 -14
|
@@ -14,14 +14,5 @@ export declare function readClarificationRoundProjection(db: SqliteDatabase, rou
|
|
|
14
14
|
export declare function readClarificationRoundsForThread(db: SqliteDatabase, threadId: ClarificationThreadRef, options?: {
|
|
15
15
|
throughRoundIndex?: number;
|
|
16
16
|
}): ClarificationRoundProjection[];
|
|
17
|
-
export declare function readSubmittedTaskCompileClarificationRounds(db: SqliteDatabase, options?: {
|
|
18
|
-
afterSubmittedAt?: string;
|
|
19
|
-
limit?: number;
|
|
20
|
-
}): ClarificationRoundProjection[];
|
|
21
|
-
export declare function readSubmittedTaskCompileClarificationRoundsAfterCursor(db: SqliteDatabase, options: {
|
|
22
|
-
afterSubmittedAt: string;
|
|
23
|
-
afterRoundId: ClarificationRoundRef;
|
|
24
|
-
limit?: number;
|
|
25
|
-
}): ClarificationRoundProjection[];
|
|
26
17
|
export declare function readClarificationThreadResponse(db: SqliteDatabase, threadId: ClarificationThreadRef): GetClarificationThreadResponse | null;
|
|
27
18
|
//# sourceMappingURL=clarification-records.d.ts.map
|
|
@@ -165,63 +165,6 @@ export function readClarificationRoundsForThread(db, threadId, options = {}) {
|
|
|
165
165
|
.all(threadId, options.throughRoundIndex);
|
|
166
166
|
return rows.map((row) => mapClarificationRoundRow(row));
|
|
167
167
|
}
|
|
168
|
-
export function readSubmittedTaskCompileClarificationRounds(db, options = {}) {
|
|
169
|
-
const limit = Math.max(1, Math.min(options.limit ?? 20, 100));
|
|
170
|
-
const rows = options.afterSubmittedAt === undefined
|
|
171
|
-
? db
|
|
172
|
-
.prepare(`
|
|
173
|
-
SELECT clarification_rounds.*
|
|
174
|
-
FROM clarification_rounds
|
|
175
|
-
JOIN clarification_threads
|
|
176
|
-
ON clarification_threads.id = clarification_rounds.clarification_thread_id
|
|
177
|
-
WHERE clarification_threads.owner_kind = 'task_compile'
|
|
178
|
-
AND clarification_rounds.status = 'sealed'
|
|
179
|
-
AND clarification_rounds.submitted_at IS NOT NULL
|
|
180
|
-
ORDER BY clarification_rounds.submitted_at DESC, clarification_rounds.id DESC
|
|
181
|
-
LIMIT ?
|
|
182
|
-
`)
|
|
183
|
-
.all(limit)
|
|
184
|
-
: db
|
|
185
|
-
.prepare(`
|
|
186
|
-
SELECT clarification_rounds.*
|
|
187
|
-
FROM clarification_rounds
|
|
188
|
-
JOIN clarification_threads
|
|
189
|
-
ON clarification_threads.id = clarification_rounds.clarification_thread_id
|
|
190
|
-
WHERE clarification_threads.owner_kind = 'task_compile'
|
|
191
|
-
AND clarification_rounds.status = 'sealed'
|
|
192
|
-
AND clarification_rounds.submitted_at IS NOT NULL
|
|
193
|
-
AND clarification_rounds.submitted_at > ?
|
|
194
|
-
ORDER BY clarification_rounds.submitted_at ASC, clarification_rounds.id ASC
|
|
195
|
-
LIMIT ?
|
|
196
|
-
`)
|
|
197
|
-
.all(options.afterSubmittedAt, limit);
|
|
198
|
-
const sortedRows = options.afterSubmittedAt === undefined ? rows.toReversed() : rows;
|
|
199
|
-
return sortedRows.map((row) => mapClarificationRoundRow(row));
|
|
200
|
-
}
|
|
201
|
-
export function readSubmittedTaskCompileClarificationRoundsAfterCursor(db, options) {
|
|
202
|
-
const limit = Math.max(1, Math.min(options.limit ?? 20, 100));
|
|
203
|
-
const rows = db
|
|
204
|
-
.prepare(`
|
|
205
|
-
SELECT clarification_rounds.*
|
|
206
|
-
FROM clarification_rounds
|
|
207
|
-
JOIN clarification_threads
|
|
208
|
-
ON clarification_threads.id = clarification_rounds.clarification_thread_id
|
|
209
|
-
WHERE clarification_threads.owner_kind = 'task_compile'
|
|
210
|
-
AND clarification_rounds.status = 'sealed'
|
|
211
|
-
AND clarification_rounds.submitted_at IS NOT NULL
|
|
212
|
-
AND (
|
|
213
|
-
clarification_rounds.submitted_at > ?
|
|
214
|
-
OR (
|
|
215
|
-
clarification_rounds.submitted_at = ?
|
|
216
|
-
AND clarification_rounds.id > ?
|
|
217
|
-
)
|
|
218
|
-
)
|
|
219
|
-
ORDER BY clarification_rounds.submitted_at ASC, clarification_rounds.id ASC
|
|
220
|
-
LIMIT ?
|
|
221
|
-
`)
|
|
222
|
-
.all(options.afterSubmittedAt, options.afterSubmittedAt, options.afterRoundId, limit);
|
|
223
|
-
return rows.map((row) => mapClarificationRoundRow(row));
|
|
224
|
-
}
|
|
225
168
|
export function readClarificationThreadResponse(db, threadId) {
|
|
226
169
|
const threadRow = readClarificationThreadRow(db, threadId);
|
|
227
170
|
if (threadRow === null) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { CollaborationStateCursorError } from "./serialization.js";
|
|
2
2
|
export { createIdleExecutionStatusProjection } from "./execution-status.js";
|
|
3
|
-
export { createMainChatAgentMessage, createMainChatMessage, createMainChatSystemMessage, ensureInitialProjectWelcomeMessage, hasMainChatArtifactPreviewMessage, hasMainChatTaskResultMessage, hasMainChatWorklistCompileMessage, hasMainChatWorklistFeedbackMessage, readCompletedWorklistFeedbackTaskIds, readMessageProjectionById, readMainChatMessageWindow,
|
|
4
|
-
export { createEmptyScratchpadProjection, readScratchpadReceiptSourceRefs, readScratchpadProjection,
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
3
|
+
export { createMainChatAgentMessage, createMainChatMessage, createMainChatSystemMessage, ensureInitialProjectWelcomeMessage, hasMainChatArtifactPreviewMessage, hasMainChatTaskResultMessage, hasMainChatWorklistCompileMessage, hasMainChatWorklistFeedbackMessage, readCompletedWorklistFeedbackTaskIds, readMessageProjectionById, readMainChatMessageWindow, readMainChatMessagesBeforeCursor, readMainChatMessagesForScratchpadCycle, } from "./messages.js";
|
|
4
|
+
export { createEmptyScratchpadProjection, readScratchpadReceiptSourceRefs, readScratchpadProjection, upsertScratchpadProjection, } from "./scratchpad.js";
|
|
5
|
+
export { markScratchpadRefreshFailed, markScratchpadRefreshStarted, markScratchpadRefreshSucceeded, markScratchpadSourceDirty, readScratchpadSourceState, } from "./scratchpad-source-state.js";
|
|
6
|
+
export { captureTaskCompileContext, completeTaskCompileContext, readActiveTaskCompileContext, rollbackTaskCompileContext, taskCompileContextSnapshot, } from "./task-compile-context.js";
|
|
7
|
+
export { deleteStaleClarificationSubmitReplayHints, readActiveClarificationProjection, readClarificationRoundProjection, readClarificationRoundsForThread, readClarificationThreadResponse, readSealedClarificationRoundsWithoutSuccessor, } from "./clarification-records.js";
|
|
7
8
|
export { createClarificationRoundAgentMessage, createClarificationRoundMessage, readClarificationRoundMessagesWindow, } from "./clarification-messages.js";
|
|
8
9
|
export { openNextTaskBoundClarificationRound, openNextTaskCompileClarificationRound, openTaskCompileClarificationRound, } from "./clarification-rounds.js";
|
|
9
10
|
export { closeTaskBoundClarificationAsRetaskingRequired, materializeClarificationSuccessor, materializeTaskBoundRunSuccessor, submitClarificationRound, } from "./clarification-successors.js";
|
|
@@ -13,5 +14,5 @@ export { readStaleRunningTaskIdentities, recoverStaleRunningTasksAsFailed, } fro
|
|
|
13
14
|
export { markReadStateScope, readReadStateSummary, recordReadNotificationEvent, } from "./read-state.js";
|
|
14
15
|
export { readTaskDetailProjection } from "./task-details.js";
|
|
15
16
|
export { applyTaskCompileProposal, markTaskRunStarted, readNextRunnableTask, readRecoverableScheduledRun, readCompiledTaskSummariesByWorkflowRef, readTaskProjection, readWorklistProjection, } from "./worklist.js";
|
|
16
|
-
export type { ApplyTaskCompileProposalResult, CloseTaskBoundClarificationRetaskingRequiredInput, CloseTaskBoundClarificationRetaskingRequiredResult, CreateClarificationRoundAgentMessageInput, CreateClarificationRoundMessageInput, CreateMainChatAgentMessageInput, CreateMainChatMessageInput, CreateMainChatSystemMessageInput, CursorPageOptions, MarkReadStateScopeInput, MarkReadStateScopeResult, MarkTaskRunStartedInput, MarkTaskRunStartedResult, MaterializeClarificationSuccessorInput, MaterializeTaskBoundRunSuccessorInput, MaterializeTaskBoundRunSuccessorResult, MessageAuthorInput, NextRunnableTaskResult, OpenNextTaskBoundClarificationRoundInput, OpenNextTaskBoundClarificationRoundResult, OpenNextTaskCompileClarificationRoundInput, OpenNextTaskCompileClarificationRoundResult, OpenTaskCompileClarificationRoundInput, OpenTaskCompileClarificationRoundResult,
|
|
17
|
+
export type { ApplyTaskCompileProposalResult, CloseTaskBoundClarificationRetaskingRequiredInput, CloseTaskBoundClarificationRetaskingRequiredResult, CreateClarificationRoundAgentMessageInput, CreateClarificationRoundMessageInput, CreateMainChatAgentMessageInput, CreateMainChatMessageInput, CreateMainChatSystemMessageInput, CursorPageOptions, MarkReadStateScopeInput, MarkReadStateScopeResult, MarkTaskRunStartedInput, MarkTaskRunStartedResult, MaterializeClarificationSuccessorInput, MaterializeTaskBoundRunSuccessorInput, MaterializeTaskBoundRunSuccessorResult, MessageAuthorInput, NextRunnableTaskResult, OpenNextTaskBoundClarificationRoundInput, OpenNextTaskBoundClarificationRoundResult, OpenNextTaskCompileClarificationRoundInput, OpenNextTaskCompileClarificationRoundResult, OpenTaskCompileClarificationRoundInput, OpenTaskCompileClarificationRoundResult, ReadMessageWindowOptions, ReadReadStateSummaryInput, RecoverStaleRunningTasksResult, RecoverableScheduledRun, RecordReadNotificationEventInput, RecordRecoverySummaryInput, RecordRecoverySummaryResult, RecordRunNeedsHumanResultInput, RecordRunNeedsHumanResultResult, RecordRunResultInput, RecordRunResultResult, RunResultPromotionProjection, ScratchpadSnapshotInput, ScratchpadContentSnapshot, ScratchpadSourceRefInput, CaptureTaskCompileContextInput, CompleteTaskCompileContextInput, RollbackTaskCompileContextInput, TaskCompileContextRecord, SealedClarificationRoundWithoutSuccessor, SubmitClarificationRoundInput, TaskCompileProposalInput, TaskCompileProposalModuleInput, TaskCompileProposalTaskInput, } from "./types.js";
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { CollaborationStateCursorError } from "./serialization.js";
|
|
2
2
|
export { createIdleExecutionStatusProjection } from "./execution-status.js";
|
|
3
|
-
export { createMainChatAgentMessage, createMainChatMessage, createMainChatSystemMessage, ensureInitialProjectWelcomeMessage, hasMainChatArtifactPreviewMessage, hasMainChatTaskResultMessage, hasMainChatWorklistCompileMessage, hasMainChatWorklistFeedbackMessage, readCompletedWorklistFeedbackTaskIds, readMessageProjectionById, readMainChatMessageWindow,
|
|
4
|
-
export { createEmptyScratchpadProjection, readScratchpadReceiptSourceRefs, readScratchpadProjection,
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
3
|
+
export { createMainChatAgentMessage, createMainChatMessage, createMainChatSystemMessage, ensureInitialProjectWelcomeMessage, hasMainChatArtifactPreviewMessage, hasMainChatTaskResultMessage, hasMainChatWorklistCompileMessage, hasMainChatWorklistFeedbackMessage, readCompletedWorklistFeedbackTaskIds, readMessageProjectionById, readMainChatMessageWindow, readMainChatMessagesBeforeCursor, readMainChatMessagesForScratchpadCycle, } from "./messages.js";
|
|
4
|
+
export { createEmptyScratchpadProjection, readScratchpadReceiptSourceRefs, readScratchpadProjection, upsertScratchpadProjection, } from "./scratchpad.js";
|
|
5
|
+
export { markScratchpadRefreshFailed, markScratchpadRefreshStarted, markScratchpadRefreshSucceeded, markScratchpadSourceDirty, readScratchpadSourceState, } from "./scratchpad-source-state.js";
|
|
6
|
+
export { captureTaskCompileContext, completeTaskCompileContext, readActiveTaskCompileContext, rollbackTaskCompileContext, taskCompileContextSnapshot, } from "./task-compile-context.js";
|
|
7
|
+
export { deleteStaleClarificationSubmitReplayHints, readActiveClarificationProjection, readClarificationRoundProjection, readClarificationRoundsForThread, readClarificationThreadResponse, readSealedClarificationRoundsWithoutSuccessor, } from "./clarification-records.js";
|
|
7
8
|
export { createClarificationRoundAgentMessage, createClarificationRoundMessage, readClarificationRoundMessagesWindow, } from "./clarification-messages.js";
|
|
8
9
|
export { openNextTaskBoundClarificationRound, openNextTaskCompileClarificationRound, openTaskCompileClarificationRound, } from "./clarification-rounds.js";
|
|
9
10
|
export { closeTaskBoundClarificationAsRetaskingRequired, materializeClarificationSuccessor, materializeTaskBoundRunSuccessor, submitClarificationRound, } from "./clarification-successors.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type MessageId, type RunResultId, type TaskId, type WorkflowInvocationRef } from "@tutti/shared/ids";
|
|
2
2
|
import type { MessageProjection, MessageWindow } from "@tutti/shared/schemas/api";
|
|
3
3
|
import { type SqliteDatabase } from "../store/index.js";
|
|
4
|
-
import type { CreateMainChatAgentMessageInput, CreateMainChatMessageInput, CreateMainChatSystemMessageInput,
|
|
4
|
+
import type { CreateMainChatAgentMessageInput, CreateMainChatMessageInput, CreateMainChatSystemMessageInput, ReadMessageWindowOptions } from "./types.js";
|
|
5
5
|
import type { MessageRow } from "./storage-types.js";
|
|
6
6
|
export declare function mapMessageRow(row: MessageRow, db?: SqliteDatabase): MessageProjection;
|
|
7
7
|
export declare function createMainChatMessage(db: SqliteDatabase, input: CreateMainChatMessageInput): MessageProjection;
|
|
@@ -23,11 +23,9 @@ export declare function hasMainChatWorklistCompileMessage(db: SqliteDatabase, wo
|
|
|
23
23
|
export declare function hasMainChatArtifactPreviewMessage(db: SqliteDatabase, runResultId: RunResultId): boolean;
|
|
24
24
|
export declare function readCompletedWorklistFeedbackTaskIds(db: SqliteDatabase): Set<TaskId>;
|
|
25
25
|
export declare function readMainChatMessageWindow(db: SqliteDatabase, options?: ReadMessageWindowOptions): MessageWindow;
|
|
26
|
-
export declare function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
after_id: MessageId;
|
|
30
|
-
limit: number;
|
|
26
|
+
export declare function readMainChatMessagesForScratchpadCycle(db: SqliteDatabase, after?: {
|
|
27
|
+
created_at: string;
|
|
28
|
+
message_id: MessageId;
|
|
31
29
|
}): MessageProjection[];
|
|
32
30
|
export declare function readMainChatMessagesBeforeCursor(db: SqliteDatabase, options: {
|
|
33
31
|
before_created_at: string;
|
|
@@ -440,35 +440,28 @@ export function readMainChatMessageWindow(db, options = {}) {
|
|
|
440
440
|
}
|
|
441
441
|
return { items, window };
|
|
442
442
|
}
|
|
443
|
-
export function
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
created_at > ?
|
|
466
|
-
OR (created_at = ? AND id > ?)
|
|
467
|
-
)
|
|
468
|
-
ORDER BY created_at ASC, id ASC
|
|
469
|
-
LIMIT ?
|
|
470
|
-
`)
|
|
471
|
-
.all(options.after_created_at, options.after_created_at, options.after_id, limit);
|
|
443
|
+
export function readMainChatMessagesForScratchpadCycle(db, after) {
|
|
444
|
+
const rows = after === undefined
|
|
445
|
+
? db
|
|
446
|
+
.prepare(`
|
|
447
|
+
SELECT *
|
|
448
|
+
FROM messages
|
|
449
|
+
WHERE scope_kind = 'main_chat'
|
|
450
|
+
ORDER BY created_at ASC, id ASC
|
|
451
|
+
`)
|
|
452
|
+
.all()
|
|
453
|
+
: db
|
|
454
|
+
.prepare(`
|
|
455
|
+
SELECT *
|
|
456
|
+
FROM messages
|
|
457
|
+
WHERE scope_kind = 'main_chat'
|
|
458
|
+
AND (
|
|
459
|
+
created_at > ?
|
|
460
|
+
OR (created_at = ? AND id > ?)
|
|
461
|
+
)
|
|
462
|
+
ORDER BY created_at ASC, id ASC
|
|
463
|
+
`)
|
|
464
|
+
.all(after.created_at, after.created_at, after.message_id);
|
|
472
465
|
return rows.map((row) => mapMessageRow(row, db));
|
|
473
466
|
}
|
|
474
467
|
export function readMainChatMessagesBeforeCursor(db, options) {
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import type { ActivityRef,
|
|
1
|
+
import type { ActivityRef, MessageId } from "@tutti/shared/ids";
|
|
2
2
|
import type { SqliteDatabase } from "../store/index.js";
|
|
3
3
|
export type ScratchpadMainChatCursor = {
|
|
4
4
|
created_at: string;
|
|
5
5
|
message_id: MessageId;
|
|
6
6
|
};
|
|
7
|
-
export type ScratchpadTaskCompileCursor = {
|
|
8
|
-
submitted_at: string;
|
|
9
|
-
round_id: ClarificationRoundRef;
|
|
10
|
-
};
|
|
11
7
|
export type ScratchpadSourceState = {
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
cycle_start_cursor?: ScratchpadMainChatCursor;
|
|
9
|
+
refreshed_through_cursor?: ScratchpadMainChatCursor;
|
|
14
10
|
dirty_since?: string;
|
|
15
11
|
in_flight?: {
|
|
16
12
|
activity_ref: ActivityRef;
|
|
@@ -22,16 +18,12 @@ export type ScratchpadSourceState = {
|
|
|
22
18
|
updated_at?: string;
|
|
23
19
|
};
|
|
24
20
|
export type ScratchpadSourceCursorUpdate = {
|
|
25
|
-
|
|
26
|
-
task_compile_cursor?: ScratchpadTaskCompileCursor;
|
|
21
|
+
refreshed_through_cursor?: ScratchpadMainChatCursor;
|
|
27
22
|
};
|
|
28
23
|
export declare function readScratchpadSourceState(db: SqliteDatabase): ScratchpadSourceState;
|
|
29
24
|
export declare function markScratchpadSourceDirty(db: SqliteDatabase, input?: {
|
|
30
25
|
now?: () => Date;
|
|
31
26
|
}): ScratchpadSourceState;
|
|
32
|
-
export declare function advanceScratchpadTaskCompileSourceCursor(db: SqliteDatabase, input: ScratchpadTaskCompileCursor & {
|
|
33
|
-
now?: () => Date;
|
|
34
|
-
}): ScratchpadSourceState;
|
|
35
27
|
export declare function markScratchpadRefreshStarted(db: SqliteDatabase, input: {
|
|
36
28
|
activityRef: ActivityRef;
|
|
37
29
|
now?: () => Date;
|
|
@@ -4,17 +4,18 @@ function mapScratchpadSourceStateRow(row) {
|
|
|
4
4
|
if (row === undefined) {
|
|
5
5
|
return state;
|
|
6
6
|
}
|
|
7
|
-
if (row.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
if (row.cycle_start_cursor_created_at !== null &&
|
|
8
|
+
row.cycle_start_cursor_message_id !== null) {
|
|
9
|
+
state.cycle_start_cursor = {
|
|
10
|
+
created_at: row.cycle_start_cursor_created_at,
|
|
11
|
+
message_id: row.cycle_start_cursor_message_id,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
|
-
if (row.
|
|
14
|
-
row.
|
|
15
|
-
state.
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (row.refreshed_through_cursor_created_at !== null &&
|
|
15
|
+
row.refreshed_through_cursor_message_id !== null) {
|
|
16
|
+
state.refreshed_through_cursor = {
|
|
17
|
+
created_at: row.refreshed_through_cursor_created_at,
|
|
18
|
+
message_id: row.refreshed_through_cursor_message_id,
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
if (row.dirty_since !== null) {
|
|
@@ -49,6 +50,9 @@ function nextDirtySinceForSourceChange(current, changedAt) {
|
|
|
49
50
|
isIsoAfter(current.dirty_since, current.in_flight.started_at)) {
|
|
50
51
|
return current.dirty_since;
|
|
51
52
|
}
|
|
53
|
+
if (!isIsoAfter(changedAt, current.in_flight.started_at)) {
|
|
54
|
+
return new Date(new Date(current.in_flight.started_at).getTime() + 1).toISOString();
|
|
55
|
+
}
|
|
52
56
|
return changedAt;
|
|
53
57
|
}
|
|
54
58
|
function dirtySinceAfterRefreshSuccess(current) {
|
|
@@ -59,21 +63,14 @@ function dirtySinceAfterRefreshSuccess(current) {
|
|
|
59
63
|
}
|
|
60
64
|
return null;
|
|
61
65
|
}
|
|
62
|
-
function isTaskCompileCursorAfter(left, right) {
|
|
63
|
-
const submittedOrder = left.submitted_at.localeCompare(right.submitted_at);
|
|
64
|
-
if (submittedOrder !== 0) {
|
|
65
|
-
return submittedOrder > 0;
|
|
66
|
-
}
|
|
67
|
-
return left.round_id > right.round_id;
|
|
68
|
-
}
|
|
69
66
|
export function readScratchpadSourceState(db) {
|
|
70
67
|
const row = db
|
|
71
68
|
.prepare(`
|
|
72
69
|
SELECT
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
cycle_start_cursor_created_at,
|
|
71
|
+
cycle_start_cursor_message_id,
|
|
72
|
+
refreshed_through_cursor_created_at,
|
|
73
|
+
refreshed_through_cursor_message_id,
|
|
77
74
|
dirty_since,
|
|
78
75
|
in_flight_activity_ref,
|
|
79
76
|
in_flight_started_at,
|
|
@@ -103,32 +100,6 @@ export function markScratchpadSourceDirty(db, input = {}) {
|
|
|
103
100
|
`).run(dirtySince, updatedAt);
|
|
104
101
|
return readScratchpadSourceState(db);
|
|
105
102
|
}
|
|
106
|
-
export function advanceScratchpadTaskCompileSourceCursor(db, input) {
|
|
107
|
-
const current = readScratchpadSourceState(db);
|
|
108
|
-
const nextCursor = {
|
|
109
|
-
submitted_at: input.submitted_at,
|
|
110
|
-
round_id: input.round_id,
|
|
111
|
-
};
|
|
112
|
-
if (current.task_compile_cursor !== undefined &&
|
|
113
|
-
!isTaskCompileCursorAfter(nextCursor, current.task_compile_cursor)) {
|
|
114
|
-
return current;
|
|
115
|
-
}
|
|
116
|
-
const updatedAt = nowIso(input.now);
|
|
117
|
-
db.prepare(`
|
|
118
|
-
INSERT INTO scratchpad_source_state (
|
|
119
|
-
id,
|
|
120
|
-
task_compile_cursor_submitted_at,
|
|
121
|
-
task_compile_cursor_round_id,
|
|
122
|
-
updated_at
|
|
123
|
-
)
|
|
124
|
-
VALUES ('current', ?, ?, ?)
|
|
125
|
-
ON CONFLICT(id) DO UPDATE SET
|
|
126
|
-
task_compile_cursor_submitted_at = excluded.task_compile_cursor_submitted_at,
|
|
127
|
-
task_compile_cursor_round_id = excluded.task_compile_cursor_round_id,
|
|
128
|
-
updated_at = excluded.updated_at
|
|
129
|
-
`).run(nextCursor.submitted_at, nextCursor.round_id, updatedAt);
|
|
130
|
-
return readScratchpadSourceState(db);
|
|
131
|
-
}
|
|
132
103
|
export function markScratchpadRefreshStarted(db, input) {
|
|
133
104
|
const updatedAt = nowIso(input.now);
|
|
134
105
|
db.prepare(`
|
|
@@ -149,16 +120,13 @@ export function markScratchpadRefreshStarted(db, input) {
|
|
|
149
120
|
export function markScratchpadRefreshSucceeded(db, input) {
|
|
150
121
|
const updatedAt = nowIso(input.now);
|
|
151
122
|
const current = readScratchpadSourceState(db);
|
|
152
|
-
const
|
|
153
|
-
const taskCompileCursor = input.task_compile_cursor ?? current.task_compile_cursor;
|
|
123
|
+
const refreshedThroughCursor = input.refreshed_through_cursor ?? current.refreshed_through_cursor;
|
|
154
124
|
const dirtySince = dirtySinceAfterRefreshSuccess(current);
|
|
155
125
|
db.prepare(`
|
|
156
126
|
INSERT INTO scratchpad_source_state (
|
|
157
127
|
id,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
task_compile_cursor_submitted_at,
|
|
161
|
-
task_compile_cursor_round_id,
|
|
128
|
+
refreshed_through_cursor_created_at,
|
|
129
|
+
refreshed_through_cursor_message_id,
|
|
162
130
|
dirty_since,
|
|
163
131
|
in_flight_activity_ref,
|
|
164
132
|
in_flight_started_at,
|
|
@@ -166,19 +134,17 @@ export function markScratchpadRefreshSucceeded(db, input) {
|
|
|
166
134
|
backoff_until,
|
|
167
135
|
updated_at
|
|
168
136
|
)
|
|
169
|
-
VALUES ('current', ?, ?, ?,
|
|
137
|
+
VALUES ('current', ?, ?, ?, NULL, NULL, ?, NULL, ?)
|
|
170
138
|
ON CONFLICT(id) DO UPDATE SET
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
task_compile_cursor_submitted_at = excluded.task_compile_cursor_submitted_at,
|
|
174
|
-
task_compile_cursor_round_id = excluded.task_compile_cursor_round_id,
|
|
139
|
+
refreshed_through_cursor_created_at = excluded.refreshed_through_cursor_created_at,
|
|
140
|
+
refreshed_through_cursor_message_id = excluded.refreshed_through_cursor_message_id,
|
|
175
141
|
dirty_since = excluded.dirty_since,
|
|
176
142
|
in_flight_activity_ref = NULL,
|
|
177
143
|
in_flight_started_at = NULL,
|
|
178
144
|
last_completed_at = excluded.last_completed_at,
|
|
179
145
|
backoff_until = NULL,
|
|
180
146
|
updated_at = excluded.updated_at
|
|
181
|
-
`).run(
|
|
147
|
+
`).run(refreshedThroughCursor?.created_at ?? null, refreshedThroughCursor?.message_id ?? null, dirtySince, updatedAt, updatedAt);
|
|
182
148
|
return readScratchpadSourceState(db);
|
|
183
149
|
}
|
|
184
150
|
export function markScratchpadRefreshFailed(db, input = {}) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { ScratchpadProjection } from "@tutti/shared/schemas/api";
|
|
2
2
|
import type { SqliteDatabase } from "../store/index.js";
|
|
3
3
|
import type { ScratchpadSourceRefRow } from "./storage-types.js";
|
|
4
|
-
import type { ScratchpadSnapshotInput
|
|
4
|
+
import type { ScratchpadSnapshotInput } from "./types.js";
|
|
5
5
|
export declare function createEmptyScratchpadProjection(): ScratchpadProjection;
|
|
6
6
|
export declare function upsertScratchpadProjection(db: SqliteDatabase, input: ScratchpadSnapshotInput): ScratchpadProjection;
|
|
7
|
-
export declare function submitScratchpadProjection(db: SqliteDatabase, input: SubmitScratchpadInput): ScratchpadProjection;
|
|
8
7
|
export declare function readScratchpadProjection(db: SqliteDatabase): ScratchpadProjection;
|
|
9
8
|
export declare function readScratchpadReceiptSourceRefs(db: SqliteDatabase, workflowRef: string): ScratchpadSourceRefRow[];
|
|
10
9
|
//# sourceMappingURL=scratchpad.d.ts.map
|
|
@@ -33,25 +33,6 @@ function replaceCurrentScratchpadSourceRefs(db, sourceRefs) {
|
|
|
33
33
|
insert.run(sourceRef.message_id, sourceRef.source_scope, sourceRef.created_at);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
function copyCurrentScratchpadSourcesToReceipt(db, workflowRef) {
|
|
37
|
-
db.prepare("DELETE FROM scratchpad_receipt_sources WHERE workflow_ref = ?").run(workflowRef);
|
|
38
|
-
db.prepare(`
|
|
39
|
-
INSERT INTO scratchpad_receipt_sources (
|
|
40
|
-
workflow_ref,
|
|
41
|
-
message_id,
|
|
42
|
-
source_scope,
|
|
43
|
-
created_at
|
|
44
|
-
)
|
|
45
|
-
SELECT
|
|
46
|
-
?,
|
|
47
|
-
message_id,
|
|
48
|
-
source_scope,
|
|
49
|
-
created_at
|
|
50
|
-
FROM scratchpad_source_refs
|
|
51
|
-
WHERE scratchpad_id = 'current'
|
|
52
|
-
ORDER BY created_at ASC, message_id ASC
|
|
53
|
-
`).run(workflowRef);
|
|
54
|
-
}
|
|
55
36
|
export function createEmptyScratchpadProjection() {
|
|
56
37
|
return {
|
|
57
38
|
id: "current",
|
|
@@ -135,46 +116,6 @@ export function upsertScratchpadProjection(db, input) {
|
|
|
135
116
|
replaceCurrentScratchpadSourceRefs(db, input.source_refs);
|
|
136
117
|
return readScratchpadProjection(db);
|
|
137
118
|
}
|
|
138
|
-
export function submitScratchpadProjection(db, input) {
|
|
139
|
-
const submittedAt = nowIso(input.now);
|
|
140
|
-
const scratchpad = readScratchpadProjection(db);
|
|
141
|
-
if (scratchpad.state === "empty") {
|
|
142
|
-
return scratchpad;
|
|
143
|
-
}
|
|
144
|
-
db.prepare(`
|
|
145
|
-
INSERT INTO scratchpad_receipts (
|
|
146
|
-
workflow_ref,
|
|
147
|
-
activity_ref,
|
|
148
|
-
topic,
|
|
149
|
-
background_summary,
|
|
150
|
-
current_consensus_json,
|
|
151
|
-
open_questions_json,
|
|
152
|
-
task_changes_json,
|
|
153
|
-
submitted_at
|
|
154
|
-
)
|
|
155
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
156
|
-
ON CONFLICT(workflow_ref) DO UPDATE SET
|
|
157
|
-
activity_ref = excluded.activity_ref,
|
|
158
|
-
topic = excluded.topic,
|
|
159
|
-
background_summary = excluded.background_summary,
|
|
160
|
-
current_consensus_json = excluded.current_consensus_json,
|
|
161
|
-
open_questions_json = excluded.open_questions_json,
|
|
162
|
-
task_changes_json = excluded.task_changes_json,
|
|
163
|
-
submitted_at = excluded.submitted_at
|
|
164
|
-
`).run(input.workflow_ref, input.activity_ref, scratchpad.topic, scratchpad.background_summary, stringifyJson(scratchpad.current_consensus), stringifyJson(scratchpad.open_questions), stringifyJson(scratchpad.task_changes), submittedAt);
|
|
165
|
-
copyCurrentScratchpadSourcesToReceipt(db, input.workflow_ref);
|
|
166
|
-
db.prepare(`
|
|
167
|
-
UPDATE scratchpad
|
|
168
|
-
SET
|
|
169
|
-
state = 'submitted',
|
|
170
|
-
submitted_by_activity_ref = ?,
|
|
171
|
-
submitted_by_workflow_ref = ?,
|
|
172
|
-
submitted_at = ?,
|
|
173
|
-
updated_at = ?
|
|
174
|
-
WHERE id = 'current'
|
|
175
|
-
`).run(input.activity_ref, input.workflow_ref, submittedAt, submittedAt);
|
|
176
|
-
return readScratchpadProjection(db);
|
|
177
|
-
}
|
|
178
119
|
export function readScratchpadProjection(db) {
|
|
179
120
|
const receipts = readScratchpadReceipts(db);
|
|
180
121
|
const row = db
|
|
@@ -37,14 +37,14 @@ export type ScratchpadReceiptRow = {
|
|
|
37
37
|
};
|
|
38
38
|
export type ScratchpadSourceRefRow = {
|
|
39
39
|
message_id: MessageId;
|
|
40
|
-
source_scope: "main_chat"
|
|
40
|
+
source_scope: "main_chat";
|
|
41
41
|
created_at: string;
|
|
42
42
|
};
|
|
43
43
|
export type ScratchpadSourceStateRow = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
cycle_start_cursor_created_at: string | null;
|
|
45
|
+
cycle_start_cursor_message_id: string | null;
|
|
46
|
+
refreshed_through_cursor_created_at: string | null;
|
|
47
|
+
refreshed_through_cursor_message_id: string | null;
|
|
48
48
|
dirty_since: string | null;
|
|
49
49
|
in_flight_activity_ref: string | null;
|
|
50
50
|
in_flight_started_at: string | null;
|
|
@@ -53,6 +53,26 @@ export type ScratchpadSourceStateRow = {
|
|
|
53
53
|
backoff_until: string | null;
|
|
54
54
|
updated_at: string;
|
|
55
55
|
};
|
|
56
|
+
export type ActiveTaskCompileContextRow = {
|
|
57
|
+
workflow_ref: string;
|
|
58
|
+
captured_by_activity_ref: string;
|
|
59
|
+
submitted_at: string;
|
|
60
|
+
topic: string;
|
|
61
|
+
background_summary: string;
|
|
62
|
+
current_consensus_json: string;
|
|
63
|
+
open_questions_json: string;
|
|
64
|
+
task_changes_json: string;
|
|
65
|
+
scratchpad_updated_at: string;
|
|
66
|
+
source_window_after_created_at: string | null;
|
|
67
|
+
source_window_after_message_id: string | null;
|
|
68
|
+
source_window_through_created_at: string | null;
|
|
69
|
+
source_window_through_message_id: string | null;
|
|
70
|
+
};
|
|
71
|
+
export type ActiveTaskCompileContextSourceRow = {
|
|
72
|
+
workflow_ref: string;
|
|
73
|
+
message_id: MessageId;
|
|
74
|
+
created_at: string;
|
|
75
|
+
};
|
|
56
76
|
export type TaskModuleRow = {
|
|
57
77
|
id: string;
|
|
58
78
|
name: string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { WorkflowInvocationRef } from "@tutti/shared/ids";
|
|
2
|
+
import { type SqliteDatabase } from "../store/index.js";
|
|
3
|
+
import type { CaptureTaskCompileContextInput, CompleteTaskCompileContextInput, RollbackTaskCompileContextInput, ScratchpadContentSnapshot, TaskCompileContextRecord } from "./types.js";
|
|
4
|
+
export declare function readActiveTaskCompileContext(db: SqliteDatabase, workflowRef?: WorkflowInvocationRef): TaskCompileContextRecord | null;
|
|
5
|
+
export declare function captureTaskCompileContext(db: SqliteDatabase, input: CaptureTaskCompileContextInput): TaskCompileContextRecord;
|
|
6
|
+
export declare function completeTaskCompileContext(db: SqliteDatabase, input: CompleteTaskCompileContextInput): {
|
|
7
|
+
updated_at?: string;
|
|
8
|
+
submitted_at?: string;
|
|
9
|
+
updated_by_activity_ref?: string;
|
|
10
|
+
submitted_by_activity_ref?: string;
|
|
11
|
+
submitted_by_workflow_ref?: string;
|
|
12
|
+
id: "current";
|
|
13
|
+
topic: string;
|
|
14
|
+
background_summary: string;
|
|
15
|
+
current_consensus: string[];
|
|
16
|
+
open_questions: string[];
|
|
17
|
+
task_changes: string[];
|
|
18
|
+
state: "ready" | "empty" | "submitted";
|
|
19
|
+
receipts: {
|
|
20
|
+
compiled_tasks?: {
|
|
21
|
+
status: "failed" | "done" | "todo" | "running" | "pending";
|
|
22
|
+
task_id: string;
|
|
23
|
+
title: string;
|
|
24
|
+
summary: string;
|
|
25
|
+
module_id: string;
|
|
26
|
+
module_name: string;
|
|
27
|
+
}[];
|
|
28
|
+
activity_ref: string;
|
|
29
|
+
workflow_ref: string;
|
|
30
|
+
topic: string;
|
|
31
|
+
background_summary: string;
|
|
32
|
+
current_consensus: string[];
|
|
33
|
+
open_questions: string[];
|
|
34
|
+
task_changes: string[];
|
|
35
|
+
submitted_at: string;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
export declare function rollbackTaskCompileContext(db: SqliteDatabase, input: RollbackTaskCompileContextInput): boolean;
|
|
39
|
+
export declare function taskCompileContextSnapshot(context: TaskCompileContextRecord): ScratchpadContentSnapshot;
|
|
40
|
+
//# sourceMappingURL=task-compile-context.d.ts.map
|