triflux 10.4.0 → 10.7.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/.claude-plugin/marketplace.json +34 -0
- package/.claude-plugin/plugin.json +22 -0
- package/bin/tfx-doctor-tui.mjs +1 -1
- package/bin/tfx-doctor.mjs +6 -1
- package/bin/tfx-profile.mjs +1 -1
- package/bin/tfx-setup-tui.mjs +1 -1
- package/bin/tfx-setup.mjs +6 -1
- package/bin/triflux.mjs +2396 -1140
- package/config/mcp-registry.json +29 -0
- package/hooks/agent-route-guard.mjs +12 -8
- package/hooks/cross-review-tracker.mjs +21 -8
- package/hooks/error-context.mjs +19 -7
- package/hooks/hook-adaptive-collector.mjs +18 -16
- package/hooks/hook-manager.mjs +93 -32
- package/hooks/hook-orchestrator.mjs +108 -24
- package/hooks/hook-registry.json +267 -256
- package/hooks/keyword-rules.json +6 -10
- package/hooks/lib/resolve-root.mjs +1 -1
- package/hooks/mcp-config-watcher.mjs +6 -2
- package/hooks/pipeline-stop.mjs +3 -6
- package/hooks/safety-guard.mjs +99 -28
- package/hooks/session-start-fast.mjs +143 -0
- package/hooks/subagent-verifier.mjs +5 -4
- package/hub/account-broker.mjs +256 -60
- package/hub/adaptive-diagnostic.mjs +75 -48
- package/hub/adaptive-inject.mjs +96 -58
- package/hub/adaptive-memory.mjs +156 -42
- package/hub/adaptive.mjs +60 -31
- package/hub/assign-callbacks.mjs +163 -126
- package/hub/bridge.mjs +0 -1
- package/hub/cli-adapter-base.mjs +200 -48
- package/hub/codex-adapter.mjs +76 -96
- package/hub/codex-compat.mjs +3 -3
- package/hub/codex-preflight.mjs +63 -37
- package/hub/delegator/contracts.mjs +19 -23
- package/hub/delegator/index.mjs +14 -14
- package/hub/delegator/service.mjs +88 -64
- package/hub/delegator/tool-definitions.mjs +35 -35
- package/hub/fullcycle.mjs +33 -17
- package/hub/gemini-adapter.mjs +69 -94
- package/hub/hitl.mjs +202 -143
- package/hub/intent.mjs +161 -38
- package/hub/lib/cache-guard.mjs +43 -17
- package/hub/lib/mcp-response-cache.mjs +66 -32
- package/hub/lib/memory-store.mjs +285 -111
- package/hub/lib/path-utils.mjs +35 -37
- package/hub/lib/process-utils.mjs +106 -37
- package/hub/lib/spawn-trace.mjs +527 -0
- package/hub/lib/ssh-command.mjs +34 -4
- package/hub/lib/ssh-retry.mjs +5 -1
- package/hub/lib/uuidv7.mjs +4 -3
- package/hub/memory-doctor.mjs +266 -106
- package/hub/middleware/request-logger.mjs +61 -34
- package/hub/paths.mjs +9 -9
- package/hub/pipeline/gates/confidence.mjs +34 -15
- package/hub/pipeline/gates/consensus.mjs +27 -15
- package/hub/pipeline/gates/index.mjs +7 -3
- package/hub/pipeline/gates/selfcheck.mjs +57 -19
- package/hub/pipeline/index.mjs +77 -42
- package/hub/pipeline/state.mjs +10 -10
- package/hub/pipeline/transitions.mjs +40 -23
- package/hub/platform.mjs +57 -48
- package/hub/promote-penalties.mjs +25 -7
- package/hub/quality/deslop.mjs +70 -49
- package/hub/research.mjs +32 -25
- package/hub/router.mjs +924 -791
- package/hub/routing/complexity.mjs +132 -29
- package/hub/routing/index.mjs +17 -12
- package/hub/routing/q-learning.mjs +76 -28
- package/hub/server.mjs +4 -4
- package/hub/session-fingerprint.mjs +127 -61
- package/hub/state.mjs +84 -43
- package/hub/store-adapter.mjs +59 -26
- package/hub/store.mjs +356 -153
- package/hub/team/agent-map.json +22 -7
- package/hub/team/ansi.mjs +186 -122
- package/hub/team/backend.mjs +28 -10
- package/hub/team/cli/commands/attach.mjs +57 -37
- package/hub/team/cli/commands/control.mjs +29 -8
- package/hub/team/cli/commands/debug.mjs +95 -74
- package/hub/team/cli/commands/focus.mjs +80 -53
- package/hub/team/cli/commands/interrupt.mjs +18 -6
- package/hub/team/cli/commands/kill.mjs +16 -5
- package/hub/team/cli/commands/list.mjs +31 -24
- package/hub/team/cli/commands/send.mjs +19 -6
- package/hub/team/cli/commands/start/index.mjs +154 -31
- package/hub/team/cli/commands/start/parse-args.mjs +38 -11
- package/hub/team/cli/commands/start/start-headless.mjs +112 -36
- package/hub/team/cli/commands/start/start-in-process.mjs +50 -40
- package/hub/team/cli/commands/start/start-mux.mjs +122 -73
- package/hub/team/cli/commands/start/start-wt.mjs +86 -69
- package/hub/team/cli/commands/status.mjs +43 -14
- package/hub/team/cli/commands/stop.mjs +11 -4
- package/hub/team/cli/commands/task.mjs +8 -3
- package/hub/team/cli/commands/tasks.mjs +13 -13
- package/hub/team/cli/index.mjs +2 -2
- package/hub/team/cli/manifest.mjs +38 -8
- package/hub/team/cli/render.mjs +52 -30
- package/hub/team/cli/services/attach-fallback.mjs +74 -54
- package/hub/team/cli/services/hub-client.mjs +42 -14
- package/hub/team/cli/services/member-selector.mjs +37 -30
- package/hub/team/cli/services/native-control.mjs +143 -116
- package/hub/team/cli/services/runtime-mode.mjs +2 -1
- package/hub/team/cli/services/state-store.mjs +25 -8
- package/hub/team/cli/services/task-model.mjs +40 -30
- package/hub/team/conductor-mesh-bridge.mjs +24 -23
- package/hub/team/conductor.mjs +8 -4
- package/hub/team/dashboard-anchor.mjs +4 -5
- package/hub/team/dashboard-layout.mjs +3 -1
- package/hub/team/dashboard-open.mjs +41 -21
- package/hub/team/dashboard.mjs +76 -28
- package/hub/team/event-log.mjs +18 -10
- package/hub/team/handoff.mjs +31 -15
- package/hub/team/headless.mjs +2 -1
- package/hub/team/health-probe.mjs +69 -54
- package/hub/team/launcher-template.mjs +16 -13
- package/hub/team/native-supervisor.mjs +65 -21
- package/hub/team/native.mjs +74 -35
- package/hub/team/nativeProxy.mjs +184 -113
- package/hub/team/notify.mjs +120 -77
- package/hub/team/orchestrator.mjs +166 -161
- package/hub/team/pane.mjs +12 -7
- package/hub/team/process-cleanup.mjs +25 -16
- package/hub/team/psmux.mjs +491 -201
- package/hub/team/remote-probe.mjs +68 -52
- package/hub/team/remote-session.mjs +117 -59
- package/hub/team/remote-watcher.mjs +61 -33
- package/hub/team/routing.mjs +51 -25
- package/hub/team/runtime-strategy.mjs +3 -1
- package/hub/team/session.mjs +675 -611
- package/hub/team/shared.mjs +13 -13
- package/hub/team/staleState.mjs +72 -30
- package/hub/team/swarm-locks.mjs +15 -13
- package/hub/team/swarm-planner.mjs +32 -21
- package/hub/team/swarm-reconciler.mjs +48 -23
- package/hub/team/tui-lite.mjs +266 -68
- package/hub/team/tui-remote-adapter.mjs +14 -10
- package/hub/team/tui-viewer.mjs +99 -43
- package/hub/team/tui.mjs +708 -271
- package/hub/team/worktree-lifecycle.mjs +152 -58
- package/hub/team/wt-manager.mjs +24 -14
- package/hub/token-mode.mjs +71 -71
- package/hub/tray.mjs +411 -368
- package/hub/workers/claude-worker.mjs +162 -118
- package/hub/workers/codex-mcp.mjs +558 -507
- package/hub/workers/delegator-mcp.mjs +507 -333
- package/hub/workers/factory.mjs +21 -21
- package/hub/workers/gemini-worker.mjs +115 -84
- package/hub/workers/interface.mjs +6 -1
- package/hub/workers/worker-utils.mjs +21 -14
- package/hud/colors.mjs +27 -9
- package/hud/constants.mjs +162 -26
- package/hud/context-monitor.mjs +82 -41
- package/hud/hud-qos-status.mjs +129 -49
- package/hud/mission-board.mjs +6 -3
- package/hud/providers/claude.mjs +226 -115
- package/hud/providers/codex.mjs +62 -22
- package/hud/providers/gemini.mjs +168 -56
- package/hud/renderers.mjs +384 -119
- package/hud/terminal.mjs +101 -31
- package/hud/utils.mjs +78 -38
- package/mesh/index.mjs +11 -5
- package/mesh/mesh-budget.mjs +18 -9
- package/mesh/mesh-heartbeat.mjs +1 -1
- package/mesh/mesh-queue.mjs +3 -5
- package/mesh/mesh-router.mjs +5 -4
- package/package.json +56 -21
- package/scripts/__tests__/gen-skill-docs.test.mjs +36 -7
- package/scripts/__tests__/keyword-detector.test.mjs +77 -28
- package/scripts/__tests__/mcp-guard-engine.test.mjs +58 -20
- package/scripts/__tests__/remote-spawn-transfer.test.mjs +30 -19
- package/scripts/__tests__/remote-spawn.test.mjs +10 -4
- package/scripts/__tests__/session-start-fast.test.mjs +36 -0
- package/scripts/__tests__/skill-template.test.mjs +98 -50
- package/scripts/__tests__/smoke.test.mjs +1 -1
- package/scripts/__tests__/spawn-trace.test.mjs +102 -0
- package/scripts/__tests__/tfx-doctor-diagnose.test.mjs +48 -0
- package/scripts/cache-doctor.mjs +11 -4
- package/scripts/cache-warmup.mjs +96 -37
- package/scripts/claudemd-sync.mjs +27 -17
- package/scripts/codex-gateway-preflight.mjs +52 -37
- package/scripts/codex-mcp-gateway-sync.mjs +59 -39
- package/scripts/config-audit.mjs +232 -0
- package/scripts/convert-to-tmpl.mjs +54 -0
- package/scripts/cross-review-gate.mjs +35 -12
- package/scripts/cross-review-tracker.mjs +21 -8
- package/scripts/demo.mjs +35 -17
- package/scripts/doctor-diagnose.mjs +284 -0
- package/scripts/gen-skill-docs.mjs +7 -2
- package/scripts/gen-skill-manifest.mjs +2 -1
- package/scripts/headless-guard.mjs +86 -48
- package/scripts/hub-ensure.mjs +139 -120
- package/scripts/keyword-detector.mjs +293 -272
- package/scripts/keyword-rules-expander.mjs +538 -521
- package/scripts/lib/claudemd-scanner.mjs +6 -1
- package/scripts/lib/context.mjs +3 -3
- package/scripts/lib/cross-review-utils.mjs +6 -3
- package/scripts/lib/env-probe.mjs +47 -28
- package/scripts/lib/gemini-profiles.mjs +44 -10
- package/scripts/lib/handoff.mjs +33 -17
- package/scripts/lib/hook-utils.mjs +8 -6
- package/scripts/lib/keyword-rules.mjs +43 -19
- package/scripts/lib/logger.mjs +24 -24
- package/scripts/lib/mcp-filter.mjs +377 -239
- package/scripts/lib/mcp-guard-engine.mjs +194 -79
- package/scripts/lib/mcp-manifest.mjs +23 -13
- package/scripts/lib/mcp-server-catalog.mjs +355 -118
- package/scripts/lib/psmux-info.mjs +11 -6
- package/scripts/lib/remote-spawn-transfer.mjs +44 -14
- package/scripts/lib/skill-template.mjs +30 -7
- package/scripts/mcp-check.mjs +58 -39
- package/scripts/mcp-gateway-config.mjs +83 -39
- package/scripts/mcp-gateway-ensure.mjs +43 -35
- package/scripts/mcp-gateway-integration-test.mjs +70 -58
- package/scripts/mcp-gateway-start.mjs +126 -60
- package/scripts/mcp-gateway-verify.mjs +24 -22
- package/scripts/mcp-safety-guard.mjs +44 -11
- package/scripts/notion-read.mjs +669 -554
- package/scripts/pack.mjs +94 -89
- package/scripts/preflight-cache.mjs +27 -10
- package/scripts/preinstall.mjs +42 -13
- package/scripts/remote-spawn.mjs +309 -94
- package/scripts/run.cjs +8 -5
- package/scripts/session-spawn-helper.mjs +130 -39
- package/scripts/session-stale-cleanup.mjs +123 -0
- package/scripts/setup.mjs +941 -492
- package/scripts/test-lock.mjs +20 -7
- package/scripts/test-tfx-route-no-claude-native.mjs +61 -57
- package/scripts/tfx-batch-stats.mjs +117 -96
- package/scripts/tfx-gate-activate.mjs +11 -4
- package/scripts/tfx-route-post.mjs +87 -20
- package/scripts/tfx-route-worker.mjs +57 -51
- package/scripts/tfx-route.sh +41 -124
- package/scripts/tmp-cleanup.mjs +21 -7
- package/scripts/token-snapshot.mjs +204 -85
- package/skills/.omc/state/idle-notif-cooldown.json +1 -1
- package/skills/.omc/state/last-tool-error.json +1 -1
- package/skills/.omc/state/subagent-tracking.json +1 -1
- package/skills/_templates/base.md +1 -6
- package/skills/merge-worktree/SKILL.md.tmpl +144 -0
- package/skills/shared/telemetry-segment.md +6 -0
- package/skills/star-prompt/SKILL.md.tmpl +222 -0
- package/skills/tfx-analysis/SKILL.md.tmpl +107 -0
- package/skills/tfx-analysis/skill.json +1 -6
- package/skills/tfx-auto/SKILL.md +1 -0
- package/skills/{tfx-workspace/skill-snapshot/tfx-auto-codex/SKILL.md → tfx-auto-codex/SKILL.md.tmpl} +33 -4
- package/skills/tfx-auto-codex/skill.json +1 -3
- package/skills/tfx-autopilot/SKILL.md.tmpl +116 -0
- package/skills/tfx-autopilot/skill.json +1 -5
- package/skills/tfx-autoresearch/SKILL.md.tmpl +136 -0
- package/skills/tfx-autoroute/SKILL.md.tmpl +189 -0
- package/skills/tfx-autoroute/skill.json +1 -7
- package/skills/tfx-codex/SKILL.md +1 -0
- package/skills/tfx-codex/skill.json +1 -3
- package/skills/tfx-codex-swarm/SKILL.md.tmpl +16 -0
- package/skills/tfx-codex-swarm/evals/evals.json +1 -1
- package/skills/tfx-codex-swarm/skill.json +1 -4
- package/skills/tfx-codex-swarm-workspace/iteration-1/benchmark.json +54 -12
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/with_skill/grading.json +35 -7
- package/skills/tfx-codex-swarm-workspace/iteration-1/full-swarm-all-prds/without_skill/grading.json +35 -7
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/with_skill/grading.json +25 -5
- package/skills/tfx-codex-swarm-workspace/iteration-1/implicit-swarm-no-keywords/without_skill/grading.json +25 -5
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/with_skill/grading.json +20 -4
- package/skills/tfx-codex-swarm-workspace/iteration-1/selective-spawn-with-override/without_skill/grading.json +16 -4
- package/skills/tfx-consensus/SKILL.md.tmpl +146 -0
- package/skills/tfx-debate/SKILL.md.tmpl +192 -0
- package/skills/tfx-debate/skill.json +1 -7
- package/skills/tfx-deep-analysis/SKILL.md.tmpl +228 -0
- package/skills/tfx-deep-analysis/skill.json +1 -5
- package/skills/tfx-deep-interview/SKILL.md.tmpl +203 -0
- package/skills/tfx-deep-plan/SKILL.md.tmpl +282 -0
- package/skills/tfx-deep-qa/SKILL.md.tmpl +165 -0
- package/skills/tfx-deep-qa/skill.json +1 -6
- package/skills/tfx-deep-research/SKILL.md.tmpl +217 -0
- package/skills/tfx-deep-review/SKILL.md.tmpl +179 -0
- package/skills/tfx-doctor/SKILL.md +21 -0
- package/skills/tfx-doctor/SKILL.md.tmpl +172 -0
- package/skills/tfx-doctor/skill.json +1 -3
- package/skills/tfx-find/SKILL.md +1 -0
- package/skills/tfx-forge/SKILL.md.tmpl +187 -0
- package/skills/tfx-fullcycle/SKILL.md.tmpl +286 -0
- package/skills/tfx-fullcycle/skill.json +1 -6
- package/skills/{tfx-workspace/skill-snapshot/tfx-gemini/SKILL.md → tfx-gemini/SKILL.md.tmpl} +16 -7
- package/skills/tfx-gemini/skill.json +1 -3
- package/skills/tfx-hooks/SKILL.md.tmpl +216 -0
- package/skills/tfx-hooks/skill.json +1 -3
- package/skills/tfx-hub/SKILL.md.tmpl +212 -0
- package/skills/tfx-hub/skill.json +1 -3
- package/skills/tfx-index/SKILL.md +1 -0
- package/skills/tfx-index/skill.json +1 -6
- package/skills/tfx-interview/SKILL.md.tmpl +285 -0
- package/skills/tfx-multi/SKILL.md.tmpl +183 -0
- package/skills/tfx-multi/skill.json +1 -3
- package/skills/tfx-panel/SKILL.md.tmpl +189 -0
- package/skills/tfx-panel/skill.json +1 -7
- package/skills/tfx-persist/SKILL.md.tmpl +270 -0
- package/skills/tfx-persist/skill.json +1 -7
- package/skills/tfx-plan/SKILL.md +1 -0
- package/skills/tfx-plan/skill.json +1 -6
- package/skills/tfx-profile/SKILL.md.tmpl +239 -0
- package/skills/tfx-profile/skill.json +1 -3
- package/skills/tfx-prune/SKILL.md.tmpl +200 -0
- package/skills/tfx-prune/skill.json +1 -7
- package/skills/tfx-psmux-rules/SKILL.md.tmpl +326 -0
- package/skills/tfx-psmux-rules/skill.json +1 -4
- package/skills/tfx-qa/SKILL.md +1 -0
- package/skills/tfx-qa/skill.json +1 -6
- package/skills/tfx-ralph/SKILL.md.tmpl +28 -0
- package/skills/tfx-ralph/skill.json +1 -4
- package/skills/tfx-remote-setup/SKILL.md.tmpl +576 -0
- package/skills/tfx-remote-setup/skill.json +1 -3
- package/skills/tfx-remote-spawn/SKILL.md.tmpl +263 -0
- package/skills/tfx-remote-spawn/references/hosts.json +16 -16
- package/skills/tfx-remote-spawn/skill.json +1 -4
- package/skills/tfx-research/SKILL.md +1 -0
- package/skills/tfx-review/SKILL.md +1 -0
- package/skills/tfx-review/skill.json +1 -6
- package/skills/tfx-setup/SKILL.md.tmpl +504 -0
- package/skills/tfx-setup/skill.json +1 -3
- package/skills/tfx-swarm/SKILL.md +22 -0
- package/skills/tfx-swarm/SKILL.md.tmpl +218 -0
- package/tui/codex-profile.mjs +457 -0
- package/tui/core.mjs +266 -0
- package/tui/doctor.mjs +375 -0
- package/tui/gemini-profile.mjs +299 -0
- package/tui/monitor-data.mjs +152 -0
- package/tui/monitor.mjs +339 -0
- package/tui/setup.mjs +533 -0
- package/CLAUDE.md +0 -193
- package/references/hosts.json +0 -33
- package/skills/tfx-workspace/async-tests/run-tests.sh +0 -203
- package/skills/tfx-workspace/evals/evals.json +0 -79
- package/skills/tfx-workspace/iteration-1/benchmark.json +0 -162
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/eval_metadata.json +0 -11
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/grading.json +0 -9
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/outputs/analysis.md +0 -154
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/old_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/grading.json +0 -9
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/outputs/analysis.md +0 -126
- package/skills/tfx-workspace/iteration-1/codex-gemini-remap/with_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/eval_metadata.json +0 -11
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/grading.json +0 -9
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/outputs/analysis.md +0 -119
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/old_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/grading.json +0 -9
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/outputs/analysis.md +0 -115
- package/skills/tfx-workspace/iteration-1/doctor-diagnosis/with_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/eval_metadata.json +0 -10
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/grading.json +0 -8
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/outputs/analysis.md +0 -86
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/old_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/grading.json +0 -8
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/outputs/analysis.md +0 -81
- package/skills/tfx-workspace/iteration-1/hub-start-sequence/with_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/multi-team-creation/eval_metadata.json +0 -12
- package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/grading.json +0 -10
- package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/outputs/analysis.md +0 -316
- package/skills/tfx-workspace/iteration-1/multi-team-creation/old_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/grading.json +0 -10
- package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/outputs/analysis.md +0 -352
- package/skills/tfx-workspace/iteration-1/multi-team-creation/with_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/review.html +0 -1325
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/eval_metadata.json +0 -12
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/grading.json +0 -10
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/outputs/analysis.md +0 -97
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/old_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/grading.json +0 -10
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/outputs/analysis.md +0 -94
- package/skills/tfx-workspace/iteration-1/routing-implement-shortcut/with_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/eval_metadata.json +0 -12
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/grading.json +0 -10
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/outputs/analysis.md +0 -209
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/old_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/grading.json +0 -10
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/outputs/analysis.md +0 -193
- package/skills/tfx-workspace/iteration-1/routing-multi-task-triage/with_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-2/benchmark.json +0 -62
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/eval_metadata.json +0 -13
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/grading.json +0 -11
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/outputs/analysis.md +0 -382
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/old_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/grading.json +0 -11
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/outputs/analysis.md +0 -333
- package/skills/tfx-workspace/iteration-2/multi-team-creation-refactored/with_skill/timing.json +0 -5
- package/skills/tfx-workspace/iteration-2/review.html +0 -1325
- package/skills/tfx-workspace/skill-snapshot/tfx-auto/SKILL.md +0 -217
- package/skills/tfx-workspace/skill-snapshot/tfx-codex/SKILL.md +0 -65
- package/skills/tfx-workspace/skill-snapshot/tfx-doctor/SKILL.md +0 -94
- package/skills/tfx-workspace/skill-snapshot/tfx-hub/SKILL.md +0 -133
- package/skills/tfx-workspace/skill-snapshot/tfx-multi/SKILL.md +0 -426
- package/skills/tfx-workspace/skill-snapshot/tfx-setup/SKILL.md +0 -101
package/scripts/notion-read.mjs
CHANGED
|
@@ -1,556 +1,671 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// notion-read.mjs v1.2 — Notion 대형 페이지 리더 (Codex/Gemini/Claude MCP 위임)
|
|
3
|
-
//
|
|
4
|
-
// Codex/Gemini/Claude CLI에 설치된 Notion MCP를 활용하여 대형 페이지를 마크다운으로 추출.
|
|
5
|
-
// 폴백 체인: Codex(무료) → Gemini(무료) → Claude(최후) → 에러
|
|
6
|
-
// 이관 모드(--delegate): Claude(notion-guest 우선) 단독 실행 + 결과 파일 저장
|
|
7
|
-
//
|
|
8
|
-
// 사용법:
|
|
9
|
-
// node notion-read.mjs <notion-url-or-page-id> [옵션]
|
|
10
|
-
// tfx notion-read <notion-url-or-page-id> [옵션]
|
|
11
|
-
//
|
|
12
|
-
// 옵션:
|
|
13
|
-
// --output, -o <file> 결과 파일 저장 (기본: stdout)
|
|
14
|
-
// --timeout, -t <sec> CLI 타임아웃 (기본: 600)
|
|
15
|
-
// --cli, -c <codex|gemini> CLI 강제 지정 (기본: 자동 + 폴백)
|
|
16
|
-
// --depth, -d <n> 중첩 블록 최대 깊이 (기본: 3)
|
|
17
|
-
// --guest notion-guest 통합 사용 (기본: notion)
|
|
18
|
-
// --delegate Claude 이관 모드 (notion-guest 우선, 파일 저장)
|
|
19
|
-
|
|
20
|
-
import { execSync } from
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
-
|
|
146
|
-
-
|
|
147
|
-
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
- 페이지
|
|
161
|
-
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// notion-read.mjs v1.2 — Notion 대형 페이지 리더 (Codex/Gemini/Claude MCP 위임)
|
|
3
|
+
//
|
|
4
|
+
// Codex/Gemini/Claude CLI에 설치된 Notion MCP를 활용하여 대형 페이지를 마크다운으로 추출.
|
|
5
|
+
// 폴백 체인: Codex(무료) → Gemini(무료) → Claude(최후) → 에러
|
|
6
|
+
// 이관 모드(--delegate): Claude(notion-guest 우선) 단독 실행 + 결과 파일 저장
|
|
7
|
+
//
|
|
8
|
+
// 사용법:
|
|
9
|
+
// node notion-read.mjs <notion-url-or-page-id> [옵션]
|
|
10
|
+
// tfx notion-read <notion-url-or-page-id> [옵션]
|
|
11
|
+
//
|
|
12
|
+
// 옵션:
|
|
13
|
+
// --output, -o <file> 결과 파일 저장 (기본: stdout)
|
|
14
|
+
// --timeout, -t <sec> CLI 타임아웃 (기본: 600)
|
|
15
|
+
// --cli, -c <codex|gemini> CLI 강제 지정 (기본: 자동 + 폴백)
|
|
16
|
+
// --depth, -d <n> 중첩 블록 최대 깊이 (기본: 3)
|
|
17
|
+
// --guest notion-guest 통합 사용 (기본: notion)
|
|
18
|
+
// --delegate Claude 이관 모드 (notion-guest 우선, 파일 저장)
|
|
19
|
+
|
|
20
|
+
import { execSync } from "child_process";
|
|
21
|
+
import {
|
|
22
|
+
appendFileSync,
|
|
23
|
+
existsSync,
|
|
24
|
+
mkdirSync,
|
|
25
|
+
readFileSync,
|
|
26
|
+
unlinkSync,
|
|
27
|
+
writeFileSync,
|
|
28
|
+
} from "fs";
|
|
29
|
+
import { homedir, tmpdir } from "os";
|
|
30
|
+
import { dirname, join, resolve } from "path";
|
|
31
|
+
|
|
32
|
+
import { buildExecArgs } from "../hub/codex-adapter.mjs";
|
|
33
|
+
|
|
34
|
+
const VERSION = "1.2";
|
|
35
|
+
const CLAUDE_DIR = join(homedir(), ".claude");
|
|
36
|
+
const MCP_CACHE = join(CLAUDE_DIR, "cache", "mcp-inventory.json");
|
|
37
|
+
const LOG_FILE = join(CLAUDE_DIR, "logs", "tfx-route-stats.jsonl");
|
|
38
|
+
const _ACC_FILE = join(CLAUDE_DIR, "cache", "sv-accumulator.json");
|
|
39
|
+
|
|
40
|
+
// ── ANSI 색상 ──
|
|
41
|
+
const AMBER = "\x1b[38;5;214m";
|
|
42
|
+
const GREEN = "\x1b[38;5;82m";
|
|
43
|
+
const RED = "\x1b[38;5;196m";
|
|
44
|
+
const YELLOW = "\x1b[33m";
|
|
45
|
+
const DIM = "\x1b[2m";
|
|
46
|
+
const BOLD = "\x1b[1m";
|
|
47
|
+
const RESET = "\x1b[0m";
|
|
48
|
+
const GRAY = "\x1b[38;5;245m";
|
|
49
|
+
|
|
50
|
+
// ── URL 파싱 ──
|
|
51
|
+
function parseNotionUrl(input) {
|
|
52
|
+
// 32자리 hex (하이픈 없는 page_id)
|
|
53
|
+
if (/^[a-f0-9]{32}$/i.test(input)) {
|
|
54
|
+
return { pageId: input, blockId: null };
|
|
55
|
+
}
|
|
56
|
+
// UUID 형식
|
|
57
|
+
if (
|
|
58
|
+
/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(
|
|
59
|
+
input,
|
|
60
|
+
)
|
|
61
|
+
) {
|
|
62
|
+
return { pageId: input.replace(/-/g, ""), blockId: null };
|
|
63
|
+
}
|
|
64
|
+
// URL에서 page_id + optional #block_id 추출
|
|
65
|
+
const urlMatch = input.match(/([a-f0-9]{32})(?:#([a-f0-9]{32}))?/i);
|
|
66
|
+
if (urlMatch) {
|
|
67
|
+
return { pageId: urlMatch[1], blockId: urlMatch[2] || null };
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ── MCP 가용성 확인 ──
|
|
73
|
+
function getNotionMcpClis(useGuest) {
|
|
74
|
+
const serverName = useGuest ? "notion-guest" : "notion";
|
|
75
|
+
const result = { codex: false, gemini: false };
|
|
76
|
+
|
|
77
|
+
if (!existsSync(MCP_CACHE)) return result;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const inv = JSON.parse(readFileSync(MCP_CACHE, "utf8"));
|
|
81
|
+
|
|
82
|
+
if (inv.codex?.servers) {
|
|
83
|
+
result.codex = inv.codex.servers.some(
|
|
84
|
+
(s) =>
|
|
85
|
+
s.name === serverName &&
|
|
86
|
+
(s.status === "enabled" || s.status === "configured"),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (inv.gemini?.servers) {
|
|
90
|
+
result.gemini = inv.gemini.servers.some(
|
|
91
|
+
(s) =>
|
|
92
|
+
s.name === serverName &&
|
|
93
|
+
(s.status === "enabled" || s.status === "configured"),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
} catch {}
|
|
97
|
+
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ── CLI 존재 확인 ──
|
|
102
|
+
function cliExists(name) {
|
|
103
|
+
try {
|
|
104
|
+
const cmd =
|
|
105
|
+
process.platform === "win32"
|
|
106
|
+
? `where ${name} 2>nul`
|
|
107
|
+
: `which ${name} 2>/dev/null`;
|
|
108
|
+
const result = execSync(cmd, {
|
|
109
|
+
encoding: "utf8",
|
|
110
|
+
timeout: 5000,
|
|
111
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
112
|
+
windowsHide: true,
|
|
113
|
+
});
|
|
114
|
+
return !!result.trim();
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ── 프롬프트 생성 ──
|
|
121
|
+
function buildPrompt(pageId, blockId, depth, useGuest, includeComments) {
|
|
122
|
+
const mcpServer = useGuest ? "notion-guest" : "notion";
|
|
123
|
+
const targetBlock = blockId || pageId;
|
|
124
|
+
const blockNote = blockId
|
|
125
|
+
? `\n시작 블록: ${blockId} — 이 블록과 그 하위 블록만 읽어라.`
|
|
126
|
+
: "";
|
|
127
|
+
|
|
128
|
+
return `Notion 페이지를 마크다운으로 추출하라.
|
|
129
|
+
|
|
130
|
+
페이지 ID: ${pageId}${blockNote}
|
|
131
|
+
|
|
132
|
+
## 실행 지침
|
|
133
|
+
|
|
134
|
+
${mcpServer} MCP 서버의 도구를 사용하라.
|
|
135
|
+
|
|
136
|
+
### 1단계: 페이지 메타데이터
|
|
137
|
+
페이지 조회 도구를 호출하라 (page_id: "${pageId}").
|
|
138
|
+
제목과 주요 속성을 기록하라.
|
|
139
|
+
404 에러가 나면 ${useGuest ? "notion" : "notion-guest"} 서버로 재시도하라.
|
|
140
|
+
|
|
141
|
+
### 2단계: 블록 읽기 (페이지네이션 필수)
|
|
142
|
+
블록 자식 조회 도구를 호출하라 (block_id: "${targetBlock}", page_size: 100).
|
|
143
|
+
|
|
144
|
+
**페이지네이션 — 반드시 수행:**
|
|
145
|
+
- 응답의 has_more가 true이면, next_cursor를 start_cursor로 전달하여 반복 호출.
|
|
146
|
+
- has_more가 false가 될 때까지 계속 반복. 대형 페이지는 5-10회 이상 필요.
|
|
147
|
+
- 절대 첫 페이지만 읽고 멈추지 마라.
|
|
148
|
+
|
|
149
|
+
### 3단계: 중첩 블록 재귀
|
|
150
|
+
각 블록의 has_children이 true이면, 해당 block_id로 블록 자식 조회를 재귀 호출.
|
|
151
|
+
최대 깊이: ${depth}단계. 깊이 초과 시 "[깊이 초과]" 표시.
|
|
152
|
+
|
|
153
|
+
### 4단계: 댓글 수집${
|
|
154
|
+
includeComments
|
|
155
|
+
? `
|
|
156
|
+
페이지 및 블록 댓글을 수집하라.
|
|
157
|
+
- 댓글 조회 도구를 호출하라 (block_id: "${pageId}")로 페이지 전체 댓글을 가져와라.
|
|
158
|
+
- 응답의 has_more가 true이면 next_cursor로 반복.
|
|
159
|
+
- 각 댓글의 parent.type이 "block_id"이면 해당 블록의 인라인 댓글이다.
|
|
160
|
+
- parent.type이 "page_id"이면 페이지 레벨 토론 댓글이다.
|
|
161
|
+
- 404 에러 발생 시 댓글 권한이 없는 것이므로 건너뛰어라.`
|
|
162
|
+
: `
|
|
163
|
+
댓글 수집을 건너뛴다 (--comments 플래그 미지정).`
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
### 5단계: 마크다운 변환
|
|
167
|
+
- heading_1/2/3 → #/##/###
|
|
168
|
+
- paragraph → rich_text의 plain_text 연결
|
|
169
|
+
- bulleted_list_item → - 항목
|
|
170
|
+
- numbered_list_item → 1. 항목
|
|
171
|
+
- to_do → - [ ] 또는 - [x]
|
|
172
|
+
- toggle → **제목** + 하위 내용 들여쓰기
|
|
173
|
+
- code → \`\`\`언어 + 코드 + \`\`\`
|
|
174
|
+
- quote → > 인용
|
|
175
|
+
- callout → > 콜아웃
|
|
176
|
+
- table + table_row → 마크다운 테이블 (| 헤더 | ... |)
|
|
177
|
+
- image → 
|
|
178
|
+
- bookmark → [북마크](url)
|
|
179
|
+
- divider → ---
|
|
180
|
+
- column_list/column → 순서대로 출력
|
|
181
|
+
- child_page → [하위 페이지: 제목]
|
|
182
|
+
- child_database → [하위 DB: 제목]
|
|
183
|
+
- synced_block → 원본 내용 출력
|
|
184
|
+
- 기타 → [블록타입: 지원안됨]
|
|
185
|
+
|
|
186
|
+
### 출력 규칙
|
|
187
|
+
- 페이지 제목을 # 헤더로 시작
|
|
188
|
+
- 모든 블록을 빠짐없이 순서대로 출력
|
|
189
|
+
- 읽기 실패 블록은 <!-- 읽기 실패: block_id --> 주석 남기기
|
|
190
|
+
- rich_text의 annotations (bold, italic, code, strikethrough) 반영
|
|
191
|
+
- 링크는 [텍스트](url) 형식${
|
|
192
|
+
includeComments
|
|
193
|
+
? `
|
|
194
|
+
- 블록 인라인 댓글: 해당 블록 바로 아래에 > **[댓글]** @작성자: 내용 형식으로 삽입
|
|
195
|
+
- 페이지 토론 댓글: 문서 맨 끝에 ## 토론 섹션으로 모아서 출력
|
|
196
|
+
- 댓글의 rich_text도 마크다운으로 변환`
|
|
197
|
+
: ""
|
|
198
|
+
}
|
|
199
|
+
- 최종 결과만 출력 — 중간 과정 설명 불필요`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ── CLI 실행 (임시 파일 + execSync — Windows .cmd 호환) ──
|
|
203
|
+
function runWithCli(cliType, prompt, timeout, runMode = "fg") {
|
|
204
|
+
const cliName =
|
|
205
|
+
cliType === "claude" ? "claude" : cliType === "codex" ? "codex" : "gemini";
|
|
206
|
+
if (!cliExists(cliName)) {
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
output: "",
|
|
210
|
+
error: `${cliType} CLI 미설치`,
|
|
211
|
+
cli: cliType,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 프롬프트를 임시 파일에 저장 (shell escaping 회피)
|
|
216
|
+
const promptFile = join(tmpdir(), `notion-prompt-${Date.now()}.md`);
|
|
217
|
+
writeFileSync(promptFile, prompt, "utf8");
|
|
218
|
+
const promptPath = promptFile.replace(/\\/g, "/");
|
|
219
|
+
|
|
220
|
+
// CLI에 전달할 짧은 메타 프롬프트
|
|
221
|
+
const metaPrompt = `Read the file at ${promptPath} and execute all instructions in it exactly as described. Output only the final markdown result.`;
|
|
222
|
+
|
|
223
|
+
let cmd;
|
|
224
|
+
if (cliType === "codex") {
|
|
188
225
|
cmd = buildExecArgs({ prompt: metaPrompt });
|
|
189
|
-
} else if (cliType ===
|
|
190
|
-
cmd = `gemini -m gemini-3-flash-preview -y --allowed-mcp-server-names notion,notion-guest --prompt "${metaPrompt}"`;
|
|
191
|
-
} else {
|
|
192
|
-
// Claude CLI — print 모드 (MCP 도구 자동 접근)
|
|
193
|
-
cmd = `claude -p "${metaPrompt}"`;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
console.error(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
let
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
${
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
tfx notion-read
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
case
|
|
368
|
-
|
|
369
|
-
break;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
- notion-guest
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
226
|
+
} else if (cliType === "gemini") {
|
|
227
|
+
cmd = `gemini -m gemini-3-flash-preview -y --allowed-mcp-server-names notion,notion-guest --prompt "${metaPrompt}"`;
|
|
228
|
+
} else {
|
|
229
|
+
// Claude CLI — print 모드 (MCP 도구 자동 접근)
|
|
230
|
+
cmd = `claude -p "${metaPrompt}"`;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
console.error(
|
|
234
|
+
`${AMBER}▸${RESET} ${cliType}로 실행 중... (timeout: ${timeout}s)`,
|
|
235
|
+
);
|
|
236
|
+
const startTime = Date.now();
|
|
237
|
+
|
|
238
|
+
let stdout = "";
|
|
239
|
+
let stderr = "";
|
|
240
|
+
let exitCode = 0;
|
|
241
|
+
|
|
242
|
+
try {
|
|
243
|
+
stdout = execSync(cmd, {
|
|
244
|
+
encoding: "utf8",
|
|
245
|
+
timeout: (timeout + 30) * 1000,
|
|
246
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
247
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
248
|
+
cwd: process.cwd(),
|
|
249
|
+
windowsHide: true,
|
|
250
|
+
});
|
|
251
|
+
} catch (e) {
|
|
252
|
+
exitCode = e.status || (e.killed ? 124 : 1);
|
|
253
|
+
stdout = e.stdout || "";
|
|
254
|
+
stderr = e.stderr || "";
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const elapsed = Math.round((Date.now() - startTime) / 1000);
|
|
258
|
+
|
|
259
|
+
// 임시 파일 정리
|
|
260
|
+
try {
|
|
261
|
+
unlinkSync(promptFile);
|
|
262
|
+
} catch {}
|
|
263
|
+
|
|
264
|
+
// 실행 로그 기록
|
|
265
|
+
logExecution(cliType, exitCode, elapsed, timeout, stderr, runMode);
|
|
266
|
+
|
|
267
|
+
if (exitCode === 0 && stdout) {
|
|
268
|
+
return { success: true, output: stdout, cli: cliType, elapsed };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const isTimeout = exitCode === 124;
|
|
272
|
+
return {
|
|
273
|
+
success: false,
|
|
274
|
+
output: stdout,
|
|
275
|
+
error: isTimeout ? `timeout (${timeout}s)` : `exit ${exitCode}`,
|
|
276
|
+
stderr: stderr.slice(-500),
|
|
277
|
+
cli: cliType,
|
|
278
|
+
elapsed,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ── Codex JSON-line 출력 정리 ──
|
|
283
|
+
function cleanCodexOutput(raw) {
|
|
284
|
+
const lines = raw.split(/\r?\n/);
|
|
285
|
+
const texts = [];
|
|
286
|
+
|
|
287
|
+
for (const line of lines) {
|
|
288
|
+
const trimmed = line.trim();
|
|
289
|
+
if (!trimmed) continue;
|
|
290
|
+
|
|
291
|
+
// JSON-line 형식이면 파싱
|
|
292
|
+
if (trimmed.startsWith("{")) {
|
|
293
|
+
try {
|
|
294
|
+
const obj = JSON.parse(trimmed);
|
|
295
|
+
if (["message", "completed", "output_text"].includes(obj.type)) {
|
|
296
|
+
const text = obj.text || obj.content || obj.output || "";
|
|
297
|
+
if (text) texts.push(text);
|
|
298
|
+
}
|
|
299
|
+
continue;
|
|
300
|
+
} catch {
|
|
301
|
+
// JSON 파싱 실패 → 일반 텍스트로 처리
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
texts.push(line);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return texts.join("\n");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ── 실행 로그 (tfx-route.sh 호환) ──
|
|
312
|
+
function logExecution(
|
|
313
|
+
cliType,
|
|
314
|
+
exitCode,
|
|
315
|
+
elapsed,
|
|
316
|
+
timeout,
|
|
317
|
+
stderr,
|
|
318
|
+
runMode = "fg",
|
|
319
|
+
) {
|
|
320
|
+
try {
|
|
321
|
+
const logDir = dirname(LOG_FILE);
|
|
322
|
+
if (!existsSync(logDir)) mkdirSync(logDir, { recursive: true });
|
|
323
|
+
|
|
324
|
+
const ts = new Date().toISOString();
|
|
325
|
+
const status =
|
|
326
|
+
exitCode === 0 ? "success" : exitCode === 124 ? "timeout" : "failed";
|
|
327
|
+
const entry = JSON.stringify({
|
|
328
|
+
ts,
|
|
329
|
+
agent: "notion-read",
|
|
330
|
+
cli: cliType,
|
|
331
|
+
effort:
|
|
332
|
+
cliType === "codex"
|
|
333
|
+
? "high"
|
|
334
|
+
: cliType === "claude"
|
|
335
|
+
? "sonnet"
|
|
336
|
+
: "flash",
|
|
337
|
+
run_mode: runMode,
|
|
338
|
+
opus_oversight: "false",
|
|
339
|
+
status,
|
|
340
|
+
exit_code: exitCode,
|
|
341
|
+
elapsed_sec: elapsed,
|
|
342
|
+
timeout_sec: timeout,
|
|
343
|
+
mcp_profile: runMode === "delegate" ? "notion-guest" : "notion",
|
|
344
|
+
input_tokens: 0,
|
|
345
|
+
output_tokens: 0,
|
|
346
|
+
total_tokens: 0,
|
|
347
|
+
});
|
|
348
|
+
appendFileSync(LOG_FILE, entry + "\n");
|
|
349
|
+
} catch {}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// ── 메인 ──
|
|
353
|
+
function main() {
|
|
354
|
+
const args = process.argv.slice(2);
|
|
355
|
+
|
|
356
|
+
if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
|
|
357
|
+
console.log(`
|
|
358
|
+
${AMBER}${BOLD}notion-read${RESET} ${DIM}v${VERSION}${RESET}
|
|
359
|
+
${GRAY}Notion 대형 페이지 리더 — Codex/Gemini MCP 위임${RESET}
|
|
360
|
+
|
|
361
|
+
${BOLD}사용법${RESET}
|
|
362
|
+
tfx notion-read <notion-url-or-page-id> [옵션]
|
|
363
|
+
|
|
364
|
+
${BOLD}옵션${RESET}
|
|
365
|
+
--output, -o <file> 결과 파일 저장 (기본: stdout)
|
|
366
|
+
--timeout, -t <sec> CLI 타임아웃 (기본: 600)
|
|
367
|
+
--cli, -c <codex|gemini|claude> CLI 강제 지정 (기본: 자동 + 폴백)
|
|
368
|
+
--depth, -d <n> 중첩 블록 최대 깊이 (기본: 3)
|
|
369
|
+
--comments 블록/페이지 댓글 포함
|
|
370
|
+
--guest notion-guest 통합 사용
|
|
371
|
+
--delegate Claude 이관 모드 (notion-guest 우선, 파일 저장)
|
|
372
|
+
|
|
373
|
+
${BOLD}폴백 체인${RESET}
|
|
374
|
+
Codex(무료) → Gemini(무료) → Claude(최후) → 에러
|
|
375
|
+
|
|
376
|
+
${BOLD}예시${RESET}
|
|
377
|
+
tfx notion-read https://notion.so/Page-abc123def456...
|
|
378
|
+
tfx notion-read abc123def456... --output page.md --comments
|
|
379
|
+
tfx notion-read abc123def456... --cli gemini --timeout 900
|
|
380
|
+
tfx notion-read abc123def456... --guest --comments
|
|
381
|
+
tfx notion-read abc123def456... --delegate
|
|
382
|
+
tfx notion-read abc123def456... --delegate --output .notion-cache/page.md
|
|
383
|
+
`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 인자 파싱
|
|
388
|
+
const input = args[0];
|
|
389
|
+
let outputFile = null;
|
|
390
|
+
let timeout = 600;
|
|
391
|
+
let forceCli = null;
|
|
392
|
+
let depth = 3;
|
|
393
|
+
let useGuest = false;
|
|
394
|
+
let includeComments = false;
|
|
395
|
+
let delegateMode = false;
|
|
396
|
+
|
|
397
|
+
for (let i = 1; i < args.length; i++) {
|
|
398
|
+
switch (args[i]) {
|
|
399
|
+
case "--output":
|
|
400
|
+
case "-o":
|
|
401
|
+
outputFile = args[++i];
|
|
402
|
+
break;
|
|
403
|
+
case "--timeout":
|
|
404
|
+
case "-t":
|
|
405
|
+
timeout = parseInt(args[++i], 10) || 600;
|
|
406
|
+
break;
|
|
407
|
+
case "--cli":
|
|
408
|
+
case "-c":
|
|
409
|
+
forceCli = args[++i];
|
|
410
|
+
break;
|
|
411
|
+
case "--depth":
|
|
412
|
+
case "-d":
|
|
413
|
+
depth = parseInt(args[++i], 10) || 3;
|
|
414
|
+
break;
|
|
415
|
+
case "--guest":
|
|
416
|
+
useGuest = true;
|
|
417
|
+
break;
|
|
418
|
+
case "--comments":
|
|
419
|
+
includeComments = true;
|
|
420
|
+
break;
|
|
421
|
+
case "--delegate":
|
|
422
|
+
delegateMode = true;
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// URL 파싱
|
|
428
|
+
const parsed = parseNotionUrl(input);
|
|
429
|
+
if (!parsed) {
|
|
430
|
+
console.error(`${RED}✗${RESET} 유효하지 않은 Notion URL/ID: ${input}`);
|
|
431
|
+
process.exit(1);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
console.error(
|
|
435
|
+
`${AMBER}▸${RESET} 페이지: ${parsed.pageId}${parsed.blockId ? ` (블록: ${parsed.blockId})` : ""}`,
|
|
436
|
+
);
|
|
437
|
+
console.error(
|
|
438
|
+
`${GRAY} 통합: ${delegateMode ? "notion-guest(우선)" : useGuest ? "notion-guest" : "notion"} | 깊이: ${depth} | 댓글: ${includeComments ? "O" : "X"} | 타임아웃: ${timeout}s${RESET}`,
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
// 프롬프트 생성
|
|
442
|
+
const prompt = buildPrompt(
|
|
443
|
+
parsed.pageId,
|
|
444
|
+
parsed.blockId,
|
|
445
|
+
depth,
|
|
446
|
+
useGuest,
|
|
447
|
+
includeComments,
|
|
448
|
+
);
|
|
449
|
+
// Claude 폴백용: notion/notion-guest 양쪽 시도 프롬프트
|
|
450
|
+
const claudePrompt = buildPrompt(
|
|
451
|
+
parsed.pageId,
|
|
452
|
+
parsed.blockId,
|
|
453
|
+
depth,
|
|
454
|
+
false,
|
|
455
|
+
includeComments,
|
|
456
|
+
).replace(
|
|
457
|
+
"notion MCP 서버의 도구를 사용하라.",
|
|
458
|
+
"가능하면 notion-guest MCP 서버를 먼저 사용하라. 실패하면 notion MCP 서버를 사용하라.",
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
// delegate 모드: Claude 단독 + notion-guest 우선 + 파일 저장
|
|
462
|
+
if (delegateMode) {
|
|
463
|
+
console.error(
|
|
464
|
+
`${AMBER}▸${RESET} delegate 모드 활성화: Claude로 notion-guest 우선 접근`,
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
const delegatePrompt = `${claudePrompt}
|
|
468
|
+
|
|
469
|
+
### delegate 모드 추가 지시
|
|
470
|
+
- notion-guest MCP 서버를 최우선으로 먼저 시도하라.
|
|
471
|
+
- notion-guest가 실패하거나 미구성일 때만 notion 서버로 폴백하라.
|
|
472
|
+
- 도구 호출 결과를 바탕으로 최종 마크다운만 출력하라.`;
|
|
473
|
+
|
|
474
|
+
const delegateResult = runWithCli(
|
|
475
|
+
"claude",
|
|
476
|
+
delegatePrompt,
|
|
477
|
+
timeout,
|
|
478
|
+
"delegate",
|
|
479
|
+
);
|
|
480
|
+
if (!delegateResult.success) {
|
|
481
|
+
console.error(
|
|
482
|
+
`${RED}✗${RESET} delegate 모드 실패: ${delegateResult.error}`,
|
|
483
|
+
);
|
|
484
|
+
if (delegateResult.stderr) {
|
|
485
|
+
console.error(
|
|
486
|
+
`${GRAY} stderr: ${delegateResult.stderr.slice(0, 250)}${RESET}`,
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
console.error(
|
|
490
|
+
`${GRAY} 대안: --delegate 없이 실행해 기존 폴백 체인을 사용하세요.${RESET}`,
|
|
491
|
+
);
|
|
492
|
+
console.error(
|
|
493
|
+
`${GRAY} 예: tfx notion-read ${parsed.pageId} --comments${RESET}`,
|
|
494
|
+
);
|
|
495
|
+
process.exit(1);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const delegateOutput = delegateResult.output.trim();
|
|
499
|
+
const isDelegateFailureOutput =
|
|
500
|
+
(delegateOutput.includes("조회 실패") ||
|
|
501
|
+
delegateOutput.includes("읽기 실패") ||
|
|
502
|
+
delegateOutput.includes("not_found")) &&
|
|
503
|
+
delegateOutput.length < 500;
|
|
504
|
+
|
|
505
|
+
if (delegateOutput.length <= 100 || isDelegateFailureOutput) {
|
|
506
|
+
console.error(
|
|
507
|
+
`${RED}✗${RESET} delegate 모드 실패: Claude 결과가 비정상적입니다.`,
|
|
508
|
+
);
|
|
509
|
+
console.error(
|
|
510
|
+
`${GRAY} 대안: --delegate 없이 실행해 Codex/Gemini/Claude 폴백 체인을 사용하세요.${RESET}`,
|
|
511
|
+
);
|
|
512
|
+
process.exit(1);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const delegateTarget =
|
|
516
|
+
outputFile || join(".notion-cache", `${parsed.pageId}.md`);
|
|
517
|
+
const delegateDir = dirname(delegateTarget);
|
|
518
|
+
if (delegateDir && delegateDir !== "." && !existsSync(delegateDir)) {
|
|
519
|
+
mkdirSync(delegateDir, { recursive: true });
|
|
520
|
+
}
|
|
521
|
+
writeFileSync(delegateTarget, delegateOutput, "utf8");
|
|
522
|
+
|
|
523
|
+
const savedPath = resolve(delegateTarget);
|
|
524
|
+
console.error(`${GREEN}✓${RESET} delegate 결과 저장: ${savedPath}`);
|
|
525
|
+
console.error(`${GRAY} 후속 작업 참조 경로: ${savedPath}${RESET}`);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// MCP 가용성 확인
|
|
530
|
+
const mcpAvail = getNotionMcpClis(useGuest);
|
|
531
|
+
console.error(
|
|
532
|
+
`${GRAY} MCP: codex=${mcpAvail.codex ? "O" : "X"} gemini=${mcpAvail.gemini ? "O" : "X"}${RESET}`,
|
|
533
|
+
);
|
|
534
|
+
|
|
535
|
+
// MCP 미설치 안내
|
|
536
|
+
if (!mcpAvail.codex && !mcpAvail.gemini) {
|
|
537
|
+
console.error(`${YELLOW}!${RESET} Codex/Gemini에 Notion MCP 미설치.`);
|
|
538
|
+
console.error(`${GRAY} Codex: codex mcp add notion${RESET}`);
|
|
539
|
+
console.error(
|
|
540
|
+
`${GRAY} Gemini: ~/.gemini/settings.json에 notion 서버 추가${RESET}`,
|
|
541
|
+
);
|
|
542
|
+
console.error(`${GRAY} 설치 후 tfx doctor --reset으로 캐시 갱신${RESET}`);
|
|
543
|
+
} else if (!mcpAvail.codex) {
|
|
544
|
+
console.error(
|
|
545
|
+
`${GRAY} Codex에 Notion MCP 미설치: codex mcp add notion${RESET}`,
|
|
546
|
+
);
|
|
547
|
+
} else if (!mcpAvail.gemini) {
|
|
548
|
+
console.error(
|
|
549
|
+
`${GRAY} Gemini에 Notion MCP 미설치: ~/.gemini/settings.json 확인${RESET}`,
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// CLI 실행 순서 결정 (Codex → Gemini → Claude)
|
|
554
|
+
let cliOrder;
|
|
555
|
+
if (forceCli) {
|
|
556
|
+
cliOrder = [forceCli];
|
|
557
|
+
} else {
|
|
558
|
+
cliOrder = [];
|
|
559
|
+
if (mcpAvail.codex) cliOrder.push("codex");
|
|
560
|
+
if (mcpAvail.gemini) cliOrder.push("gemini");
|
|
561
|
+
// Claude는 항상 최종 폴백 (자체 Notion MCP — notion-guest 포함)
|
|
562
|
+
cliOrder.push("claude");
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// 실행 + 폴백
|
|
566
|
+
let lastResult = null;
|
|
567
|
+
let notionAccessFailed = false;
|
|
568
|
+
|
|
569
|
+
for (const cli of cliOrder) {
|
|
570
|
+
const currentPrompt = cli === "claude" ? claudePrompt : prompt;
|
|
571
|
+
const result = runWithCli(cli, currentPrompt, timeout);
|
|
572
|
+
lastResult = result;
|
|
573
|
+
|
|
574
|
+
if (result.success) {
|
|
575
|
+
// Codex JSON-line 출력 정리
|
|
576
|
+
let output =
|
|
577
|
+
cli === "codex" ? cleanCodexOutput(result.output) : result.output;
|
|
578
|
+
output = output.trim();
|
|
579
|
+
|
|
580
|
+
// 실패 마커 감지 (404, 접근 실패 등)
|
|
581
|
+
const isFailureOutput =
|
|
582
|
+
(output.includes("조회 실패") ||
|
|
583
|
+
output.includes("읽기 실패") ||
|
|
584
|
+
output.includes("not_found")) &&
|
|
585
|
+
output.length < 500;
|
|
586
|
+
|
|
587
|
+
if (output.length > 100 && !isFailureOutput) {
|
|
588
|
+
console.error(
|
|
589
|
+
`${GREEN}✓${RESET} ${cli}로 성공 (${output.length} chars, ${result.elapsed}s)`,
|
|
590
|
+
);
|
|
591
|
+
|
|
592
|
+
if (outputFile) {
|
|
593
|
+
const outDir = dirname(outputFile);
|
|
594
|
+
if (outDir && outDir !== "." && !existsSync(outDir)) {
|
|
595
|
+
mkdirSync(outDir, { recursive: true });
|
|
596
|
+
}
|
|
597
|
+
writeFileSync(outputFile, output, "utf8");
|
|
598
|
+
console.error(`${GREEN}✓${RESET} 저장: ${outputFile}`);
|
|
599
|
+
} else {
|
|
600
|
+
console.log(output);
|
|
601
|
+
}
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// 404 접근 실패 감지
|
|
606
|
+
if (isFailureOutput) {
|
|
607
|
+
notionAccessFailed = true;
|
|
608
|
+
console.error(
|
|
609
|
+
`${YELLOW}!${RESET} ${cli}: Notion 접근 실패 (404) — 폴백`,
|
|
610
|
+
);
|
|
611
|
+
if (!useGuest && cli !== "claude") {
|
|
612
|
+
console.error(
|
|
613
|
+
`${GRAY} --guest 플래그로 notion-guest 통합 시도 가능${RESET}`,
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
} else {
|
|
617
|
+
console.error(
|
|
618
|
+
`${YELLOW}!${RESET} ${cli}: 출력 부족 (${output.length} chars) — 폴백`,
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
} else {
|
|
622
|
+
console.error(`${YELLOW}!${RESET} ${cli} 실패: ${result.error}`);
|
|
623
|
+
if (result.stderr) {
|
|
624
|
+
console.error(
|
|
625
|
+
`${GRAY} stderr: ${result.stderr.slice(0, 200)}${RESET}`,
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// 다음 CLI로 폴백
|
|
631
|
+
const idx = cliOrder.indexOf(cli);
|
|
632
|
+
if (idx < cliOrder.length - 1) {
|
|
633
|
+
const next = cliOrder[idx + 1];
|
|
634
|
+
console.error(`${AMBER}▸${RESET} ${next}로 폴백 시도...`);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// 전체 실패
|
|
639
|
+
console.error(`${RED}✗${RESET} 모든 CLI 실패`);
|
|
640
|
+
if (notionAccessFailed) {
|
|
641
|
+
console.error(`${YELLOW}!${RESET} Notion 페이지 접근 권한 문제.`);
|
|
642
|
+
console.error(
|
|
643
|
+
`${GRAY} 1. Notion에서 페이지 → ... → 연결(Connections)에서 통합 추가${RESET}`,
|
|
644
|
+
);
|
|
645
|
+
console.error(
|
|
646
|
+
`${GRAY} 2. --guest 플래그로 notion-guest 통합 시도${RESET}`,
|
|
647
|
+
);
|
|
648
|
+
console.error(
|
|
649
|
+
`${GRAY} 3. --cli claude로 Claude 직접 사용 (Claude에 접근 권한 있는 경우)${RESET}`,
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// 부분 결과라도 출력
|
|
654
|
+
if (lastResult?.output) {
|
|
655
|
+
const partial = lastResult.output.trim();
|
|
656
|
+
if (partial.length > 10) {
|
|
657
|
+
const cleaned =
|
|
658
|
+
lastResult.cli === "codex" ? cleanCodexOutput(partial) : partial;
|
|
659
|
+
if (outputFile) {
|
|
660
|
+
writeFileSync(outputFile, cleaned, "utf8");
|
|
661
|
+
console.error(`${YELLOW}!${RESET} 부분 결과 저장: ${outputFile}`);
|
|
662
|
+
} else {
|
|
663
|
+
console.log(cleaned);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
process.exit(1);
|
|
669
|
+
}
|
|
670
|
+
|
|
556
671
|
main();
|