@powerformer/refly-cli 0.1.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/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@powerformer/refly-cli",
3
+ "version": "0.1.0",
4
+ "description": "Refly CLI - Command-line interface for Refly workflow orchestration",
5
+ "bin": {
6
+ "refly": "./dist/bin/refly.js"
7
+ },
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "scripts": {
11
+ "build": "tsup",
12
+ "build:test": "REFLY_BUILD_ENV=test tsup",
13
+ "build:staging": "REFLY_BUILD_ENV=staging tsup",
14
+ "build:prod": "REFLY_BUILD_ENV=production tsup",
15
+ "dev": "tsup --watch",
16
+ "clean": "rimraf dist",
17
+ "typecheck": "tsc --noEmit",
18
+ "test": "vitest run",
19
+ "prepublishOnly": "pnpm run build"
20
+ },
21
+ "keywords": ["refly", "cli", "workflow", "automation"],
22
+ "author": "Refly AI",
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "commander": "^12.1.0",
26
+ "zod": "^3.23.8",
27
+ "open": "^10.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20.19.0",
31
+ "rimraf": "^6.0.1",
32
+ "tsup": "^8.3.5",
33
+ "typescript": "^5.6.3",
34
+ "vitest": "^2.1.9"
35
+ },
36
+ "engines": {
37
+ "node": ">=18.0.0"
38
+ },
39
+ "files": ["dist", "skill"]
40
+ }
package/skill/SKILL.md ADDED
@@ -0,0 +1,247 @@
1
+ ---
2
+ name: refly
3
+ description: |
4
+ Refly workflow orchestration via local CLI (secure). Use this skill when the user asks to:
5
+ - Create / edit / run workflows (DAG/pipeline/工作流/编排/automation)
6
+ - Run or debug workflow nodes (node.run, 单节点调试)
7
+ - Build multi-step document pipelines (parse/summarize/translate/export)
8
+ - Manage workflow runs (status/abort/logs)
9
+ Triggers: refly, workflow, DAG, pipeline, 自动化流程, 多步骤任务, 编排任务, 创建工作流, 运行流程.
10
+ Requires: @refly/cli installed and authenticated.
11
+ ---
12
+
13
+ # Refly Skill (CLI-first, Secure, DAG-native)
14
+
15
+ ## 0) Mandatory Execution Rules (NON-NEGOTIABLE)
16
+
17
+ When this skill is triggered:
18
+
19
+ 1. MUST use Refly CLI for all actions.
20
+ - Do NOT call Refly API directly.
21
+ - Do NOT fabricate API calls, workflow IDs, run IDs, node IDs, or outputs.
22
+
23
+ 2. MUST rely only on CLI JSON output for state.
24
+ - Never assume a workflow exists unless CLI returned it.
25
+
26
+ 3. MUST keep token private.
27
+ - Never print, request, or infer tokens.
28
+ - If auth fails, instruct the user to run `refly login` or `refly init`.
29
+
30
+ 4. MUST present results based on verified CLI JSON fields.
31
+
32
+ If any rule cannot be satisfied, STOP and tell the user exactly what to run next.
33
+
34
+ ---
35
+
36
+ ## 1) Preconditions / Environment Check
37
+
38
+ Before any operation:
39
+
40
+ ```bash
41
+ refly status
42
+ ```
43
+
44
+ - If `ok=false` and `error.code=AUTH_REQUIRED`: run `refly login` (or `refly init`).
45
+ - If `error.code=CLI_NOT_FOUND`: install `npm i -g @refly/cli` and rerun.
46
+
47
+ ---
48
+
49
+ ## 2) Output Contract (STRICT)
50
+
51
+ Success:
52
+ ```json
53
+ { "ok": true, "type": "workflow.create", "version": "1.0", "payload": {} }
54
+ ```
55
+
56
+ Error:
57
+ ```json
58
+ { "ok": false, "type": "error", "version": "1.0", "error": { "code": "AUTH_REQUIRED", "message": "...", "hint": "refly login" } }
59
+ ```
60
+
61
+ Rules:
62
+ - Only trust `payload`.
63
+ - If `ok=false`, do NOT proceed. Show `hint`.
64
+
65
+ ---
66
+
67
+ ## 3) Core Commands
68
+
69
+ ### Authentication
70
+ ```bash
71
+ refly init # Initialize and install skill
72
+ refly login # Authenticate with API key
73
+ refly logout # Remove credentials
74
+ refly status # Check CLI and auth status
75
+ refly whoami # Show current user
76
+ ```
77
+
78
+ ### Workflow CRUD
79
+ ```bash
80
+ refly workflow create --name "<name>" --spec '<json>'
81
+ refly workflow generate --query "<natural language description>" # AI-powered workflow generation
82
+ refly workflow edit <workflowId> --ops '<json>'
83
+ refly workflow get <workflowId>
84
+ refly workflow list
85
+ refly workflow delete <workflowId>
86
+ ```
87
+
88
+ ### Workflow Run & Monitoring
89
+ ```bash
90
+ refly workflow run <workflowId> --input '<json>'
91
+ refly workflow status <runId> # Get detailed execution status
92
+ refly workflow status <runId> --watch # Watch until completion (polls every 2s)
93
+ refly workflow run detail <runId> # Full workflow execution detail
94
+ refly workflow run node <runId> <nodeId> # Single node execution result
95
+ refly workflow run toolcalls <runId> # All tool calls in workflow
96
+ refly workflow abort <runId>
97
+ ```
98
+
99
+ ### Node Operations
100
+ ```bash
101
+ refly node types # List available node types
102
+ refly node run --type "<nodeType>" --input '<json>' # Run a node for debugging
103
+ refly node result <resultId> # Get node execution result
104
+ refly node result <resultId> --include-tool-calls # Include tool call details
105
+ ```
106
+
107
+ ### Tool Inspection
108
+ ```bash
109
+ refly tool calls --result-id <resultId> # Get tool execution results for a node
110
+ refly tool get <callId> # Get single tool call detail
111
+ ```
112
+
113
+ ### Action Result
114
+ ```bash
115
+ refly action result <resultId> # Action result with default sanitization
116
+ refly action result <resultId> --version <n> # Specific version
117
+ refly action result <resultId> --raw # Disable sanitization/truncation
118
+ refly action result <resultId> --include-files # Include related files
119
+ ```
120
+
121
+ ### File Operations
122
+ ```bash
123
+ refly file list # List files
124
+ refly file list --canvas-id <id> # Filter by canvas
125
+ refly file get <fileId> # Get file metadata and content
126
+ refly file download <fileId> -o ./output.txt # Download file to local filesystem
127
+ ```
128
+
129
+ ---
130
+
131
+ ## 4) AI Workflow Generation
132
+
133
+ Use `workflow generate` to create workflows from natural language:
134
+
135
+ ```bash
136
+ # Basic generation
137
+ refly workflow generate --query "Parse PDF, summarize content, translate to Chinese"
138
+
139
+ # With options
140
+ refly workflow generate \
141
+ --query "Research topic, write article, export to markdown" \
142
+ --model-id <modelId> \
143
+ --locale zh \
144
+ --timeout 300000
145
+
146
+ # With predefined variables
147
+ refly workflow generate \
148
+ --query "Process documents from input folder" \
149
+ --variables '[{"variableId":"v1","name":"inputFolder","variableType":"string"}]'
150
+ ```
151
+
152
+ The generate command:
153
+ - Invokes AI to parse the natural language query
154
+ - Creates a workflow plan with tasks
155
+ - Builds the DAG with appropriate nodes and edges
156
+ - Returns workflowId, planId, and task details
157
+
158
+ ---
159
+
160
+ ## 5) DAG Rules (STRICT)
161
+
162
+ - Unique node ids.
163
+ - No cycles.
164
+ - Dependencies reference existing nodes only.
165
+ - Insert X between A→B by rewiring dependencies.
166
+
167
+ ---
168
+
169
+ ## 6) Workflow Spec Schema (v1)
170
+
171
+ ```json
172
+ {
173
+ "version": 1,
174
+ "name": "string",
175
+ "description": "string?",
176
+ "nodes": [
177
+ {
178
+ "id": "string",
179
+ "type": "string",
180
+ "input": {},
181
+ "dependsOn": ["string"]
182
+ }
183
+ ],
184
+ "metadata": {
185
+ "tags": ["string"],
186
+ "owner": "string?"
187
+ }
188
+ }
189
+ ```
190
+
191
+ ---
192
+
193
+ ## 7) Error Codes
194
+
195
+ | Code | Description | Hint |
196
+ |------|-------------|------|
197
+ | AUTH_REQUIRED | Not authenticated | refly login |
198
+ | CLI_NOT_FOUND | CLI not installed | npm i -g @refly/cli |
199
+ | NETWORK_ERROR | API unreachable | Check connection |
200
+ | NOT_FOUND | Resource not found | Verify ID |
201
+ | CONFLICT | State conflict | Check status |
202
+ | INTERNAL_ERROR | Unexpected error | Report issue |
203
+
204
+ ---
205
+
206
+ ## 8) References
207
+
208
+ - `references/workflow-schema.md` - Full schema documentation
209
+ - `references/node-types.md` - Available node types
210
+ - `references/api-errors.md` - Complete error reference
211
+
212
+ ## 9) Execution Results Workflow (Recommended)
213
+
214
+ Use this flow when tracking a running workflow and extracting results:
215
+
216
+ 1. **Start run**: `refly workflow run <workflowId> --input '<json>'`
217
+ 2. **Monitor status**: `refly workflow status <runId> --watch`
218
+ 3. **On node finish**: `refly workflow run node <runId> <nodeId>`
219
+ 4. **Tool calls** (optional): `refly workflow run toolcalls <runId>` or `refly tool get <callId>`
220
+ 5. **Raw output** for debugging: add `--raw` to disable sanitization
221
+
222
+ ## 10) CLI Backend API Reference (Workflow/Node/Tool)
223
+
224
+ Workflow:
225
+ - `POST /v1/cli/workflow` create
226
+ - `POST /v1/cli/workflow/generate` AI generate
227
+ - `GET /v1/cli/workflow` list
228
+ - `GET /v1/cli/workflow/:id` detail
229
+ - `PATCH /v1/cli/workflow/:id` update
230
+ - `DELETE /v1/cli/workflow/:id` delete
231
+ - `POST /v1/cli/workflow/:id/run` start run
232
+ - `GET /v1/cli/workflow/run/:runId` run status
233
+ - `POST /v1/cli/workflow/run/:runId/abort` abort run
234
+ - `GET /v1/cli/workflow/run/:runId/detail` run detail
235
+ - `GET /v1/cli/workflow/run/:runId/node/:nodeId` node result (workflow scope)
236
+ - `GET /v1/cli/workflow/run/:runId/toolcalls` tool calls (workflow scope)
237
+
238
+ Node:
239
+ - `GET /v1/cli/node/types` list node types
240
+ - `POST /v1/cli/node/run` run a single node (not implemented yet)
241
+
242
+ Tool:
243
+ - `GET /v1/cli/toolcall?resultId=<id>&version=<n>` tool calls for action result
244
+ - `GET /v1/cli/toolcall/:callId` single tool call detail
245
+
246
+ Action (related):
247
+ - `GET /v1/cli/action/result?resultId=<id>&version=<n>&sanitizeForDisplay=<bool>&includeFiles=<bool>`
@@ -0,0 +1,120 @@
1
+ # API Errors Reference
2
+
3
+ All CLI errors use stable error codes for reliable error handling.
4
+
5
+ ## Error Response Format
6
+
7
+ ```json
8
+ {
9
+ "ok": false,
10
+ "type": "error",
11
+ "version": "1.0",
12
+ "error": {
13
+ "code": "ERROR_CODE",
14
+ "message": "Human-readable description",
15
+ "details": { },
16
+ "hint": "Suggested action"
17
+ }
18
+ }
19
+ ```
20
+
21
+ ## Error Codes
22
+
23
+ ### Authentication Errors
24
+
25
+ | Code | Description | Hint |
26
+ |------|-------------|------|
27
+ | AUTH_REQUIRED | Not authenticated or token expired | Run `refly login` |
28
+ | AUTH_INVALID | Invalid credentials | Check API key |
29
+ | AUTH_EXPIRED | Token has expired | Run `refly login` |
30
+
31
+ ### CLI Errors
32
+
33
+ | Code | Description | Hint |
34
+ |------|-------------|------|
35
+ | CLI_NOT_FOUND | CLI not installed or not in PATH | Run `npm i -g @refly/cli` |
36
+ | CONFIG_ERROR | Configuration file corrupted | Run `refly init` |
37
+ | VERSION_MISMATCH | CLI version incompatible with API | Run `npm update -g @refly/cli` |
38
+
39
+ ### Builder Errors
40
+
41
+ | Code | Description | Hint |
42
+ |------|-------------|------|
43
+ | BUILDER_NOT_STARTED | No active builder session | Run `refly builder start` |
44
+ | BUILDER_ALREADY_STARTED | Builder session already exists | Run `refly builder abort` first |
45
+ | VALIDATION_REQUIRED | Must validate before commit | Run `refly builder validate` |
46
+ | VALIDATION_ERROR | DAG validation failed | See error details |
47
+ | DUPLICATE_NODE_ID | Node ID already exists | Use unique node ID |
48
+ | NODE_NOT_FOUND | Referenced node does not exist | Check node ID |
49
+ | CYCLE_DETECTED | Circular dependency in DAG | Remove cycle |
50
+ | INVALID_STATE | Invalid state transition | Check `refly builder status` |
51
+
52
+ ### Workflow Errors
53
+
54
+ | Code | Description | Hint |
55
+ |------|-------------|------|
56
+ | WORKFLOW_NOT_FOUND | Workflow does not exist | Check workflow ID |
57
+ | WORKFLOW_EXISTS | Workflow name already taken | Use different name |
58
+ | RUN_NOT_FOUND | Workflow run does not exist | Check run ID |
59
+ | RUN_FAILED | Workflow execution failed | Check run details |
60
+ | RUN_ABORTED | Workflow was aborted | - |
61
+
62
+ ### Node Errors
63
+
64
+ | Code | Description | Hint |
65
+ |------|-------------|------|
66
+ | INVALID_NODE_TYPE | Unknown node type | Run `refly node types` |
67
+ | INVALID_NODE_INPUT | Node input validation failed | Check input schema |
68
+ | NODE_EXECUTION_ERROR | Node execution failed | See error details |
69
+
70
+ ### Network Errors
71
+
72
+ | Code | Description | Hint |
73
+ |------|-------------|------|
74
+ | NETWORK_ERROR | Cannot connect to API | Check internet connection |
75
+ | TIMEOUT | Request timed out | Retry later |
76
+ | API_ERROR | API returned error | See error message |
77
+
78
+ ### General Errors
79
+
80
+ | Code | Description | Hint |
81
+ |------|-------------|------|
82
+ | NOT_FOUND | Resource not found | Verify resource ID |
83
+ | CONFLICT | Resource conflict | Refresh and retry |
84
+ | PERMISSION_DENIED | Insufficient permissions | Check access rights |
85
+ | INVALID_INPUT | Invalid input data | Check input format |
86
+ | INTERNAL_ERROR | Unexpected error | Report issue |
87
+
88
+ ## Handling Errors
89
+
90
+ ### In Claude Code
91
+
92
+ When `ok=false`:
93
+ 1. Do NOT proceed with the operation
94
+ 2. Show the user the `error.message`
95
+ 3. Suggest the action in `error.hint`
96
+ 4. If `error.details` exists, include relevant information
97
+
98
+ ### Example Error Handling
99
+
100
+ ```bash
101
+ # Check status before operations
102
+ result=$(refly status)
103
+ if [ "$(echo $result | jq -r '.ok')" = "false" ]; then
104
+ code=$(echo $result | jq -r '.error.code')
105
+ hint=$(echo $result | jq -r '.error.hint')
106
+ echo "Error: $code. Try: $hint"
107
+ exit 1
108
+ fi
109
+ ```
110
+
111
+ ## Exit Codes
112
+
113
+ | Exit Code | Meaning |
114
+ |-----------|---------|
115
+ | 0 | Success |
116
+ | 1 | General error |
117
+ | 2 | Authentication error |
118
+ | 3 | Validation error |
119
+ | 4 | Network error |
120
+ | 5 | Not found |
@@ -0,0 +1,91 @@
1
+ # Node Types Reference
2
+
3
+ This document describes the available node types for Refly workflows.
4
+
5
+ ## Fetching Node Types
6
+
7
+ Use the CLI to get the current list of supported node types:
8
+
9
+ ```bash
10
+ refly node types
11
+ ```
12
+
13
+ Response:
14
+ ```json
15
+ {
16
+ "ok": true,
17
+ "type": "node.types",
18
+ "version": "1.0",
19
+ "payload": {
20
+ "types": [
21
+ {
22
+ "name": "document.parse",
23
+ "description": "Parse document content",
24
+ "inputSchema": { ... },
25
+ "outputSchema": { ... }
26
+ }
27
+ ]
28
+ }
29
+ }
30
+ ```
31
+
32
+ ## Node Type Cache
33
+
34
+ - Location: `~/.refly/cache/node-types.json`
35
+ - TTL: 24 hours
36
+ - Force refresh: `refly node types --refresh`
37
+
38
+ ## Common Node Categories
39
+
40
+ ### Document Processing
41
+ - `document.parse` - Parse various document formats
42
+ - `document.export` - Export to different formats
43
+ - `document.split` - Split document into chunks
44
+
45
+ ### LLM Operations
46
+ - `llm.summarize` - Summarize text content
47
+ - `llm.translate` - Translate content
48
+ - `llm.generate` - Generate content from prompt
49
+ - `llm.chat` - Interactive chat completion
50
+
51
+ ### Data Operations
52
+ - `data.input` - Accept external input
53
+ - `data.output` - Produce workflow output
54
+ - `data.merge` - Merge multiple inputs
55
+ - `data.filter` - Filter data by criteria
56
+ - `data.transform` - Transform data structure
57
+
58
+ ### Control Flow
59
+ - `control.condition` - Conditional branching
60
+ - `control.loop` - Iterate over items
61
+ - `control.parallel` - Parallel execution
62
+
63
+ ## Testing Nodes
64
+
65
+ Run a single node for debugging:
66
+
67
+ ```bash
68
+ refly node run --type "llm.summarize" --input '{"text": "Long text here..."}'
69
+ ```
70
+
71
+ Response:
72
+ ```json
73
+ {
74
+ "ok": true,
75
+ "type": "node.run",
76
+ "version": "1.0",
77
+ "payload": {
78
+ "result": { ... },
79
+ "metrics": {
80
+ "durationMs": 1234,
81
+ "tokensUsed": 500
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ ## Notes
88
+
89
+ - Node types depend on your Refly backend configuration
90
+ - Some nodes may require specific permissions
91
+ - Input/output schemas are validated at runtime
@@ -0,0 +1,95 @@
1
+ # Workflow Schema Reference
2
+
3
+ This document defines the canonical workflow spec used by `refly workflow create --spec`.
4
+
5
+ ## Spec Shape (v1)
6
+
7
+ ```json
8
+ {
9
+ "version": 1,
10
+ "name": "string (required)",
11
+ "description": "string (optional)",
12
+ "nodes": [
13
+ {
14
+ "id": "string (required, unique)",
15
+ "type": "string (required, must be valid node type)",
16
+ "input": "object (required, node-specific configuration)",
17
+ "dependsOn": "string[] (optional, list of node IDs)"
18
+ }
19
+ ],
20
+ "metadata": {
21
+ "tags": "string[] (optional)",
22
+ "owner": "string (optional)"
23
+ }
24
+ }
25
+ ```
26
+
27
+ ## Field Descriptions
28
+
29
+ ### Top-level Fields
30
+
31
+ | Field | Type | Required | Description |
32
+ |-------|------|----------|-------------|
33
+ | version | number | Yes | Schema version, currently `1` |
34
+ | name | string | Yes | Workflow name, must be unique per user |
35
+ | description | string | No | Human-readable description |
36
+ | nodes | array | Yes | List of workflow nodes |
37
+ | metadata | object | No | Additional metadata |
38
+
39
+ ### Node Fields
40
+
41
+ | Field | Type | Required | Description |
42
+ |-------|------|----------|-------------|
43
+ | id | string | Yes | Unique identifier within workflow |
44
+ | type | string | Yes | Node type from `refly node types` |
45
+ | input | object | Yes | Node-specific input configuration |
46
+ | dependsOn | string[] | No | IDs of nodes that must complete first |
47
+
48
+ ## DAG Rules
49
+
50
+ 1. **Unique IDs**: Each node `id` must be unique within the workflow
51
+ 2. **No Cycles**: The dependency graph must be acyclic
52
+ 3. **Valid References**: All `dependsOn` entries must reference existing node IDs
53
+ 4. **No Self-Reference**: A node cannot depend on itself
54
+ 5. **Valid Types**: All `type` values must be in the allowed node types list
55
+
56
+ ## Examples
57
+
58
+ ### Simple Sequential Workflow
59
+
60
+ ```json
61
+ {
62
+ "version": 1,
63
+ "name": "document-processor",
64
+ "nodes": [
65
+ { "id": "parse", "type": "document.parse", "input": { "format": "pdf" } },
66
+ { "id": "summarize", "type": "llm.summarize", "input": {}, "dependsOn": ["parse"] },
67
+ { "id": "export", "type": "document.export", "input": { "format": "md" }, "dependsOn": ["summarize"] }
68
+ ]
69
+ }
70
+ ```
71
+
72
+ ### Parallel Processing
73
+
74
+ ```json
75
+ {
76
+ "version": 1,
77
+ "name": "parallel-analysis",
78
+ "nodes": [
79
+ { "id": "input", "type": "data.input", "input": {} },
80
+ { "id": "analyze-a", "type": "analyze.sentiment", "input": {}, "dependsOn": ["input"] },
81
+ { "id": "analyze-b", "type": "analyze.keywords", "input": {}, "dependsOn": ["input"] },
82
+ { "id": "merge", "type": "data.merge", "input": {}, "dependsOn": ["analyze-a", "analyze-b"] }
83
+ ]
84
+ }
85
+ ```
86
+
87
+ ## Validation Errors
88
+
89
+ | Error | Description |
90
+ |-------|-------------|
91
+ | DUPLICATE_NODE_ID | Two nodes have the same ID |
92
+ | INVALID_NODE_TYPE | Node type not in allowed list |
93
+ | MISSING_DEPENDENCY | dependsOn references non-existent node |
94
+ | CYCLE_DETECTED | Circular dependency found |
95
+ | MISSING_REQUIRED_FIELD | Required field is missing |