@crewx/sdk 0.9.0-rc.93 → 0.9.0-rc.95

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 (42) hide show
  1. package/dist/account/config.d.ts +29 -0
  2. package/dist/account/env-bootstrap.d.ts +5 -0
  3. package/dist/account/errors.d.ts +1 -1
  4. package/dist/account/index.d.ts +4 -2
  5. package/dist/account/index.js +2 -1
  6. package/dist/conversation/types.d.ts +1 -0
  7. package/dist/desktop/index.d.ts +1 -0
  8. package/dist/desktop/index.js +3 -3
  9. package/dist/esm/account/index.js +2 -1
  10. package/dist/esm/desktop/index.js +3 -3
  11. package/dist/esm/index.js +263 -225
  12. package/dist/esm/plugins/index.js +119 -88
  13. package/dist/esm/process/index.js +1 -0
  14. package/dist/esm/repository/index.js +205 -93
  15. package/dist/events/types.d.ts +1 -0
  16. package/dist/index.browser.js +4 -4
  17. package/dist/index.d.ts +14 -2
  18. package/dist/index.js +264 -226
  19. package/dist/lifecycle/task-heartbeat.d.ts +41 -0
  20. package/dist/lifecycle/task-stop.d.ts +30 -0
  21. package/dist/migrations/0025_task_heartbeat.sql +8 -0
  22. package/dist/migrations/meta/_journal.json +7 -0
  23. package/dist/plugins/index.d.ts +1 -1
  24. package/dist/plugins/index.js +119 -88
  25. package/dist/plugins/sqlite-tracing.d.ts +10 -0
  26. package/dist/process/index.d.ts +2 -0
  27. package/dist/process/index.js +1 -0
  28. package/dist/process/process-control.d.ts +40 -0
  29. package/dist/prompt/tag-names.d.ts +18 -0
  30. package/dist/provider/task-error.types.d.ts +2 -1
  31. package/dist/repository/index.d.ts +13 -2
  32. package/dist/repository/index.js +255 -143
  33. package/dist/repository/task-status.d.ts +14 -0
  34. package/dist/repository/task.repository.d.ts +69 -8
  35. package/dist/repository/usage-backfill.d.ts +62 -0
  36. package/dist/repository/usage-from-logs.d.ts +21 -0
  37. package/dist/schema/tasks.d.ts +55 -0
  38. package/dist/types/index.d.ts +2 -0
  39. package/dist/utils/runner-env.d.ts +3 -0
  40. package/package.json +9 -1
  41. package/templates/agents/default.yaml +37 -23
  42. package/templates/documents/crewx-quick-guide.md +1 -1
@@ -0,0 +1,41 @@
1
+ import type { TaskRepository } from '../repository/task.repository.js';
2
+ export declare const TASK_HEARTBEAT_INTERVAL_MS = 10000;
3
+ export declare const TASK_HEARTBEAT_STALE_MS = 30000;
4
+ export declare const TASK_HEARTBEAT_HARD_STALE_MS: number;
5
+ export declare const TASK_STOP_POLL_INTERVAL_MS = 1000;
6
+ export declare function resolveTaskHeartbeatIntervalMs(): number;
7
+ export declare function resolveTaskHeartbeatStaleMs(): number;
8
+ export declare function resolveTaskHeartbeatHardStaleMs(): number;
9
+ export interface TaskHeartbeatRow {
10
+ id?: string;
11
+ status: string;
12
+ run_epoch: number | null;
13
+ stop_requested_at: string | null;
14
+ stop_requested_epoch: number | null;
15
+ pid?: number | null;
16
+ metadata?: string | null;
17
+ started_at?: string;
18
+ duration_ms?: number | null;
19
+ }
20
+ export interface HeartbeatTickResult {
21
+ accepted: boolean;
22
+ row: TaskHeartbeatRow | null;
23
+ }
24
+ export interface TaskHeartbeatOptions {
25
+ taskId: string;
26
+ runEpoch: number;
27
+ onStopRequested?: (row: TaskHeartbeatRow) => void | Promise<void>;
28
+ }
29
+ export interface TaskHeartbeatHandle {
30
+ timer: ReturnType<typeof setInterval>;
31
+ runEpoch: number;
32
+ stopRequested: boolean;
33
+ lastHeartbeatAt: number;
34
+ heartbeatElapsedMs: number;
35
+ }
36
+ export declare const taskHeartbeatRegistry: Map<string, TaskHeartbeatHandle>;
37
+ export declare function runHeartbeatTick(repo: Pick<TaskRepository, 'heartbeatTask' | 'getTask'>, options: TaskHeartbeatOptions & {
38
+ writeHeartbeat?: boolean;
39
+ }): HeartbeatTickResult;
40
+ export declare function stopTaskHeartbeat(taskId: string, runEpoch?: number | null): boolean;
41
+ export declare function startTaskHeartbeat(repo: Pick<TaskRepository, 'heartbeatTask' | 'getTask'>, options: TaskHeartbeatOptions): boolean;
@@ -0,0 +1,30 @@
1
+ import type { TaskRepository } from '../repository/task.repository.js';
2
+ import { checkProcessOwnershipAsync as defaultCheckProcessOwnershipAsync, terminateProcessTree as defaultTerminateProcessTree, type ProcessControlOptions } from '../process/process-control.js';
3
+ export declare const TASK_STOP_DEFAULT_GRACE_MS = 5000;
4
+ export declare const TASK_STOP_DEFAULT_POLL_MS = 250;
5
+ export declare function resolveTaskStopMethod(requestedAt: string | null | undefined, completedAt?: string | number, graceMs?: number): 'cooperative' | 'forced';
6
+ export declare const TASK_STOP_OWNED_PROCESS_MARKERS: readonly ["crewx", "claude", "codex", "opencode", "grok", "node"];
7
+ export type StopTaskStatus = 'stopped' | 'not_running' | 'already_requested' | 'ownership_unverified' | 'failed';
8
+ export interface StopTaskResult {
9
+ status: StopTaskStatus;
10
+ method?: 'cooperative' | 'forced';
11
+ finalStatus: string | null;
12
+ pid?: number;
13
+ error?: string;
14
+ }
15
+ export interface StopTaskProcessControl {
16
+ checkProcessOwnershipAsync?: typeof defaultCheckProcessOwnershipAsync;
17
+ terminateProcessTree?: typeof defaultTerminateProcessTree;
18
+ }
19
+ export interface StopTaskOptions {
20
+ graceMs?: number;
21
+ pollMs?: number;
22
+ platform?: NodeJS.Platform;
23
+ ownershipMarkers?: readonly string[];
24
+ processControl?: StopTaskProcessControl;
25
+ processControlOptions?: ProcessControlOptions;
26
+ }
27
+ type StopTaskRepository = Pick<TaskRepository, 'requestTaskStop' | 'getTask' | 'finalizeTaskStop'>;
28
+ export declare function stopTask(taskId: string, options?: StopTaskOptions): Promise<StopTaskResult>;
29
+ export declare function stopTask(repo: StopTaskRepository, taskId: string, options?: StopTaskOptions): Promise<StopTaskResult>;
30
+ export {};
@@ -0,0 +1,8 @@
1
+ ALTER TABLE `tasks` ADD `heartbeat_at` text;
2
+ --> statement-breakpoint
3
+ ALTER TABLE `tasks` ADD `stop_requested_at` text;
4
+ --> statement-breakpoint
5
+ ALTER TABLE `tasks` ADD `stop_requested_epoch` integer;
6
+ --> statement-breakpoint
7
+ CREATE INDEX IF NOT EXISTS `idx_tasks_status_heartbeat`
8
+ ON `tasks` (`status`, `heartbeat_at`);
@@ -176,6 +176,13 @@
176
176
  "when": 1788604428845,
177
177
  "tag": "0024_storage_metadata",
178
178
  "breakpoints": true
179
+ },
180
+ {
181
+ "idx": 25,
182
+ "version": "6",
183
+ "when": 1789128000000,
184
+ "tag": "0025_task_heartbeat",
185
+ "breakpoints": true
179
186
  }
180
187
  ]
181
188
  }
@@ -1,6 +1,6 @@
1
1
  export { FileLoggerPlugin } from './file-logger';
2
2
  export type { FileLoggerPluginOptions } from './file-logger';
3
3
  export { SqliteTracingPlugin } from './sqlite-tracing';
4
- export type { SqliteTracingPluginOptions } from './sqlite-tracing';
4
+ export type { SqliteTracingPluginOptions, SqliteTracingRunnerIdentity } from './sqlite-tracing';
5
5
  export { ConversationPlugin } from './conversation';
6
6
  export type { ConversationPluginOptions } from './conversation';