hermes-pilot 0.0.0-stage → 0.2.2
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/LICENSE +21 -0
- package/README.ja.md +419 -0
- package/README.md +428 -2
- package/__init__.py +15 -0
- package/apps/bridge/src/api-errors.js +165 -0
- package/apps/bridge/src/architect.js +1298 -0
- package/apps/bridge/src/auth.js +202 -0
- package/apps/bridge/src/capabilities.js +256 -0
- package/apps/bridge/src/capture.js +145 -0
- package/apps/bridge/src/chat-profile.js +95 -0
- package/apps/bridge/src/config.js +73 -0
- package/apps/bridge/src/discord.js +89 -0
- package/apps/bridge/src/gitinfo.js +211 -0
- package/apps/bridge/src/hermes.js +97 -0
- package/apps/bridge/src/inbox.js +347 -0
- package/apps/bridge/src/kanban.js +361 -0
- package/apps/bridge/src/lang.js +60 -0
- package/apps/bridge/src/live.js +285 -0
- package/apps/bridge/src/memos.js +150 -0
- package/apps/bridge/src/ops.js +201 -0
- package/apps/bridge/src/pair-codes.js +125 -0
- package/apps/bridge/src/pipeline-optimizer.js +513 -0
- package/apps/bridge/src/pipeline-watcher.js +1022 -0
- package/apps/bridge/src/qr.js +808 -0
- package/apps/bridge/src/repos.js +544 -0
- package/apps/bridge/src/review-watcher.js +271 -0
- package/apps/bridge/src/review.js +1749 -0
- package/apps/bridge/src/search.js +162 -0
- package/apps/bridge/src/server.js +1745 -0
- package/apps/bridge/src/snippets.js +373 -0
- package/apps/bridge/src/specs.js +806 -0
- package/apps/bridge/src/tail.js +28 -0
- package/apps/bridge/src/telemetry.js +667 -0
- package/apps/bridge/src/term-snippets.js +228 -0
- package/apps/bridge/src/transcript.js +231 -0
- package/apps/bridge/src/usage.js +294 -0
- package/apps/bridge/src/workerFeed.js +72 -0
- package/apps/dashboard/index.js +2014 -0
- package/apps/dashboard/manifest.json +14 -0
- package/apps/dashboard/pilot_dashboard.py +1466 -0
- package/apps/dashboard/plugin_api.py +237 -0
- package/apps/dashboard/plugin_init.py +15 -0
- package/apps/dashboard/style.css +928 -0
- package/apps/web/dist/assets/TermPane-DYP7pi_n.css +32 -0
- package/apps/web/dist/assets/TermPane-q4f5Zu0I.js +12 -0
- package/apps/web/dist/assets/index-BzUof8lw.js +94 -0
- package/apps/web/dist/assets/index-DwZdbPU7.css +1 -0
- package/apps/web/dist/favicon.ico +0 -0
- package/apps/web/dist/icon-180-v6.png +0 -0
- package/apps/web/dist/icon-192-v6.png +0 -0
- package/apps/web/dist/icon-512-v6.png +0 -0
- package/apps/web/dist/icon-maskable-192-v6.png +0 -0
- package/apps/web/dist/icon-maskable-512-v6.png +0 -0
- package/apps/web/dist/icon-v6.svg +15 -0
- package/apps/web/dist/index.html +21 -0
- package/apps/web/dist/manifest.webmanifest +49 -0
- package/apps/web/dist/sw.js +69 -0
- package/bin/hermes-pilot.mjs +964 -0
- package/dashboard/dist/index.js +2014 -0
- package/dashboard/dist/style.css +928 -0
- package/dashboard/manifest.json +14 -0
- package/dashboard/pilot_dashboard.py +1466 -0
- package/dashboard/plugin_api.py +237 -0
- package/package.json +75 -4
- package/plugin.json +70 -0
- package/plugin.yaml +4 -0
- package/scripts/deploy.mjs +58 -0
- package/scripts/migrate-to-hermes-pilot.mjs +472 -0
- package/scripts/postinstall.mjs +32 -0
- package/scripts/sync-dashboard.mjs +98 -0
- package/skills/annotation/SKILL.md +138 -0
- package/skills/quick-review/SKILL.md +200 -0
- package/skills/quick-review/assets/sheet-template.html +175 -0
- package/skills/spec-architect/SKILL.md +226 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 旧環境(`~/Projects/akapen` / `~/.hermes/plugin-data/akapen` / `~/.hermes/mobile-pwa`)から
|
|
4
|
+
* `~/.hermes/plugin-data/hermes-pilot/` への物理移行(D6 / SPEC §4.4)。
|
|
5
|
+
*
|
|
6
|
+
* 方針(D55):
|
|
7
|
+
* - **物理コピーのみ**。旧ディレクトリは削除しない(既存データを壊さない)
|
|
8
|
+
* - **冪等**: `fs.cpSync(..., { force: false })` は既にあるファイルを上書きしない。2 回流しても増えない
|
|
9
|
+
* - 画像の `mtime` を保つ(`preserveTimestamps: true`。一覧の撮影日時順ソートが壊れない)
|
|
10
|
+
* - **Hermes の state を直接書き換えない**: `kanban.db` は read-write で開かない(`[akapen]` タグは
|
|
11
|
+
* `apps/bridge/src/review.js` が後方互換で読むので置換自体が不要)。cron は
|
|
12
|
+
* `hermes cron list` → `hermes cron remove <id>` の公式 CLI だけを通す。
|
|
13
|
+
*
|
|
14
|
+
* 使い方: `npm run migrate:pilot`(`hermes-pilot migrate` と明示 `init --yes` から呼ぶ)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import fs from 'node:fs'
|
|
18
|
+
import os from 'node:os'
|
|
19
|
+
import path from 'node:path'
|
|
20
|
+
import { spawnSync } from 'node:child_process'
|
|
21
|
+
import { fileURLToPath } from 'node:url'
|
|
22
|
+
|
|
23
|
+
const TAG_OLD = '[akapen]'
|
|
24
|
+
const TAG_NEW = '[review]'
|
|
25
|
+
|
|
26
|
+
/** ディレクトリを冪等にコピーし、コピーしたファイル数を返す。 */
|
|
27
|
+
function copyDirIfExists(src, dest) {
|
|
28
|
+
if (!fs.existsSync(src)) return { copied: 0, skipped: true }
|
|
29
|
+
fs.mkdirSync(dest, { recursive: true })
|
|
30
|
+
let copied = 0
|
|
31
|
+
let total = 0
|
|
32
|
+
const walk = (from, to) => {
|
|
33
|
+
let ents = []
|
|
34
|
+
try {
|
|
35
|
+
ents = fs.readdirSync(from, { withFileTypes: true })
|
|
36
|
+
} catch {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
for (const e of ents) {
|
|
40
|
+
const s = path.join(from, e.name)
|
|
41
|
+
const d = path.join(to, e.name)
|
|
42
|
+
if (e.isDirectory()) {
|
|
43
|
+
fs.mkdirSync(d, { recursive: true })
|
|
44
|
+
walk(s, d)
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
total += 1
|
|
48
|
+
if (fs.existsSync(d)) continue // 冪等: 既にあるものは触らない
|
|
49
|
+
fs.cpSync(s, d, { recursive: true, force: false, preserveTimestamps: true })
|
|
50
|
+
copied += 1
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
walk(src, dest)
|
|
54
|
+
return { copied, total, skipped: false }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 単一ファイルを冪等にコピーする。 */
|
|
58
|
+
function copyFileIfExists(src, dest) {
|
|
59
|
+
if (!fs.existsSync(src)) return { copied: 0, skipped: true }
|
|
60
|
+
if (fs.existsSync(dest)) return { copied: 0, skipped: true }
|
|
61
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
62
|
+
fs.cpSync(src, dest, { recursive: false, force: false, preserveTimestamps: true })
|
|
63
|
+
return { copied: 1, skipped: false }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** `~` を home に展開し、絶対パスへ。 */
|
|
67
|
+
function expand(p, home) {
|
|
68
|
+
return path.resolve(String(p).replace(/^~/, home))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* `HERMES_HOME` がプロファイルディレクトリ(`~/.hermes/profiles/<name>`)を指していることがある
|
|
73
|
+
* (worker / cron から実行した場合)。その時は 2 つ上(`~/.hermes`)を Hermes ホームとして扱う。
|
|
74
|
+
* そうしないと kanban.db を見つけられず、データも `profiles/<name>/plugin-data` に散らばる。
|
|
75
|
+
*/
|
|
76
|
+
export function resolveHermesHome(raw, home = os.homedir()) {
|
|
77
|
+
const abs = path.resolve(String(raw).replace(/^~/, home))
|
|
78
|
+
if (path.basename(path.dirname(abs)) === 'profiles') return path.dirname(path.dirname(abs))
|
|
79
|
+
return abs
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 監視対象の `kanban.db`(ルート+各ボード)。
|
|
84
|
+
*
|
|
85
|
+
* **存在確認だけ**で、DB は開かない(D55: `[akapen]` タグの置換は廃止。`review.js` が
|
|
86
|
+
* `[akapen]` / `[review]` の両方を読むため書き換える必要が無い)。レポート用の一覧を返す。
|
|
87
|
+
*/
|
|
88
|
+
export function findKanbanDbs(hermesHome) {
|
|
89
|
+
const out = []
|
|
90
|
+
const root = path.join(hermesHome, 'kanban.db')
|
|
91
|
+
if (fs.existsSync(root)) out.push(root)
|
|
92
|
+
const boardsDir = path.join(hermesHome, 'kanban', 'boards')
|
|
93
|
+
let ents = []
|
|
94
|
+
try {
|
|
95
|
+
ents = fs.readdirSync(boardsDir, { withFileTypes: true })
|
|
96
|
+
} catch {
|
|
97
|
+
return out
|
|
98
|
+
}
|
|
99
|
+
for (const e of ents) {
|
|
100
|
+
if (!e.isDirectory()) continue
|
|
101
|
+
const p = path.join(boardsDir, e.name, 'kanban.db')
|
|
102
|
+
if (fs.existsSync(p)) out.push(p)
|
|
103
|
+
}
|
|
104
|
+
return out
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** `boards/mobile/board.json` の `default_workdir` を新パスへ(旧パスを指している時だけ)。 */
|
|
108
|
+
export function rewriteBoardWorkdir(hermesHome, { oldWorkdir, newWorkdir }) {
|
|
109
|
+
const out = []
|
|
110
|
+
const boardsDir = path.join(hermesHome, 'kanban', 'boards')
|
|
111
|
+
let ents = []
|
|
112
|
+
try {
|
|
113
|
+
ents = fs.readdirSync(boardsDir, { withFileTypes: true })
|
|
114
|
+
} catch {
|
|
115
|
+
return out
|
|
116
|
+
}
|
|
117
|
+
for (const e of ents) {
|
|
118
|
+
if (!e.isDirectory()) continue
|
|
119
|
+
const file = path.join(boardsDir, e.name, 'board.json')
|
|
120
|
+
let meta
|
|
121
|
+
try {
|
|
122
|
+
meta = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
123
|
+
} catch {
|
|
124
|
+
continue
|
|
125
|
+
}
|
|
126
|
+
if (!meta || typeof meta.default_workdir !== 'string') continue
|
|
127
|
+
const cur = path.resolve(meta.default_workdir.replace(/^~/, os.homedir()))
|
|
128
|
+
if (cur !== path.resolve(oldWorkdir)) continue
|
|
129
|
+
meta.default_workdir = newWorkdir
|
|
130
|
+
fs.writeFileSync(file, `${JSON.stringify(meta, null, 2)}\n`, 'utf8')
|
|
131
|
+
out.push(file)
|
|
132
|
+
}
|
|
133
|
+
return out
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 旧外部 cron(Pilot の reviewWatcher / pipelineWatcher と二重通知になる)の名前(D44)。 */
|
|
137
|
+
export const LEGACY_CRON_NAMES = ['mobile-akapen-watch', 'mobile-review-watch']
|
|
138
|
+
|
|
139
|
+
/** ジョブ 1 件が旧 cron かを、名前系フィールドの部分一致で判定する。 */
|
|
140
|
+
export function isLegacyCronEntry(job, names = LEGACY_CRON_NAMES) {
|
|
141
|
+
if (!job || typeof job !== 'object') return false
|
|
142
|
+
for (const key of ['name', 'id', 'script', 'prompt', 'label', 'title']) {
|
|
143
|
+
const v = job[key]
|
|
144
|
+
if (typeof v === 'string' && names.some((n) => v.includes(n))) return true
|
|
145
|
+
}
|
|
146
|
+
return false
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* `hermes cron list` の 1 行目(` <id> [active]`)を拾うための正規表現。
|
|
151
|
+
* ANSI カラーは `stripAnsi()` で落としてから当てる。
|
|
152
|
+
*/
|
|
153
|
+
const CRON_JOB_HEAD_RE = /^\s{0,6}([A-Za-z0-9_.:-]+)\s+\[(active|paused|disabled|completed)\]\s*$/
|
|
154
|
+
const CRON_NAME_RE = /^\s+Name:\s*(.+?)\s*$/
|
|
155
|
+
const ANSI_RE = /\x1b\[[0-9;]*m/g
|
|
156
|
+
|
|
157
|
+
/** ANSI カラーコードを落とす。 */
|
|
158
|
+
export function stripAnsi(text) {
|
|
159
|
+
return String(text ?? '').replace(ANSI_RE, '')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* `hermes cron list` のテキスト出力を `[{id, name, text}]` にする。
|
|
164
|
+
*
|
|
165
|
+
* 出力形式(`hermes_cli/cron.py` の `cron_list`):
|
|
166
|
+
* ```text
|
|
167
|
+
* ┌───┐
|
|
168
|
+
* │ Scheduled Jobs (profile: default) │
|
|
169
|
+
* └───┘
|
|
170
|
+
*
|
|
171
|
+
* 7cad0b034fff [active]
|
|
172
|
+
* Name: kanban-reap
|
|
173
|
+
* Schedule: */30 * * * *
|
|
174
|
+
* ```
|
|
175
|
+
* ジョブの無い環境は `No scheduled jobs in profile '…'` だけなので空配列になる。
|
|
176
|
+
*
|
|
177
|
+
* @param {string} text `hermes cron list` の stdout
|
|
178
|
+
* @returns {{id: string, name: string, text: string}[]}
|
|
179
|
+
*/
|
|
180
|
+
export function parseCronList(text) {
|
|
181
|
+
const jobs = []
|
|
182
|
+
let cur = null
|
|
183
|
+
for (const line of stripAnsi(text).split(/\r?\n/)) {
|
|
184
|
+
const head = line.match(CRON_JOB_HEAD_RE)
|
|
185
|
+
if (head) {
|
|
186
|
+
cur = { id: head[1], name: '', text: line.trim() }
|
|
187
|
+
jobs.push(cur)
|
|
188
|
+
continue
|
|
189
|
+
}
|
|
190
|
+
if (!cur) continue
|
|
191
|
+
const name = line.match(CRON_NAME_RE)
|
|
192
|
+
if (name) {
|
|
193
|
+
cur.name = name[1]
|
|
194
|
+
continue
|
|
195
|
+
}
|
|
196
|
+
if (line.trim()) cur.text += `\n${line.trim()}`
|
|
197
|
+
}
|
|
198
|
+
return jobs
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* `hermes` CLI を 1 回呼ぶ既定ランナー(テストでは DI で差し替える)。
|
|
203
|
+
* @param {string} cmd
|
|
204
|
+
* @param {string[]} args
|
|
205
|
+
* @param {{env?: object}} [opts]
|
|
206
|
+
* @returns {{status: number|null, stdout: string, stderr: string, error: string|null}}
|
|
207
|
+
*/
|
|
208
|
+
export function defaultCronRunner(cmd, args, { env = process.env } = {}) {
|
|
209
|
+
try {
|
|
210
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8', env })
|
|
211
|
+
return {
|
|
212
|
+
status: r.status,
|
|
213
|
+
stdout: r.stdout ?? '',
|
|
214
|
+
stderr: r.stderr ?? '',
|
|
215
|
+
error: r.error ? String(r.error.message ?? r.error) : null,
|
|
216
|
+
}
|
|
217
|
+
} catch (err) {
|
|
218
|
+
return { status: null, stdout: '', stderr: '', error: String(err?.message ?? err) }
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 旧外部 cron(`mobile-akapen-watch` / `mobile-review-watch`)を **公式 CLI 経由で** 削除する(D44 / D55)。
|
|
224
|
+
*
|
|
225
|
+
* 方針:
|
|
226
|
+
* - `~/.hermes/cron/jobs.json` などの **state ファイルは一切読まない・書かない**。`hermes cron list` の
|
|
227
|
+
* テキスト出力から ID を抽出し、`hermes cron remove <id>` を呼ぶ(スキーマ変更に自動追従する)
|
|
228
|
+
* - **冪等**: 既に無ければ CLI を 1 回呼ぶだけで終わる
|
|
229
|
+
* - `dryRun: true` では検出だけ行い、`cron remove` を呼ばない
|
|
230
|
+
* - 失敗は握りつぶさず `errors` に積む(1 件失敗しても残りは続行)
|
|
231
|
+
*
|
|
232
|
+
* @param {string} hermesHome 互換のため受け取るが、判定には使わない(レポートに残すだけ)
|
|
233
|
+
* @param {object} [opts]
|
|
234
|
+
* @param {boolean} [opts.dryRun] 検出だけ行う
|
|
235
|
+
* @param {string[]} [opts.names] 旧 cron 名
|
|
236
|
+
* @param {(cmd: string, args: string[], o?: object) => {status: number|null, stdout: string, stderr: string, error: string|null}} [opts.runner] CLI ランナー(テスト用 DI)
|
|
237
|
+
* @param {string} [opts.hermesBin] `hermes` 実行ファイル(既定は PATH の `hermes`)
|
|
238
|
+
* @param {object} [opts.env] ランナーに渡す環境変数
|
|
239
|
+
* @returns {{hermesHome: string, via: string, detected: number, removed: number, names: string[], ids: string[], scanned: number, errors: object[], dryRun: boolean}}
|
|
240
|
+
*/
|
|
241
|
+
export function cleanupLegacyCrons(
|
|
242
|
+
hermesHome,
|
|
243
|
+
{
|
|
244
|
+
dryRun = false,
|
|
245
|
+
names = LEGACY_CRON_NAMES,
|
|
246
|
+
runner = null,
|
|
247
|
+
hermesBin = process.env.HERMES_PILOT_HERMES_BIN || 'hermes',
|
|
248
|
+
env = process.env,
|
|
249
|
+
} = {},
|
|
250
|
+
) {
|
|
251
|
+
const resolved = path.resolve(String(hermesHome).replace(/^~/, os.homedir()))
|
|
252
|
+
const result = {
|
|
253
|
+
hermesHome: resolved,
|
|
254
|
+
via: `${hermesBin} cron`,
|
|
255
|
+
detected: 0,
|
|
256
|
+
removed: 0,
|
|
257
|
+
names: [],
|
|
258
|
+
ids: [],
|
|
259
|
+
scanned: 0,
|
|
260
|
+
errors: [],
|
|
261
|
+
dryRun: Boolean(dryRun),
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// テストから DI を忘れたまま本物の `hermes cron remove` が走ると実環境の cron が消える。
|
|
265
|
+
// node:test 配下(NODE_TEST_CONTEXT)ではランナー未指定を「実行しない」に倒す。
|
|
266
|
+
const run = runner ?? (process.env.NODE_TEST_CONTEXT ? null : defaultCronRunner)
|
|
267
|
+
if (!run) {
|
|
268
|
+
result.errors.push({
|
|
269
|
+
cmd: `${hermesBin} cron list`,
|
|
270
|
+
error: 'refusing to run the hermes CLI inside node:test without an injected runner',
|
|
271
|
+
stderr: '',
|
|
272
|
+
})
|
|
273
|
+
return result
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const listed = run(hermesBin, ['cron', 'list'], { env })
|
|
277
|
+
if (!listed || listed.error || listed.status !== 0) {
|
|
278
|
+
result.errors.push({
|
|
279
|
+
cmd: `${hermesBin} cron list`,
|
|
280
|
+
error: String(listed?.error ?? `exit ${listed?.status}`),
|
|
281
|
+
stderr: String(listed?.stderr ?? '').trim().slice(0, 400),
|
|
282
|
+
})
|
|
283
|
+
return result
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const jobs = parseCronList(listed.stdout)
|
|
287
|
+
result.scanned = jobs.length
|
|
288
|
+
const legacy = jobs.filter((job) => isLegacyCronEntry({ id: job.id, name: job.name }, names))
|
|
289
|
+
result.detected = legacy.length
|
|
290
|
+
if (!legacy.length) return result
|
|
291
|
+
|
|
292
|
+
const label = (job) => job.name || job.id
|
|
293
|
+
if (dryRun) {
|
|
294
|
+
result.names = legacy.map(label)
|
|
295
|
+
result.ids = legacy.map((job) => job.id)
|
|
296
|
+
return result
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
for (const job of legacy) {
|
|
300
|
+
const r = runner(hermesBin, ['cron', 'remove', job.id], { env })
|
|
301
|
+
if (r && !r.error && r.status === 0) {
|
|
302
|
+
result.removed += 1
|
|
303
|
+
result.names.push(label(job))
|
|
304
|
+
result.ids.push(job.id)
|
|
305
|
+
continue
|
|
306
|
+
}
|
|
307
|
+
result.errors.push({
|
|
308
|
+
cmd: `${hermesBin} cron remove ${job.id}`,
|
|
309
|
+
error: String(r?.error ?? `exit ${r?.status}`),
|
|
310
|
+
stderr: String(r?.stderr ?? '').trim().slice(0, 400),
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
return result
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* 移行本体。
|
|
318
|
+
*
|
|
319
|
+
* @param {{home?: string, hermesHome?: string, pluginDataDir?: string, srcRoot?: string, dryRun?: boolean,
|
|
320
|
+
* runner?: Function, hermesBin?: string, env?: object}} [opts]
|
|
321
|
+
* @returns {object} レポート
|
|
322
|
+
*/
|
|
323
|
+
export function migrate(opts = {}) {
|
|
324
|
+
const home = opts.home ?? process.env.HOME ?? os.homedir()
|
|
325
|
+
const hermesHome = resolveHermesHome(opts.hermesHome ?? process.env.HERMES_HOME ?? path.join(home, '.hermes'), home)
|
|
326
|
+
const pluginDataDir =
|
|
327
|
+
opts.pluginDataDir ?? process.env.HP_DATA_DIR ?? path.join(hermesHome, 'plugin-data', 'hermes-pilot')
|
|
328
|
+
const reviewDir = path.join(pluginDataDir, 'review')
|
|
329
|
+
const srcRoot = opts.srcRoot ?? path.join(home, 'Projects', 'akapen')
|
|
330
|
+
const oldPluginData = path.join(hermesHome, 'plugin-data', 'akapen')
|
|
331
|
+
const oldMobilePwa = path.join(hermesHome, 'mobile-pwa')
|
|
332
|
+
|
|
333
|
+
const report = {
|
|
334
|
+
home,
|
|
335
|
+
hermesHome,
|
|
336
|
+
pluginDataDir,
|
|
337
|
+
reviewDir,
|
|
338
|
+
srcRoot,
|
|
339
|
+
copied: { sheets: 0, shots: 0, library: 0, reviewFiles: 0, session: 0 },
|
|
340
|
+
existing: { sheets: 0, shots: 0, library: 0 },
|
|
341
|
+
kanban: [],
|
|
342
|
+
boards: [],
|
|
343
|
+
crons: {
|
|
344
|
+
hermesHome: hermesHome,
|
|
345
|
+
via: 'hermes cron',
|
|
346
|
+
detected: 0,
|
|
347
|
+
removed: 0,
|
|
348
|
+
names: [],
|
|
349
|
+
ids: [],
|
|
350
|
+
scanned: 0,
|
|
351
|
+
errors: [],
|
|
352
|
+
dryRun: Boolean(opts.dryRun),
|
|
353
|
+
},
|
|
354
|
+
skipped: [],
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const cronOpts = {
|
|
358
|
+
dryRun: Boolean(opts.dryRun),
|
|
359
|
+
runner: opts.runner,
|
|
360
|
+
hermesBin: opts.hermesBin,
|
|
361
|
+
// `hermes cron` は HERMES_HOME のプロファイルのストアを見る。移行対象の Hermes home を明示して
|
|
362
|
+
// 「別プロファイルの cron を消す / 消すべきものが見えない」を取り違えないようにする。
|
|
363
|
+
env: opts.env ?? { ...process.env, HERMES_HOME: hermesHome },
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (opts.dryRun) {
|
|
367
|
+
// dryRun でも「何が消えるか」だけは返す(ファイルも cron ストアも触らない)
|
|
368
|
+
report.kanban = findKanbanDbs(hermesHome).map((db) => ({ db, updated: 0, written: false }))
|
|
369
|
+
report.crons = cleanupLegacyCrons(hermesHome, cronOpts)
|
|
370
|
+
return report
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// 1) シート・画像の物理コピー(mtime 保持)
|
|
374
|
+
for (const [key, sub] of [
|
|
375
|
+
['sheets', 'sheets'],
|
|
376
|
+
['shots', 'shots'],
|
|
377
|
+
['library', 'library'],
|
|
378
|
+
]) {
|
|
379
|
+
const src = path.join(srcRoot, sub)
|
|
380
|
+
const r = copyDirIfExists(src, path.join(reviewDir, sub))
|
|
381
|
+
if (r.skipped) {
|
|
382
|
+
report.skipped.push(`${sub}: 旧ディレクトリが無い`)
|
|
383
|
+
continue
|
|
384
|
+
}
|
|
385
|
+
report.copied[key] = r.copied
|
|
386
|
+
report.existing[key] = r.total
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// 2) 旧 plugin-data/akapen の JSONL と紐づけマップを review/ へ
|
|
390
|
+
fs.mkdirSync(reviewDir, { recursive: true })
|
|
391
|
+
for (const name of ['feed.jsonl', 'chat-reports.jsonl', 'task-chats.json']) {
|
|
392
|
+
const r = copyFileIfExists(path.join(oldPluginData, name), path.join(reviewDir, name))
|
|
393
|
+
if (r.skipped) report.skipped.push(`${name}: 既にあるか旧ファイルが無い`)
|
|
394
|
+
report.copied.reviewFiles += r.copied
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// 3) mobile-pwa の token / snippets / audit を plugin-data/hermes-pilot へ
|
|
398
|
+
fs.mkdirSync(pluginDataDir, { recursive: true })
|
|
399
|
+
for (const name of ['token', 'snippets.json', 'audit.jsonl']) {
|
|
400
|
+
const r = copyFileIfExists(path.join(oldMobilePwa, name), path.join(pluginDataDir, name))
|
|
401
|
+
if (r.skipped) report.skipped.push(`${name}: 既にあるか旧ファイルが無い`)
|
|
402
|
+
report.copied.session += r.copied
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// 4) kanban.db は **存在確認だけ**(D55: 直接 read-write しない。[akapen] は review.js が後方互換で読む)
|
|
406
|
+
report.kanban = findKanbanDbs(hermesHome).map((db) => ({ db, updated: 0, written: false }))
|
|
407
|
+
|
|
408
|
+
// 5) ボードの default_workdir を新パスへ
|
|
409
|
+
report.boards = rewriteBoardWorkdir(hermesHome, {
|
|
410
|
+
oldWorkdir: srcRoot,
|
|
411
|
+
newWorkdir: reviewDir,
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
// 6) 旧外部 cron(mobile-akapen-watch / mobile-review-watch)を公式 CLI で除去(D44 / D55)
|
|
415
|
+
report.crons = cleanupLegacyCrons(hermesHome, cronOpts)
|
|
416
|
+
|
|
417
|
+
return report
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** レポートを 1 画面に整形する(stdout 用)。 */
|
|
421
|
+
export function formatReport(r, { tagOld = TAG_OLD, tagNew = TAG_NEW, dryRun = false } = {}) {
|
|
422
|
+
const lines = []
|
|
423
|
+
lines.push('=== hermes-pilot migration ===')
|
|
424
|
+
lines.push(`from: ${r.srcRoot}`)
|
|
425
|
+
lines.push(`to: ${r.pluginDataDir}`)
|
|
426
|
+
lines.push(`home: ${r.hermesHome}${dryRun ? '(dry run: 何も書き換えていません)' : ''}`)
|
|
427
|
+
lines.push('')
|
|
428
|
+
lines.push(`sheets : 新規 ${r.copied.sheets} / 既存 ${r.existing.sheets}`)
|
|
429
|
+
lines.push(`shots : 新規 ${r.copied.shots} / 既存 ${r.existing.shots}`)
|
|
430
|
+
lines.push(`library: 新規 ${r.copied.library} / 既存 ${r.existing.library}`)
|
|
431
|
+
lines.push(`review/*.jsonl + task-chats: 新規 ${r.copied.reviewFiles}`)
|
|
432
|
+
lines.push(`token/snippets/audit: 新規 ${r.copied.session}`)
|
|
433
|
+
lines.push('')
|
|
434
|
+
lines.push(
|
|
435
|
+
`kanban.db: ${r.kanban.length} 個を確認 / ${tagOld} → ${tagNew} の書換は廃止(review.js が両タグを読みます・DB は開きません)`,
|
|
436
|
+
)
|
|
437
|
+
for (const k of r.kanban) lines.push(` * ${k.db}`)
|
|
438
|
+
if (r.boards.length) {
|
|
439
|
+
lines.push(`board の default_workdir 更新: ${r.boards.length} 件`)
|
|
440
|
+
for (const b of r.boards) lines.push(` * ${b}`)
|
|
441
|
+
}
|
|
442
|
+
const crons = r.crons ?? { detected: 0, removed: 0, names: [], scanned: 0, errors: [], dryRun: false }
|
|
443
|
+
const cronErrs = crons.errors ?? []
|
|
444
|
+
lines.push('')
|
|
445
|
+
if (crons.removed) {
|
|
446
|
+
lines.push(`旧 cron のクリーンアップ: ${crons.removed} 件を削除(${crons.via ?? 'hermes cron remove'}: ${crons.names.join(', ')})`)
|
|
447
|
+
} else if (crons.detected) {
|
|
448
|
+
lines.push(`旧 cron のクリーンアップ: ${crons.detected} 件を検出(dry run のため未削除: ${crons.names.join(', ')})`)
|
|
449
|
+
} else if (!cronErrs.length) {
|
|
450
|
+
lines.push('旧 cron のクリーンアップ: 0 件(mobile-akapen-watch / mobile-review-watch は既に無い)')
|
|
451
|
+
}
|
|
452
|
+
for (const e of cronErrs.slice(0, 3)) lines.push(` ! ${e.cmd}: ${e.error}${e.stderr ? ` (${e.stderr.split('\n')[0]})` : ''}`)
|
|
453
|
+
if (cronErrs.length > 3) lines.push(` ! …他 ${cronErrs.length - 3} 件`)
|
|
454
|
+
lines.push('')
|
|
455
|
+
lines.push('旧ディレクトリは削除していません(物理コピーのみ)。')
|
|
456
|
+
return lines.join('\n')
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// CLI(`npm run migrate:pilot` / `node scripts/migrate-to-hermes-pilot.mjs [--dry-run]`)
|
|
460
|
+
const invokedDirectly =
|
|
461
|
+
process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url))
|
|
462
|
+
if (invokedDirectly) {
|
|
463
|
+
// `HERMES_HOME` が環境にあると `HOME` を変えても実ストアを見る。何も壊さず下見したい時は --dry-run。
|
|
464
|
+
const dryRun = process.argv.includes('--dry-run') || process.argv.includes('-n')
|
|
465
|
+
try {
|
|
466
|
+
const report = migrate({ dryRun })
|
|
467
|
+
console.log(formatReport(report, { dryRun }))
|
|
468
|
+
} catch (err) {
|
|
469
|
+
console.error(`[migrate] 失敗: ${err?.stack ?? err}`)
|
|
470
|
+
process.exit(1)
|
|
471
|
+
}
|
|
472
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* npm install 後に node-pty の spawn-helper へ実行権限を与える。
|
|
4
|
+
*
|
|
5
|
+
* node-pty 1.1.0 の prebuilds は tar 展開時に exec bit を落とすことがあり、
|
|
6
|
+
* その状態だと `pty.spawn()` が `posix_spawnp failed` で失敗する(実測)。
|
|
7
|
+
*/
|
|
8
|
+
import { chmodSync, existsSync, readdirSync } from 'node:fs'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
|
|
11
|
+
const root = path.resolve(import.meta.dirname, '../node_modules/node-pty/prebuilds')
|
|
12
|
+
if (!existsSync(root)) {
|
|
13
|
+
console.log('[postinstall] node-pty の prebuilds が見つかりません(スキップ)')
|
|
14
|
+
process.exit(0)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let fixed = 0
|
|
18
|
+
for (const platform of readdirSync(root, { withFileTypes: true })) {
|
|
19
|
+
if (!platform.isDirectory()) continue
|
|
20
|
+
for (const name of ['spawn-helper', 'spawn-helper.exe']) {
|
|
21
|
+
const file = path.join(root, platform.name, name)
|
|
22
|
+
if (!existsSync(file)) continue
|
|
23
|
+
try {
|
|
24
|
+
chmodSync(file, 0o755)
|
|
25
|
+
fixed += 1
|
|
26
|
+
console.log(`[postinstall] chmod +x ${path.relative(process.cwd(), file)}`)
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.warn(`[postinstall] chmod 失敗: ${err?.message}`)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
console.log(`[postinstall] node-pty spawn-helper: ${fixed} 件を修正`)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `apps/dashboard/` → リポジトリルートのプラグイン構成へ同期する(D56)。
|
|
4
|
+
*
|
|
5
|
+
* 背景: `hermes plugins install hajimemanila/hermes-pilot --ref <sha>` はリポジトリを
|
|
6
|
+
* そのまま `<plugins>/hermes-pilot/` に展開する。その時点で
|
|
7
|
+
* `__init__.py` と `dashboard/{manifest.json,plugin_api.py,pilot_dashboard.py,dist/*}`
|
|
8
|
+
* がルートに無いと、Hermes のプラグインローダもダッシュボードも何も見つけられない。
|
|
9
|
+
*
|
|
10
|
+
* 編集は今まで通り `apps/dashboard/` 側で行い(テストもそちらを読む)、
|
|
11
|
+
* このスクリプトがルートへ**バイト一致**の写しを作る。`--check` は差分があれば exit 1。
|
|
12
|
+
*
|
|
13
|
+
* node scripts/sync-dashboard.mjs # ルートへ書き出す
|
|
14
|
+
* node scripts/sync-dashboard.mjs --check # 差分の検出だけ(CI / npm run verify)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import fs from 'node:fs'
|
|
18
|
+
import path from 'node:path'
|
|
19
|
+
import { fileURLToPath } from 'node:url'
|
|
20
|
+
|
|
21
|
+
/** リポジトリのルート(このファイルは `scripts/` の下)。 */
|
|
22
|
+
export const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 写し元(編集する側)→ 写し先(インストール直後に読まれる側)。
|
|
26
|
+
* `bin/hermes-pilot.mjs` の `DASHBOARD_FILES` と同じ対応でなければならない。
|
|
27
|
+
*/
|
|
28
|
+
export const ROOT_LAYOUT = [
|
|
29
|
+
{ from: 'apps/dashboard/plugin_init.py', to: '__init__.py' },
|
|
30
|
+
{ from: 'apps/dashboard/manifest.json', to: 'dashboard/manifest.json' },
|
|
31
|
+
{ from: 'apps/dashboard/plugin_api.py', to: 'dashboard/plugin_api.py' },
|
|
32
|
+
{ from: 'apps/dashboard/pilot_dashboard.py', to: 'dashboard/pilot_dashboard.py' },
|
|
33
|
+
{ from: 'apps/dashboard/index.js', to: 'dashboard/dist/index.js' },
|
|
34
|
+
{ from: 'apps/dashboard/style.css', to: 'dashboard/dist/style.css' },
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 1 ファイルの同期結果を返す。
|
|
39
|
+
* @param {{from: string, to: string}} pair 対応
|
|
40
|
+
* @param {string} root リポジトリのルート
|
|
41
|
+
* @returns {'missing'|'stale'|'ok'} `missing` = 写し元が無い, `stale` = 不一致, `ok` = 一致
|
|
42
|
+
*/
|
|
43
|
+
export function statusOf(pair, root = ROOT) {
|
|
44
|
+
const src = path.join(root, pair.from)
|
|
45
|
+
const dest = path.join(root, pair.to)
|
|
46
|
+
if (!fs.existsSync(src)) return 'missing'
|
|
47
|
+
if (!fs.existsSync(dest)) return 'stale'
|
|
48
|
+
return fs.readFileSync(src).equals(fs.readFileSync(dest)) ? 'ok' : 'stale'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* ルート構成を同期する。
|
|
53
|
+
* @param {{root?: string, check?: boolean, log?: (line: string) => void}} [opts] オプション
|
|
54
|
+
* @returns {{written: string[], stale: string[], missing: string[]}} 結果
|
|
55
|
+
*/
|
|
56
|
+
export function syncDashboard({ root = ROOT, check = false, log = () => {} } = {}) {
|
|
57
|
+
const written = []
|
|
58
|
+
const stale = []
|
|
59
|
+
const missing = []
|
|
60
|
+
for (const pair of ROOT_LAYOUT) {
|
|
61
|
+
const state = statusOf(pair, root)
|
|
62
|
+
if (state === 'missing') {
|
|
63
|
+
missing.push(pair.from)
|
|
64
|
+
log(`! 写し元が無い / missing source: ${pair.from}`)
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
if (state === 'ok') continue
|
|
68
|
+
stale.push(pair.to)
|
|
69
|
+
if (check) {
|
|
70
|
+
log(`✗ 未同期 / out of sync: ${pair.to} ← ${pair.from}`)
|
|
71
|
+
continue
|
|
72
|
+
}
|
|
73
|
+
const dest = path.join(root, pair.to)
|
|
74
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
75
|
+
fs.copyFileSync(path.join(root, pair.from), dest)
|
|
76
|
+
written.push(pair.to)
|
|
77
|
+
log(`✓ ${pair.from} → ${pair.to}`)
|
|
78
|
+
}
|
|
79
|
+
return { written, stale, missing }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
|
83
|
+
if (isMain) {
|
|
84
|
+
const check = process.argv.slice(2).includes('--check')
|
|
85
|
+
const result = syncDashboard({ check, log: (line) => process.stdout.write(`${line}\n`) })
|
|
86
|
+
if (result.missing.length) {
|
|
87
|
+
process.stderr.write(`写し元が見つかりません / missing sources: ${result.missing.join(', ')}\n`)
|
|
88
|
+
process.exit(2)
|
|
89
|
+
}
|
|
90
|
+
if (check && result.stale.length) {
|
|
91
|
+
process.stderr.write(
|
|
92
|
+
`ルートのプラグイン構成が apps/dashboard/ とずれています / out of sync:\n ${result.stale.join('\n ')}\n` +
|
|
93
|
+
'→ `node scripts/sync-dashboard.mjs` で同期してください。\n',
|
|
94
|
+
)
|
|
95
|
+
process.exit(1)
|
|
96
|
+
}
|
|
97
|
+
if (!check && !result.written.length) process.stdout.write('既に同期済み / already in sync\n')
|
|
98
|
+
}
|