@atolis-hq/wake 0.1.22 → 0.2.0

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.
@@ -0,0 +1,31 @@
1
+ export async function runSandboxSetupCommand(deps) {
2
+ deps.log('Wake sandbox setup starting.');
3
+ await deps.prepareCodexHome();
4
+ await deps.ensureSshKey();
5
+ if (await deps.prompt('Configure GitHub auth? [y/N]')) {
6
+ deps.log('Optional best practice: sign in with a dedicated GitHub identity for Wake-managed agent work, rather than your main personal account. Make sure it has only the repository access Wake needs.');
7
+ await deps.runInteractive('gh', ['auth', 'login']);
8
+ await deps.runInteractive('gh', ['auth', 'setup-git']);
9
+ }
10
+ else {
11
+ deps.log('Skipping GitHub auth setup.');
12
+ }
13
+ if (await deps.prompt('Configure Claude auth? [y/N]')) {
14
+ await deps.runInteractive('claude', ['auth', 'login', '--claudeai']);
15
+ }
16
+ else {
17
+ deps.log('Skipping Claude auth setup.');
18
+ }
19
+ if (await deps.prompt('Configure Codex auth? [y/N]')) {
20
+ await deps.runInteractive('codex', ['login']);
21
+ }
22
+ else {
23
+ deps.log('Skipping Codex auth setup.');
24
+ }
25
+ if (await deps.prompt('Configure Cursor auth? [y/N]')) {
26
+ await deps.runInteractive('agent', ['login']);
27
+ }
28
+ else {
29
+ deps.log('Skipping Cursor auth setup.');
30
+ }
31
+ }
@@ -1,19 +1,27 @@
1
- import { chmod, copyFile, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
2
- import { dirname, join, resolve } from 'node:path';
1
+ import { access, chmod, copyFile, mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
2
+ import { basename, dirname, join, resolve } from 'node:path';
3
3
  import { createDefaultWakeConfig } from '../config/defaults.js';
4
4
  import { writeJsonFile } from '../lib/json-file.js';
5
- const runtimeDirectoryNames = [
6
- 'events',
7
- 'state',
8
- 'runs',
9
- 'workspaces',
10
- 'repos',
11
- 'sources',
12
- 'locks',
13
- 'logs',
14
- ];
5
+ import { createWakePaths } from '../lib/paths.js';
15
6
  const promptFileNames = ['refine.md', 'implement.md'];
16
- const dockerAssetNames = ['Dockerfile', 'setup.sh', 'log-command.sh'];
7
+ function sanitizeContainerName(name) {
8
+ const sanitized = name
9
+ .toLowerCase()
10
+ .replace(/[^a-z0-9_.-]+/g, '-')
11
+ .replace(/-+/g, '-')
12
+ .replace(/^[-._]+|[-._]+$/g, '');
13
+ return sanitized.length > 0 ? sanitized : 'wake';
14
+ }
15
+ export async function detectDevMode(repoRoot) {
16
+ try {
17
+ await access(join(repoRoot, 'src', 'main.ts'));
18
+ await access(join(repoRoot, 'tsconfig.json'));
19
+ return 'source';
20
+ }
21
+ catch {
22
+ return 'packaged';
23
+ }
24
+ }
17
25
  export async function assertEmptyDirectory(targetDir) {
18
26
  try {
19
27
  const entries = await readdir(targetDir);
@@ -45,129 +53,40 @@ async function copyAssets(repoRoot, sourceDir, targetDir, fileNames) {
45
53
  await copyFile(sourceFile, targetFile);
46
54
  }));
47
55
  }
48
- async function writeLaunchers(wakeRoot, repoRoot) {
49
- const posixRepoRoot = repoRoot.replaceAll('\\', '/');
50
- const shellLauncher = [
51
- '#!/usr/bin/env bash',
52
- 'set -euo pipefail',
53
- '',
54
- `WAKE_REPO="${posixRepoRoot}"`,
55
- 'DIST_MAIN="$WAKE_REPO/dist/src/main.js"',
56
- 'SOURCE_MAIN="$WAKE_REPO/src/main.ts"',
57
- 'CONTAINER_MAIN="/app/dist/src/main.js"',
58
- '',
59
- 'run_local_wake() {',
60
- ' if [[ -f "$DIST_MAIN" ]]; then',
61
- ' exec env MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL=\'*\' node "$DIST_MAIN" "$@"',
62
- ' fi',
63
- ' exec env MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL=\'*\' npx tsx "$SOURCE_MAIN" "$@"',
64
- '}',
65
- '',
66
- 'rewrite_runtime_args() {',
67
- ' local rewritten_args=()',
68
- ' local saw_wake_root=0',
69
- ' while (($# > 0)); do',
70
- ' if [[ "$1" == "--wake-root" ]]; then',
71
- ' saw_wake_root=1',
72
- ' shift',
73
- ' if (($# > 0)); then',
74
- ' shift',
75
- ' fi',
76
- ' rewritten_args+=("--wake-root" "/wake")',
77
- ' continue',
78
- ' fi',
79
- ' rewritten_args+=("$1")',
80
- ' shift',
81
- ' done',
82
- ' if [[ $saw_wake_root -eq 0 ]]; then',
83
- ' rewritten_args+=("--wake-root" "/wake")',
84
- ' fi',
85
- ' printf \'%s\\0\' "${rewritten_args[@]}"',
86
- '}',
87
- '',
88
- 'case "${1:-}" in',
89
- ' init|sandbox|stop)',
90
- ' run_local_wake "$@"',
91
- ' ;;',
92
- ' *)',
93
- ' mapfile -d \'\' -t rewritten_args < <(rewrite_runtime_args "$@")',
94
- ' run_local_wake sandbox exec -- node "$CONTAINER_MAIN" "${rewritten_args[@]}"',
95
- ' ;;',
96
- 'esac',
97
- '',
98
- ].join('\n');
99
- const powerShellLauncher = [
100
- '$ErrorActionPreference = "Stop"',
101
- '',
102
- `$wakeRepo = "${repoRoot.replaceAll('"', '""')}"`,
103
- '$distMain = Join-Path $wakeRepo "dist/src/main.js"',
104
- '$sourceMain = Join-Path $wakeRepo "src/main.ts"',
105
- '$containerMain = "/app/dist/src/main.js"',
106
- '$command = if ($Args.Count -gt 0) { [string] $Args[0] } else { "" }',
107
- '',
108
- 'function Invoke-WakeLocal {',
109
- ' param([string[]] $WakeArgs)',
110
- ' if (Test-Path $distMain) {',
111
- ' & node $distMain @WakeArgs',
112
- ' exit $LASTEXITCODE',
113
- ' }',
114
- ' & npx tsx $sourceMain @WakeArgs',
115
- ' exit $LASTEXITCODE',
116
- '}',
117
- '',
118
- 'switch ($command) {',
119
- ' "init" {',
120
- ' Invoke-WakeLocal -WakeArgs $Args',
121
- ' }',
122
- ' "sandbox" {',
123
- ' Invoke-WakeLocal -WakeArgs $Args',
124
- ' }',
125
- ' "stop" {',
126
- ' Invoke-WakeLocal -WakeArgs $Args',
127
- ' }',
128
- ' default {',
129
- ' $rewrittenArgs = New-Object System.Collections.Generic.List[string]',
130
- ' $sawWakeRoot = $false',
131
- ' for ($index = 0; $index -lt $Args.Count; $index++) {',
132
- ' $arg = [string] $Args[$index]',
133
- ' if ($arg -eq "--wake-root") {',
134
- ' $sawWakeRoot = $true',
135
- ' if ($index + 1 -lt $Args.Count) {',
136
- ' $index++',
137
- ' }',
138
- " $rewrittenArgs.Add('--wake-root')",
139
- " $rewrittenArgs.Add('/wake')",
140
- ' continue',
141
- ' }',
142
- ' $rewrittenArgs.Add($arg)',
143
- ' }',
144
- ' if (-not $sawWakeRoot) {',
145
- " $rewrittenArgs.Add('--wake-root')",
146
- " $rewrittenArgs.Add('/wake')",
147
- ' }',
148
- " Invoke-WakeLocal -WakeArgs (@('sandbox', 'exec', '--', 'node', $containerMain) + $rewrittenArgs.ToArray())",
149
- ' }',
150
- '}',
151
- '',
152
- ].join('\n');
153
- await writeFile(join(wakeRoot, 'wake.sh'), shellLauncher, 'utf8');
154
- await writeFile(join(wakeRoot, 'wake.ps1'), powerShellLauncher, 'utf8');
155
- await chmod(join(wakeRoot, 'wake.sh'), 0o755);
156
- }
157
56
  export async function scaffoldWakeHome(input) {
158
57
  const wakeRoot = resolve(input.wakeRoot);
159
58
  const repoRoot = resolve(input.repoRoot);
59
+ const devMode = input.devModeOverride ?? (await detectDevMode(repoRoot));
60
+ const defaults = createDefaultWakeConfig(wakeRoot);
160
61
  const config = {
161
- ...createDefaultWakeConfig(wakeRoot),
62
+ ...defaults,
63
+ sandbox: {
64
+ ...defaults.sandbox,
65
+ containerName: `wake-sandbox-${sanitizeContainerName(basename(wakeRoot))}`,
66
+ },
162
67
  dev: {
163
68
  repoRoot,
69
+ mode: devMode,
164
70
  },
165
71
  };
166
- await Promise.all(runtimeDirectoryNames.map((directoryName) => mkdir(join(wakeRoot, directoryName), { recursive: true })));
72
+ const paths = createWakePaths(wakeRoot);
73
+ const runtimeDirectories = [
74
+ paths.dataRoot,
75
+ join(paths.dataRoot, 'events'),
76
+ join(paths.dataRoot, 'state'),
77
+ join(paths.dataRoot, 'runs'),
78
+ join(paths.dataRoot, 'sources'),
79
+ join(paths.dataRoot, 'repos'),
80
+ join(paths.dataRoot, 'locks'),
81
+ join(paths.dataRoot, 'logs'),
82
+ join(paths.dataRoot, 'control'),
83
+ join(paths.dataRoot, 'container-home'),
84
+ join(paths.dataRoot, 'transcripts'),
85
+ paths.workspaceRoot,
86
+ ];
87
+ await Promise.all(runtimeDirectories.map((directoryPath) => mkdir(directoryPath, { recursive: true })));
167
88
  await Promise.all([
168
89
  copyAssets(repoRoot, 'prompts', join(wakeRoot, 'prompts'), promptFileNames),
169
- copyAssets(repoRoot, 'docker', join(wakeRoot, 'docker'), dockerAssetNames),
170
90
  writeJsonFile(join(wakeRoot, 'config.json'), config),
171
- writeLaunchers(wakeRoot, repoRoot),
172
91
  ]);
173
92
  }
@@ -4,7 +4,7 @@ const START_PROCESS_CHECK = [
4
4
  'sh',
5
5
  '-lc',
6
6
  [
7
- 'pid="$(cat /wake/logs/start.pid)"',
7
+ 'pid="$(cat /wake/.wake/logs/start.pid)"',
8
8
  'test -n "$pid"',
9
9
  'kill -0 "$pid"',
10
10
  'tr "\\0" " " < "/proc/$pid/cmdline" | grep -F "node /app/dist/src/main.js start --wake-root /wake" >/dev/null',
@@ -61,7 +61,7 @@ async function assertPromptsRootAccessible(promptsRoot) {
61
61
  }
62
62
  await access(promptsRoot);
63
63
  }
64
- export async function runStartupPreflight(config, deps = {}) {
64
+ export async function collectStartupPreflightFailures(config, deps = {}) {
65
65
  const failures = [];
66
66
  const loadPrompt = deps.loadPrompt ?? defaultLoadPrompt;
67
67
  const checkRunnerCommand = deps.checkRunnerCommand ?? defaultCheckRunnerCommand;
@@ -121,6 +121,10 @@ export async function runStartupPreflight(config, deps = {}) {
121
121
  }
122
122
  }
123
123
  }
124
+ return failures;
125
+ }
126
+ export async function runStartupPreflight(config, deps = {}) {
127
+ const failures = await collectStartupPreflightFailures(config, deps);
124
128
  if (failures.length > 0) {
125
129
  throw formatPreflightFailures(failures);
126
130
  }
@@ -15,12 +15,16 @@ export async function loadWakeConfig(options) {
15
15
  // no config file — schema defaults apply
16
16
  }
17
17
  }
18
+ // wakeRoot is always the live invocation's --wake-root/cwd, never a value
19
+ // to accept from a (possibly stale, possibly container-context) config
20
+ // file — spread rawPaths first so wakeRoot always wins. promptsRoot and
21
+ // any other paths key stay file-overridable.
18
22
  const rawPaths = raw.paths ?? {};
19
23
  return parseWakeConfig({
20
24
  ...raw,
21
25
  paths: {
22
- wakeRoot,
23
26
  ...rawPaths,
27
+ wakeRoot,
24
28
  },
25
29
  });
26
30
  }
@@ -433,6 +433,7 @@ export const wakeConfigSchema = z
433
433
  dev: z
434
434
  .object({
435
435
  repoRoot: z.string().optional(),
436
+ mode: z.enum(['source', 'packaged']).optional(),
436
437
  })
437
438
  .default({}),
438
439
  scheduler: z
@@ -6,40 +6,43 @@ export function sanitizePathKey(value) {
6
6
  return value.replace(/[^A-Za-z0-9._-]/g, '__');
7
7
  }
8
8
  export function createWakePaths(wakeRoot) {
9
+ const dataRoot = join(wakeRoot, '.wake');
9
10
  return {
10
11
  wakeRoot,
11
- containerHomeRoot: join(wakeRoot, 'container-home'),
12
+ dataRoot,
13
+ containerHomeRoot: join(dataRoot, 'container-home'),
12
14
  configFile: join(wakeRoot, 'config.json'),
13
- ledgerFile: join(wakeRoot, 'ledger.json'),
14
- pauseFile: join(wakeRoot, 'PAUSE'),
15
- tickRequestFile: join(wakeRoot, 'control', 'tick-request.json'),
16
- tickLockFile: join(wakeRoot, 'locks', 'tick.lock'),
17
- runnerLockFile: join(wakeRoot, 'locks', 'runner.lock'),
18
- issueFixtureFile: join(wakeRoot, 'fixtures', 'issues.json'),
15
+ ledgerFile: join(dataRoot, 'ledger.json'),
16
+ pauseFile: join(dataRoot, 'PAUSE'),
17
+ tickRequestFile: join(dataRoot, 'control', 'tick-request.json'),
18
+ tickLockFile: join(dataRoot, 'locks', 'tick.lock'),
19
+ runnerLockFile: join(dataRoot, 'locks', 'runner.lock'),
20
+ issueFixtureFile: join(dataRoot, 'fixtures', 'issues.json'),
19
21
  workspaceRoot: join(wakeRoot, 'workspaces'),
20
- transcriptsRoot: join(wakeRoot, 'transcripts'),
21
- reposRoot: join(wakeRoot, 'repos'),
22
- repoRoot: (repo) => join(wakeRoot, 'repos', sanitizeRepo(repo)),
23
- sourceStateRoot: join(wakeRoot, 'sources'),
22
+ transcriptsRoot: join(dataRoot, 'transcripts'),
23
+ reposRoot: join(dataRoot, 'repos'),
24
+ repoRoot: (repo) => join(dataRoot, 'repos', sanitizeRepo(repo)),
25
+ sourceStateRoot: join(dataRoot, 'sources'),
24
26
  // Keyed on the minted work id, which is filename-safe by construction
25
27
  // (src/lib/work-id.ts) — hence no sanitizePathKey here. No durable path
26
28
  // embeds a provider, repo, or issue segment (spec §3).
27
- workItemStateFile: (workId) => join(wakeRoot, 'state', `${workId}.json`),
28
- archivedWorkItemStateFile: (workId) => join(wakeRoot, 'state', 'archive', `${workId}.json`),
29
- sourceStateFile: (source, key) => join(wakeRoot, 'sources', sanitizePathKey(source), `${sanitizePathKey(key)}.json`),
30
- runFile: (runId) => join(wakeRoot, 'runs', `${runId}.json`),
31
- runDateFile: (date, runId) => join(wakeRoot, 'runs', 'by-date', date, `${runId}.json`),
32
- eventFile: (date) => join(wakeRoot, 'events', `${date}.jsonl`),
33
- eventEnvelopeFile: (eventId) => join(wakeRoot, 'events-by-id', `${sanitizePathKey(eventId)}.json`),
34
- logFile: (date) => join(wakeRoot, 'logs', `${date}.log`),
29
+ workItemStateFile: (workId) => join(dataRoot, 'state', `${workId}.json`),
30
+ archivedWorkItemStateFile: (workId) => join(dataRoot, 'state', 'archive', `${workId}.json`),
31
+ sourceStateFile: (source, key) => join(dataRoot, 'sources', sanitizePathKey(source), `${sanitizePathKey(key)}.json`),
32
+ runFile: (runId) => join(dataRoot, 'runs', `${runId}.json`),
33
+ runDateFile: (date, runId) => join(dataRoot, 'runs', 'by-date', date, `${runId}.json`),
34
+ eventFile: (date) => join(dataRoot, 'events', `${date}.jsonl`),
35
+ eventEnvelopeFile: (eventId) => join(dataRoot, 'events-by-id', `${sanitizePathKey(eventId)}.json`),
36
+ logFile: (date) => join(dataRoot, 'logs', `${date}.log`),
35
37
  // Workspaces and transcripts are ephemeral scratch rather than durable
36
38
  // state, but they re-key to the work id anyway: they are 1:1 with a work
37
39
  // item, not a ticket, and a ticket-shaped path here would preserve the
38
40
  // second ticket-shaped identity this change exists to remove (spec §3).
39
41
  workspaceDir: (workId) => join(wakeRoot, 'workspaces', workId),
40
- transcriptWorkDir: (workId) => join(wakeRoot, 'transcripts', workId),
41
- transcriptSessionDir: (workId, sessionKey) => join(wakeRoot, 'transcripts', workId, sanitizePathKey(sessionKey)),
42
- resourceIndexRoot: join(wakeRoot, 'state', 'index'),
43
- resourceIndexShardFile: (shard) => join(wakeRoot, 'state', 'index', `${shard}.json`),
42
+ transcriptWorkDir: (workId) => join(dataRoot, 'transcripts', workId),
43
+ transcriptSessionDir: (workId, sessionKey) => join(dataRoot, 'transcripts', workId, sanitizePathKey(sessionKey)),
44
+ resourceIndexRoot: join(dataRoot, 'state', 'index'),
45
+ resourceIndexShardFile: (shard) => join(dataRoot, 'state', 'index', `${shard}.json`),
46
+ controlPlaneUiUrlFile: join(dataRoot, 'control-plane-ui-url'),
44
47
  };
45
48
  }