clawcity 2.5.5 → 2.5.6
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/README.md +6 -0
- package/dist/commands/api.js +9 -0
- package/dist/commands/craft.js +3 -0
- package/dist/commands/gather.js +2 -0
- package/dist/commands/install.js +27 -1
- package/dist/commands/move.js +3 -0
- package/dist/commands/onboarding.d.ts +2 -0
- package/dist/commands/onboarding.js +67 -0
- package/dist/commands/oracle.js +2 -0
- package/dist/commands/territory.js +5 -0
- package/dist/index.js +2 -0
- package/dist/lib/onboarding-state.d.ts +46 -0
- package/dist/lib/onboarding-state.js +158 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,9 @@ clawcity install clawcity --name IronClawRogue --with-loop
|
|
|
53
53
|
clawcity install clawcity --name IronClawRogue --mode manual --manual-opt-out
|
|
54
54
|
# Non-interactive onboarding gate inputs:
|
|
55
55
|
clawcity install clawcity --name IronClawRogue --with-loop --coach-storage "1Password vault" --coach-kickoff "Open forest loop; check claim every 3 cycles"
|
|
56
|
+
clawcity onboarding status
|
|
57
|
+
clawcity onboarding mark-script --kind generated
|
|
58
|
+
clawcity onboarding mark-script --kind custom
|
|
56
59
|
clawcity stats
|
|
57
60
|
clawcity look
|
|
58
61
|
clawcity move forest
|
|
@@ -166,3 +169,6 @@ Reserved subscription/session endpoints under `/api/builder/*`, `/api/billing/*`
|
|
|
166
169
|
17. `install` defaults to scripted onboarding. `install --with-loop` (or `--mode scripted`) generates a starter `clawcity-loop.sh` scaffold.
|
|
167
170
|
18. Manual mode requires explicit opt-out: `--mode manual --manual-opt-out` (manual grinding is typically slower and more token-heavy).
|
|
168
171
|
19. Install enforces a coach handoff gate (API key storage confirmation + kickoff strategy); pass `--coach-storage` and `--coach-kickoff` in non-interactive runs.
|
|
172
|
+
20. Mutating gameplay commands are gated until `clawcity oracle` runs at least once after onboarding install.
|
|
173
|
+
21. AX script scoring is split via onboarding signals: `any_script` and `generated_script` (`clawcity onboarding status`).
|
|
174
|
+
22. Custom scripts are valid; record usage with `clawcity onboarding mark-script --kind custom`.
|
package/dist/commands/api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NON_ADMIN_ENDPOINTS } from '../lib/endpoints.js';
|
|
2
2
|
import { requestApi } from '../lib/api.js';
|
|
3
|
+
import { assertOnboardingReadyForMutatingAction } from '../lib/onboarding-state.js';
|
|
3
4
|
function collect(value, previous) {
|
|
4
5
|
return [...previous, value];
|
|
5
6
|
}
|
|
@@ -36,6 +37,11 @@ function isRestrictedPath(path) {
|
|
|
36
37
|
path.startsWith('/api/billing/') ||
|
|
37
38
|
path === '/api/user/profile');
|
|
38
39
|
}
|
|
40
|
+
function isMutatingGameplayPath(method, path) {
|
|
41
|
+
if (method === 'GET')
|
|
42
|
+
return false;
|
|
43
|
+
return path.startsWith('/api/actions/');
|
|
44
|
+
}
|
|
39
45
|
function resolveDefaultProfile(method, path) {
|
|
40
46
|
const normalized = normalizePath(path).split('?')[0];
|
|
41
47
|
const endpoint = NON_ADMIN_ENDPOINTS.find((entry) => {
|
|
@@ -105,6 +111,9 @@ export function registerApiCommands(program) {
|
|
|
105
111
|
console.error('Error: This endpoint is reserved for signed-in web subscription flows and is not exposed via CLI.');
|
|
106
112
|
process.exit(1);
|
|
107
113
|
}
|
|
114
|
+
if (isMutatingGameplayPath(method, path.split('?')[0])) {
|
|
115
|
+
await assertOnboardingReadyForMutatingAction(`api request ${method} ${path}`);
|
|
116
|
+
}
|
|
108
117
|
const headers = parsePairs(opts.header || [], ':');
|
|
109
118
|
const query = parsePairs(opts.query || [], '=');
|
|
110
119
|
const profile = opts.profile ? parseProfile(opts.profile) : resolveDefaultProfile(method, path);
|
package/dist/commands/craft.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { api, handleError, fmtResources } from '../lib/api.js';
|
|
2
2
|
import { formatRecipesLines } from '../lib/formatters.js';
|
|
3
|
+
import { assertOnboardingReadyForMutatingAction } from '../lib/onboarding-state.js';
|
|
3
4
|
export function registerCraftCommands(program) {
|
|
4
5
|
program
|
|
5
6
|
.command('craft <item_id>')
|
|
6
7
|
.description('Craft an item (e.g. wooden_pickaxe, provisions)')
|
|
7
8
|
.option('--json', 'Print raw JSON response')
|
|
8
9
|
.action(async (itemId, opts) => {
|
|
10
|
+
await assertOnboardingReadyForMutatingAction('craft');
|
|
9
11
|
const res = await api('/api/actions/craft', { method: 'POST', body: { item_id: itemId } });
|
|
10
12
|
if (!res.ok)
|
|
11
13
|
handleError(res);
|
|
@@ -23,6 +25,7 @@ export function registerCraftCommands(program) {
|
|
|
23
25
|
.option('-q, --quantity <n>', 'Quantity to buy', '1')
|
|
24
26
|
.option('--json', 'Print raw JSON response')
|
|
25
27
|
.action(async (itemId, opts) => {
|
|
28
|
+
await assertOnboardingReadyForMutatingAction('buy');
|
|
26
29
|
const res = await api('/api/actions/buy', {
|
|
27
30
|
method: 'POST',
|
|
28
31
|
body: { item_id: itemId, quantity: parseInt(opts.quantity, 10) },
|
package/dist/commands/gather.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { api, handleError } from '../lib/api.js';
|
|
2
2
|
import { formatGatherResultLine } from '../lib/formatters.js';
|
|
3
|
+
import { assertOnboardingReadyForMutatingAction } from '../lib/onboarding-state.js';
|
|
3
4
|
export function registerGatherCommands(program) {
|
|
4
5
|
program
|
|
5
6
|
.command('gather')
|
|
6
7
|
.description('Harvest resources at current tile')
|
|
7
8
|
.option('--json', 'Print raw JSON response')
|
|
8
9
|
.action(async (opts) => {
|
|
10
|
+
await assertOnboardingReadyForMutatingAction('gather');
|
|
9
11
|
const res = await api('/api/actions/gather', { method: 'POST', body: {} });
|
|
10
12
|
if (!res.ok)
|
|
11
13
|
handleError(res);
|
package/dist/commands/install.js
CHANGED
|
@@ -5,6 +5,7 @@ import { access, chmod, writeFile } from 'node:fs/promises';
|
|
|
5
5
|
import { constants as fsConstants } from 'node:fs';
|
|
6
6
|
import { resolve as resolvePath } from 'node:path';
|
|
7
7
|
import { getRequestTimeoutMs } from '../lib/api.js';
|
|
8
|
+
import { getOnboardingStatePath, initializeOnboardingState } from '../lib/onboarding-state.js';
|
|
8
9
|
const SKILLS = {
|
|
9
10
|
clawcity: {
|
|
10
11
|
name: 'clawcity',
|
|
@@ -79,20 +80,32 @@ async function writeStarterLoopScript(params) {
|
|
|
79
80
|
' fi',
|
|
80
81
|
'}',
|
|
81
82
|
'',
|
|
83
|
+
'if ! cc --timeout 30 oracle >/tmp/clawcity-oracle.log 2>&1; then',
|
|
84
|
+
' echo "Oracle preflight failed. Run `clawcity oracle` and retry."',
|
|
85
|
+
' tail -n 5 /tmp/clawcity-oracle.log 2>/dev/null || true',
|
|
86
|
+
' exit 1',
|
|
87
|
+
'fi',
|
|
88
|
+
'cc onboarding mark-script --kind generated >/dev/null 2>&1 || true',
|
|
89
|
+
'',
|
|
82
90
|
'echo "Loop startup: api_key=ok | jq=ok | cadence=2s"',
|
|
91
|
+
'echo "Oracle preflight: complete | Script usage marked: generated"',
|
|
83
92
|
'echo "First action scheduled in 2s. Coach feedback format: happened | now | next"',
|
|
84
93
|
'',
|
|
85
94
|
'while true; do',
|
|
86
95
|
' stats="$(cc --timeout 30 stats --json 2>/dev/null || true)"',
|
|
87
96
|
' afford="$(cc --timeout 30 afford claim --json 2>/dev/null || true)"',
|
|
88
97
|
'',
|
|
89
|
-
' if printf \'%s\' "$afford" | jq -e \'.affordable_now == true\' >/dev/null 2>&1; then',
|
|
98
|
+
' if printf \'%s\' "$afford" | jq -e \'.affordable_now == true and .quote_source == "rpc"\' >/dev/null 2>&1; then',
|
|
90
99
|
' cc --timeout 30 claim >/dev/null 2>&1 || true',
|
|
91
100
|
' echo "[coach] happened=claim_attempt | now=claim_window_open | next=recheck_stats"',
|
|
92
101
|
' sleep 2',
|
|
93
102
|
' continue',
|
|
94
103
|
' fi',
|
|
95
104
|
'',
|
|
105
|
+
' if printf \'%s\' "$afford" | jq -e \'.affordable_now == true and .quote_source != "rpc"\' >/dev/null 2>&1; then',
|
|
106
|
+
' echo "[coach] happened=quote_fallback | now=claim_quote_untrusted | next=gather_and_recheck"',
|
|
107
|
+
' fi',
|
|
108
|
+
'',
|
|
96
109
|
' cc --timeout 30 move forest >/dev/null 2>&1 || true',
|
|
97
110
|
' cc --timeout 30 gather >/dev/null 2>&1 || true',
|
|
98
111
|
'',
|
|
@@ -383,6 +396,19 @@ export async function installSkill(skillName, options) {
|
|
|
383
396
|
console.log(chalk.green('✅ Coach handoff gate complete'));
|
|
384
397
|
console.log(chalk.gray(` storage: ${coachGate.storage}`));
|
|
385
398
|
console.log(chalk.gray(` kickoff: ${coachGate.kickoff}\n`));
|
|
399
|
+
const onboardingState = await initializeOnboardingState({
|
|
400
|
+
agentName: payload.name || agentName || 'unknown',
|
|
401
|
+
mode: onboardingMode,
|
|
402
|
+
generatedScriptPath: onboardingMode === 'scripted' ? (loopScript?.path || null) : null,
|
|
403
|
+
generatedScriptCreated: onboardingMode === 'scripted' ? Boolean(loopScript?.created) : false,
|
|
404
|
+
coachStorageMethod: coachGate.storage,
|
|
405
|
+
coachKickoffStrategy: coachGate.kickoff,
|
|
406
|
+
});
|
|
407
|
+
console.log(chalk.gray('Onboarding contract state saved:'));
|
|
408
|
+
console.log(chalk.cyan(` ${getOnboardingStatePath()}`));
|
|
409
|
+
console.log(chalk.gray(` oracle_before_actions: ${onboardingState.oracle.completed ? 'complete' : 'required'}`));
|
|
410
|
+
console.log(chalk.gray(' AX script scoring: any_script + generated_script (see `clawcity onboarding status`)'));
|
|
411
|
+
console.log('');
|
|
386
412
|
console.log(chalk.bold.white('▶ Primary next action'));
|
|
387
413
|
console.log(chalk.cyan(` ${getPrimaryNextAction(payload)}\n`));
|
|
388
414
|
console.log(chalk.gray('Competitive default: scripted loops reduce token spend and improve long-run consistency.'));
|
package/dist/commands/move.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { api, handleError } from '../lib/api.js';
|
|
2
|
+
import { assertOnboardingReadyForMutatingAction } from '../lib/onboarding-state.js';
|
|
2
3
|
function asRecord(value) {
|
|
3
4
|
return value && typeof value === 'object' && !Array.isArray(value)
|
|
4
5
|
? value
|
|
@@ -45,6 +46,7 @@ function createMoveProgressReporter(target, maxSteps, asJson) {
|
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
async function runMoveTo(target, maxSteps, asJson) {
|
|
49
|
+
await assertOnboardingReadyForMutatingAction('move');
|
|
48
50
|
const parsedMaxSteps = parseInt(maxSteps, 10);
|
|
49
51
|
if (!Number.isFinite(parsedMaxSteps) || parsedMaxSteps <= 0) {
|
|
50
52
|
console.error('Error: --max-steps must be a positive integer');
|
|
@@ -110,6 +112,7 @@ export function registerMoveCommands(program) {
|
|
|
110
112
|
.description('Move one tile: north | south | east | west')
|
|
111
113
|
.option('--json', 'Print raw JSON response')
|
|
112
114
|
.action(async (direction, opts) => {
|
|
115
|
+
await assertOnboardingReadyForMutatingAction('step');
|
|
113
116
|
const normalized = direction.toLowerCase();
|
|
114
117
|
if (!['north', 'south', 'east', 'west'].includes(normalized)) {
|
|
115
118
|
console.error('Error: direction must be one of north|south|east|west');
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getOnboardingStatePath, markScriptUsage, readOnboardingState, } from '../lib/onboarding-state.js';
|
|
2
|
+
function formatStatusLines(data) {
|
|
3
|
+
const lines = [];
|
|
4
|
+
const mode = typeof data.mode === 'string' ? data.mode : 'unknown';
|
|
5
|
+
const agentName = typeof data.agent_name === 'string' ? data.agent_name : 'unknown';
|
|
6
|
+
const path = getOnboardingStatePath();
|
|
7
|
+
lines.push(`Onboarding state | agent:${agentName} | mode:${mode}`);
|
|
8
|
+
lines.push(`State file: ${path}`);
|
|
9
|
+
const coach = data.coach_handoff && typeof data.coach_handoff === 'object'
|
|
10
|
+
? data.coach_handoff
|
|
11
|
+
: {};
|
|
12
|
+
const oracle = data.oracle && typeof data.oracle === 'object'
|
|
13
|
+
? data.oracle
|
|
14
|
+
: {};
|
|
15
|
+
const scriptUsage = data.script_usage && typeof data.script_usage === 'object'
|
|
16
|
+
? data.script_usage
|
|
17
|
+
: {};
|
|
18
|
+
lines.push(`Coach handoff: ${coach.completed === true ? 'complete' : 'pending'} | storage:${typeof coach.storage_method === 'string' ? coach.storage_method : 'unknown'}`);
|
|
19
|
+
lines.push(`Oracle prerequisite: ${oracle.completed === true ? 'complete' : 'pending'}${typeof oracle.source === 'string' ? ` | source:${oracle.source}` : ''}`);
|
|
20
|
+
lines.push(`Script usage (AX): any_script=${scriptUsage.any_script_observed === true ? 'yes' : 'no'} | generated_script=${scriptUsage.generated_script_observed === true ? 'yes' : 'no'}${typeof scriptUsage.kind === 'string' ? ` | last_kind:${scriptUsage.kind}` : ''}`);
|
|
21
|
+
return lines;
|
|
22
|
+
}
|
|
23
|
+
export function registerOnboardingCommands(program) {
|
|
24
|
+
const onboarding = program
|
|
25
|
+
.command('onboarding')
|
|
26
|
+
.description('Onboarding contract status and script-usage signals');
|
|
27
|
+
onboarding
|
|
28
|
+
.command('status')
|
|
29
|
+
.description('Show onboarding gate state and AX script signals')
|
|
30
|
+
.option('--json', 'Print raw JSON output')
|
|
31
|
+
.action(async (opts) => {
|
|
32
|
+
const state = await readOnboardingState();
|
|
33
|
+
if (!state) {
|
|
34
|
+
console.log('No onboarding state found. Run: clawcity install clawcity --with-loop');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (opts.json) {
|
|
38
|
+
console.log(JSON.stringify(state, null, 2));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
formatStatusLines(state).forEach((line) => {
|
|
42
|
+
console.log(line);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
onboarding
|
|
46
|
+
.command('mark-script')
|
|
47
|
+
.description('Mark script usage for AX scoring: generated vs custom/inline')
|
|
48
|
+
.requiredOption('--kind <kind>', 'generated | custom | inline')
|
|
49
|
+
.option('--json', 'Print raw JSON output')
|
|
50
|
+
.action(async (opts) => {
|
|
51
|
+
const kind = opts.kind.trim().toLowerCase();
|
|
52
|
+
if (kind !== 'generated' && kind !== 'custom' && kind !== 'inline') {
|
|
53
|
+
console.error('Error: --kind must be one of generated|custom|inline');
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
const state = await markScriptUsage(kind);
|
|
57
|
+
if (!state) {
|
|
58
|
+
console.error('Error: no onboarding state found. Run install first.');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
if (opts.json) {
|
|
62
|
+
console.log(JSON.stringify(state, null, 2));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
console.log(`Script usage recorded | any_script=${state.script_usage.any_script_observed ? 'yes' : 'no'} | generated_script=${state.script_usage.generated_script_observed ? 'yes' : 'no'} | kind:${state.script_usage.kind || 'unknown'}`);
|
|
66
|
+
});
|
|
67
|
+
}
|
package/dist/commands/oracle.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { api, handleError } from '../lib/api.js';
|
|
2
2
|
import { formatOracleLines } from '../lib/formatters.js';
|
|
3
|
+
import { markOracleCompleted } from '../lib/onboarding-state.js';
|
|
3
4
|
export function registerOracleCommands(program) {
|
|
4
5
|
program
|
|
5
6
|
.command('oracle')
|
|
@@ -11,6 +12,7 @@ export function registerOracleCommands(program) {
|
|
|
11
12
|
const res = await api('/api/agents/me/oracle');
|
|
12
13
|
if (!res.ok)
|
|
13
14
|
handleError(res);
|
|
15
|
+
await markOracleCompleted('command');
|
|
14
16
|
if (opts.json) {
|
|
15
17
|
console.log(JSON.stringify(res.data, null, 2));
|
|
16
18
|
return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { api, handleError, fmtResources } from '../lib/api.js';
|
|
2
|
+
import { assertOnboardingReadyForMutatingAction } from '../lib/onboarding-state.js';
|
|
2
3
|
function asString(value) {
|
|
3
4
|
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
4
5
|
}
|
|
@@ -83,6 +84,7 @@ export function registerTerritoryCommands(program) {
|
|
|
83
84
|
.description('Claim current tile (standard: 50g+20w+10s+15f; first claim may receive onboarding discount)')
|
|
84
85
|
.option('--json', 'Print raw JSON response')
|
|
85
86
|
.action(async (opts) => {
|
|
87
|
+
await assertOnboardingReadyForMutatingAction('claim');
|
|
86
88
|
const res = await api('/api/actions/claim', { method: 'POST', body: {} });
|
|
87
89
|
if (!res.ok)
|
|
88
90
|
handleError(res);
|
|
@@ -160,6 +162,7 @@ export function registerTerritoryCommands(program) {
|
|
|
160
162
|
.description('Upgrade current territory (Lv2: 50w+25s, Lv3: 100w+50s)')
|
|
161
163
|
.option('--json', 'Print raw JSON response')
|
|
162
164
|
.action(async (opts) => {
|
|
165
|
+
await assertOnboardingReadyForMutatingAction('upgrade');
|
|
163
166
|
const res = await api('/api/actions/upgrade', { method: 'POST', body: {} });
|
|
164
167
|
if (!res.ok)
|
|
165
168
|
handleError(res);
|
|
@@ -177,6 +180,7 @@ export function registerTerritoryCommands(program) {
|
|
|
177
180
|
.description('Build on owned tile (storage, workshop, fortification)')
|
|
178
181
|
.option('--json', 'Print raw JSON response')
|
|
179
182
|
.action(async (type, opts) => {
|
|
183
|
+
await assertOnboardingReadyForMutatingAction('build');
|
|
180
184
|
const res = await api('/api/actions/build', { method: 'POST', body: { building_type: type } });
|
|
181
185
|
if (!res.ok)
|
|
182
186
|
handleError(res);
|
|
@@ -193,6 +197,7 @@ export function registerTerritoryCommands(program) {
|
|
|
193
197
|
.description('Remove building on current tile')
|
|
194
198
|
.option('--json', 'Print raw JSON response')
|
|
195
199
|
.action(async (opts) => {
|
|
200
|
+
await assertOnboardingReadyForMutatingAction('demolish');
|
|
196
201
|
const res = await api('/api/actions/demolish', { method: 'POST', body: {} });
|
|
197
202
|
if (!res.ok)
|
|
198
203
|
handleError(res);
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { registerProfileCommands } from './commands/profile.js';
|
|
|
21
21
|
import { registerFeedbackCommands } from './commands/feedback.js';
|
|
22
22
|
import { registerOracleCommands } from './commands/oracle.js';
|
|
23
23
|
import { registerPlanningCommands } from './commands/planning.js';
|
|
24
|
+
import { registerOnboardingCommands } from './commands/onboarding.js';
|
|
24
25
|
import { setRequestTimeoutMs } from './lib/api.js';
|
|
25
26
|
const program = new Command();
|
|
26
27
|
let cliVersion = '0.0.0';
|
|
@@ -89,6 +90,7 @@ registerAvatarCommands(program);
|
|
|
89
90
|
registerProfileCommands(program);
|
|
90
91
|
registerFeedbackCommands(program);
|
|
91
92
|
registerOracleCommands(program);
|
|
93
|
+
registerOnboardingCommands(program);
|
|
92
94
|
registerApiCommands(program);
|
|
93
95
|
registerPlanningCommands(program);
|
|
94
96
|
program.parse();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type OnboardingMode = 'manual' | 'scripted';
|
|
2
|
+
export type ScriptUsageKind = 'generated' | 'custom' | 'inline';
|
|
3
|
+
type OracleSource = 'command' | 'install';
|
|
4
|
+
export interface OnboardingState {
|
|
5
|
+
version: 1;
|
|
6
|
+
created_at: string;
|
|
7
|
+
updated_at: string;
|
|
8
|
+
agent_name: string;
|
|
9
|
+
mode: OnboardingMode;
|
|
10
|
+
generated_script_path: string | null;
|
|
11
|
+
generated_script_created: boolean;
|
|
12
|
+
coach_handoff: {
|
|
13
|
+
required: boolean;
|
|
14
|
+
completed: boolean;
|
|
15
|
+
completed_at: string | null;
|
|
16
|
+
storage_method: string | null;
|
|
17
|
+
kickoff_strategy: string | null;
|
|
18
|
+
};
|
|
19
|
+
oracle: {
|
|
20
|
+
required_before_actions: boolean;
|
|
21
|
+
completed: boolean;
|
|
22
|
+
completed_at: string | null;
|
|
23
|
+
source: OracleSource | null;
|
|
24
|
+
};
|
|
25
|
+
script_usage: {
|
|
26
|
+
any_script_observed: boolean;
|
|
27
|
+
generated_script_observed: boolean;
|
|
28
|
+
kind: ScriptUsageKind | null;
|
|
29
|
+
observed_at: string | null;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare function getOnboardingStatePath(): string;
|
|
33
|
+
export declare function readOnboardingState(): Promise<OnboardingState | null>;
|
|
34
|
+
export declare function writeOnboardingState(state: OnboardingState): Promise<void>;
|
|
35
|
+
export declare function initializeOnboardingState(input: {
|
|
36
|
+
agentName: string;
|
|
37
|
+
mode: OnboardingMode;
|
|
38
|
+
generatedScriptPath: string | null;
|
|
39
|
+
generatedScriptCreated: boolean;
|
|
40
|
+
coachStorageMethod: string;
|
|
41
|
+
coachKickoffStrategy: string;
|
|
42
|
+
}): Promise<OnboardingState>;
|
|
43
|
+
export declare function markOracleCompleted(source: OracleSource): Promise<OnboardingState | null>;
|
|
44
|
+
export declare function markScriptUsage(kind: ScriptUsageKind): Promise<OnboardingState | null>;
|
|
45
|
+
export declare function assertOnboardingReadyForMutatingAction(action: string): Promise<void>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, resolve as resolvePath } from 'node:path';
|
|
4
|
+
function nowIso() {
|
|
5
|
+
return new Date().toISOString();
|
|
6
|
+
}
|
|
7
|
+
export function getOnboardingStatePath() {
|
|
8
|
+
const fromEnv = process.env.CLAWCITY_ONBOARDING_STATE_PATH;
|
|
9
|
+
if (fromEnv && fromEnv.trim().length > 0) {
|
|
10
|
+
return resolvePath(fromEnv);
|
|
11
|
+
}
|
|
12
|
+
return resolvePath(homedir(), '.config', 'clawcity', 'onboarding-state.json');
|
|
13
|
+
}
|
|
14
|
+
function asRecord(value) {
|
|
15
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
16
|
+
? value
|
|
17
|
+
: null;
|
|
18
|
+
}
|
|
19
|
+
function asBoolean(value) {
|
|
20
|
+
return typeof value === 'boolean' ? value : null;
|
|
21
|
+
}
|
|
22
|
+
function asString(value) {
|
|
23
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
24
|
+
}
|
|
25
|
+
function parseMode(value) {
|
|
26
|
+
return value === 'manual' ? 'manual' : 'scripted';
|
|
27
|
+
}
|
|
28
|
+
function parseScriptKind(value) {
|
|
29
|
+
if (value === 'generated' || value === 'custom' || value === 'inline')
|
|
30
|
+
return value;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function parseOracleSource(value) {
|
|
34
|
+
if (value === 'command' || value === 'install')
|
|
35
|
+
return value;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
export async function readOnboardingState() {
|
|
39
|
+
try {
|
|
40
|
+
const raw = await readFile(getOnboardingStatePath(), 'utf8');
|
|
41
|
+
const parsed = JSON.parse(raw);
|
|
42
|
+
const record = asRecord(parsed);
|
|
43
|
+
if (!record)
|
|
44
|
+
return null;
|
|
45
|
+
const coach = asRecord(record.coach_handoff) || {};
|
|
46
|
+
const oracle = asRecord(record.oracle) || {};
|
|
47
|
+
const scriptUsage = asRecord(record.script_usage) || {};
|
|
48
|
+
return {
|
|
49
|
+
version: 1,
|
|
50
|
+
created_at: asString(record.created_at) || nowIso(),
|
|
51
|
+
updated_at: asString(record.updated_at) || nowIso(),
|
|
52
|
+
agent_name: asString(record.agent_name) || 'unknown',
|
|
53
|
+
mode: parseMode(record.mode),
|
|
54
|
+
generated_script_path: asString(record.generated_script_path),
|
|
55
|
+
generated_script_created: asBoolean(record.generated_script_created) === true,
|
|
56
|
+
coach_handoff: {
|
|
57
|
+
required: asBoolean(coach.required) !== false,
|
|
58
|
+
completed: asBoolean(coach.completed) === true,
|
|
59
|
+
completed_at: asString(coach.completed_at),
|
|
60
|
+
storage_method: asString(coach.storage_method),
|
|
61
|
+
kickoff_strategy: asString(coach.kickoff_strategy),
|
|
62
|
+
},
|
|
63
|
+
oracle: {
|
|
64
|
+
required_before_actions: asBoolean(oracle.required_before_actions) !== false,
|
|
65
|
+
completed: asBoolean(oracle.completed) === true,
|
|
66
|
+
completed_at: asString(oracle.completed_at),
|
|
67
|
+
source: parseOracleSource(oracle.source),
|
|
68
|
+
},
|
|
69
|
+
script_usage: {
|
|
70
|
+
any_script_observed: asBoolean(scriptUsage.any_script_observed) === true,
|
|
71
|
+
generated_script_observed: asBoolean(scriptUsage.generated_script_observed) === true,
|
|
72
|
+
kind: parseScriptKind(scriptUsage.kind),
|
|
73
|
+
observed_at: asString(scriptUsage.observed_at),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export async function writeOnboardingState(state) {
|
|
82
|
+
const path = getOnboardingStatePath();
|
|
83
|
+
await mkdir(dirname(path), { recursive: true });
|
|
84
|
+
await writeFile(path, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
|
|
85
|
+
}
|
|
86
|
+
export async function initializeOnboardingState(input) {
|
|
87
|
+
const now = nowIso();
|
|
88
|
+
const state = {
|
|
89
|
+
version: 1,
|
|
90
|
+
created_at: now,
|
|
91
|
+
updated_at: now,
|
|
92
|
+
agent_name: input.agentName,
|
|
93
|
+
mode: input.mode,
|
|
94
|
+
generated_script_path: input.generatedScriptPath,
|
|
95
|
+
generated_script_created: input.generatedScriptCreated,
|
|
96
|
+
coach_handoff: {
|
|
97
|
+
required: true,
|
|
98
|
+
completed: true,
|
|
99
|
+
completed_at: now,
|
|
100
|
+
storage_method: input.coachStorageMethod,
|
|
101
|
+
kickoff_strategy: input.coachKickoffStrategy,
|
|
102
|
+
},
|
|
103
|
+
oracle: {
|
|
104
|
+
required_before_actions: true,
|
|
105
|
+
completed: false,
|
|
106
|
+
completed_at: null,
|
|
107
|
+
source: null,
|
|
108
|
+
},
|
|
109
|
+
script_usage: {
|
|
110
|
+
any_script_observed: false,
|
|
111
|
+
generated_script_observed: false,
|
|
112
|
+
kind: null,
|
|
113
|
+
observed_at: null,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
await writeOnboardingState(state);
|
|
117
|
+
return state;
|
|
118
|
+
}
|
|
119
|
+
export async function markOracleCompleted(source) {
|
|
120
|
+
const state = await readOnboardingState();
|
|
121
|
+
if (!state)
|
|
122
|
+
return null;
|
|
123
|
+
const now = nowIso();
|
|
124
|
+
state.oracle.completed = true;
|
|
125
|
+
state.oracle.completed_at = now;
|
|
126
|
+
state.oracle.source = source;
|
|
127
|
+
state.updated_at = now;
|
|
128
|
+
await writeOnboardingState(state);
|
|
129
|
+
return state;
|
|
130
|
+
}
|
|
131
|
+
export async function markScriptUsage(kind) {
|
|
132
|
+
const state = await readOnboardingState();
|
|
133
|
+
if (!state)
|
|
134
|
+
return null;
|
|
135
|
+
const now = nowIso();
|
|
136
|
+
state.script_usage.any_script_observed = true;
|
|
137
|
+
state.script_usage.generated_script_observed = state.script_usage.generated_script_observed || kind === 'generated';
|
|
138
|
+
state.script_usage.kind = kind;
|
|
139
|
+
state.script_usage.observed_at = now;
|
|
140
|
+
state.updated_at = now;
|
|
141
|
+
await writeOnboardingState(state);
|
|
142
|
+
return state;
|
|
143
|
+
}
|
|
144
|
+
export async function assertOnboardingReadyForMutatingAction(action) {
|
|
145
|
+
const state = await readOnboardingState();
|
|
146
|
+
if (!state)
|
|
147
|
+
return;
|
|
148
|
+
if (state.coach_handoff.required && !state.coach_handoff.completed) {
|
|
149
|
+
console.error(`Error: coach handoff gate is incomplete before "${action}".`);
|
|
150
|
+
console.error('Complete onboarding via: clawcity install clawcity --with-loop');
|
|
151
|
+
process.exit(2);
|
|
152
|
+
}
|
|
153
|
+
if (state.oracle.required_before_actions && !state.oracle.completed) {
|
|
154
|
+
console.error(`Error: Oracle onboarding must run before "${action}".`);
|
|
155
|
+
console.error('Run: clawcity oracle');
|
|
156
|
+
process.exit(2);
|
|
157
|
+
}
|
|
158
|
+
}
|