@muwi/core 0.10.2 → 0.10.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": "@muwi/core",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "AI가 스스로 짠 작업 플로우를 기록한다. 어느 AI 도구든 커넥터로, 어느 멀티플렉서든 터미널 연결로 붙는다",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/cli.js CHANGED
@@ -9,7 +9,7 @@ import { cmdBoard } from './board.js';
9
9
  import { cmdPeek, cmdResume, cmdRun, cmdTell, cmdTidy, cmdWait } from './delegate.js';
10
10
  import { Fail, dur, join, needPlan, out, parseArgs, resolveWork, str, } from './kit.js';
11
11
  import { hasTerminals, loadPlugins, pluginFailures, terminals, views } from './plugins.js';
12
- import { fromSubagent, markNode } from './node.js';
12
+ import { earlyStart, fromSubagent, markNode } from './node.js';
13
13
  import { addNode, carryStatus, diffPlan, isEmptyDiff, parsePlan, removeNode, } from './plan.js';
14
14
  import { readSession, sessionKey, sessionLabel } from './session.js';
15
15
  import { installedTools, newerElsewhere, olderThan, readInstall, refreshSetup, removeSetup, runSetup } from './setup.js';
@@ -371,6 +371,9 @@ function cmdNode(id , action , text
371
371
  const label = { doing: '시작', done: '끝', waiting: '응답 대기', blocked: '막힘', todo: '잠시 멈춤 (다시 start하면 같은 회차로 이어져요)' }[status];
372
372
  out(`${status === 'todo' ? '⏸' : MARK[status]} ${id} ${label} (${work}, ${done}/${result.nodes.length} 끝)`);
373
373
  if (status === 'done' && done === result.nodes.length) out('모든 노드가 끝났어요.');
374
+ // 앞 노드가 끝나기 전에 시작했다: 같이 하는 거면 계획을 고치라고 알린다. 맡은 서브에이전트는 계획을 고치지 않으므로 알리지 않는다
375
+ const early = status === 'doing' && !sub ? earlyStart(result.nodes, id) : null;
376
+ if (early) out(early);
374
377
  }
375
378
 
376
379
  function cmdFlag(a , dir ) {
@@ -651,7 +654,7 @@ function cmdSetup(a , dir ) {
651
654
  if (!done.length) {
652
655
  const have = installedTools().map(t => t.id);
653
656
  out(`AI 도구에는 아직 넣지 않았어요. 넣으려면 muwi setup --tool <도구> 또는 muwi setup --all${have.length ? ` (이 컴퓨터에 깔린 도구: ${have.join(', ')})` : ''}`);
654
- } else out('이미 열려 있는 세션은 다시 시작해야 새로 넣은 훅이 돌아요.');
657
+ }
655
658
  tellNewer();
656
659
  }
657
660
 
@@ -690,7 +693,7 @@ async function cmdUpdate(a , dir ) {
690
693
  const set = spawnSync(t.bin, ['setup'], { stdio: 'inherit', shell: win });
691
694
  if (set.status !== 0) throw new Fail(`새 판의 muwi setup이 ${set.status ?? set.error?.message}로 끝났어요. ${t.bin} setup을 직접 실행해 보세요`);
692
695
  } else out('muwi setup을 한 적이 없어서 맞출 것이 없어요. 쓰려면 muwi setup --tool <도구>를 실행하세요');
693
- out(`${current} → ${latest}로 올렸어요. 열려 있는 AI 세션은 새로 열면 새 판으로 돌아요.`);
696
+ out(`${current} → ${latest}로 올렸어요.`);
694
697
  }
695
698
 
696
699
  /** 설정의 이름, 기본값, 설명은 보기가 정한다 (보기 규격의 config). 코어에는 설정이 없다 */
@@ -37,6 +37,28 @@ export function removeHooks(settings ) {
37
37
  return next;
38
38
  }
39
39
 
40
+ /**
41
+ * 설정 파일에 걸린 우리 훅 (사건과 묶음). 업데이트로 훅이 바뀌었는지 볼 때 쓴다 (열린 세션은 시작할 때 훅을 읽어 둔다).
42
+ * 사건 표가 "hooks" 아래에 있든 파일 맨 위에 있든(hooks.json) 읽는다. 읽지 못하면 빈 글
43
+ */
44
+ export function ourHooks(file ) {
45
+ let settings ;
46
+ try {
47
+ settings = JSON.parse(fs.readFileSync(file, 'utf8'));
48
+ } catch {
49
+ return '';
50
+ }
51
+ if (!settings || typeof settings !== 'object') return '';
52
+ const nested = (settings ).hooks;
53
+ const table = (nested && typeof nested === 'object' && !Array.isArray(nested) ? nested : settings) ;
54
+ return Object.entries(table)
55
+ .flatMap(([event, groups]) => (Array.isArray(groups) ? (groups ) : [])
56
+ .filter(isOurs)
57
+ .map(g => `${event} ${JSON.stringify({ ...g, hooks: (g.hooks ?? []).filter(h => isOurCommand(h.command)) })}`))
58
+ .sort()
59
+ .join('\n');
60
+ }
61
+
40
62
  /** 걸 훅 하나: 어느 사건에, 어떤 도구에(matcher), 어떤 명령을 */
41
63
 
42
64
 
package/src/node.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import crypto from 'node:crypto';
4
4
  import { readSession, touchSession } from './session.js';
5
5
  import { appendEvent, clock, nowIso, readPlan, withLock, workDir, writePlan } from './store.js';
6
-
6
+
7
7
 
8
8
  /** 서브에이전트가 "곧 시작한다"고 훅이 적어 둔 것을 얼마 동안 믿을지 */
9
9
  const STARTING_MS = 120_000;
@@ -34,6 +34,25 @@ export function fromSubagent(dir , work , id , key
34
34
  * 회차: 처음 시작하거나, 끝냈거나 막혔던 노드를 다시 시작하면 새 회차다.
35
35
  * 기다리다 이어 하거나, 잠시 멈췄다(pause) 다시 하거나, 하는 중에 다른 쪽이 이어받는 것은 같은 회차다.
36
36
  */
37
+ /**
38
+ * 앞 노드가 끝나기 전에 시작한 노드에 붙일 말. 그래프는 계획대로 앞 노드 다음에 그려지고 "순서 앞당김"으로만 보이므로,
39
+ * 같이 하는 거면 계획에서 나란히 두라고 알린다 (막지는 않는다). 나란히 = 안 끝난 앞 노드 대신 그 노드의 앞 노드들 뒤
40
+ */
41
+ export function earlyStart(nodes , id ) {
42
+ const byId = new Map(nodes.map(n => [n.id, n]));
43
+ const node = byId.get(id);
44
+ if (!node) return null;
45
+ const open = (node.after ?? []).filter(p => byId.has(p) && byId.get(p) .status !== 'done');
46
+ if (!open.length) return null;
47
+ const side = [...new Set([...(node.after ?? []).filter(p => byId.has(p) && !open.includes(p)), ...open.flatMap(p => byId.get(p) .after ?? [])])];
48
+ const names = open.join(', ');
49
+ return [
50
+ `앞 노드 ${names}가 아직 끝나지 않았어요. 그래프에는 계획대로 ${names} 다음에 그려지고 "순서 앞당김"으로 보여요.`,
51
+ `같이 하는 거면 계획에서 나란히 두세요: muwi show로 지금 계획을 보고 ${id}의 after를 ${side.length ? `[${side.map(s => `"${s}"`).join(', ')}]` : '빈 목록(맨 앞)'}으로 바꿔 muwi plan --why "<같이 하는 이유>" '<계획 JSON>'으로 다시 적어요.`,
52
+ `순서대로 하려던 거면 muwi node ${id} pause로 멈추고 ${names}를 먼저 끝내요.`,
53
+ ].join('\n');
54
+ }
55
+
37
56
  export function markNode(dir , work , id , status , note , key , env = process.env, o = {}) {
38
57
  // 서브에이전트가 시작하는 것이면 훅이 방금 그 서브에이전트를 적어 뒀다 (명령에서는 세션 id가 같아 구분할 수 없다).
39
58
  // 훅이 알려 주지 않는 도구에서는 서브에이전트가 스스로 밝힌다 (--sub). 그때는 이름을 지어 준다
package/src/setup.js CHANGED
@@ -10,6 +10,7 @@ import { pluginFailures, pluginPaths, views, } from './plugins.
10
10
  import { nowIso, readJson, writeJson } from './store.js';
11
11
  import { copyDir, installBlock, shPath, uninstallBlock, writeText } from './connectors/files.js';
12
12
  import { adapterOf } from './connectors/index.js';
13
+ import { ourHooks } from './connectors/settings-hooks.js';
13
14
  import { TOOLS, toolHome, toolSkills, } from './connectors/tools.js';
14
15
 
15
16
 
@@ -175,17 +176,42 @@ export function runSetup(o ) {
175
176
  }
176
177
 
177
178
  const want = new Set ([...(o.tools ?? []), ...Object.keys(before?.tools ?? {})]);
179
+ // 열린 세션을 다시 열어야 하는 도구: 처음 넣었거나(fresh), 걸린 훅·플러그인 파일이 바뀌었다(changed)
180
+ const fresh = [];
181
+ const changed = [];
178
182
  // 표의 순서대로 넣는다
179
183
  for (const tool of TOOLS.filter(t => want.has(t.id))) {
184
+ const prev = before?.tools?.[tool.id];
185
+ const was = prev ? wiringOf(prev) : null;
180
186
  const done = installTool(tool, { root: o.root, env, platform, home: toolHome(tool, env, p.home) }, p.home, block, skill);
181
187
  if (tool.note) log(` ${tool.note}`);
182
188
  install.tools = { ...(install.tools ?? {}), [tool.id]: done };
183
189
  log(`${tool.name} 커넥터: ${[done.instructions, done.skill, ...(done.settings ?? []), ...(done.files ?? [])].filter(Boolean).join(', ')}`);
190
+ if (was === null) fresh.push(tool.name);
191
+ else if (was !== wiringOf(done)) changed.push(tool.name);
184
192
  }
193
+ if (fresh.length) log(`이미 열려 있는 ${fresh.join(', ')} 세션은 다시 열어야 muwi 훅이 돌아요.`);
194
+ if (changed.length) log(`열려 있는 ${changed.join(', ')} 세션은 다시 열어야 바뀐 훅이 돌아요.`);
195
+ if (install.tools && !fresh.length && !changed.length) log('훅은 그대로라 열려 있는 세션도 다음 훅부터 이 판으로 돌아요. 다시 열지 않아도 돼요.');
185
196
  writeJson(installFile(o.dir), install);
186
197
  return install;
187
198
  }
188
199
 
200
+ /**
201
+ * 도구에 걸린 muwi의 훅과 플러그인 파일. 열린 세션은 시작할 때 이것을 읽어 두므로, 바뀌면 그 세션을 다시 열어야 한다.
202
+ * 훅이 부르는 파일(hooks/tool.sh와 코어)은 같은 자리에서 바뀌므로 다음 훅부터 새 판으로 돈다
203
+ */
204
+ function wiringOf(done ) {
205
+ const read = (f ) => {
206
+ try {
207
+ return fs.readFileSync(f, 'utf8');
208
+ } catch {
209
+ return '';
210
+ }
211
+ };
212
+ return [...(done.settings ?? []).map(f => `${f}\n${ourHooks(f)}`), ...(done.files ?? []).map(f => `${f}\n${read(f)}`)].join('\n\n');
213
+ }
214
+
189
215
  /** 한 도구에 커넥터를 넣는다: 지침(늘 읽히는 파일이 있으면), 사용법 skill, 훅 */
190
216
  function installTool(tool , ctx , userHome , block , skill ) {
191
217
  const done = {};