@sna-sdk/core 0.0.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.
- package/bin/sna.js +18 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +104 -0
- package/dist/core/providers/claude-code.d.ts +9 -0
- package/dist/core/providers/claude-code.js +257 -0
- package/dist/core/providers/codex.d.ts +18 -0
- package/dist/core/providers/codex.js +14 -0
- package/dist/core/providers/index.d.ts +14 -0
- package/dist/core/providers/index.js +22 -0
- package/dist/core/providers/types.d.ts +52 -0
- package/dist/core/providers/types.js +0 -0
- package/dist/db/schema.d.ts +13 -0
- package/dist/db/schema.js +41 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +6 -0
- package/dist/lib/logger.d.ts +18 -0
- package/dist/lib/logger.js +50 -0
- package/dist/lib/sna-run.d.ts +25 -0
- package/dist/lib/sna-run.js +74 -0
- package/dist/scripts/emit.d.ts +2 -0
- package/dist/scripts/emit.js +48 -0
- package/dist/scripts/hook.d.ts +2 -0
- package/dist/scripts/hook.js +34 -0
- package/dist/scripts/init-db.d.ts +2 -0
- package/dist/scripts/init-db.js +3 -0
- package/dist/scripts/sna.d.ts +2 -0
- package/dist/scripts/sna.js +650 -0
- package/dist/scripts/workflow.d.ts +112 -0
- package/dist/scripts/workflow.js +622 -0
- package/dist/server/index.d.ts +30 -0
- package/dist/server/index.js +43 -0
- package/dist/server/routes/agent.d.ts +8 -0
- package/dist/server/routes/agent.js +148 -0
- package/dist/server/routes/emit.d.ts +11 -0
- package/dist/server/routes/emit.js +15 -0
- package/dist/server/routes/events.d.ts +12 -0
- package/dist/server/routes/events.js +54 -0
- package/dist/server/routes/run.d.ts +19 -0
- package/dist/server/routes/run.js +51 -0
- package/dist/server/session-manager.d.ts +64 -0
- package/dist/server/session-manager.js +101 -0
- package/dist/server/standalone.js +820 -0
- package/package.json +91 -0
- package/skills/sna-down/SKILL.md +23 -0
- package/skills/sna-up/SKILL.md +40 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* workflow.ts — SNA Workflow Engine
|
|
3
|
+
*
|
|
4
|
+
* Enforces step ordering, data validation, and event emission for skills.
|
|
5
|
+
* Low-intelligence models (Haiku) can't skip steps or forget events.
|
|
6
|
+
*
|
|
7
|
+
* Step types:
|
|
8
|
+
* exec — CLI auto-executes a command, extracts fields from response
|
|
9
|
+
* instruction — displays task to the model, receives structured data via stdin
|
|
10
|
+
*
|
|
11
|
+
* Instruction steps with `submit` + `handler`:
|
|
12
|
+
* 1. Model submits JSON to stdin (sna <id> next <<'EOF' ... EOF)
|
|
13
|
+
* 2. CLI validates against submit schema
|
|
14
|
+
* 3. CLI executes handler (e.g. curl to app API) with submitted data
|
|
15
|
+
* 4. CLI extracts fields from API response → context
|
|
16
|
+
* 5. CLI emits event with interpolated message
|
|
17
|
+
*
|
|
18
|
+
* CLI:
|
|
19
|
+
* sna new <skill> [--param val ...] → create task, auto-run exec steps
|
|
20
|
+
* sna <task-id> start → (re)start task
|
|
21
|
+
* sna <task-id> next [--key val | < json] → submit data for current step
|
|
22
|
+
*/
|
|
23
|
+
interface WorkflowParam {
|
|
24
|
+
type: "string" | "integer" | "number" | "boolean";
|
|
25
|
+
required?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface StepDataField {
|
|
28
|
+
key: string;
|
|
29
|
+
when: "before" | "after";
|
|
30
|
+
type: "string" | "integer" | "number" | "boolean" | "json";
|
|
31
|
+
label?: string;
|
|
32
|
+
}
|
|
33
|
+
interface SubmitItemField {
|
|
34
|
+
type: "string" | "integer" | "number" | "boolean";
|
|
35
|
+
required?: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface SubmitDef {
|
|
38
|
+
type: "array" | "object";
|
|
39
|
+
items?: Record<string, SubmitItemField>;
|
|
40
|
+
}
|
|
41
|
+
interface WorkflowStep {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
exec?: string;
|
|
45
|
+
instruction?: string;
|
|
46
|
+
extract?: Record<string, string>;
|
|
47
|
+
data?: StepDataField[];
|
|
48
|
+
submit?: SubmitDef;
|
|
49
|
+
handler?: string;
|
|
50
|
+
event?: string;
|
|
51
|
+
timeout?: number;
|
|
52
|
+
}
|
|
53
|
+
interface WorkflowDef {
|
|
54
|
+
version: number;
|
|
55
|
+
skill: string;
|
|
56
|
+
params?: Record<string, WorkflowParam>;
|
|
57
|
+
steps: WorkflowStep[];
|
|
58
|
+
complete: string;
|
|
59
|
+
error: string;
|
|
60
|
+
}
|
|
61
|
+
interface StepStatus {
|
|
62
|
+
status: "pending" | "in_progress" | "completed" | "error";
|
|
63
|
+
}
|
|
64
|
+
interface TaskState {
|
|
65
|
+
task_id: string;
|
|
66
|
+
skill: string;
|
|
67
|
+
status: "created" | "in_progress" | "completed" | "error" | "cancelled";
|
|
68
|
+
started_at: string;
|
|
69
|
+
params: Record<string, unknown>;
|
|
70
|
+
context: Record<string, unknown>;
|
|
71
|
+
current_step: number;
|
|
72
|
+
steps: Record<string, StepStatus>;
|
|
73
|
+
}
|
|
74
|
+
declare function ensureTasksDir(): void;
|
|
75
|
+
declare function generateTaskId(): string;
|
|
76
|
+
declare function loadWorkflow(skillName: string): WorkflowDef;
|
|
77
|
+
declare function loadTask(taskId: string): TaskState;
|
|
78
|
+
declare function saveTask(task: TaskState): void;
|
|
79
|
+
declare function interpolate(template: string, context: Record<string, unknown>): string;
|
|
80
|
+
declare function kebabToSnake(s: string): string;
|
|
81
|
+
declare function parseCliFlags(args: string[]): Record<string, string>;
|
|
82
|
+
declare function coerceValue(raw: string, type: string): unknown;
|
|
83
|
+
declare function readStdin(): string;
|
|
84
|
+
declare function validateSubmitData(step: WorkflowStep, raw: string): unknown;
|
|
85
|
+
/**
|
|
86
|
+
* Resolve a dot-path (e.g. "a.b[0].c") against a data structure.
|
|
87
|
+
* Supports: field access (.a), nested (.a.b.c), array index (.[0], .a[0]).
|
|
88
|
+
*/
|
|
89
|
+
declare function resolvePath(data: unknown, pathStr: string): unknown;
|
|
90
|
+
declare function applyExtract(data: unknown, expr: string): unknown;
|
|
91
|
+
declare function cmdNew(args: string[]): void;
|
|
92
|
+
declare function cmdWorkflow(taskId: string, args: string[]): void;
|
|
93
|
+
declare function cmdCancel(taskId: string): void;
|
|
94
|
+
declare function cmdTasks(): void;
|
|
95
|
+
declare const _test: {
|
|
96
|
+
resolvePath: typeof resolvePath;
|
|
97
|
+
applyExtract: typeof applyExtract;
|
|
98
|
+
interpolate: typeof interpolate;
|
|
99
|
+
coerceValue: typeof coerceValue;
|
|
100
|
+
kebabToSnake: typeof kebabToSnake;
|
|
101
|
+
parseCliFlags: typeof parseCliFlags;
|
|
102
|
+
validateSubmitData: typeof validateSubmitData;
|
|
103
|
+
readStdin: typeof readStdin;
|
|
104
|
+
loadWorkflow: typeof loadWorkflow;
|
|
105
|
+
loadTask: typeof loadTask;
|
|
106
|
+
saveTask: typeof saveTask;
|
|
107
|
+
generateTaskId: typeof generateTaskId;
|
|
108
|
+
ensureTasksDir: typeof ensureTasksDir;
|
|
109
|
+
TASKS_DIR: string;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export { _test, cmdCancel, cmdNew, cmdTasks, cmdWorkflow };
|