@tyhld/conductor 0.12.181 → 0.12.182
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/dist/headless.js
CHANGED
|
@@ -1384,6 +1384,13 @@ resumeNote) {
|
|
|
1384
1384
|
? stayInRepoDir(cfg.workDir, 'この PC の設定で便ごとの作業場所を使わない(CONDUCTOR_JOB_WORKTREE=off)')
|
|
1385
1385
|
: prepareJobWorkDir({ repoDir: cfg.workDir, site: cfg.site, commandId: cmd.id, isResume });
|
|
1386
1386
|
log(`site=${cfg.site} id=${cmd.id} ${work.note}`);
|
|
1387
|
+
// ★続きの便なのに作業場所が消えていた(機械の再起動など)ときは、どこでも起こさず止める(便 434ca0a8)。
|
|
1388
|
+
// リポの元の場所(秘密のファイルが在る所)で起こさない。呼び出し側が理由つきで人の手番にする。
|
|
1389
|
+
if (work.stop !== undefined) {
|
|
1390
|
+
lastSpawnError = work.stop;
|
|
1391
|
+
log(`ERROR site=${cfg.site} id=${cmd.id} ${lastSpawnError}`);
|
|
1392
|
+
return null;
|
|
1393
|
+
}
|
|
1387
1394
|
const env = { ...process.env };
|
|
1388
1395
|
delete env.CLAUDECODE;
|
|
1389
1396
|
delete env.ANTHROPIC_API_KEY;
|
package/dist/job-workdir.js
CHANGED
|
@@ -9,10 +9,18 @@
|
|
|
9
9
|
*
|
|
10
10
|
* 【決め】
|
|
11
11
|
* ・便を渡す前に、その現場のリポから `git worktree add --detach` で
|
|
12
|
-
* /
|
|
12
|
+
* ~/.local/state/conductor/jobs/conductor-job-<現場>-<便ID> を作る(最新の origin の既定の枝が元)。
|
|
13
13
|
* ★枝を作らない(--detach)=リポの元の場所の未記録の変更・ほかの枝には1バイトも触らない。
|
|
14
|
+
* ・置き場は PC の再起動で消えない所(便 434ca0a8・調べ便 f56468b3)。前は /tmp/claude-<uid> の下で、
|
|
15
|
+
* WSL の起き直しのたびに起動時の片付け(systemd-tmpfiles の D /tmp)で中身ごと消え、
|
|
16
|
+
* 記録前の職人の仕事が失われていた(11/04 以降、残した作業場所 9件のうち 8件・便 f96627f8 の 13ファイル)。
|
|
17
|
+
* ★部品や控えの置き場(npm-cache など・消えても取り直せる物)は今までどおり /tmp/claude-<uid> の下。
|
|
14
18
|
* ・同じ便の続き(自動再開・利用上限の後の配り直し)は、同じ作業場所を使い直す
|
|
15
19
|
* (Claude Code の会話の記録は起きた場所ごとに分かれるので、場所が変わると続きから起こせない)。
|
|
20
|
+
* ★移す前の古い置き場(/tmp/claude-<uid>)に残っている作業場所は、消さない・動かさない。続きの便は
|
|
21
|
+
* その場所で使い直す(会話の記録がその場所に在るため)。
|
|
22
|
+
* ・続きの便なのに作業場所がどこにも無い(機械の再起動などで消えた)ときは、リポの元の場所で起こさず
|
|
23
|
+
* 止めて人の手番にする(便 434ca0a8・実地 便 13a394e4 の2回目=元の場所で起こしていた)。
|
|
16
24
|
* ・リポの元の場所の `.claude/settings.local.json`(記録されない守り)と、記録されていない
|
|
17
25
|
* `.claude/settings.json` は、作業場所へ写す=★守りは1つも落とさない
|
|
18
26
|
* (作業場所には記録された物しか無いので、写さないと現場ごとの守りが外れる)。
|
|
@@ -25,6 +33,7 @@
|
|
|
25
33
|
*/
|
|
26
34
|
import { spawnSync } from 'node:child_process';
|
|
27
35
|
import { copyFileSync, existsSync, mkdirSync, realpathSync, unlinkSync } from 'node:fs';
|
|
36
|
+
import os from 'node:os';
|
|
28
37
|
import path from 'node:path';
|
|
29
38
|
/** 取り寄せ・作業場所づくりの上限時間(無応答の通信で配り役の輪を長く止めない)。 */
|
|
30
39
|
export const JOB_WORKDIR_GIT_TIMEOUT_MS = 120_000;
|
|
@@ -45,11 +54,22 @@ export const defaultGitRun = (args, opts) => {
|
|
|
45
54
|
stderr: (r.stderr ?? '') || (r.error ? r.error.message : ''),
|
|
46
55
|
};
|
|
47
56
|
};
|
|
48
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* 作業場所を置く根(★再起動で消えない ~/.local/state/conductor/jobs・XDG_STATE_HOME があればそちら)。
|
|
59
|
+
* 試験では環境変数で差し替える。
|
|
60
|
+
* ★職人の囲いは起きた場所(作業場所)に書けるので、囲いの書ける場所を広げる必要は無い。
|
|
61
|
+
* ★秘密のファイルが在る場所(~/projects の下など)には置かない。
|
|
62
|
+
*/
|
|
49
63
|
export function jobDirRoot(env = process.env) {
|
|
50
64
|
const override = (env.CONDUCTOR_JOB_DIR_ROOT ?? '').trim();
|
|
51
65
|
if (override)
|
|
52
66
|
return override;
|
|
67
|
+
const home = (env.HOME ?? '').trim() || os.homedir();
|
|
68
|
+
const state = (env.XDG_STATE_HOME ?? '').trim() || path.join(home, '.local', 'state');
|
|
69
|
+
return path.join(state, 'conductor', 'jobs');
|
|
70
|
+
}
|
|
71
|
+
/** 移す前の古い置き場(/tmp/claude-<uid>)。★続きの便の使い直しにだけ見る(新しく作らない・消さない)。 */
|
|
72
|
+
export function legacyJobDirRoot() {
|
|
53
73
|
const uid = typeof process.getuid === 'function' ? process.getuid() : 1000;
|
|
54
74
|
return path.join('/tmp', `claude-${uid}`);
|
|
55
75
|
}
|
|
@@ -61,6 +81,8 @@ export function jobWorkDirPath(site, commandId, root = jobDirRoot()) {
|
|
|
61
81
|
return null;
|
|
62
82
|
return path.join(root, `${JOB_WORKDIR_PREFIX}${safeSite}-${safeId}`);
|
|
63
83
|
}
|
|
84
|
+
/** 続きの便なのに作業場所が無いときの理由(★事実のとおりに書く・リポの元の場所では起こさない)。 */
|
|
85
|
+
export const JOB_WORKDIR_GONE_REASON = '作業場所が消えていました(機械の再起動など)。続きの便はリポの元の場所では起こさず止めます(人の手番)';
|
|
64
86
|
/** 今までどおりリポの元の場所で起こす決まり(★純粋関数)。 */
|
|
65
87
|
export function stayInRepoDir(repoDir, why) {
|
|
66
88
|
return {
|
|
@@ -95,6 +117,21 @@ function isRegisteredWorktree(repoDir, dir, git) {
|
|
|
95
117
|
.filter((l) => l.startsWith('worktree '))
|
|
96
118
|
.some((l) => samePath(l.slice('worktree '.length).trim(), dir));
|
|
97
119
|
}
|
|
120
|
+
const NOT_REPO_TOP = 'リポではない(git の作業場所の根ではない)';
|
|
121
|
+
const NO_ORIGIN_BASE = 'origin の既定の枝(origin/HEAD・origin/main)が無い';
|
|
122
|
+
/** repoDir が git の作業場所の根か。 */
|
|
123
|
+
function isRepoTop(repoDir, git) {
|
|
124
|
+
const top = git(['-C', repoDir, 'rev-parse', '--show-toplevel']);
|
|
125
|
+
return top.status === 0 && samePath(top.stdout.trim(), repoDir);
|
|
126
|
+
}
|
|
127
|
+
/** 作業場所の元にする origin の既定の枝(無ければ null)。 */
|
|
128
|
+
function originBase(repoDir, git) {
|
|
129
|
+
for (const ref of ['origin/HEAD', 'origin/main']) {
|
|
130
|
+
if (git(['-C', repoDir, 'rev-parse', '--verify', '--quiet', `refs/remotes/${ref}`]).status === 0)
|
|
131
|
+
return ref;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
98
135
|
/** リポの元の場所の守りの設定を作業場所へ写す(★記録された物=作業場所に既に在る物は写さない)。 */
|
|
99
136
|
function copySettings(repoDir, dir) {
|
|
100
137
|
const copied = [];
|
|
@@ -118,50 +155,72 @@ function copySettings(repoDir, dir) {
|
|
|
118
155
|
/**
|
|
119
156
|
* 職人を起こす場所を決める(★必要なら作業場所を作る)。例外は投げない。
|
|
120
157
|
*
|
|
121
|
-
* isResume …
|
|
122
|
-
*
|
|
158
|
+
* isResume … 前の会話の続きから起こすか。続きなのに作業場所がどこにも無い(機械の再起動などで
|
|
159
|
+
* 消えた)ときは、リポの元の場所で起こさず止める(stop に理由が入る・便 434ca0a8)。
|
|
160
|
+
* ★移す前の古い置き場(legacyRoot)に作業場所が残っていれば、そこで使い直す(消さない・動かさない)。
|
|
161
|
+
* ★作業場所を作れない現場(リポでない・origin の枝が無い)は、はじめから元の場所で起きているので、
|
|
162
|
+
* 続きも今までどおり元の場所で起こす。
|
|
123
163
|
*/
|
|
124
164
|
export function prepareJobWorkDir(opts) {
|
|
125
165
|
const git = opts.git ?? defaultGitRun;
|
|
126
166
|
const repoDir = opts.repoDir;
|
|
127
167
|
const fallback = (why) => stayInRepoDir(repoDir, why);
|
|
128
|
-
const
|
|
168
|
+
const root = opts.root ?? jobDirRoot();
|
|
169
|
+
const target = jobWorkDirPath(opts.site, opts.commandId, root);
|
|
129
170
|
if (target === null)
|
|
130
171
|
return fallback('現場名か便IDに使えない文字しか無い');
|
|
131
|
-
|
|
132
|
-
if (!isRegisteredWorktree(repoDir,
|
|
172
|
+
const reuse = (dir) => {
|
|
173
|
+
if (!isRegisteredWorktree(repoDir, dir, git)) {
|
|
133
174
|
// ★この配り役が作った物ではないかもしれないので、触らない。
|
|
134
|
-
return fallback(`同じ名前の物が既に在り、このリポの作業場所ではない: ${
|
|
175
|
+
return fallback(`同じ名前の物が既に在り、このリポの作業場所ではない: ${dir}`);
|
|
135
176
|
}
|
|
136
177
|
try {
|
|
137
|
-
const copied = copySettings(repoDir,
|
|
178
|
+
const copied = copySettings(repoDir, dir);
|
|
138
179
|
return {
|
|
139
|
-
dir
|
|
140
|
-
note: `同じ便の作業場所を使い直します: ${
|
|
180
|
+
dir, repoDir, worktree: true, reused: true, base: null, copiedSettings: copied,
|
|
181
|
+
note: `同じ便の作業場所を使い直します: ${dir}`,
|
|
141
182
|
};
|
|
142
183
|
}
|
|
143
184
|
catch (err) {
|
|
144
185
|
return fallback(err instanceof Error ? err.message : String(err));
|
|
145
186
|
}
|
|
187
|
+
};
|
|
188
|
+
if (opts.isResume) {
|
|
189
|
+
// ★続きの便は、作業場所を使い直せないときにリポの元の場所で起こさない(止めて人の手番)。
|
|
190
|
+
const stopResume = (why, dir) => ({
|
|
191
|
+
...stayInRepoDir(repoDir, why), note: `${why}: ${dir}`, stop: why,
|
|
192
|
+
});
|
|
193
|
+
const resumeIn = (dir) => {
|
|
194
|
+
const w = reuse(dir);
|
|
195
|
+
return w.worktree
|
|
196
|
+
? w
|
|
197
|
+
: stopResume(`続きの便の作業場所を使えません(${w.note})。リポの元の場所では起こさず止めます(人の手番)`, dir);
|
|
198
|
+
};
|
|
199
|
+
if (existsSync(target))
|
|
200
|
+
return resumeIn(target);
|
|
201
|
+
// ★移す前に始まった便の続きは、古い置き場に残った作業場所で使い直す(会話の記録がそこに在る)。
|
|
202
|
+
const legacyRoot = opts.legacyRoot ?? legacyJobDirRoot();
|
|
203
|
+
const legacy = samePath(legacyRoot, root) ? null : jobWorkDirPath(opts.site, opts.commandId, legacyRoot);
|
|
204
|
+
if (legacy !== null && existsSync(legacy))
|
|
205
|
+
return resumeIn(legacy);
|
|
206
|
+
// ★作業場所を作れない現場(リポでない・origin の枝が無い)は、はじめから元の場所で起きている
|
|
207
|
+
// (会話の記録もそこに在る)ので、続きも今までどおり元の場所で起こす。
|
|
208
|
+
if (!isRepoTop(repoDir, git))
|
|
209
|
+
return fallback(NOT_REPO_TOP);
|
|
210
|
+
if (originBase(repoDir, git) === null)
|
|
211
|
+
return fallback(NO_ORIGIN_BASE);
|
|
212
|
+
return stopResume(JOB_WORKDIR_GONE_REASON, target);
|
|
146
213
|
}
|
|
147
|
-
if (
|
|
148
|
-
return
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return fallback('リポではない(git の作業場所の根ではない)');
|
|
152
|
-
}
|
|
214
|
+
if (existsSync(target))
|
|
215
|
+
return reuse(target);
|
|
216
|
+
if (!isRepoTop(repoDir, git))
|
|
217
|
+
return fallback(NOT_REPO_TOP);
|
|
153
218
|
// 最新を取り寄せる。★失敗しても手元の origin の枝で続ける(取り寄せの失敗で便を止めない)。
|
|
154
219
|
const fetched = git(['-C', repoDir, 'fetch', 'origin', '--quiet'], { timeoutMs: JOB_WORKDIR_GIT_TIMEOUT_MS });
|
|
155
220
|
const fetchNote = fetched.status === 0 ? '' : `・取り寄せに失敗したので手元の origin の枝を使います(${tail(fetched.stderr)})`;
|
|
156
|
-
|
|
157
|
-
for (const ref of ['origin/HEAD', 'origin/main']) {
|
|
158
|
-
if (git(['-C', repoDir, 'rev-parse', '--verify', '--quiet', `refs/remotes/${ref}`]).status === 0) {
|
|
159
|
-
base = ref;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
221
|
+
const base = originBase(repoDir, git);
|
|
163
222
|
if (base === null)
|
|
164
|
-
return fallback(
|
|
223
|
+
return fallback(NO_ORIGIN_BASE);
|
|
165
224
|
try {
|
|
166
225
|
mkdirSync(path.dirname(target), { recursive: true });
|
|
167
226
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""便ごとの作業場所の新しい置き場で、番人の守りが1つも緩まないことの試験(便 434ca0a8)。
|
|
3
|
+
|
|
4
|
+
実行: python3 scripts/hooks/test_job_workdir_root.py
|
|
5
|
+
1件でも期待と違えば exit 1。
|
|
6
|
+
|
|
7
|
+
【なぜ要るか】
|
|
8
|
+
便ごとの作業場所の置き場を /tmp/claude-<uid> の下から、再起動で消えない
|
|
9
|
+
~/.local/state/conductor/jobs の下へ移した(src/job-workdir.ts の jobDirRoot)。
|
|
10
|
+
/tmp の下では「一時領域」として扱われていた判定があるので、移した先でも
|
|
11
|
+
番人の「作業場所の中か」の判定が正しく効き、作業場所の外は今までどおり止まることを固定する。
|
|
12
|
+
|
|
13
|
+
【ここで固定すること】
|
|
14
|
+
(1) 作業場所の中を名指しで消す形は通る(相対・絶対のどちらも)
|
|
15
|
+
(2) 作業場所そのもの・保護対象(.git・.claude・.tyhld)・作業場所の外(ほかの便の作業場所・
|
|
16
|
+
状態の置き場・リポの元の場所)は今までどおり止まる
|
|
17
|
+
(3) 作業場所の守りの設定(.claude/settings*.json)への書き込みは止まる・ふつうのファイルは書ける
|
|
18
|
+
(4) ★番人の判定は1行も変えていない(置き場が変わっても同じ物差しで効く)
|
|
19
|
+
|
|
20
|
+
★作業場所は実在しなくてよい(判定は名前とパスだけで決まる)。ホームの下に何も作らない。
|
|
21
|
+
"""
|
|
22
|
+
import os
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
26
|
+
|
|
27
|
+
import policy # noqa: E402
|
|
28
|
+
|
|
29
|
+
failures = []
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def check(label, got, want):
|
|
33
|
+
ok = got == want
|
|
34
|
+
if not ok:
|
|
35
|
+
failures.append(f'{label}: got={got!r} want={want!r}')
|
|
36
|
+
print(f'{"OK " if ok else "NG "} {label:72} {str(got)[:32]}')
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
HOME = os.path.expanduser('~')
|
|
40
|
+
ROOT = os.path.join(HOME, '.local', 'state', 'conductor', 'jobs')
|
|
41
|
+
WD = os.path.join(ROOT, 'conductor-job-demo-434ca0a8-probe')
|
|
42
|
+
OTHER = os.path.join(ROOT, 'conductor-job-demo-other-probe')
|
|
43
|
+
RM = 'r' + 'm'
|
|
44
|
+
SET = 'settings'
|
|
45
|
+
|
|
46
|
+
os.environ['CONDUCTOR_WORK_DIR'] = WD
|
|
47
|
+
|
|
48
|
+
print('\n=== (1) 作業場所の中を名指しで消す形は通る ===')
|
|
49
|
+
for cmd in (f'{RM} -r build', f'{RM} -r {WD}/build', f'{RM} {WD}/a.html', f'{RM} -r {WD}/node_modules/.tmp-x'):
|
|
50
|
+
check(f'allow {cmd[-60:]}', policy.decide_bash(cmd, cwd=WD)['decision'], policy.ALLOW)
|
|
51
|
+
|
|
52
|
+
print('\n=== (2) 作業場所そのもの・保護対象・作業場所の外は止まる ===')
|
|
53
|
+
for cmd in (
|
|
54
|
+
f'{RM} -r {WD}',
|
|
55
|
+
f'{RM} -r {WD}/.git',
|
|
56
|
+
f'{RM} -r {WD}/.claude',
|
|
57
|
+
f'{RM} -r {WD}/.tyhld',
|
|
58
|
+
f'{RM} -r .git',
|
|
59
|
+
f'{RM} -r {WD}/../conductor-job-demo-other-probe',
|
|
60
|
+
f'{RM} -r {OTHER}/build',
|
|
61
|
+
f'{RM} -r {ROOT}',
|
|
62
|
+
f'{RM} -r {os.path.join(HOME, ".local", "state", "conductor", "reports")}',
|
|
63
|
+
f'{RM} -r {os.path.join(HOME, "projects", "conductor", "src")}',
|
|
64
|
+
):
|
|
65
|
+
check(f'deny {cmd[-60:]}', policy.decide_bash(cmd, cwd=WD)['decision'], policy.DENY)
|
|
66
|
+
|
|
67
|
+
print('\n=== (3) 守りの設定へは書けない・ふつうのファイルは書ける ===')
|
|
68
|
+
for name in (f'{SET}.json', f'{SET}.local.json'):
|
|
69
|
+
p = os.path.join(WD, '.claude', name)
|
|
70
|
+
check(f'Write deny {p[-60:]}', policy.decide_write(p, cwd=WD)['decision'], policy.DENY)
|
|
71
|
+
p = os.path.join(WD, 'src', 'a.ts')
|
|
72
|
+
check(f'Write allow {p[-60:]}', policy.decide_write(p, cwd=WD)['decision'], policy.ALLOW)
|
|
73
|
+
|
|
74
|
+
print()
|
|
75
|
+
if failures:
|
|
76
|
+
print(f'FAIL {len(failures)} 件')
|
|
77
|
+
for f in failures:
|
|
78
|
+
print(' ' + f)
|
|
79
|
+
sys.exit(1)
|
|
80
|
+
print('PASS')
|
|
@@ -18,7 +18,9 @@ description: 采配くんの便(プロンプト末尾に CONDUCTOR_JOB:<id>
|
|
|
18
18
|
|
|
19
19
|
1. **着手時の確認と枝分かれ** — `git status && git log --oneline -3 && git stash list` を確認してから main を最新化し、新ブランチを切る。
|
|
20
20
|
- ★**枝は最新の `origin/main` から切る(手元の `main` から切らない・えふさん決定 2026-10-26)。** `git fetch origin` を1回打ち、`git switch -c <作業ブランチ名> --no-track origin/main`(鉄則7-⓪の形)。手元の `main` は古いまま置かれていることがある(実地 便 613837fd:275件遅れ)ので、そこから切ると古い土台の上で作業することになる。
|
|
21
|
-
- ★**便ごとの作業場所で起きたとき(えふさん決定 2026-11-04・便 27a9fb19)。** 画面なし方式の配り役は、便を渡す前に現場のリポから `git worktree` で
|
|
21
|
+
- ★**便ごとの作業場所で起きたとき(えふさん決定 2026-11-04・便 27a9fb19)。** 画面なし方式の配り役は、便を渡す前に現場のリポから `git worktree` で `~/.local/state/conductor/jobs/conductor-job-<現場>-<便ID>` を作り(最新の origin の既定の枝・枝は未作成)、**職人をそこで起こす**。便の本文に `【作業場所】…` の段が付いていればこの形。
|
|
22
|
+
- ★置き場は PC の再起動で消えない所(便 434ca0a8)。前は `/tmp/claude-1000` の下で、再起動のたびに中身ごと消え、記録前の仕事が失われていた。移す前に始まった便の続きは古い置き場の作業場所をそのまま使う。★続きの便なのに作業場所が消えていたときは、配り役がリポの元の場所で起こさず止めて人の手番にする。
|
|
23
|
+
- ★部品や控えの置き場(`npm-cache` など・消えても取り直せる物)と使い捨ての物は、今までどおり `/tmp/claude-1000` の下(鉄則13)。
|
|
22
24
|
- **cd は不要**(もう作業場所に居る)。**リポの元の場所(`~/projects/<現場>`)では命令を動かさない**(記録されない秘密のファイルが在るので、そこで python3 などを動かすと番人が正しく止める=実地 便 e0796fcd)。
|
|
23
25
|
- 枝は `git switch -c <作業ブランチ名> --no-track origin/main` で切る。**新しい worktree は作らない**(下の「切り替えられないとき」の形は要らない)。
|
|
24
26
|
- 部品(`node_modules` 等)は作業場所に無いので、「手元で流す検査」⑤の命令で入れる(置き場は `/tmp/claude-1000` の下)。
|