dream-wf 0.1.2 → 0.1.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dream-wf",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Trellis workflow patch installer and MCP/skill aggregator for Cursor, Claude Code, OpenCode and Codex.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli/index.js CHANGED
@@ -280,7 +280,7 @@ function formatBanner() {
280
280
  "██║ ██║██╔═══██╗ ██╔════╝ ██╔═══██╗ ██║╚██╔╝██║",
281
281
  "███████╔╝ ██║ ██║ ███████╗ ██║ ██║ ██║ ╚═╝ ██║",
282
282
  "╚══════╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝",
283
- " Dream WorkFlow v0.1.2",
283
+ " Dream WorkFlow v0.1.3",
284
284
  ].join("\n");
285
285
 
286
286
  if (!process.stdout.isTTY || process.env.NO_COLOR) {
@@ -292,7 +292,7 @@ function formatBanner() {
292
292
 
293
293
  function helpText() {
294
294
  return [
295
- "dream-wf v0.1.2 · Trellis workflow 安装聚合器",
295
+ "dream-wf v0.1.3 · Trellis workflow 安装聚合器",
296
296
  "",
297
297
  "Usage:",
298
298
  " dream-wf # 交互式 TUI(推荐)",
@@ -5,6 +5,9 @@ import { writeIfChanged } from '../../lib/files.js';
5
5
  import { installCommonDreamWfFiles, installManagedBlock, installSelectedSkills } from '../shared.js';
6
6
  import { installMcpServers } from '../../lib/mcp.js';
7
7
 
8
+ const CLAUDE_GUARD_COMMAND = 'python3 -X utf8 .claude/hooks/dream-wf-guard.py';
9
+ const LEGACY_CLAUDE_GUARD_COMMAND = 'python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/dream-wf-guard.py"';
10
+
8
11
  export async function installClaudeCode(packageRoot, targetRoot, options) {
9
12
  const results = [];
10
13
 
@@ -39,16 +42,18 @@ async function mergeClaudeSettings(rootDir) {
39
42
  settings.hooks = settings.hooks ?? {};
40
43
  settings.hooks.PreToolUse = settings.hooks.PreToolUse ?? [];
41
44
 
42
- const changed = pushUniqueByCommand(settings.hooks.PreToolUse, {
45
+ const migrated = replaceHookCommand(settings.hooks.PreToolUse, LEGACY_CLAUDE_GUARD_COMMAND, CLAUDE_GUARD_COMMAND);
46
+ const added = pushUniqueByCommand(settings.hooks.PreToolUse, {
43
47
  matcher: '*',
44
48
  hooks: [
45
49
  {
46
50
  type: 'command',
47
- command: 'python3 "$CLAUDE_PROJECT_DIR/.claude/hooks/dream-wf-guard.py"',
51
+ command: CLAUDE_GUARD_COMMAND,
48
52
  timeout: 10
49
53
  }
50
54
  ]
51
55
  });
56
+ const changed = migrated || added;
52
57
 
53
58
  if (changed) {
54
59
  await writeJsonObject(settingsPath, settings);
@@ -56,3 +61,20 @@ async function mergeClaudeSettings(rootDir) {
56
61
 
57
62
  return { changed, action: changed ? 'updated' : 'unchanged', path: settingsPath };
58
63
  }
64
+
65
+ function replaceHookCommand(items, oldCommand, newCommand) {
66
+ let changed = false;
67
+ for (const item of items) {
68
+ if (!item || typeof item !== 'object' || !Array.isArray(item.hooks)) {
69
+ continue;
70
+ }
71
+
72
+ for (const hook of item.hooks) {
73
+ if (hook?.command === oldCommand) {
74
+ hook.command = newCommand;
75
+ changed = true;
76
+ }
77
+ }
78
+ }
79
+ return changed;
80
+ }
@@ -5,6 +5,10 @@ import { writeIfChanged, readTextIfExists, writeTextFile } from '../../lib/files
5
5
  import { installCommonDreamWfFiles, installManagedBlock, installSelectedSkills } from '../shared.js';
6
6
  import { installMcpServers } from '../../lib/mcp.js';
7
7
 
8
+ const CODEX_GUARD_MATCHER = 'Bash|Shell|shell|apply_patch|Edit|Write';
9
+ const CODEX_GUARD_COMMAND = 'python3 -X utf8 .codex/hooks/dream-wf-guard.py';
10
+ const LEGACY_CODEX_GUARD_COMMAND = 'python3 "$CODEX_PROJECT_DIR/.codex/hooks/dream-wf-guard.py"';
11
+
8
12
  // Codex CLI 读取项目根的 AGENTS.md 作为入口规则。
9
13
  // Codex 支持 PreToolUse 阻塞式 hook,配置在 .codex/hooks.json(和 config.toml [hooks] 段等效)。
10
14
  // 需要在 config.toml 里加 [features] hooks = true 来启用 hooks 功能。
@@ -64,16 +68,18 @@ async function mergeCodexHooks(rootDir) {
64
68
  hooks.hooks = hooks.hooks ?? {};
65
69
  hooks.hooks.PreToolUse = hooks.hooks.PreToolUse ?? [];
66
70
 
67
- const changed = pushUniqueByCommand(hooks.hooks.PreToolUse, {
68
- matcher: 'Bash|Shell|shell|apply_patch|Edit|Write',
71
+ const migrated = replaceHookCommand(hooks.hooks.PreToolUse, LEGACY_CODEX_GUARD_COMMAND, CODEX_GUARD_COMMAND);
72
+ const added = pushUniqueByCommand(hooks.hooks.PreToolUse, {
73
+ matcher: CODEX_GUARD_MATCHER,
69
74
  hooks: [
70
75
  {
71
76
  type: 'command',
72
- command: 'python3 "$CODEX_PROJECT_DIR/.codex/hooks/dream-wf-guard.py"',
77
+ command: CODEX_GUARD_COMMAND,
73
78
  timeout: 10
74
79
  }
75
80
  ]
76
81
  });
82
+ const changed = migrated || added;
77
83
 
78
84
  if (changed) {
79
85
  await writeJsonObject(hooksPath, hooks);
@@ -81,3 +87,20 @@ async function mergeCodexHooks(rootDir) {
81
87
 
82
88
  return { changed, action: changed ? 'updated' : 'unchanged', path: hooksPath };
83
89
  }
90
+
91
+ function replaceHookCommand(items, oldCommand, newCommand) {
92
+ let changed = false;
93
+ for (const item of items) {
94
+ if (!item || typeof item !== 'object' || !Array.isArray(item.hooks)) {
95
+ continue;
96
+ }
97
+
98
+ for (const hook of item.hooks) {
99
+ if (hook?.command === oldCommand) {
100
+ hook.command = newCommand;
101
+ changed = true;
102
+ }
103
+ }
104
+ }
105
+ return changed;
106
+ }