Spaces:
Sleeping
Sleeping
File size: 2,548 Bytes
7dbcecf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { homedir } from 'node:os';
const DEFAULT_STATE_PATH = join(homedir(), '.config', 'sin', 'sin-code-devops', 'onboarding-state.json');
type OnboardingState = {
ownerEmail?: string;
notes?: string;
updatedAt?: string;
};
export type TemplateAgentAction =
| { action: 'agent.help' }
| { action: 'sin.code.devops.health' }
| { action: 'sin.code.devops.onboarding.status' }
| { action: 'sin.code.devops.onboarding.save'; ownerEmail?: string; notes?: string; confirm?: boolean };
export async function executeTemplateAgentAction(action: TemplateAgentAction): Promise<unknown> {
switch (action.action) {
case 'agent.help':
return buildHelpPayload();
case 'sin.code.devops.health':
return {
ok: true,
agent: 'sin-code-devops',
primaryModel: 'opencode/qwen3.6-plus-free',
team: 'Team Coding',
};
case 'sin.code.devops.onboarding.status':
return {
ok: true,
statePath: DEFAULT_STATE_PATH,
state: await readState(),
};
case 'sin.code.devops.onboarding.save':
if (!action.confirm) {
throw new Error('input_required:confirm=true required');
}
return {
ok: true,
statePath: DEFAULT_STATE_PATH,
state: await writeState({
ownerEmail: clean(action.ownerEmail),
notes: clean(action.notes),
updatedAt: new Date().toISOString(),
}),
};
}
}
function buildHelpPayload() {
return {
ok: true,
agent: 'sin-code-devops',
actions: ['sin.code.devops.health', 'sin.code.devops.onboarding.status', 'sin.code.devops.onboarding.save'],
controlPlane: {
projectionMode: 'control-plane-first',
capabilityRegistry: 'control_plane.capabilities',
consumerAuthScript: './scripts/hf_pull_script.py',
completeInstallScript: './scripts/complete-install.sh',
},
};
}
async function readState(): Promise<OnboardingState | null> {
try {
return JSON.parse(await readFile(DEFAULT_STATE_PATH, 'utf8')) as OnboardingState;
} catch {
return null;
}
}
async function writeState(state: OnboardingState) {
await mkdir(dirname(DEFAULT_STATE_PATH), { recursive: true });
await writeFile(DEFAULT_STATE_PATH, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
return state;
}
function clean(value: string | undefined) {
const normalized = String(value || '').trim();
return normalized || undefined;
}
|