Skip to content
Merged
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
7 changes: 7 additions & 0 deletions packages/cli/src/cli-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type MakaCliCommand =
}
| { kind: 'run'; args: string[] }
| { kind: 'activate'; args: string[] }
| { kind: 'session-export'; args: string[] }
| { kind: 'eval'; args: string[] }
| { kind: 'acp' }
| RuntimeHostCliCommand
Expand Down Expand Up @@ -83,6 +84,7 @@ export function parseMakaCliArgs(
if (first?.startsWith('--')) return parseTuiArgs(argv);
if (first === 'run' || first === '-p') return { kind: 'run', args: argv.slice(1) };
if (first === 'activate') return { kind: 'activate', args: argv.slice(1) };
if (first === 'session-export') return { kind: 'session-export', args: argv.slice(1) };
if (first === 'eval') return { kind: 'eval', args: argv.slice(1) };
if (first === 'update') return parseRuntimeHostInstalledUpdateCommand(argv.slice(1));
if (first === 'runtime-host') return parseRuntimeHostCommand(argv.slice(1));
Expand Down Expand Up @@ -136,6 +138,7 @@ function helpText(cliCommand: string): string {
` ${cliCommand} --acp Serve ACP v1 over stdio (initialize, session/new, session/list)`,
` ${cliCommand} run ... Run one non-interactive model turn`,
` ${cliCommand} activate ... Run one Cloud Session activation and emit JSONL`,
` ${cliCommand} session-export --workspace-root <dir> --session <id> --out <file.maka-session>`,
` ${cliCommand} -p ... Alias for ${cliCommand} run`,
` ${cliCommand} eval ... Run one declarative multi-arm experiment`,
` ${cliCommand} update --target <latest|next|version> Update this npm-global CLI and its local Runtime Host`,
Expand Down Expand Up @@ -293,6 +296,10 @@ export async function runMakaCli(
const { runMakaActivationCli } = await import('./activation-command.js');
return runMakaActivationCli(command.args);
}
case 'session-export': {
const { runMakaSessionExportCli } = await import('./session-export-command.js');
return runMakaSessionExportCli(command.args);
}
case 'eval': {
const { configureInstalledEvalBundle } = await import('./eval-bundle-path.js');
configureInstalledEvalBundle();
Expand Down
72 changes: 72 additions & 0 deletions packages/cli/src/session-export-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { exportSessionBundle } from '@maka/runtime/session-export';

const USAGE = 'maka session-export --workspace-root <dir> --session <id> --out <file.maka-session>';

const FAILURE_EXIT_CODES: Record<string, number> = {
session_not_found: 2,
session_active: 3,
artifact_missing: 4,
destination_exists: 5,
workspace_not_found: 6,
};

function parseArgs(args: string[]): Record<string, string> {
const values: Record<string, string> = {};
for (let index = 0; index < args.length; index += 2) {
const name = args[index];
const value = args[index + 1];
if (!name || !value) throw new Error(USAGE);
if (name === '--workspace-root') values.workspaceRoot = value;
else if (name === '--session') values.sessionId = value;
else if (name === '--out') values.destination = value;
else throw new Error(USAGE);
}
if (!values.workspaceRoot || !values.sessionId || !values.destination) throw new Error(USAGE);
return values;
}

export async function runMakaSessionExportCli(args: string[]): Promise<number> {
let parsed: Record<string, string>;
try {
parsed = parseArgs(args);
} catch (error) {
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
return 1;
}
const result = await exportSessionBundle({
workspaceRoot: parsed.workspaceRoot,
sessionId: parsed.sessionId,
destination: parsed.destination,
});
if (!result.ok) {
process.stderr.write(`${JSON.stringify(result.reason)}\n`);
return FAILURE_EXIT_CODES[result.reason.kind] ?? 1;
}
process.stdout.write(
`${JSON.stringify({
export: result.export,
archiveDigest: result.artifact.archiveDigest,
compressedBytes: result.artifact.compressedBytes,
})}\n`,
);
return 0;
}
1 change: 1 addition & 0 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"./sandbox-boundary-tool": "./dist/sandbox-boundary-tool.js",
"./scheduled-task-tools": "./dist/scheduled-task-tools.js",
"./session-recap": "./dist/session-recap.js",
"./session-export": "./dist/session-export.js",
"./session-trace-projection": "./dist/session-trace-projection.js",
"./shell-detect": "./dist/shell-detect.js",
"./shell-run-contract": "./dist/shell-run-contract.js",
Expand Down
Loading
Loading