Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
bun script/agent.ts models opencode-go > /dev/null
bun script/agent.ts shortcuts > /dev/null
- name: Test agent launcher (mock harnesses)
run: bun test script/agent.test.ts script/claude-settings.test.ts script/devices.test.ts
run: bun test script/agent.test.ts script/claude-settings.test.ts script/devices.test.ts script/res.test.ts
- name: Test agent router modules
run: bun test $(ls script/agent.*.test.ts script/agent/*.test.ts 2>/dev/null | grep -v windows)
- name: Guard secret material
Expand All @@ -78,7 +78,7 @@ jobs:
- name: Validate agent launcher config (Windows)
run: bun script/agent.ts check
- name: Test Windows layers (batch shims, .cmd shortcuts, PowerShell wrapper)
run: bun test script/agent.test.ts script/agent.windows.test.ts script/agent.entrypoint.windows.test.ts script/devices.test.ts
run: bun test script/agent.test.ts script/agent.windows.test.ts script/agent.entrypoint.windows.test.ts script/devices.test.ts script/res.test.ts
- name: Test Windows link adapter (adoption-first symlinks)
run: bun test script/link.windows.test.ts
- name: Parse-check PowerShell scripts
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ git submodule status --recursive
│ ├── test-workflow # bootstrap / Infisical regression test
│ ├── secrets-doctor # validate Infisical project access
│ ├── with-secrets # process-scoped Infisical runtime injection
│ ├── res.ts # res observation config + agent plugin convergence
│ └── check-secrets # reject secret material / legacy SOPS state in Git
├── docs/
│ ├── adr/
Expand Down Expand Up @@ -381,3 +382,30 @@ SSH公開鍵の失効ではない。失効は接続先のSSH認可を別途変
旧lockは稼働中devicesプロセスがないことを手動確認してからlockディレクトリだけを整理する。
Windowsの非管理SSH configや秘密鍵のACLは同期で変更しない。不適合は事前に
エラーとし、所有者が必要な権限修正を別途行う。

### res (Device Resource Utility) の導入

`res` はデバイスのリソース観測 CLI(rebuildup/res)。バイナリ導入は
`pc-setup` の machine-global mise baseline(`cargo:device-resource-utility`)が所有し、
dotfiles は `res` が PATH にあるデバイスだけを対象に収束させる。

```sh
bun script/res.ts sync # 手動同期(mise run res-sync でも同じ)
res doctor # 導入・scheduler・観測の健全性確認
```

`script/bootstrap` 末尾でも自動実行される。`res` 非搭載のデバイスでは何もせず終了する。
実行内容(すべて冪等):

- `res doctor` が config / scheduler / DB の欠落を報告した場合のみ `res setup` を実行
- `config.toml` の `[[inventory.roots]]` に、実在する canonical 候補
(`~/src`、`~/Desktop`、`~/work`、各種 toolchain/cache、`~/AppData`、VM 領域)を追加。
既存 entry とユーザー追加分は保持し、存在しない path と他 root に包含される path は追加しない
- `[[ssh.hosts]]` に `~/.ssh/devices.conf`(devices sync 管理)の `device-*` alias を追加。
`rex-*` は同一 endpoint のため対象外。probe は `echo ok`(cmd/PowerShell/sh 共通)
- 検出された agent runtime(claude / codex / opencode / pi)へ res plugin を install

res の `config.toml` は device identity を含む per-device ファイルであり `home/` では配布しない。
デバイス固有の追加 roots / hosts は machine-local overlay
`~/.config/dotfiles/res/observe.local.toml`(commit しない、`[[inventory.roots]]` /
`[[ssh.hosts]]` と同じブロック形式)へ記述する。
4 changes: 4 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ bunx skills@1.9.1 add rebuildup/aude-skills --skill \
--agent claude-code --agent codex -y
"""

[tasks.res-sync]
description = "Converge res observation config and agent plugins on this device"
run = "bun script/res.ts sync"

[tasks.skills-update]
description = "Update tracked project-local Agent Skills non-interactively"
run = "bunx skills@1.9.1 update -p -y"
4 changes: 4 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,8 @@ fi

"$repo_root/script/check-secrets"

# res (Device Resource Utility) convergence is per-device opt-in: the script
# exits quietly when res is not on PATH and never fails bootstrap.
bun "$repo_root/script/res.ts" sync

printf '\nbootstrap complete\n'
150 changes: 150 additions & 0 deletions script/res.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { describe, expect, test } from 'bun:test';
import { platform } from 'node:os';
import { join, resolve } from 'node:path';
import {
deviceHostsFromSshConfig,
doctorProblems,
existingKeys,
mergeConfig,
parseOverlay,
selectInventoryRoots,
} from './res.ts';

const HOME = platform() === 'win32' ? 'C:\\home\\tester' : '/home/tester';
const homePath = (...segs: string[]) => resolve(join(HOME, ...segs));

describe('selectInventoryRoots', () => {
test('keeps only existing directories and drops nested duplicates', () => {
const existing = new Set([
homePath('src'),
homePath('AppData'),
homePath('AppData', 'Local', 'mise'),
]);
const roots = selectInventoryRoots(HOME, [
{ path: '~/src', label: 'src' },
{ path: '~/Desktop', label: 'desktop' },
{ path: '~/AppData', label: 'appdata' },
{ path: '~/AppData/Local/mise', label: 'mise' },
], (p) => existing.has(p));
expect(roots.map((r) => r.path)).toEqual(['~/src', '~/AppData']);
});

test('returns empty when nothing exists', () => {
expect(selectInventoryRoots(HOME, [{ path: '~/nope' }], () => false)).toEqual([]);
});
});

describe('deviceHostsFromSshConfig', () => {
test('collects device-* aliases and excludes rex-* duplicates', () => {
const conf = [
'Host device-mac',
' HostName 100.83.203.34',
'Host rex-mac',
' HostName 100.83.203.34',
'Host device-windows device-wsl',
'Host *',
].join('\n');
expect(deviceHostsFromSshConfig(conf)).toEqual(['device-mac', 'device-windows', 'device-wsl']);
});
});

describe('mergeConfig', () => {
const base = [
'schema_version = 1',
'',
'[identity]',
'device_id = "abc"',
'',
'[[inventory.roots]]',
'path = "~/Desktop"',
'label = "desktop"',
'',
'[[ssh.hosts]]',
'host = "wsl-ubuntu"',
'probe_command = "true"',
'',
].join('\n');

test('appends missing entries and preserves existing content', () => {
const { text, added } = mergeConfig(base, [
{ kind: 'inventory.roots', path: '~/src', label: 'src' },
{ kind: 'inventory.roots', path: '~/Desktop', label: 'desktop' },
{ kind: 'ssh.hosts', host: 'device-mac', probe_command: 'echo ok' },
{ kind: 'ssh.hosts', host: 'wsl-ubuntu' },
], HOME);
expect(added).toHaveLength(2);
expect(text).toContain('device_id = "abc"');
expect(text).toContain('path = "~/Desktop"');
expect(text).toContain('[[inventory.roots]]\npath = "~/src"\nlabel = "src"');
expect(text).toContain('[[ssh.hosts]]\nhost = "device-mac"\nprobe_command = "echo ok"');
// existing wsl-ubuntu host not duplicated
expect(text.match(/host = "wsl-ubuntu"/g)).toHaveLength(1);
});

test('is idempotent on second merge', () => {
const once = mergeConfig(base, [
{ kind: 'inventory.roots', path: '~/src' },
{ kind: 'ssh.hosts', host: 'device-mac' },
], HOME);
const twice = mergeConfig(once.text, [
{ kind: 'inventory.roots', path: '~/src' },
{ kind: 'ssh.hosts', host: 'device-mac' },
], HOME);
expect(twice.added).toHaveLength(0);
expect(twice.text).toBe(once.text);
});

test('matches existing roots written as absolute paths', () => {
const abs = homePath('src');
const cfg = `schema_version = 1\n\n[[inventory.roots]]\npath = "${abs}"\n`;
const { added } = mergeConfig(cfg, [{ kind: 'inventory.roots', path: '~/src' }], HOME);
expect(added).toHaveLength(0);
});
});

describe('parseOverlay', () => {
test('parses inventory and ssh blocks', () => {
const frag = [
'[[inventory.roots]]',
'path = "D:/extra/projects"',
'label = "extra"',
'',
'[[ssh.hosts]]',
'host = "xserver"',
'probe_command = "hostname"',
].join('\n');
expect(parseOverlay(frag)).toEqual([
{ kind: 'inventory.roots', path: 'D:/extra/projects', label: 'extra' },
{ kind: 'ssh.hosts', host: 'xserver', probe_command: 'hostname' },
]);
});
});

describe('doctorProblems', () => {
test('reports non-ok checks', () => {
const json = JSON.stringify({ data: { checks: [
{ name: 'cli_version', status: 'ok' },
{ name: 'scheduler', status: 'missing' },
] } });
expect(doctorProblems(json)).toEqual(['scheduler']);
});

test('tolerates malformed output', () => {
expect(doctorProblems('not json')).toEqual([]);
});
});

describe('existingKeys', () => {
test('scopes keys to their section', () => {
const cfg = [
'[[inventory.roots]]',
'path = "~/a"',
'[[ssh.hosts]]',
'host = "h1"',
'[[collection.system]]',
'enabled = true',
].join('\n');
expect([...existingKeys(cfg, 'inventory.roots')]).toEqual(['~/a']);
expect([...existingKeys(cfg, 'ssh.hosts')]).toEqual(['h1']);
});
});
Loading
Loading