@myclaw163/clawclaw-cli 0.8.34 → 0.8.36
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/docs/configuration.md +19 -0
- package/docs/runtime/owner-lifecycle-and-observability.md +2 -2
- package/package.json +2 -1
- package/skills/clawclaw/SKILL.md +5 -1
- package/skills/clawclaw/references/COMMANDS.md +3 -1
- package/skills/clawclaw/references/STREAM.md +2 -0
- package/src/commands/load.ts +6 -0
- package/src/lib/agent-workspace-skills.ts +4 -0
- package/src/lib/auth.ts +25 -9
- package/src/lib/workspace-runtime-lock.ts +47 -0
- package/src/runtime/clawclaw/behavior-input.ts +5 -3
- package/src/runtime/clawclaw/notifications.ts +16 -0
- package/src/runtime/clawclaw/owner-lock-error.ts +25 -0
- package/src/runtime/clawclaw/owner-lock.ts +221 -0
- package/src/runtime/clawclaw/owner.ts +30 -225
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +64 -0
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +3 -1
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +3 -1
- package/src/runtime/clawclaw/runtime-state.ts +4 -2
- package/src/runtime/clawclaw/starting-owner-control.ts +26 -0
- package/src/runtime/clawclaw/task-choice-projection.ts +93 -0
- package/src/runtime/owner-control.ts +10 -0
- package/src/runtime/process-identity.ts +72 -0
- package/src/sdk/module-input/index.ts +1 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { readFileSync, readlinkSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
export interface ProcessIdentity {
|
|
6
|
+
/** OS process creation value, never the time the lock file was written. */
|
|
7
|
+
birth: string;
|
|
8
|
+
startedAtMs: number;
|
|
9
|
+
executable: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function inspectProcessIdentity(pid: number): ProcessIdentity | null {
|
|
13
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return null;
|
|
14
|
+
try {
|
|
15
|
+
if (process.platform === 'win32') {
|
|
16
|
+
const systemRoot = process.env.SystemRoot ?? 'C:\\Windows';
|
|
17
|
+
const script = `$ErrorActionPreference='Stop'; $p=[System.Diagnostics.Process]::GetProcessById(${pid}); `
|
|
18
|
+
+ '$t=$p.StartTime.ToUniversalTime(); '
|
|
19
|
+
+ '@{birth=$t.Ticks.ToString();startedAtMs=([DateTimeOffset]$t).ToUnixTimeMilliseconds();executable=$p.ProcessName} | ConvertTo-Json -Compress';
|
|
20
|
+
const output = execFileSync(join(systemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'),
|
|
21
|
+
['-NoLogo', '-NoProfile', '-NonInteractive', '-Command', script],
|
|
22
|
+
{ encoding: 'utf8', windowsHide: true, timeout: 5_000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
23
|
+
return JSON.parse(output) as ProcessIdentity;
|
|
24
|
+
}
|
|
25
|
+
if (process.platform === 'linux') {
|
|
26
|
+
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
27
|
+
const ticks = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19]);
|
|
28
|
+
const boot = Number(/^btime (\d+)$/m.exec(readFileSync('/proc/stat', 'utf8'))?.[1]);
|
|
29
|
+
const hz = Number(execFileSync('getconf', ['CLK_TCK'], { encoding: 'utf8', timeout: 2_000 }));
|
|
30
|
+
return { birth: `${boot}:${ticks}`, startedAtMs: (boot + ticks / hz) * 1_000,
|
|
31
|
+
executable: readlinkSync(`/proc/${pid}/exe`) };
|
|
32
|
+
}
|
|
33
|
+
if (process.platform === 'darwin') {
|
|
34
|
+
const options = { encoding: 'utf8' as const, timeout: 2_000, env: { ...process.env, LC_ALL: 'C' } };
|
|
35
|
+
const birth = execFileSync('/bin/ps', ['-p', String(pid), '-o', 'lstart='], options).trim();
|
|
36
|
+
const executable = execFileSync('/bin/ps', ['-p', String(pid), '-o', 'comm='], options).trim();
|
|
37
|
+
const startedAtMs = Date.parse(birth);
|
|
38
|
+
return birth && executable && Number.isFinite(startedAtMs) ? { birth, startedAtMs, executable } : null;
|
|
39
|
+
}
|
|
40
|
+
} catch {}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function sameProcessIdentity(a: ProcessIdentity | null, b: ProcessIdentity | null): boolean {
|
|
45
|
+
return !!a && !!b && a.birth === b.birth && a.executable === b.executable;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Recheck immediately before signalling; a PID alone never authorizes a kill. */
|
|
49
|
+
export function terminateVerifiedProcess(pid: number, identity: ProcessIdentity, signal: NodeJS.Signals): void {
|
|
50
|
+
if (pid === process.pid || !sameProcessIdentity(identity, inspectProcessIdentity(pid))) {
|
|
51
|
+
throw new Error(`Refusing to terminate an unverified ClawClaw runtime (pid ${pid}).`);
|
|
52
|
+
}
|
|
53
|
+
if (process.platform === 'win32') {
|
|
54
|
+
const systemRoot = process.env.SystemRoot ?? 'C:\\Windows';
|
|
55
|
+
if (!/^\d+$/.test(identity.birth)) throw new Error('Invalid Windows process creation identity.');
|
|
56
|
+
// Retain the kernel handle before validating creation time. Killing via that
|
|
57
|
+
// Process object cannot target a later process that happens to reuse the PID.
|
|
58
|
+
// Runtime computation workers are threads of this process, so they exit too.
|
|
59
|
+
const script = `$ErrorActionPreference='Stop'; $p=[System.Diagnostics.Process]::GetProcessById(${pid}); `
|
|
60
|
+
+ `try { $null=$p.Handle; if ($p.StartTime.ToUniversalTime().Ticks.ToString() -ne '${identity.birth}') `
|
|
61
|
+
+ "{ throw 'runtime_identity_changed' }; $p.Kill(); } finally { $p.Dispose() }";
|
|
62
|
+
execFileSync(join(systemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'),
|
|
63
|
+
['-NoLogo', '-NoProfile', '-NonInteractive', '-Command', script],
|
|
64
|
+
{ stdio: 'ignore', windowsHide: true, timeout: 5_000 });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (sameProcessIdentity(identity, inspectProcessIdentity(pid))) {
|
|
68
|
+
try { process.kill(pid, signal); } catch (error) {
|
|
69
|
+
if ((error as NodeJS.ErrnoException).code !== 'ESRCH') throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -44,6 +44,7 @@ export interface GameSelf {
|
|
|
44
44
|
readonly kills_remaining?: number | null;
|
|
45
45
|
readonly activity?: Readonly<GamePlayerActivity>;
|
|
46
46
|
readonly crab_teammates?: readonly Readonly<PlayerRef>[];
|
|
47
|
+
/** Current task choices and execution/completion facts. Unstarted crab sabotage is omitted until ready. */
|
|
47
48
|
readonly tasks?: readonly Readonly<GameTask>[];
|
|
48
49
|
}
|
|
49
50
|
|