@geekbeer/minion 3.34.0 → 3.36.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.
@@ -255,6 +255,7 @@ async function executeTransformNode(node) {
255
255
  assigned_role,
256
256
  input_data,
257
257
  transform_instruction,
258
+ input_contracts,
258
259
  output_contracts,
259
260
  } = node
260
261
 
@@ -290,7 +291,12 @@ async function executeTransformNode(node) {
290
291
 
291
292
  // 2. Create ephemeral skill from transform_instruction.
292
293
  // Write to every active plugin's skill dir so any Primary can find it.
293
- const skillContent = buildTransformSkillContent(transform_instruction, input_data, output_contracts)
294
+ const skillContent = buildTransformSkillContent(
295
+ transform_instruction,
296
+ input_data,
297
+ input_contracts,
298
+ output_contracts,
299
+ )
294
300
  for (const dir of ephemeralSkillDirs) {
295
301
  await fs.mkdir(dir, { recursive: true })
296
302
  await fs.writeFile(path.join(dir, 'SKILL.md'), skillContent, 'utf-8')
@@ -357,51 +363,88 @@ async function executeTransformNode(node) {
357
363
 
358
364
  /**
359
365
  * Build SKILL.md content for a transform node's ephemeral skill.
366
+ *
367
+ * Transform is contract-driven: the Output Contract is the authoritative
368
+ * target shape, enforced by HQ's runtime validator on node-complete.
369
+ * `instruction` is an optional hint layered on top for cases where the
370
+ * contract alone doesn't convey the intent (unit conversion, filter
371
+ * criteria, renaming conventions, etc.).
360
372
  */
361
- function buildTransformSkillContent(instruction, inputData, outputContracts) {
373
+ function buildTransformSkillContent(instruction, inputData, inputContracts, outputContracts) {
362
374
  const lines = [
363
375
  '---',
364
376
  'name: dag-transform',
365
377
  'description: DAG Transform Node',
366
378
  '---',
367
379
  '',
368
- 'You are a data transformation step in a DAG workflow.',
380
+ 'You are a data transformation step in a DAG workflow. Your job is to',
381
+ 'reshape the Input Data into an object that conforms **exactly** to the',
382
+ 'Output Contract. HQ will reject the result if any required field is',
383
+ 'missing or has the wrong type.',
369
384
  '',
370
385
  '## Input Data',
371
386
  '```json',
372
387
  JSON.stringify(inputData, null, 2),
373
388
  '```',
374
- '',
375
- '## Transform Instruction',
376
- instruction,
377
389
  ]
378
390
 
391
+ if (inputContracts && inputContracts.length > 0) {
392
+ lines.push('', '## Input Contract')
393
+ lines.push('The Input Data above conforms to:')
394
+ for (const ic of inputContracts) {
395
+ lines.push(`### ${ic.contract_name}`)
396
+ lines.push(ic.contract.description || '')
397
+ appendContractTable(lines, ic.contract.fields || [])
398
+ }
399
+ }
400
+
379
401
  if (outputContracts && outputContracts.length > 0) {
380
- lines.push('', '## Output Contract')
381
- lines.push('Your output MUST conform to the following contract(s):')
402
+ lines.push('', '## Output Contract (REQUIRED)')
403
+ lines.push(
404
+ 'Produce a JSON object matching this contract. Every required field',
405
+ 'must be present with the declared type. Extra fields are discarded.',
406
+ )
382
407
  for (const oc of outputContracts) {
383
408
  lines.push(`### ${oc.contract_name}`)
384
409
  lines.push(oc.contract.description || '')
385
- lines.push('| Field | Type | Required | Description |')
386
- lines.push('|-------|------|----------|-------------|')
387
- for (const f of oc.contract.fields || []) {
388
- const typeDisplay = f.type === 'array' && f.items ? `array<${f.items}>` : f.type
389
- lines.push(`| ${f.key} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |`)
390
- }
410
+ appendContractTable(lines, oc.contract.fields || [])
391
411
  }
412
+ } else {
413
+ lines.push(
414
+ '',
415
+ '## Output Contract',
416
+ '⚠️ No output contract was declared on the outgoing edge. This transform',
417
+ 'node is misconfigured and should not have reached execution. Return',
418
+ 'the input data unchanged and fail loudly.',
419
+ )
420
+ }
421
+
422
+ if (instruction && instruction.trim()) {
423
+ lines.push('', '## Hint (optional)')
424
+ lines.push(instruction.trim())
392
425
  }
393
426
 
394
427
  lines.push(
395
428
  '',
396
429
  '## Task',
397
- 'Apply the transform instruction to the input data above.',
398
- 'Output the result as a JSON object in an "## Output Data" section with a json code block.',
430
+ '1. Read Input Data and the Output Contract carefully.',
431
+ '2. Construct a JSON object satisfying the Output Contract.',
432
+ '3. Output it under a "## Output Data" section with a json code block.',
399
433
  'Do NOT output anything other than the Output Data section.',
400
434
  )
401
435
 
402
436
  return lines.join('\n')
403
437
  }
404
438
 
439
+ function appendContractTable(lines, fields) {
440
+ lines.push('| Field | Type | Required | Description |')
441
+ lines.push('|-------|------|----------|-------------|')
442
+ for (const f of fields) {
443
+ const typeDisplay = f.type === 'array' && f.items ? `array<${f.items}>` : f.type
444
+ lines.push(`| ${f.name} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |`)
445
+ }
446
+ }
447
+
405
448
  /**
406
449
  * Resolve skill_version_id to skill name via HQ API.
407
450
  */
@@ -1110,7 +1110,7 @@ POST `/api/minion/dag-workflows/:id/publish` (body なし):
1110
1110
  | `fan_out` | `fan_out_source`, `template` | `template` は sub-graph `{ nodes, edges }` |
1111
1111
  | `join` | `join_mode`, `aggregation` | |
1112
1112
  | `conditional` | `condition_type`, `branches` or `default_branch` | |
1113
- | `transform` | `transform_instruction`, `assigned_role` | |
1113
+ | `transform` | `assigned_role`, incoming edge 1 本 + outgoing edge 1 本 (両方 `contract` 必須) | `transform_instruction` は optional hint。I/O 型は edge の contract から自動導出される |
1114
1114
 
1115
1115
  **review ノード追加の例:**
1116
1116
  ```json
@@ -1207,7 +1207,7 @@ POST `/api/minion/dag-workflows/:id/publish` (body なし):
1207
1207
  {
1208
1208
  description: string // contract の説明
1209
1209
  fields: [{
1210
- key: string // フィールド名
1210
+ name: string // フィールド名(※ "key" ではない)
1211
1211
  type: "string" | "number" | "boolean" | "url" | "array" | "object" // フィールド型
1212
1212
  description: string // フィールドの説明
1213
1213
  required?: boolean // 必須フラグ (省略時 false)
@@ -1216,6 +1216,8 @@ POST `/api/minion/dag-workflows/:id/publish` (body なし):
1216
1216
  }
1217
1217
  ```
1218
1218
 
1219
+ **⚠️ 重要: 各 field には必ず `name` プロパティを使用すること(`key` ではない)**。他のスキーマ言語(JSON Schema、OpenAPI 等)の慣習に引きずられて `key` と書かないように注意。構造バリデーションで弾かれる(400エラー)。
1220
+
1219
1221
  **注意:**
1220
1222
  - エッジに設定する `contract` は `graph.contracts` に存在する名前でなければならない(存在しない名前を指定すると 400 エラー)
1221
1223
  - **エッジが参照できる Contract は 1 つのみ**。`edge.contract` に配列を渡すことは不可(400エラー)。複数の型構造を束ねたい場合は、それらを束ねた複合Contractを1つ定義してから参照すること
@@ -1232,16 +1234,16 @@ POST `/api/minion/dag-workflows/:id/publish` (body なし):
1232
1234
  "Article": {
1233
1235
  "description": "個別の記事",
1234
1236
  "fields": [
1235
- { "key": "title", "type": "string", "required": true, "description": "タイトル" },
1236
- { "key": "url", "type": "url", "description": "記事URL" }
1237
+ { "name": "title", "type": "string", "required": true, "description": "タイトル" },
1238
+ { "name": "url", "type": "url", "description": "記事URL" }
1237
1239
  ]
1238
1240
  },
1239
1241
  "NewsCollection": {
1240
1242
  "description": "収集されたニュース全体",
1241
1243
  "fields": [
1242
- { "key": "articles", "type": "array", "items": "Article", "required": true, "description": "記事リスト" },
1243
- { "key": "collected_at", "type": "string", "required": true, "description": "収集日時" },
1244
- { "key": "count", "type": "number", "required": true, "description": "件数" }
1244
+ { "name": "articles", "type": "array", "items": "Article", "required": true, "description": "記事リスト" },
1245
+ { "name": "collected_at", "type": "string", "required": true, "description": "収集日時" },
1246
+ { "name": "count", "type": "number", "required": true, "description": "件数" }
1245
1247
  ]
1246
1248
  }
1247
1249
  },
@@ -1265,8 +1267,8 @@ POST `/api/minion/dag-workflows/:id/publish` (body なし):
1265
1267
  "prototype": {
1266
1268
  "description": "プロトタイプ成果物",
1267
1269
  "fields": [
1268
- { "key": "git_url", "type": "url", "description": "リポジトリURL", "required": true },
1269
- { "key": "preview_url", "type": "url", "description": "プレビューURL" }
1270
+ { "name": "git_url", "type": "url", "description": "リポジトリURL", "required": true },
1271
+ { "name": "preview_url", "type": "url", "description": "プレビューURL" }
1270
1272
  ]
1271
1273
  }
1272
1274
  }
@@ -1281,7 +1283,7 @@ POST `/api/minion/dag-workflows/:id/publish` (body なし):
1281
1283
  "contract": {
1282
1284
  "description": "プロトタイプ成果物",
1283
1285
  "fields": [
1284
- { "key": "git_url", "type": "url", "description": "リポジトリURL", "required": true }
1286
+ { "name": "git_url", "type": "url", "description": "リポジトリURL", "required": true }
1285
1287
  ]
1286
1288
  }
1287
1289
  }
@@ -1528,6 +1530,7 @@ Body:
1528
1530
  - `status: completed` で `requires_review` なノードはサーバ側で `review_status=review_pending` になりカスケードは停止(レビュー承認まで下流は生成されない)
1529
1531
  - `status: failed` でもカスケードは走る(fan-out join が `on_failure=ignore|collect` で集約できるため)
1530
1532
  - `output_data` は下流ノードの `input_data` に伝播する。**スキル実行時はスキル本文の「## Output Data」セクションの JSON コードブロックを抽出して `output_data` に載せる規約**(ミニオンの `dag-node-executor` がこの抽出を行う)
1533
+ - **Contract runtime validation**: 報告時に outgoing edge の `contract` で `output_data` が検証される。違反があれば HQ はノードを `failed` に書き換え、`contract_violations` カラムに構造化済み違反を保存し、`output_summary` に詳細を追記する。スキル・transform 共通。contract が貼られていない edge の先については検証スキップ
1531
1534
 
1532
1535
  Response:
1533
1536
  ```json
@@ -1589,7 +1592,7 @@ DAG ワークフローの graph は以下の構造で保存される(`dag_work
1589
1592
  | `start` | エントリポイント | ❌ (内部) |
1590
1593
  | `end` | 終端 | ❌ (内部) |
1591
1594
  | `skill` | スキル実行。`skill_version_id` と `assigned_role` が必須 | ✅ |
1592
- | `transform` | LLM によるデータ変換。`transform_instruction` が必須 | ✅ |
1595
+ | `transform` | contract 同士のブリッジ。I/O 型は incoming/outgoing edge の `contract` から自動導出、出力は HQ が contract validate。`transform_instruction` optional hint | ✅ |
1593
1596
  | `review` | レビューゲート。`approved` / `revision_requested` で分岐 | ❌ (内部) |
1594
1597
  | `fan_out` | 配列入力をテンプレートsub-graphに展開して並列実行。子が全て settle すると自ノードが completed に遷移 | ❌ (内部) |
1595
1598
  | `join` | N本の上流エッジを待ち合わせる汎用バリア。fan_out とは独立 | ❌ (内部) |
@@ -455,17 +455,64 @@ fan_out_source = ".items"
455
455
 
456
456
  ミニオンから見ると、fan-out 内の skill/transform ノードも通常どおり `pending-nodes` に返ってくる(`scope_path` が空でない点だけが違い)。
457
457
 
458
- ### Transform ノード
458
+ ### Transform ノード(contract 駆動)
459
459
 
460
- Transform ノードは LLM を使って input_data output_data に変換する軽量ノード。`transform_instruction` に自然言語で変換指示を書く。ミニオン側では `transform_instruction` を本文とする一時的なスキルを組み立てて実行する。
460
+ Transform ノードは **contract 同士のブリッジ** となる軽量ノード。入出力の shape は **incoming/outgoing edge に貼った contract から自動導出** され、LLM はその Output Contract に適合する JSON を生成する。HQ `node-complete` 報告時に output を contract で検証し、違反ならノードを failed にする。
461
461
 
462
+ **静的バリデーション要件:**
463
+
464
+ - incoming edge がちょうど 1 本で、**必ず contract を持つ**
465
+ - outgoing edge がちょうど 1 本で、**必ず contract を持つ**
466
+ - `transform_instruction` は **optional**(contract だけで意図が明確なら空欄で OK)
467
+ - `assigned_role` は必須
468
+
469
+ **典型用途: 「スキルの Markdown レポート出力 → 下流 contract の shape に整形」**
470
+
471
+ ```
472
+ incoming edge contract: compe-search-result (items: array<compe-item>, total_count, search_criteria)
473
+ outgoing edge contract: selected-items (items: array<compe-item>)
474
+
475
+ transform_instruction (optional): "上位5件のみを items に残してください"
476
+ input_data (upstream skill output): { "_raw": "# 検索レポート\n..." }
477
+ ↓ (LLM は Output Contract を見てプロンプト通りに整形)
478
+ output_data: { "items": [ {...}, {...}, {...}, {...}, {...} ] }
479
+ ↓ HQ が contract で検証、OK なら cascade 続行
462
480
  ```
463
- transform_instruction: "items 配列から title が 'Item B' のエントリを除外し、残りを返してください"
481
+
482
+ **典型用途: 配列フィルタ**
483
+
484
+ ```
485
+ transform_instruction: "items 配列から title が 'Item B' のエントリを除外"
464
486
  input_data: { "items": [{ "title": "Item A" }, { "title": "Item B" }, { "title": "Item C" }] }
465
- (LLM)
487
+
466
488
  output_data: { "items": [{ "title": "Item A" }, { "title": "Item C" }] }
467
489
  ```
468
490
 
491
+ ### DAG 構築時のノード選定フロー
492
+
493
+ スキルは汎用的で再利用可能な資産であり、ワークフロー固有の contract に合わせて SKILL.md を改修することは原則行わない。代わりに以下のフローで判断する:
494
+
495
+ 1. スキルノードの outgoing edge に contract を貼る
496
+ 2. そのスキルが contract に沿った `## Output Data` JSON ブロックを出力できるか確認
497
+ - **Yes**: そのまま接続。runtime validation が成功すれば cascade 続行
498
+ - **No**: スキルと下流ノードの間に **transform ノードを挟む**。 transform の outgoing edge に下流向け contract を貼り、incoming edge はスキルからの「実質 `_raw` だけ」の契約にする(あるいは contract を定義しない中間エッジとして置く構成)
499
+ 3. fan_out ノードの前では特に注意: incoming edge contract の `fan_out_source` が指すフィールドが `type='array'` で宣言されている必要がある(そうでなければ validator がエラーを出す)
500
+
501
+ ### 契約違反時の挙動
502
+
503
+ `node-complete` で outgoing edge の contract に `output_data` が適合しない場合:
504
+
505
+ - ノードは `status='failed'`, `outcome='failure'` として記録される
506
+ - `contract_violations` カラムに違反詳細(path / expected / actual / message)が JSON で保存される
507
+ - `output_summary` の末尾にも人間可読な違反メッセージが追記される
508
+ - 下流の join / fan-out は `on_failure` policy に従って進む(`ignore` / `collect` / `fail_all`)
509
+
510
+ **よくある違反:**
511
+
512
+ - skill が `## Output Data` セクションを出力しなかった → `{ _raw: "..." }` フォールバックとなり、required field がすべて未定義で failed
513
+ - skill 出力の型が contract と違う(`string` が required だが `number` が返った等)
514
+ - transform の出力 JSON が broken(JSON.parse 失敗→`_raw` → 同じく required 欠落)
515
+
469
516
  ### Review ノードとリビジョン
470
517
 
471
518
  Review ノードはレビューゲート。`review_status=review_pending` で下流カスケードが停止する。レビュアーが:
@@ -441,7 +441,8 @@ async function buildContextPrefix(message, context, sessionId, workspaceId) {
441
441
  ` hq dag remove-edge ${context.dagWorkflowId} <edge-id> # エッジ削除`,
442
442
  ` hq dag validate ${context.dagWorkflowId} # ドラフト検証(公開せず)`,
443
443
  ` hq publish dag-workflow ${context.dagWorkflowId} # 公開`,
444
- `Contract編集時の重要な規則: edge.contract は単一Contract名(string)のみ、配列不可。List<X> は type:"array" + items:"X" で表現。詳細は ~/.minion/docs/api-reference.md の「Contracts API」参照。`,
444
+ `Contract編集時の重要な規則: edge.contract は単一Contract名(string)のみ、配列不可。List<X> は type:"array" + items:"X" で表現。**contract.fields[] の各要素は { "name": "...", "type": "...", ... } の形式で、"key" ではなく "name" を使うこと**(JSON Schema等の慣習に引きずられないように)。詳細は ~/.minion/docs/api-reference.md の「Contracts API」参照。`,
445
+ `Contract はランタイムで強制される型: node-complete 時に outgoing edge の contract で output_data が検証され、違反はノード failed 扱い。transform は contract 同士のブリッジ(I/O 型は edge の contract から自動導出、transform_instruction は optional hint)。スキルが contract に沿った ## Output Data を出せない場合はスキルと下流の間に transform を挟んで整形すること。`,
445
446
  `graph JSON 全文PUTは非推奨: hq put dag-workflow ${context.dagWorkflowId} <body.json>`,
446
447
  `新規作成は: hq create dag-workflow <body.json>`,
447
448
  `プロジェクト内の DAG ワークフロー一覧: hq list dag-workflows ${context.projectId}`,
@@ -128,10 +128,22 @@ async function executeRoutineSession(routine, executionId, skillNames) {
128
128
  throw new Error('No LLM configured. Set a Primary plugin via /api/llm/config or LLM_COMMAND in minion.env')
129
129
  }
130
130
 
131
- // Create tmux session with the LLM command.
132
- // PATH, HOME, DISPLAY, and minion secrets are already set in
133
- // process.env at server startup, so child processes inherit them automatically.
134
- // Per-execution identifiers are passed via -e flags for the session environment.
131
+ // Create the tmux session as an empty shell first, then configure
132
+ // remain-on-exit, then inject the command via send-keys. This avoids
133
+ // the race where a fast-failing LLM command tears down the session
134
+ // before set-option can run (see workflow-runner.js for the full
135
+ // explanation — the same fix applies here).
136
+ //
137
+ // Per-execution identifiers are passed via -e flags so the session
138
+ // shell inherits them; send-keys runs inside that shell.
139
+ const execScript = path.join(os.tmpdir(), `minion-routine-exec-${sessionName}.sh`)
140
+ await fs.writeFile(
141
+ execScript,
142
+ `#!/bin/bash\n${llmCommand}\necho $? > ${exitCodeFile}\n`,
143
+ 'utf-8',
144
+ )
145
+ await execAsync(`chmod +x "${execScript}"`)
146
+
135
147
  const tmuxCommand = [
136
148
  'tmux new-session -d',
137
149
  `-s "${sessionName}"`,
@@ -139,7 +151,6 @@ async function executeRoutineSession(routine, executionId, skillNames) {
139
151
  `-e "MINION_EXECUTION_ID=${executionId}"`,
140
152
  `-e "MINION_ROUTINE_ID=${routine.id}"`,
141
153
  `-e "MINION_ROUTINE_NAME=${routine.name.replace(/"/g, '\\"')}"`,
142
- `"${llmCommand}; echo $? > ${exitCodeFile}"`,
143
154
  ].join(' ')
144
155
 
145
156
  await execAsync(tmuxCommand, { cwd: homeDir })
@@ -155,6 +166,12 @@ async function executeRoutineSession(routine, executionId, skillNames) {
155
166
  console.error(`[RoutineRunner] Failed to set up pipe-pane: ${err.message}`)
156
167
  }
157
168
 
169
+ // Now that remain-on-exit and pipe-pane are in place, inject the
170
+ // actual command.
171
+ await execAsync(
172
+ `tmux send-keys -t "${sessionName}" "bash ${execScript}" Enter`,
173
+ )
174
+
158
175
  console.log(`[RoutineRunner] Started tmux session: ${sessionName}`)
159
176
 
160
177
  // Wait for session to complete (poll for exit code file)
@@ -107,19 +107,19 @@ async function executeWorkflowSession(workflow, executionId, skillNames, options
107
107
  contractContext += '| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n'
108
108
  for (const f of ic.contract.fields || []) {
109
109
  const typeDisplay = f.type === 'array' && f.items ? `array<${f.items}>` : f.type
110
- contractContext += `| ${f.key} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |\n`
110
+ contractContext += `| ${f.name} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |\n`
111
111
  }
112
112
  }
113
113
  contractContext += '\n'
114
114
  }
115
115
  if (options.dagOutputContracts && options.dagOutputContracts.length > 0) {
116
- contractContext += '## Output Contract\nYour output MUST conform to the following contract(s). Include all required fields in your execution report.\n'
116
+ contractContext += '## Output Contract (REQUIRED)\nEnd your execution report with a "## Output Data" section containing a single `json` code block whose content conforms **exactly** to the contract(s) below. HQ validates this JSON on completion; any missing required field or type mismatch fails the node.\n\nIf the skill\'s natural output does not match this shape, add a transform node upstream instead of reshaping inside the skill.\n\n'
117
117
  for (const oc of options.dagOutputContracts) {
118
118
  contractContext += `### ${oc.contract_name}\n${oc.contract.description || ''}\n`
119
119
  contractContext += '| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n'
120
120
  for (const f of oc.contract.fields || []) {
121
121
  const typeDisplay = f.type === 'array' && f.items ? `array<${f.items}>` : f.type
122
- contractContext += `| ${f.key} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |\n`
122
+ contractContext += `| ${f.name} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |\n`
123
123
  }
124
124
  }
125
125
  contractContext += '\n'
@@ -178,17 +178,34 @@ async function executeWorkflowSession(workflow, executionId, skillNames, options
178
178
  throw new Error('No LLM configured. Set a Primary plugin via /api/llm/config or LLM_COMMAND in minion.env')
179
179
  }
180
180
 
181
- // Create tmux session with the LLM command.
181
+ // Create the tmux session as an empty shell first, then configure it,
182
+ // then inject the command via send-keys.
183
+ //
184
+ // Why two steps instead of `tmux new-session -d <cmd>`: if the LLM
185
+ // command exits very quickly (auth failure, missing binary, etc.) the
186
+ // session dies before we can call `set-option remain-on-exit on`, and
187
+ // the subsequent set-option/pipe-pane calls fail with "no such
188
+ // window". DAG transform nodes exposed this race because ephemeral
189
+ // skills start immediately and some failure modes (invalid prompt,
190
+ // missing LLM config) return instantly.
191
+ //
192
+ // Writing the invocation to a script file also insulates the command
193
+ // from shell-escaping edge cases when send-keys types it into the
194
+ // session.
195
+ const execScript = path.join(os.tmpdir(), `minion-workflow-exec-${sessionName}.sh`)
196
+ await fs.writeFile(
197
+ execScript,
198
+ `#!/bin/bash\n${llmCommand}\necho $? > ${exitCodeFile}\n`,
199
+ 'utf-8',
200
+ )
201
+ await execAsync(`chmod +x "${execScript}"`)
202
+
182
203
  // PATH, HOME, DISPLAY, and minion secrets are already set in
183
204
  // process.env at server startup, so child processes inherit them automatically.
184
- const tmuxCommand = [
185
- 'tmux new-session -d',
186
- `-s "${sessionName}"`,
187
- '-x 200 -y 50',
188
- `"${llmCommand}; echo $? > ${exitCodeFile}"`,
189
- ].join(' ')
190
-
191
- await execAsync(tmuxCommand, { cwd: homeDir })
205
+ await execAsync(
206
+ `tmux new-session -d -s "${sessionName}" -x 200 -y 50`,
207
+ { cwd: homeDir },
208
+ )
192
209
 
193
210
  // Keep session alive after command completes (for debugging via terminal mirror)
194
211
  await execAsync(`tmux set-option -t "${sessionName}" remain-on-exit on`)
@@ -203,6 +220,13 @@ async function executeWorkflowSession(workflow, executionId, skillNames, options
203
220
  // Continue execution even if pipe-pane fails
204
221
  }
205
222
 
223
+ // Now that remain-on-exit and pipe-pane are in place, inject the
224
+ // actual command. A fast-failing command will still be captured in the
225
+ // log and the exit code file will be written.
226
+ await execAsync(
227
+ `tmux send-keys -t "${sessionName}" "bash ${execScript}" Enter`,
228
+ )
229
+
206
230
  console.log(`[WorkflowRunner] Started tmux session: ${sessionName}`)
207
231
 
208
232
  // Wait for session to complete (poll for exit code file)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekbeer/minion",
3
- "version": "3.34.0",
3
+ "version": "3.36.0",
4
4
  "description": "AI Agent runtime for Minion - manages status and skill deployment on VPS",
5
5
  "main": "linux/server.js",
6
6
  "bin": {
package/rules/core.md CHANGED
@@ -32,6 +32,9 @@ Minion
32
32
  - ノード/エッジ/contract の追加・更新は**個別API** (`/nodes` `/edges` `/contracts`) を使うこと。`PUT /dag-workflows/:id` による graph 全文PUTは型の取り違えが起きやすく、バリデーションエラーで 400 が返る
33
33
  - `edge.contract` は**単一のContract名(string)**のみ。配列は不可。複数の型構造を束ねたい場合は、それらを内包する複合Contractを1つ定義する
34
34
  - Contract内で `List<別Contract>` を表現するには `type: 'array'` + `items: "別Contract名"` を使う(詳細は `~/.minion/docs/api-reference.md` の「Contracts API」を参照)
35
+ - **Contract はランタイムで強制される型定義**。`node-complete` 報告時に outgoing edge の contract で `output_data` が検証され、違反はノード `failed` 扱い。スキルが contract に沿った `## Output Data` を出せない場合は **transform ノードをスキルと下流の間に挟んで整形**すること。スキル側の SKILL.md を各ワークフロー専用に改修するのは原則 NG(スキルは汎用資産)
36
+ - **transform ノードの I/O 型は edge の contract から自動導出**。incoming edge と outgoing edge にそれぞれ contract を必ず貼ること。`transform_instruction` は contract だけで意図が伝わらない場合の補足ヒント(任意)
37
+ - **fan_out の incoming edge に contract を貼る場合**、`fan_out_source` が指すフィールドが contract 内に `type='array'` として宣言されている必要がある(静的検証で弾かれる)
35
38
  - **Routine**: ミニオンスコープ。ミニオンローカルの定期タスク。
36
39
  - **Workspace**: ミニオンは複数のワークスペースに所属でき、スキルやプロジェクトはワークスペース単位でスコープされる。チャットセッションもワークスペース別に分離される。所属ワークスペースはハートビートで自動同期され、`hq list workspaces` で確認できる。
37
40
  - ミニオンは複数プロジェクトに `pm`、`engineer`、`accountant` として参加できる。
@@ -502,7 +502,8 @@ async function buildContextPrefix(message, context, sessionId, workspaceId) {
502
502
  ` hq dag remove-edge ${context.dagWorkflowId} <edge-id> # エッジ削除`,
503
503
  ` hq dag validate ${context.dagWorkflowId} # ドラフト検証(公開せず)`,
504
504
  ` hq publish dag-workflow ${context.dagWorkflowId} # 公開`,
505
- `Contract編集時の重要な規則: edge.contract は単一Contract名(string)のみ、配列不可。List<X> は type:"array" + items:"X" で表現。詳細は ~/.minion/docs/api-reference.md の「Contracts API」参照。`,
505
+ `Contract編集時の重要な規則: edge.contract は単一Contract名(string)のみ、配列不可。List<X> は type:"array" + items:"X" で表現。**contract.fields[] の各要素は { "name": "...", "type": "...", ... } の形式で、"key" ではなく "name" を使うこと**(JSON Schema等の慣習に引きずられないように)。詳細は ~/.minion/docs/api-reference.md の「Contracts API」参照。`,
506
+ `Contract はランタイムで強制される型: node-complete 時に outgoing edge の contract で output_data が検証され、違反はノード failed 扱い。transform は contract 同士のブリッジ(I/O 型は edge の contract から自動導出、transform_instruction は optional hint)。スキルが contract に沿った ## Output Data を出せない場合はスキルと下流の間に transform を挟んで整形すること。`,
506
507
  `graph JSON 全文PUTは非推奨: hq put dag-workflow ${context.dagWorkflowId} <body.json>`,
507
508
  `新規作成は: hq create dag-workflow <body.json>`,
508
509
  `プロジェクト内の DAG ワークフロー一覧: hq list dag-workflows ${context.projectId}`,
@@ -114,19 +114,19 @@ async function executeWorkflowSession(workflow, executionId, skillNames, options
114
114
  contractContext += '| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n'
115
115
  for (const f of ic.contract.fields || []) {
116
116
  const typeDisplay = f.type === 'array' && f.items ? `array<${f.items}>` : f.type
117
- contractContext += `| ${f.key} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |\n`
117
+ contractContext += `| ${f.name} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |\n`
118
118
  }
119
119
  }
120
120
  contractContext += '\n'
121
121
  }
122
122
  if (options.dagOutputContracts && options.dagOutputContracts.length > 0) {
123
- contractContext += '## Output Contract\nYour output MUST conform to the following contract(s). Include all required fields in your execution report.\n'
123
+ contractContext += '## Output Contract (REQUIRED)\nEnd your execution report with a "## Output Data" section containing a single `json` code block whose content conforms **exactly** to the contract(s) below. HQ validates this JSON on completion; any missing required field or type mismatch fails the node.\n\nIf the skill\'s natural output does not match this shape, add a transform node upstream instead of reshaping inside the skill.\n\n'
124
124
  for (const oc of options.dagOutputContracts) {
125
125
  contractContext += `### ${oc.contract_name}\n${oc.contract.description || ''}\n`
126
126
  contractContext += '| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n'
127
127
  for (const f of oc.contract.fields || []) {
128
128
  const typeDisplay = f.type === 'array' && f.items ? `array<${f.items}>` : f.type
129
- contractContext += `| ${f.key} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |\n`
129
+ contractContext += `| ${f.name} | ${typeDisplay} | ${f.required ? 'Yes' : 'No'} | ${f.description || ''} |\n`
130
130
  }
131
131
  }
132
132
  contractContext += '\n'