@openagentpack/cli 0.2.0-beta.0 → 0.3.0-beta-fb9e73b-20260721
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/dist/bin/agents.js
CHANGED
|
@@ -670,9 +670,9 @@ async function initCommand() {
|
|
|
670
670
|
p4.log.success(`Created ${configPath}`, { output: process.stderr });
|
|
671
671
|
const gitignorePath = ".gitignore";
|
|
672
672
|
if (await fileExists(gitignorePath)) {
|
|
673
|
-
const
|
|
674
|
-
if (!
|
|
675
|
-
await writeFile(gitignorePath,
|
|
673
|
+
const content2 = await readFile(gitignorePath, "utf8");
|
|
674
|
+
if (!content2.includes("agents.state.json")) {
|
|
675
|
+
await writeFile(gitignorePath, content2 + GITIGNORE_ADDITIONS, "utf8");
|
|
676
676
|
p4.log.success("Updated .gitignore", { output: process.stderr });
|
|
677
677
|
}
|
|
678
678
|
} else {
|
|
@@ -685,15 +685,244 @@ async function initCommand() {
|
|
|
685
685
|
});
|
|
686
686
|
}
|
|
687
687
|
|
|
688
|
+
// src/commands/memory.ts
|
|
689
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
690
|
+
import {
|
|
691
|
+
archiveMemoryStore,
|
|
692
|
+
batchCreateMemories,
|
|
693
|
+
createMemory,
|
|
694
|
+
createMemoryStore,
|
|
695
|
+
deleteMemory,
|
|
696
|
+
deleteMemoryStore,
|
|
697
|
+
getMemory,
|
|
698
|
+
getMemoryStore,
|
|
699
|
+
getMemoryVersion,
|
|
700
|
+
listMemories,
|
|
701
|
+
listMemoryStores,
|
|
702
|
+
listMemoryVersions,
|
|
703
|
+
redactMemoryVersion,
|
|
704
|
+
UserError as UserError5,
|
|
705
|
+
updateMemory,
|
|
706
|
+
updateMemoryStore
|
|
707
|
+
} from "@openagentpack/sdk";
|
|
708
|
+
|
|
709
|
+
// src/runtime.ts
|
|
710
|
+
import { listProviderNames, UserError as UserError4 } from "@openagentpack/sdk";
|
|
711
|
+
import { Command, InvalidArgumentError, Option } from "commander";
|
|
712
|
+
var DEFAULT_CONFIG_FILE = "agents.yaml";
|
|
713
|
+
function isExplicitSource(source) {
|
|
714
|
+
return source !== void 0 && source !== "default";
|
|
715
|
+
}
|
|
716
|
+
function rootCommand(command) {
|
|
717
|
+
let current = command;
|
|
718
|
+
while (current.parent) current = current.parent;
|
|
719
|
+
return current;
|
|
720
|
+
}
|
|
721
|
+
function configFileArgs(args = process.argv.slice(2)) {
|
|
722
|
+
const values = [];
|
|
723
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
724
|
+
const arg = args[i];
|
|
725
|
+
if (!arg) continue;
|
|
726
|
+
if (arg === "--") break;
|
|
727
|
+
if (arg === "-f" || arg === "--file") {
|
|
728
|
+
const value = args[i + 1];
|
|
729
|
+
if (value) {
|
|
730
|
+
values.push(value);
|
|
731
|
+
i += 1;
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (arg.startsWith("--file=")) {
|
|
736
|
+
values.push(arg.slice("--file=".length));
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
if (arg.startsWith("-f") && arg.length > 2) {
|
|
740
|
+
values.push(arg.slice(2));
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return values;
|
|
744
|
+
}
|
|
745
|
+
function configFileOption() {
|
|
746
|
+
return new Option("-f, --file <path>", "Config file path");
|
|
747
|
+
}
|
|
748
|
+
function resolveConfigFile(command) {
|
|
749
|
+
const explicitFiles = [...new Set(configFileArgs())];
|
|
750
|
+
if (explicitFiles.length > 1) {
|
|
751
|
+
throw new UserError4(
|
|
752
|
+
`Conflicting config files supplied: ${explicitFiles.join(" and ")}. Use only one --file value.`
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
const root = rootCommand(command);
|
|
756
|
+
const rootFile = root.getOptionValue("file");
|
|
757
|
+
const rootSource = root.getOptionValueSource("file");
|
|
758
|
+
const localFile = command.getOptionValue("file");
|
|
759
|
+
const localSource = command.getOptionValueSource("file");
|
|
760
|
+
if (isExplicitSource(rootSource) && isExplicitSource(localSource) && rootFile && localFile && rootFile !== localFile) {
|
|
761
|
+
throw new UserError4(`Conflicting config files supplied: ${rootFile} and ${localFile}. Use only one --file value.`);
|
|
762
|
+
}
|
|
763
|
+
if (isExplicitSource(localSource) && localFile) return localFile;
|
|
764
|
+
if (rootFile) return rootFile;
|
|
765
|
+
return DEFAULT_CONFIG_FILE;
|
|
766
|
+
}
|
|
767
|
+
function withResolvedConfigFile(handler) {
|
|
768
|
+
return async (...args) => {
|
|
769
|
+
const command = args[args.length - 1];
|
|
770
|
+
if (!(command instanceof Command)) {
|
|
771
|
+
await handler(...args);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
const handlerArgs = args.slice(0, -1);
|
|
775
|
+
const options = handlerArgs[handlerArgs.length - 1];
|
|
776
|
+
if (options && typeof options === "object") {
|
|
777
|
+
options.file = resolveConfigFile(command);
|
|
778
|
+
}
|
|
779
|
+
await handler(...handlerArgs);
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
function registeredProviderNames() {
|
|
783
|
+
return listProviderNames();
|
|
784
|
+
}
|
|
785
|
+
function providerOption(description, opts = {}) {
|
|
786
|
+
const choices = opts.allowAll ? ["all", ...registeredProviderNames()] : registeredProviderNames();
|
|
787
|
+
const option = new Option("--provider <name>", description).choices(choices);
|
|
788
|
+
if (opts.defaultValue !== void 0) option.default(opts.defaultValue);
|
|
789
|
+
return option;
|
|
790
|
+
}
|
|
791
|
+
function parsePositiveInteger(value) {
|
|
792
|
+
if (!/^\d+$/.test(value)) {
|
|
793
|
+
throw new InvalidArgumentError("must be a positive integer");
|
|
794
|
+
}
|
|
795
|
+
const parsed = Number(value);
|
|
796
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
797
|
+
throw new InvalidArgumentError("must be a positive integer");
|
|
798
|
+
}
|
|
799
|
+
return parsed;
|
|
800
|
+
}
|
|
801
|
+
function parseBooleanOption(value) {
|
|
802
|
+
if (value === "true") return true;
|
|
803
|
+
if (value === "false") return false;
|
|
804
|
+
throw new InvalidArgumentError("must be true or false");
|
|
805
|
+
}
|
|
806
|
+
function writeJson(value) {
|
|
807
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
808
|
+
`);
|
|
809
|
+
}
|
|
810
|
+
function writeJsonLine(value) {
|
|
811
|
+
process.stdout.write(`${JSON.stringify(value)}
|
|
812
|
+
`);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// src/commands/memory.ts
|
|
816
|
+
async function runtime(options) {
|
|
817
|
+
const ctx = await buildCliRuntime(options.file);
|
|
818
|
+
const provider = options.provider ?? (ctx.providers.size === 1 ? ctx.providers.keys().next().value : void 0);
|
|
819
|
+
if (!provider) throw new UserError5("Select a provider with --provider when multiple providers are configured.");
|
|
820
|
+
return { ctx, provider };
|
|
821
|
+
}
|
|
822
|
+
async function content(options) {
|
|
823
|
+
if (options.content !== void 0 && options.contentFile)
|
|
824
|
+
throw new UserError5("Use either --content or --content-file, not both.");
|
|
825
|
+
if (options.contentFile) return readFile2(options.contentFile, "utf8");
|
|
826
|
+
if (options.content !== void 0) return options.content;
|
|
827
|
+
throw new UserError5("Memory content is required; use --content or --content-file.");
|
|
828
|
+
}
|
|
829
|
+
async function memoryStoreListCommand(options) {
|
|
830
|
+
const { ctx, provider } = await runtime(options);
|
|
831
|
+
writeJson(await listMemoryStores(ctx.providers, provider, options));
|
|
832
|
+
}
|
|
833
|
+
async function memoryStoreCreateCommand(name, options) {
|
|
834
|
+
const { ctx, provider } = await runtime(options);
|
|
835
|
+
writeJson(await createMemoryStore(ctx.providers, provider, { name, description: options.description }));
|
|
836
|
+
}
|
|
837
|
+
async function memoryStoreDeleteCommand(id, options) {
|
|
838
|
+
const { ctx, provider } = await runtime(options);
|
|
839
|
+
await deleteMemoryStore(ctx.providers, provider, id);
|
|
840
|
+
writeJson({ id, type: "memory_store_deleted" });
|
|
841
|
+
}
|
|
842
|
+
async function memoryStoreGetCommand(id, options) {
|
|
843
|
+
const { ctx, provider } = await runtime(options);
|
|
844
|
+
writeJson(await getMemoryStore(ctx.providers, provider, id));
|
|
845
|
+
}
|
|
846
|
+
async function memoryStoreUpdateCommand(id, options) {
|
|
847
|
+
const { ctx, provider } = await runtime(options);
|
|
848
|
+
writeJson(
|
|
849
|
+
await updateMemoryStore(ctx.providers, provider, id, { name: options.name, description: options.description })
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
async function memoryStoreArchiveCommand(id, options) {
|
|
853
|
+
const { ctx, provider } = await runtime(options);
|
|
854
|
+
writeJson(await archiveMemoryStore(ctx.providers, provider, id));
|
|
855
|
+
}
|
|
856
|
+
async function memoryCreateCommand(storeId, path, options) {
|
|
857
|
+
const { ctx, provider } = await runtime(options);
|
|
858
|
+
writeJson(await createMemory(ctx.providers, provider, storeId, { path, content: await content(options) }));
|
|
859
|
+
}
|
|
860
|
+
async function memoryBatchCreateCommand(storeId, inputFile, options) {
|
|
861
|
+
const { ctx, provider } = await runtime(options);
|
|
862
|
+
const parsed = JSON.parse(await readFile2(inputFile, "utf8"));
|
|
863
|
+
if (!Array.isArray(parsed)) throw new UserError5("Batch input must be a JSON array of {path, content} objects.");
|
|
864
|
+
const items = parsed.map((item) => {
|
|
865
|
+
if (!item || typeof item !== "object" || typeof item.path !== "string" || typeof item.content !== "string") {
|
|
866
|
+
throw new UserError5("Every batch item must contain string path and content fields.");
|
|
867
|
+
}
|
|
868
|
+
return item;
|
|
869
|
+
});
|
|
870
|
+
writeJson(await batchCreateMemories(ctx.providers, provider, storeId, { items, on_conflict: options.onConflict }));
|
|
871
|
+
}
|
|
872
|
+
async function memoryListCommand(storeId, options) {
|
|
873
|
+
const { ctx, provider } = await runtime(options);
|
|
874
|
+
writeJson(
|
|
875
|
+
await listMemories(ctx.providers, provider, storeId, { ...options, view: options.full ? "full" : "basic" })
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
async function memoryGetCommand(storeId, memoryId, options) {
|
|
879
|
+
const { ctx, provider } = await runtime(options);
|
|
880
|
+
writeJson(await getMemory(ctx.providers, provider, storeId, memoryId));
|
|
881
|
+
}
|
|
882
|
+
async function memoryUpdateCommand(storeId, memoryId, options) {
|
|
883
|
+
const { ctx, provider } = await runtime(options);
|
|
884
|
+
const nextContent = options.content !== void 0 || options.contentFile ? await content(options) : void 0;
|
|
885
|
+
writeJson(
|
|
886
|
+
await updateMemory(ctx.providers, provider, storeId, memoryId, {
|
|
887
|
+
path: options.path,
|
|
888
|
+
content: nextContent,
|
|
889
|
+
expected_content_sha256: options.expectedSha256
|
|
890
|
+
})
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
async function memoryDeleteCommand(storeId, memoryId, options) {
|
|
894
|
+
const { ctx, provider } = await runtime(options);
|
|
895
|
+
await deleteMemory(ctx.providers, provider, storeId, memoryId, options.expectedSha256);
|
|
896
|
+
writeJson({ id: memoryId, type: "memory_deleted" });
|
|
897
|
+
}
|
|
898
|
+
async function memoryVersionListCommand(storeId, options) {
|
|
899
|
+
const { ctx, provider } = await runtime(options);
|
|
900
|
+
writeJson(
|
|
901
|
+
await listMemoryVersions(ctx.providers, provider, storeId, {
|
|
902
|
+
...options,
|
|
903
|
+
memory_id: options.memoryId,
|
|
904
|
+
view: options.full ? "full" : "basic"
|
|
905
|
+
})
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
async function memoryVersionGetCommand(storeId, versionId, options) {
|
|
909
|
+
const { ctx, provider } = await runtime(options);
|
|
910
|
+
writeJson(await getMemoryVersion(ctx.providers, provider, storeId, versionId));
|
|
911
|
+
}
|
|
912
|
+
async function memoryVersionRedactCommand(storeId, versionId, options) {
|
|
913
|
+
const { ctx, provider } = await runtime(options);
|
|
914
|
+
writeJson(await redactMemoryVersion(ctx.providers, provider, storeId, versionId));
|
|
915
|
+
}
|
|
916
|
+
|
|
688
917
|
// src/commands/migrate.ts
|
|
689
918
|
import { writeFile as writeFile2 } from "fs/promises";
|
|
690
|
-
import { migrateConfig, UserError as
|
|
919
|
+
import { migrateConfig, UserError as UserError6 } from "@openagentpack/sdk";
|
|
691
920
|
async function migrateCommand(options) {
|
|
692
921
|
const fromPath = options.from ?? "agents.synced.yaml";
|
|
693
922
|
const toPath = options.to ?? "agents.yaml";
|
|
694
923
|
const toExists = await fileExists(toPath);
|
|
695
924
|
if (!toExists) {
|
|
696
|
-
throw new
|
|
925
|
+
throw new UserError6(
|
|
697
926
|
`Target file '${toPath}' not found. Create a agents.yaml first (e.g. \`agents init\`), then run migrate.`
|
|
698
927
|
);
|
|
699
928
|
}
|
|
@@ -806,116 +1035,8 @@ function formatPrice(factor) {
|
|
|
806
1035
|
}
|
|
807
1036
|
|
|
808
1037
|
// src/commands/plan.ts
|
|
809
|
-
import { UserError as
|
|
1038
|
+
import { UserError as UserError7 } from "@openagentpack/sdk";
|
|
810
1039
|
import chalk8 from "chalk";
|
|
811
|
-
|
|
812
|
-
// src/runtime.ts
|
|
813
|
-
import { listProviderNames, UserError as UserError5 } from "@openagentpack/sdk";
|
|
814
|
-
import { Command, InvalidArgumentError, Option } from "commander";
|
|
815
|
-
var DEFAULT_CONFIG_FILE = "agents.yaml";
|
|
816
|
-
function isExplicitSource(source) {
|
|
817
|
-
return source !== void 0 && source !== "default";
|
|
818
|
-
}
|
|
819
|
-
function rootCommand(command) {
|
|
820
|
-
let current = command;
|
|
821
|
-
while (current.parent) current = current.parent;
|
|
822
|
-
return current;
|
|
823
|
-
}
|
|
824
|
-
function configFileArgs(args = process.argv.slice(2)) {
|
|
825
|
-
const values = [];
|
|
826
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
827
|
-
const arg = args[i];
|
|
828
|
-
if (!arg) continue;
|
|
829
|
-
if (arg === "--") break;
|
|
830
|
-
if (arg === "-f" || arg === "--file") {
|
|
831
|
-
const value = args[i + 1];
|
|
832
|
-
if (value) {
|
|
833
|
-
values.push(value);
|
|
834
|
-
i += 1;
|
|
835
|
-
continue;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
if (arg.startsWith("--file=")) {
|
|
839
|
-
values.push(arg.slice("--file=".length));
|
|
840
|
-
continue;
|
|
841
|
-
}
|
|
842
|
-
if (arg.startsWith("-f") && arg.length > 2) {
|
|
843
|
-
values.push(arg.slice(2));
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
return values;
|
|
847
|
-
}
|
|
848
|
-
function configFileOption() {
|
|
849
|
-
return new Option("-f, --file <path>", "Config file path");
|
|
850
|
-
}
|
|
851
|
-
function resolveConfigFile(command) {
|
|
852
|
-
const explicitFiles = [...new Set(configFileArgs())];
|
|
853
|
-
if (explicitFiles.length > 1) {
|
|
854
|
-
throw new UserError5(
|
|
855
|
-
`Conflicting config files supplied: ${explicitFiles.join(" and ")}. Use only one --file value.`
|
|
856
|
-
);
|
|
857
|
-
}
|
|
858
|
-
const root = rootCommand(command);
|
|
859
|
-
const rootFile = root.getOptionValue("file");
|
|
860
|
-
const rootSource = root.getOptionValueSource("file");
|
|
861
|
-
const localFile = command.getOptionValue("file");
|
|
862
|
-
const localSource = command.getOptionValueSource("file");
|
|
863
|
-
if (isExplicitSource(rootSource) && isExplicitSource(localSource) && rootFile && localFile && rootFile !== localFile) {
|
|
864
|
-
throw new UserError5(`Conflicting config files supplied: ${rootFile} and ${localFile}. Use only one --file value.`);
|
|
865
|
-
}
|
|
866
|
-
if (isExplicitSource(localSource) && localFile) return localFile;
|
|
867
|
-
if (rootFile) return rootFile;
|
|
868
|
-
return DEFAULT_CONFIG_FILE;
|
|
869
|
-
}
|
|
870
|
-
function withResolvedConfigFile(handler) {
|
|
871
|
-
return async (...args) => {
|
|
872
|
-
const command = args[args.length - 1];
|
|
873
|
-
if (!(command instanceof Command)) {
|
|
874
|
-
await handler(...args);
|
|
875
|
-
return;
|
|
876
|
-
}
|
|
877
|
-
const handlerArgs = args.slice(0, -1);
|
|
878
|
-
const options = handlerArgs[handlerArgs.length - 1];
|
|
879
|
-
if (options && typeof options === "object") {
|
|
880
|
-
options.file = resolveConfigFile(command);
|
|
881
|
-
}
|
|
882
|
-
await handler(...handlerArgs);
|
|
883
|
-
};
|
|
884
|
-
}
|
|
885
|
-
function registeredProviderNames() {
|
|
886
|
-
return listProviderNames();
|
|
887
|
-
}
|
|
888
|
-
function providerOption(description, opts = {}) {
|
|
889
|
-
const choices = opts.allowAll ? ["all", ...registeredProviderNames()] : registeredProviderNames();
|
|
890
|
-
const option = new Option("--provider <name>", description).choices(choices);
|
|
891
|
-
if (opts.defaultValue !== void 0) option.default(opts.defaultValue);
|
|
892
|
-
return option;
|
|
893
|
-
}
|
|
894
|
-
function parsePositiveInteger(value) {
|
|
895
|
-
if (!/^\d+$/.test(value)) {
|
|
896
|
-
throw new InvalidArgumentError("must be a positive integer");
|
|
897
|
-
}
|
|
898
|
-
const parsed = Number(value);
|
|
899
|
-
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
900
|
-
throw new InvalidArgumentError("must be a positive integer");
|
|
901
|
-
}
|
|
902
|
-
return parsed;
|
|
903
|
-
}
|
|
904
|
-
function parseBooleanOption(value) {
|
|
905
|
-
if (value === "true") return true;
|
|
906
|
-
if (value === "false") return false;
|
|
907
|
-
throw new InvalidArgumentError("must be true or false");
|
|
908
|
-
}
|
|
909
|
-
function writeJson(value) {
|
|
910
|
-
process.stdout.write(`${JSON.stringify(value, null, 2)}
|
|
911
|
-
`);
|
|
912
|
-
}
|
|
913
|
-
function writeJsonLine(value) {
|
|
914
|
-
process.stdout.write(`${JSON.stringify(value)}
|
|
915
|
-
`);
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
// src/commands/plan.ts
|
|
919
1040
|
async function planCommand(options) {
|
|
920
1041
|
const ctx = await buildCliRuntime(options.file);
|
|
921
1042
|
assertProviderConfigured(ctx, options.provider);
|
|
@@ -927,13 +1048,13 @@ async function planCommand(options) {
|
|
|
927
1048
|
if (options.json) {
|
|
928
1049
|
writeJson(plan);
|
|
929
1050
|
if (plan.diagnostics.some((d) => d.severity === "error")) {
|
|
930
|
-
throw new
|
|
1051
|
+
throw new UserError7("Plan contains errors.");
|
|
931
1052
|
}
|
|
932
1053
|
return;
|
|
933
1054
|
}
|
|
934
1055
|
renderDiagnostics(plan.diagnostics);
|
|
935
1056
|
if (diagnosticsHaveErrors(plan.diagnostics)) {
|
|
936
|
-
throw new
|
|
1057
|
+
throw new UserError7("Plan contains errors.");
|
|
937
1058
|
}
|
|
938
1059
|
const creates = plan.actions.filter((a) => a.action === "create");
|
|
939
1060
|
const updates = plan.actions.filter((a) => a.action === "update");
|
|
@@ -1137,7 +1258,7 @@ import {
|
|
|
1137
1258
|
sendSessionMessageStreaming,
|
|
1138
1259
|
startSessionRun,
|
|
1139
1260
|
startSessionRunPolling,
|
|
1140
|
-
UserError as
|
|
1261
|
+
UserError as UserError8
|
|
1141
1262
|
} from "@openagentpack/sdk";
|
|
1142
1263
|
import { sanitizeSessionEvent, sanitizeSessionEvents } from "@openagentpack/sdk/session-events";
|
|
1143
1264
|
import chalk9 from "chalk";
|
|
@@ -1179,7 +1300,7 @@ async function sessionCreateCommand(agentNameOrOptions, maybeOptions) {
|
|
|
1179
1300
|
const options = maybeOptions ?? agentNameOrOptions;
|
|
1180
1301
|
const positionalAgent = typeof agentNameOrOptions === "string" ? agentNameOrOptions : void 0;
|
|
1181
1302
|
if (positionalAgent && options.agent && positionalAgent !== options.agent) {
|
|
1182
|
-
throw new
|
|
1303
|
+
throw new UserError8("Specify agent either positionally or with --agent, not both.");
|
|
1183
1304
|
}
|
|
1184
1305
|
const ctx = await buildCliRuntime(options.file);
|
|
1185
1306
|
const run = await createSessionForAgent(ctx, {
|
|
@@ -1327,13 +1448,16 @@ function renderCollectedEvents(result, json) {
|
|
|
1327
1448
|
renderTerminalStatus(result.terminalStatus, json);
|
|
1328
1449
|
}
|
|
1329
1450
|
}
|
|
1451
|
+
function shouldStreamSession(options) {
|
|
1452
|
+
return options.stream === true && options.noStream !== true;
|
|
1453
|
+
}
|
|
1330
1454
|
async function sessionRunCommand(promptOrAgent, promptOrOptions, maybeOptions) {
|
|
1331
1455
|
const hasPositionalAgent = typeof promptOrOptions === "string";
|
|
1332
1456
|
const positionalAgent = hasPositionalAgent ? promptOrAgent : void 0;
|
|
1333
1457
|
const prompt = hasPositionalAgent ? promptOrOptions : promptOrAgent;
|
|
1334
1458
|
const options = hasPositionalAgent ? maybeOptions : promptOrOptions ?? maybeOptions;
|
|
1335
1459
|
if (positionalAgent && options.agent && positionalAgent !== options.agent) {
|
|
1336
|
-
throw new
|
|
1460
|
+
throw new UserError8("Specify agent either positionally or with --agent, not both.");
|
|
1337
1461
|
}
|
|
1338
1462
|
const runOptions = {
|
|
1339
1463
|
agent: positionalAgent ?? options.agent,
|
|
@@ -1348,25 +1472,26 @@ async function sessionRunCommand(promptOrAgent, promptOrOptions, maybeOptions) {
|
|
|
1348
1472
|
title: options.title
|
|
1349
1473
|
};
|
|
1350
1474
|
const ctx = await buildCliRuntime(options.file);
|
|
1351
|
-
const
|
|
1475
|
+
const stream = shouldStreamSession(options);
|
|
1476
|
+
const run = stream ? await startSessionRun(ctx, prompt, runOptions) : await startSessionRunPolling(ctx, prompt, runOptions);
|
|
1352
1477
|
const session = run.session;
|
|
1353
1478
|
if (!options.json) {
|
|
1354
1479
|
log.success(`Session created: ${chalk9.bold(session.id)}`);
|
|
1355
1480
|
}
|
|
1356
|
-
if (
|
|
1357
|
-
renderCollectedEvents(run, !!options.json);
|
|
1358
|
-
} else {
|
|
1481
|
+
if (stream) {
|
|
1359
1482
|
await streamAndRender(run.events, !!options.json);
|
|
1483
|
+
} else {
|
|
1484
|
+
renderCollectedEvents(run, !!options.json);
|
|
1360
1485
|
}
|
|
1361
1486
|
}
|
|
1362
1487
|
async function sessionSendCommand(sessionId, message, options) {
|
|
1363
1488
|
const ctx = await buildCliRuntime(options.file);
|
|
1364
|
-
if (options
|
|
1365
|
-
const result = await sendSessionMessagePolling(ctx, sessionId, message, { provider: options.provider });
|
|
1366
|
-
renderCollectedEvents(result, !!options.json);
|
|
1367
|
-
} else {
|
|
1489
|
+
if (shouldStreamSession(options)) {
|
|
1368
1490
|
const events = await sendSessionMessageStreaming(ctx, sessionId, message, { provider: options.provider });
|
|
1369
1491
|
await streamAndRender(events, !!options.json);
|
|
1492
|
+
} else {
|
|
1493
|
+
const result = await sendSessionMessagePolling(ctx, sessionId, message, { provider: options.provider });
|
|
1494
|
+
renderCollectedEvents(result, !!options.json);
|
|
1370
1495
|
}
|
|
1371
1496
|
}
|
|
1372
1497
|
async function sessionEventsCommand(sessionId, options) {
|
|
@@ -1418,7 +1543,7 @@ function parseMemoryStores(value) {
|
|
|
1418
1543
|
}
|
|
1419
1544
|
|
|
1420
1545
|
// src/commands/state.ts
|
|
1421
|
-
import { importResource, parseStateAddress, UserError as
|
|
1546
|
+
import { importResource, parseStateAddress, UserError as UserError9 } from "@openagentpack/sdk";
|
|
1422
1547
|
import chalk10 from "chalk";
|
|
1423
1548
|
async function stateListCommand(options) {
|
|
1424
1549
|
const ctx = await buildCliRuntime(options.file);
|
|
@@ -1442,14 +1567,14 @@ async function stateShowCommand(address, options) {
|
|
|
1442
1567
|
const ctx = await buildCliRuntime(options.file);
|
|
1443
1568
|
const parsed = parseStateAddress(address, { requireProvider: false });
|
|
1444
1569
|
const found = ctx.state.findResource(parsed);
|
|
1445
|
-
if (!found) throw new
|
|
1570
|
+
if (!found) throw new UserError9(`Resource not found: ${address}`);
|
|
1446
1571
|
console.log(JSON.stringify(found, null, 2));
|
|
1447
1572
|
}
|
|
1448
1573
|
async function stateRemoveCommand(address, options) {
|
|
1449
1574
|
const ctx = await buildCliRuntime(options.file);
|
|
1450
1575
|
const parsed = parseStateAddress(address, { requireProvider: false });
|
|
1451
1576
|
const found = ctx.state.findResource(parsed);
|
|
1452
|
-
if (!found) throw new
|
|
1577
|
+
if (!found) throw new UserError9(`Resource not found: ${address}`);
|
|
1453
1578
|
ctx.state.removeResource(found.address);
|
|
1454
1579
|
await ctx.state.save();
|
|
1455
1580
|
log.success(`Removed ${address} from state (remote resource not deleted).`);
|
|
@@ -1470,14 +1595,14 @@ import {
|
|
|
1470
1595
|
resolveSyncProvider,
|
|
1471
1596
|
syncProviderResourcesFromContext,
|
|
1472
1597
|
syncProviderResourcesFromEnv,
|
|
1473
|
-
UserError as
|
|
1598
|
+
UserError as UserError10
|
|
1474
1599
|
} from "@openagentpack/sdk";
|
|
1475
1600
|
import { stringify as stringifyYaml } from "yaml";
|
|
1476
1601
|
var DEFAULT_SYNC_OUTPUT = "agents.synced.yaml";
|
|
1477
1602
|
function ensureSyncOutputWritable(outPath, force) {
|
|
1478
1603
|
if (force) return;
|
|
1479
1604
|
if (fileExistsSync(outPath)) {
|
|
1480
|
-
throw new
|
|
1605
|
+
throw new UserError10(
|
|
1481
1606
|
`Output file '${outPath}' already exists. Use --force to overwrite, or -o/--out to write elsewhere.`
|
|
1482
1607
|
);
|
|
1483
1608
|
}
|
|
@@ -1539,7 +1664,7 @@ async function syncFromConfig(configPath, explicitProvider) {
|
|
|
1539
1664
|
}
|
|
1540
1665
|
async function syncFromEnv(explicitProvider) {
|
|
1541
1666
|
if (!explicitProvider) {
|
|
1542
|
-
throw new
|
|
1667
|
+
throw new UserError10(
|
|
1543
1668
|
"agents sync requires --provider when no config file exists, e.g. `agents sync --provider claude`."
|
|
1544
1669
|
);
|
|
1545
1670
|
}
|
|
@@ -1586,8 +1711,8 @@ async function promptSecretValues(placeholders) {
|
|
|
1586
1711
|
function loadExistingEnv(path) {
|
|
1587
1712
|
const keys = /* @__PURE__ */ new Set();
|
|
1588
1713
|
if (!fileExistsSync(path)) return keys;
|
|
1589
|
-
const
|
|
1590
|
-
for (const line of
|
|
1714
|
+
const content2 = readFileSync2(path, "utf8");
|
|
1715
|
+
for (const line of content2.split("\n")) {
|
|
1591
1716
|
const trimmed = line.trim();
|
|
1592
1717
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
1593
1718
|
const eqIdx = trimmed.indexOf("=");
|
|
@@ -1598,16 +1723,16 @@ function loadExistingEnv(path) {
|
|
|
1598
1723
|
return keys;
|
|
1599
1724
|
}
|
|
1600
1725
|
function appendEnvLine(path, key, value) {
|
|
1601
|
-
let
|
|
1726
|
+
let content2 = "";
|
|
1602
1727
|
if (fileExistsSync(path)) {
|
|
1603
|
-
|
|
1604
|
-
if (
|
|
1605
|
-
|
|
1728
|
+
content2 = readFileSync2(path, "utf8");
|
|
1729
|
+
if (content2.length > 0 && !content2.endsWith("\n")) {
|
|
1730
|
+
content2 += "\n";
|
|
1606
1731
|
}
|
|
1607
1732
|
}
|
|
1608
|
-
|
|
1733
|
+
content2 += `${key}=${value}
|
|
1609
1734
|
`;
|
|
1610
|
-
writeFileSync(path,
|
|
1735
|
+
writeFileSync(path, content2);
|
|
1611
1736
|
}
|
|
1612
1737
|
async function promptCustomSkillFiles(config, baseDir) {
|
|
1613
1738
|
const skills = config.skills ?? {};
|
|
@@ -1751,7 +1876,7 @@ async function serializeConfig(config) {
|
|
|
1751
1876
|
|
|
1752
1877
|
// src/commands/validate.ts
|
|
1753
1878
|
import { resolve as resolve4 } from "path";
|
|
1754
|
-
import { resolveProjectConfig as resolveProjectConfig2, UserError as
|
|
1879
|
+
import { resolveProjectConfig as resolveProjectConfig2, UserError as UserError11, validateProjectConfig } from "@openagentpack/sdk";
|
|
1755
1880
|
async function validateCommand(options) {
|
|
1756
1881
|
ensureCredentials();
|
|
1757
1882
|
const configPath = resolve4(options.file);
|
|
@@ -1766,7 +1891,7 @@ async function validateCommand(options) {
|
|
|
1766
1891
|
}
|
|
1767
1892
|
const errorCount = diagnostics.filter((d) => d.severity === "error").length;
|
|
1768
1893
|
if (errorCount > 0) {
|
|
1769
|
-
throw new
|
|
1894
|
+
throw new UserError11(`Validation failed with ${errorCount} error(s).`);
|
|
1770
1895
|
}
|
|
1771
1896
|
log.success("Configuration is valid.");
|
|
1772
1897
|
}
|
|
@@ -1847,13 +1972,31 @@ sessionCmd.command("create [agent-name]").description("Create a new session for
|
|
|
1847
1972
|
sessionCmd.command("list").description("List sessions from the provider").addOption(configFileOption()).option("--agent <name>", "Filter by agent name").option("--all", "Fetch all pages by following the cursor").addOption(providerOption("Target provider")).action(withResolvedConfigFile(sessionListCommand));
|
|
1848
1973
|
sessionCmd.command("get <session-id>").description("Get details of a session").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(sessionGetCommand));
|
|
1849
1974
|
sessionCmd.command("delete <session-id>").description("Delete a session").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(sessionDeleteCommand));
|
|
1850
|
-
sessionCmd.command("run <prompt-or-agent> [prompt]").description("Create a session, send a message, and
|
|
1851
|
-
sessionCmd.command("send <session-id> <message>").description("Send a message to an existing session and
|
|
1975
|
+
sessionCmd.command("run <prompt-or-agent> [prompt]").description("Create a session, send a message, and wait for the response").addOption(configFileOption()).option("--agent <name>", "Agent name (auto-detected when only one agent is configured)").option("--identity-id <id>", "Override the configured Qoder Forward Identity").option("--environment <name>", "Override agent's declared environment").option("--environment-id <id>", "Use an explicit remote environment id instead of the configured one").option("--tunnel <name>", "Override agent's declared tunnel").option("--tunnel-id <id>", "Use an explicit remote tunnel id instead of the configured one").option("--vault <name>", "Override agent's declared vault").option("--memory-stores <names>", "Override agent's declared memory stores (comma-separated)").option("--title <title>", "Session title").addOption(providerOption("Target provider")).option("--json", "Output events as JSONL").addOption(new Option2("--stream", "Stream events over SSE instead of polling").conflicts("noStream")).addOption(new Option2("--no-stream", "Use polling (deprecated; polling is now the default)").hideHelp()).action(withResolvedConfigFile(sessionRunCommand));
|
|
1976
|
+
sessionCmd.command("send <session-id> <message>").description("Send a message to an existing session and wait for the response").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--json", "Output events as JSONL").addOption(new Option2("--stream", "Stream events over SSE instead of polling").conflicts("noStream")).addOption(new Option2("--no-stream", "Use polling (deprecated; polling is now the default)").hideHelp()).action(withResolvedConfigFile(sessionSendCommand));
|
|
1852
1977
|
sessionCmd.command("events <session-id>").description("List event history for a session").addOption(configFileOption()).addOption(providerOption("Target provider")).addOption(new Option2("--limit <count>", "Maximum number of events to fetch").argParser(parsePositiveInteger)).option("--all", "Fetch all pages by following the cursor").option("--json", "Output as JSON").action(withResolvedConfigFile(sessionEventsCommand));
|
|
1853
1978
|
var deploymentCmd = program.command("deployment").description("Manage agent deployments (scheduled / triggered runs)");
|
|
1854
1979
|
deploymentCmd.command("list").description("List deployments tracked in state").addOption(configFileOption()).addOption(providerOption("Filter by provider")).action(withResolvedConfigFile(deploymentListCommand));
|
|
1855
1980
|
deploymentCmd.command("get <name>").description("Show a deployment's status and resolved bindings").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(deploymentGetCommand));
|
|
1856
1981
|
deploymentCmd.command("run <name>").description("Trigger a deployment run (native on Claude, emulated as a session on Qoder)").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(deploymentRunCommand));
|
|
1982
|
+
var memoryStoreCmd = program.command("memory-store").description("Manage persistent memory stores");
|
|
1983
|
+
memoryStoreCmd.command("create <name>").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--description <description>").action(withResolvedConfigFile(memoryStoreCreateCommand));
|
|
1984
|
+
memoryStoreCmd.command("list").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--limit <n>", "Page size", parsePositiveInteger).option("--cursor <cursor>").option("--include-archived").action(withResolvedConfigFile(memoryStoreListCommand));
|
|
1985
|
+
memoryStoreCmd.command("get <store-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(memoryStoreGetCommand));
|
|
1986
|
+
memoryStoreCmd.command("update <store-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--name <name>").option("--description <description>").action(withResolvedConfigFile(memoryStoreUpdateCommand));
|
|
1987
|
+
memoryStoreCmd.command("archive <store-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(memoryStoreArchiveCommand));
|
|
1988
|
+
memoryStoreCmd.command("delete <store-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(memoryStoreDeleteCommand));
|
|
1989
|
+
var memoryCmd = program.command("memory").description("Manage memories inside a store");
|
|
1990
|
+
memoryCmd.command("create <store-id> <path>").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--content <text>").option("--content-file <path>").action(withResolvedConfigFile(memoryCreateCommand));
|
|
1991
|
+
memoryCmd.command("batch-create <store-id> <json-file>").addOption(configFileOption()).addOption(providerOption("Target provider")).addOption(new Option2("--on-conflict <mode>", "Conflict handling (Ark)").choices(["overwrite", "fail"])).action(withResolvedConfigFile(memoryBatchCreateCommand));
|
|
1992
|
+
memoryCmd.command("list <store-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--limit <n>", "Page size", parsePositiveInteger).option("--cursor <cursor>").option("--prefix <path>").option("--depth <n>", "Hierarchy depth", parsePositiveInteger).option("--full", "Include content").action(withResolvedConfigFile(memoryListCommand));
|
|
1993
|
+
memoryCmd.command("get <store-id> <memory-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(memoryGetCommand));
|
|
1994
|
+
memoryCmd.command("update <store-id> <memory-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--path <path>").option("--content <text>").option("--content-file <path>").option("--expected-sha256 <sha256>", "Optimistic concurrency precondition").action(withResolvedConfigFile(memoryUpdateCommand));
|
|
1995
|
+
memoryCmd.command("delete <store-id> <memory-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--expected-sha256 <sha256>", "Optimistic concurrency precondition").action(withResolvedConfigFile(memoryDeleteCommand));
|
|
1996
|
+
var memoryVersionCmd = memoryCmd.command("version").description("Inspect immutable memory history");
|
|
1997
|
+
memoryVersionCmd.command("list <store-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--limit <n>", "Page size", parsePositiveInteger).option("--cursor <cursor>").option("--memory-id <id>").option("--full", "Include version content").action(withResolvedConfigFile(memoryVersionListCommand));
|
|
1998
|
+
memoryVersionCmd.command("get <store-id> <version-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(memoryVersionGetCommand));
|
|
1999
|
+
memoryVersionCmd.command("redact <store-id> <version-id>").addOption(configFileOption()).addOption(providerOption("Target provider")).action(withResolvedConfigFile(memoryVersionRedactCommand));
|
|
1857
2000
|
var modelsCmd = program.command("models").description("Discover available models from providers");
|
|
1858
2001
|
modelsCmd.command("list").description("List models available on the configured provider(s)").addOption(configFileOption()).addOption(providerOption("Target provider")).option("--json", "Output as JSON").action(withResolvedConfigFile(modelsListCommand));
|
|
1859
2002
|
|
package/dist/src/program.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openagentpack/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta-fb9e73b-20260721",
|
|
4
4
|
"description": "Open Agent Pack — Declaratively manage AI agent infrastructure",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"typecheck": "tsc --noEmit"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@openagentpack/playground": "0.
|
|
52
|
+
"@openagentpack/playground": "0.3.0-beta-fb9e73b-20260721",
|
|
53
53
|
"@types/bun": "^1.3.14",
|
|
54
54
|
"typescript": "^6.0.3"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@openagentpack/sdk": "0.
|
|
57
|
+
"@openagentpack/sdk": "0.3.0-beta-fb9e73b-20260721",
|
|
58
58
|
"@clack/prompts": "^1.5.1",
|
|
59
59
|
"chalk": "^5.6.2",
|
|
60
60
|
"commander": "^14.0.3",
|