@crewx/sdk 0.9.0-rc.174 → 0.9.0-rc.175

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 (46) hide show
  1. package/dist/desktop/index.js +3 -3
  2. package/dist/esm/desktop/index.js +3 -3
  3. package/dist/esm/index.js +388 -259
  4. package/dist/esm/plugins/index.js +95 -91
  5. package/dist/esm/process/index.js +1 -1
  6. package/dist/esm/publish/index.js +2 -2
  7. package/dist/esm/repository/index.js +334 -201
  8. package/dist/esm/skills/index.js +2 -2
  9. package/dist/index.browser.js +1 -1
  10. package/dist/index.d.ts +9 -0
  11. package/dist/index.js +377 -248
  12. package/dist/lifecycle/task-stop.d.ts +27 -1
  13. package/dist/lifecycle/update-admission.d.ts +1 -1
  14. package/dist/mcp-app/types.d.ts +1 -1
  15. package/dist/migrations/0042_breezy_blue_shield.sql +31 -0
  16. package/dist/migrations/0043_nervous_darkstar.sql +1 -0
  17. package/dist/migrations/0044_military_galactus.sql +8 -0
  18. package/dist/migrations/0045_task_pid_started_at.sql +1 -0
  19. package/dist/migrations/meta/0042_snapshot.json +4383 -0
  20. package/dist/migrations/meta/0043_snapshot.json +4390 -0
  21. package/dist/migrations/meta/0044_snapshot.json +4435 -0
  22. package/dist/migrations/meta/0045_snapshot.json +4442 -0
  23. package/dist/migrations/meta/_journal.json +28 -0
  24. package/dist/plugins/index.js +99 -95
  25. package/dist/process/index.d.ts +2 -2
  26. package/dist/process/index.js +1 -1
  27. package/dist/process/process-control.d.ts +14 -0
  28. package/dist/publish/index.js +2 -2
  29. package/dist/repository/db.d.ts +1 -0
  30. package/dist/repository/index.d.ts +7 -0
  31. package/dist/repository/index.js +292 -159
  32. package/dist/repository/run-columns.d.ts +10 -0
  33. package/dist/repository/run-history.repository.d.ts +112 -0
  34. package/dist/repository/schedule-run.repository.d.ts +103 -0
  35. package/dist/repository/task.repository.d.ts +13 -2
  36. package/dist/repository/workflow-anchor-kinds.d.ts +4 -0
  37. package/dist/schema/index.d.ts +2 -0
  38. package/dist/schema/run-column-backfill.d.ts +81 -0
  39. package/dist/schema/schedule-runs.d.ts +451 -0
  40. package/dist/schema/tasks.d.ts +114 -0
  41. package/dist/skills/index.js +2 -2
  42. package/dist/ui-plugin/html-viewer-document-policy.d.ts +23 -0
  43. package/dist/ui-plugin/index.d.ts +2 -0
  44. package/dist/ui-plugin/types.d.ts +1 -0
  45. package/dist/utils/id.d.ts +1 -1
  46. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ export declare const RUN_COLUMNS_BACKFILL = "tasks_run_columns";
2
+ export declare const WORKFLOW_RUN_INDEX = "idx_tasks_workflow_run_id";
3
+ export declare const SCHEDULE_TASKS_INDEX = "idx_tasks_ws_schedule_started";
4
+ export declare const HUMAN_TASKS_INDEX = "idx_tasks_ws_human_started";
5
+ export declare const RUN_COLUMN_INDEXES: ReadonlyArray<{
6
+ name: string;
7
+ sql: string;
8
+ }>;
9
+ export declare const SCHEDULED_TRIGGERS: readonly ["cron", "cron_manual"];
10
+ export declare function readScheduleIdFromMetadata(metadata: string | null | undefined): string | null;
@@ -0,0 +1,112 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import type { ScheduleRunMode } from './schedule-run.repository.js';
3
+ import { type TaskStatus } from './task-status.js';
4
+ export type RunHistoryOrigin = 'all' | 'mine' | 'delegated' | 'scheduled' | 'workflow';
5
+ export type RunHistoryKind = 'task' | 'workflow' | 'schedule_run';
6
+ export type RunHistoryClass = 'mine' | 'delegated' | 'scheduled' | 'workflow' | 'system' | 'unknown';
7
+ export type RunHistoryTerminalReason = 'user_stop' | 'runner_lost' | 'launch_failed';
8
+ export interface RunHistoryQuery {
9
+ workspaceId: string;
10
+ origin?: RunHistoryOrigin;
11
+ scheduleId?: string;
12
+ includeFrequentSuccess?: boolean;
13
+ agents?: readonly string[];
14
+ statuses?: readonly TaskStatus[];
15
+ q?: string;
16
+ limit?: number;
17
+ offset?: number;
18
+ }
19
+ export interface RunHistoryRow {
20
+ kind: RunHistoryKind;
21
+ id: string;
22
+ origin: RunHistoryClass;
23
+ startedAt: string;
24
+ finishedAt: string | null;
25
+ durationMs: number | null;
26
+ status: TaskStatus;
27
+ terminalReason: RunHistoryTerminalReason | null;
28
+ agentId: string | null;
29
+ mode: ScheduleRunMode | null;
30
+ taskId: string | null;
31
+ scheduleId: string | null;
32
+ scheduleName: string | null;
33
+ builtinId: string | null;
34
+ workflowRunId: string | null;
35
+ highFrequency: boolean;
36
+ errorCode: string | null;
37
+ preview: string | null;
38
+ }
39
+ export interface RunHistoryPage {
40
+ rows: RunHistoryRow[];
41
+ total: number;
42
+ }
43
+ export interface ScheduleRunSummaryLastRun {
44
+ kind: 'task' | 'schedule_run';
45
+ id: string;
46
+ taskId: string | null;
47
+ status: TaskStatus;
48
+ startedAt: string;
49
+ finishedAt: string | null;
50
+ }
51
+ export interface ScheduleRunSummary {
52
+ lastRun: ScheduleRunSummaryLastRun | null;
53
+ succeededToday: number;
54
+ failedLast24h: number;
55
+ checkedAt: string;
56
+ }
57
+ export interface ScheduleRunSummaryInput {
58
+ workspaceId: string;
59
+ scheduleIds: readonly string[];
60
+ timezoneBySchedule: Readonly<Record<string, string | undefined>>;
61
+ now: Date;
62
+ }
63
+ export interface FailedScheduleRunsSinceInput {
64
+ workspaceId: string;
65
+ since: Date;
66
+ }
67
+ export interface RunTaskIdsInput {
68
+ workspaceId: string;
69
+ taskIds: readonly string[];
70
+ }
71
+ export interface RunTaskListItemRow {
72
+ id: string;
73
+ model: string | null;
74
+ input_tokens: number | null;
75
+ output_tokens: number | null;
76
+ cost_usd: number | null;
77
+ thread_id: string | null;
78
+ metadata: string | null;
79
+ coding_agent_command: string | null;
80
+ caller_agent_id: string | null;
81
+ parent_agent_id: string | null;
82
+ }
83
+ export interface RunScheduleRunByTask {
84
+ taskId: string;
85
+ scheduleName: string | null;
86
+ builtinId: string | null;
87
+ }
88
+ export interface RunColumnBackfillInput {
89
+ batchSize?: number;
90
+ }
91
+ export interface RunColumnBackfillResult {
92
+ scanned: number;
93
+ updated: number;
94
+ done: boolean;
95
+ indexesBuilt: string[];
96
+ }
97
+ export declare const RUN_HISTORY_PREVIEW_RAW_CHARS = 1000;
98
+ export declare class RunHistoryRepository extends BaseSqliteRepository {
99
+ private readonly dbPath?;
100
+ constructor(opts?: {
101
+ dbPath?: string;
102
+ dbRoot?: string;
103
+ });
104
+ resolveDbPath(): string;
105
+ private withReadable;
106
+ listRunHistory(query: RunHistoryQuery): RunHistoryPage;
107
+ getScheduleRunSummaries(input: ScheduleRunSummaryInput): Record<string, ScheduleRunSummary>;
108
+ countFailedScheduleRunsSince(input: FailedScheduleRunsSinceInput): number;
109
+ listTaskListItems(input: RunTaskIdsInput): RunTaskListItemRow[];
110
+ listScheduleRunsByTaskIds(input: RunTaskIdsInput): RunScheduleRunByTask[];
111
+ backfillRunColumns(input?: RunColumnBackfillInput): RunColumnBackfillResult;
112
+ }
@@ -0,0 +1,103 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ export type ScheduleRunMode = 'command' | 'agent' | 'app';
3
+ export type ScheduleRunStatus = 'running' | 'success' | 'failed' | 'lost';
4
+ export interface ScheduleRun {
5
+ id: string;
6
+ scheduleId: string;
7
+ workspaceId: string;
8
+ mode: ScheduleRunMode;
9
+ trigger: string;
10
+ occurrenceKey: string | null;
11
+ taskId: string | null;
12
+ appId: string | null;
13
+ scheduleName: string | null;
14
+ builtinId: string | null;
15
+ command: string | null;
16
+ highFrequency: boolean;
17
+ status: ScheduleRunStatus;
18
+ errorCode: string | null;
19
+ exitCode: number | null;
20
+ signal: string | null;
21
+ startedAt: string;
22
+ finishedAt: string | null;
23
+ durationMs: number | null;
24
+ pid: number | null;
25
+ hostPid: number | null;
26
+ outputTail: string | null;
27
+ outputBytes: number | null;
28
+ outputTruncated: boolean;
29
+ }
30
+ export interface NewScheduleRun {
31
+ id: string;
32
+ scheduleId: string;
33
+ workspaceId: string;
34
+ mode: ScheduleRunMode;
35
+ trigger: string;
36
+ occurrenceKey?: string | null;
37
+ taskId?: string | null;
38
+ appId?: string | null;
39
+ scheduleName?: string | null;
40
+ builtinId?: string | null;
41
+ command?: string | null;
42
+ highFrequency: boolean;
43
+ status: ScheduleRunStatus;
44
+ errorCode?: string | null;
45
+ startedAt: string;
46
+ finishedAt?: string | null;
47
+ durationMs?: number | null;
48
+ pid?: number | null;
49
+ hostPid?: number | null;
50
+ }
51
+ export interface ScheduleRunFinish {
52
+ status: 'success' | 'failed' | 'lost';
53
+ errorCode?: string | null;
54
+ exitCode?: number | null;
55
+ signal?: string | null;
56
+ finishedAt: string;
57
+ durationMs: number;
58
+ outputTail?: string | null;
59
+ outputBytes?: number | null;
60
+ outputTruncated?: boolean;
61
+ }
62
+ export interface ScheduleRunListOptions {
63
+ scheduleId?: string;
64
+ mode?: ScheduleRunMode;
65
+ limit?: number;
66
+ }
67
+ export interface ScheduleRunPruneResult {
68
+ deleted: number;
69
+ tailsCleared: number;
70
+ }
71
+ export interface ScheduleRunRepositoryInterface {
72
+ insert(run: NewScheduleRun): void;
73
+ finish(id: string, finish: ScheduleRunFinish): boolean;
74
+ markLost(id: string, finish: Omit<ScheduleRunFinish, 'status'>): boolean;
75
+ get(id: string): ScheduleRun | undefined;
76
+ listByWorkspace(workspaceId: string, options?: ScheduleRunListOptions): ScheduleRun[];
77
+ listBySchedule(workspaceId: string, scheduleId: string, limit?: number): ScheduleRun[];
78
+ listRunning(workspaceId: string): ScheduleRun[];
79
+ prune(workspaceId: string, now: Date): ScheduleRunPruneResult;
80
+ }
81
+ export declare const SCHEDULE_RUN_COMMAND_MAX_BYTES: number;
82
+ export declare const SCHEDULE_RUN_SUCCESS_RETENTION_MS: number;
83
+ export declare const SCHEDULE_RUN_FAILURE_RETENTION_MS: number;
84
+ export declare const SCHEDULE_RUN_SUCCESS_TAIL_KEEP = 20;
85
+ export declare const SCHEDULE_RUN_FAILURE_TAIL_KEEP = 50;
86
+ export declare class ScheduleRunRepository extends BaseSqliteRepository implements ScheduleRunRepositoryInterface {
87
+ private readonly dbPath?;
88
+ constructor(opts?: {
89
+ dbPath?: string;
90
+ dbRoot?: string;
91
+ });
92
+ resolveDbPath(): string;
93
+ private openWritable;
94
+ private withReadable;
95
+ insert(run: NewScheduleRun): void;
96
+ finish(id: string, finish: ScheduleRunFinish): boolean;
97
+ markLost(id: string, finish: Omit<ScheduleRunFinish, 'status'>): boolean;
98
+ get(id: string): ScheduleRun | undefined;
99
+ listByWorkspace(workspaceId: string, options?: ScheduleRunListOptions): ScheduleRun[];
100
+ listBySchedule(workspaceId: string, scheduleId: string, limit?: number): ScheduleRun[];
101
+ listRunning(workspaceId: string): ScheduleRun[];
102
+ prune(workspaceId: string, now: Date): ScheduleRunPruneResult;
103
+ }
@@ -2,6 +2,8 @@ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
2
  import type { DrizzleDb } from './db.js';
3
3
  import { RepositoryError } from './errors.js';
4
4
  import { tasks } from '../schema/index.js';
5
+ import { type WorkflowAnchorTaskKind } from './workflow-anchor-kinds.js';
6
+ import { type ProcessControlOptions } from '../process/process-control.js';
5
7
  import type { TaskLogEntry, TaskLogReadResult, TaskLogState } from './task-log.repository.js';
6
8
  import { type TaskStatus, type TaskTerminalReason } from './task-status.js';
7
9
  import { type StopTaskOptions, type StopTaskGenerationForInstructionOptions, type StopTaskResult } from '../lifecycle/task-stop.js';
@@ -86,7 +88,9 @@ export interface WorkflowParentTaskRow {
86
88
  started_at: string;
87
89
  metadata: string | null;
88
90
  }
89
- export type WorkflowParentTaskKind = 'workflow_card' | 'workflow_ui_instance';
91
+ export { WORKFLOW_ANCHOR_TASK_KINDS, isWorkflowAnchorTaskKind } from './workflow-anchor-kinds.js';
92
+ export type { WorkflowAnchorTaskKind } from './workflow-anchor-kinds.js';
93
+ export type WorkflowParentTaskKind = WorkflowAnchorTaskKind;
90
94
  export interface WorkflowParentTaskLookup {
91
95
  workspaceId: string;
92
96
  workflowRunId: string;
@@ -185,6 +189,7 @@ export interface ThreadChain {
185
189
  targetAgentTurnCount: number;
186
190
  turns: ThreadChainTurn[];
187
191
  }
192
+ export declare const CANONICAL_USER_STOP_ERROR = "Stopped by user";
188
193
  export declare const HOST_SHUTDOWN_TERMINAL_ERROR = "Stopped by app shutdown";
189
194
  type TaskUsageColumns = Pick<TaskRow, 'input_tokens' | 'output_tokens' | 'cached_input_tokens' | 'cost_usd'>;
190
195
  export declare function mergeTerminalReason(metadataJson: string | null | undefined, reason: TaskTerminalReason): string;
@@ -199,12 +204,15 @@ export declare class TaskRepository extends BaseSqliteRepository {
199
204
  private readonly dbPath?;
200
205
  private readonly clock;
201
206
  private readonly taskLogRepository;
207
+ private readonly processControl;
202
208
  private lastReaperTickAt?;
209
+ private orphanReapInFlight?;
203
210
  private readonly pidNullObservedSince;
204
211
  constructor(opts?: {
205
212
  dbPath?: string;
206
213
  dbRoot?: string;
207
214
  clock?: () => number;
215
+ processControl?: ProcessControlOptions;
208
216
  });
209
217
  resolveDbPath(): string;
210
218
  private openHandle;
@@ -325,7 +333,10 @@ export declare class TaskRepository extends BaseSqliteRepository {
325
333
  readProviderInput(id: string, runEpoch: number): ProviderInputRecord | undefined;
326
334
  getTask(id: string): TaskRow | undefined;
327
335
  killTask(id: string): Promise<TaskKillResult>;
328
- reapOrphanedTasks(options?: ReapOrphanedTasksOptions): number;
336
+ reapOrphanedTasks(options?: ReapOrphanedTasksOptions): Promise<number>;
337
+ private runOrphanReaperPass;
338
+ private judgeRecordedTargets;
339
+ private terminateRecordedProcesses;
329
340
  reapRunningWorkflowTasks(graceMs?: number): number;
330
341
  findTaskStatus(taskId: string, workspaceId?: string): TaskRow | undefined;
331
342
  findChildTasks(parentTaskId: string, workspaceId?: string): TaskRow[];
@@ -0,0 +1,4 @@
1
+ export declare const WORKFLOW_ANCHOR_TASK_KINDS: readonly ["workflow_card", "workflow_ui_instance", "workflow_run"];
2
+ export type WorkflowAnchorTaskKind = (typeof WORKFLOW_ANCHOR_TASK_KINDS)[number];
3
+ export declare function isWorkflowAnchorTaskKind(value: unknown): value is WorkflowAnchorTaskKind;
4
+ export declare function readWorkflowRunIdFromMetadata(metadata: string | null | undefined): string | null;
@@ -23,3 +23,5 @@ export * from './thread-history.js';
23
23
  export * from './storage-metadata.js';
24
24
  export * from './agent-send-history.js';
25
25
  export * from './sidebar-tabs.js';
26
+ export * from './schedule-runs.js';
27
+ export * from './run-column-backfill.js';
@@ -0,0 +1,81 @@
1
+ export declare const run_column_backfill: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2
+ name: "run_column_backfill";
3
+ schema: undefined;
4
+ columns: {
5
+ name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6
+ name: "name";
7
+ tableName: "run_column_backfill";
8
+ dataType: "string";
9
+ columnType: "SQLiteText";
10
+ data: string;
11
+ driverParam: string;
12
+ notNull: true;
13
+ hasDefault: false;
14
+ isPrimaryKey: true;
15
+ isAutoincrement: false;
16
+ hasRuntimeDefault: false;
17
+ enumValues: [string, ...string[]];
18
+ baseColumn: never;
19
+ identity: undefined;
20
+ generated: undefined;
21
+ }, {}, {
22
+ length: number | undefined;
23
+ }>;
24
+ cursor: import("drizzle-orm/sqlite-core").SQLiteColumn<{
25
+ name: "cursor";
26
+ tableName: "run_column_backfill";
27
+ dataType: "number";
28
+ columnType: "SQLiteInteger";
29
+ data: number;
30
+ driverParam: number;
31
+ notNull: false;
32
+ hasDefault: false;
33
+ isPrimaryKey: false;
34
+ isAutoincrement: false;
35
+ hasRuntimeDefault: false;
36
+ enumValues: undefined;
37
+ baseColumn: never;
38
+ identity: undefined;
39
+ generated: undefined;
40
+ }, {}, {}>;
41
+ anchor_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
42
+ name: "anchor_id";
43
+ tableName: "run_column_backfill";
44
+ dataType: "string";
45
+ columnType: "SQLiteText";
46
+ data: string;
47
+ driverParam: string;
48
+ notNull: false;
49
+ hasDefault: false;
50
+ isPrimaryKey: false;
51
+ isAutoincrement: false;
52
+ hasRuntimeDefault: false;
53
+ enumValues: [string, ...string[]];
54
+ baseColumn: never;
55
+ identity: undefined;
56
+ generated: undefined;
57
+ }, {}, {
58
+ length: number | undefined;
59
+ }>;
60
+ completed_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
61
+ name: "completed_at";
62
+ tableName: "run_column_backfill";
63
+ dataType: "string";
64
+ columnType: "SQLiteText";
65
+ data: string;
66
+ driverParam: string;
67
+ notNull: false;
68
+ hasDefault: false;
69
+ isPrimaryKey: false;
70
+ isAutoincrement: false;
71
+ hasRuntimeDefault: false;
72
+ enumValues: [string, ...string[]];
73
+ baseColumn: never;
74
+ identity: undefined;
75
+ generated: undefined;
76
+ }, {}, {
77
+ length: number | undefined;
78
+ }>;
79
+ };
80
+ dialect: "sqlite";
81
+ }>;