@agimon-ai/po-team 0.0.0-alpha.180 → 0.0.0-alpha.181
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.
|
@@ -5616,6 +5616,58 @@ function nameList(value) {
|
|
|
5616
5616
|
if (!Array.isArray(value) || value.length > MAX_LIST_ITEMS || value.some((item) => typeof item !== "string" || !LIST_ITEM.test(item.trim()))) fail(`Expected a list of at most ${MAX_LIST_ITEMS} names without spaces.`);
|
|
5617
5617
|
return [...new Set(value.map((item) => item.trim()))];
|
|
5618
5618
|
}
|
|
5619
|
+
/** The same normalized file is reviewed and written, including its final newline. */
|
|
5620
|
+
function parseAgentSave(input) {
|
|
5621
|
+
const draft = record(input, "{ scope, name, content }");
|
|
5622
|
+
const scope = agentScope(draft.scope);
|
|
5623
|
+
const name = fileName(draft.name);
|
|
5624
|
+
if (typeof draft.content !== "string") fail("content must be the whole markdown file.");
|
|
5625
|
+
const content = draft.content.endsWith("\n") ? draft.content : `${draft.content}\n`;
|
|
5626
|
+
if (content.length > MAX_AGENT_FILE_CHARACTERS) fail(`content must be the whole markdown file, at most ${MAX_AGENT_FILE_CHARACTERS} characters.`);
|
|
5627
|
+
const { frontmatter, body } = require_agentDiscovery.parseFrontmatter(content);
|
|
5628
|
+
if (frontmatter.name !== name) fail(`The frontmatter must start with ---, and say name: ${name}.`);
|
|
5629
|
+
if (!frontmatter.description?.trim()) fail("The frontmatter needs a one-line description.");
|
|
5630
|
+
if (frontmatter.package) fail("Package-qualified agents are hand-authored; remove the package field.");
|
|
5631
|
+
if (!body.trim()) fail("Write the agent prompt below the frontmatter.");
|
|
5632
|
+
return {
|
|
5633
|
+
scope,
|
|
5634
|
+
name,
|
|
5635
|
+
content
|
|
5636
|
+
};
|
|
5637
|
+
}
|
|
5638
|
+
function parseAgentRef(input) {
|
|
5639
|
+
const ref = record(input, "{ scope, name }");
|
|
5640
|
+
return {
|
|
5641
|
+
scope: agentScope(ref.scope),
|
|
5642
|
+
name: fileName(ref.name)
|
|
5643
|
+
};
|
|
5644
|
+
}
|
|
5645
|
+
/** Execution and approval share validators, trimming and list deduplication. */
|
|
5646
|
+
function parseSettingsEdit(input, perAgent) {
|
|
5647
|
+
const change = record(input, "{ scope, model?, thinking?, fallbackModels?, excludeTools? }");
|
|
5648
|
+
if (change.scope !== "host" && change.scope !== "workspace" && change.scope !== "global") fail("scope must be 'host', 'workspace' or 'global'.");
|
|
5649
|
+
if (perAgent && (typeof change.agent !== "string" || !CONFIG_AGENT_NAME.test(change.agent))) fail("agent must be an agent name from teamConfig.agents().");
|
|
5650
|
+
const prefix = perAgent ? [
|
|
5651
|
+
SUBAGENTS_KEY,
|
|
5652
|
+
"agents",
|
|
5653
|
+
change.agent
|
|
5654
|
+
] : [SUBAGENTS_KEY];
|
|
5655
|
+
const edits = [
|
|
5656
|
+
...edit([...prefix, "model"], change.model, modelSpec),
|
|
5657
|
+
...edit([...prefix, "thinking"], change.thinking, thinkingLevel),
|
|
5658
|
+
...!perAgent ? [...edit([...prefix, "fallbackModels"], change.fallbackModels, nameList), ...edit([...prefix, "excludeTools"], change.excludeTools, nameList)] : []
|
|
5659
|
+
];
|
|
5660
|
+
if (!edits.length) fail("Nothing to change: pass a setting, or null to clear one.");
|
|
5661
|
+
const normalized = {
|
|
5662
|
+
scope: change.scope,
|
|
5663
|
+
...perAgent ? { agent: change.agent } : {}
|
|
5664
|
+
};
|
|
5665
|
+
for (const item of edits) normalized[item.keyPath.at(-1)] = item.value ?? null;
|
|
5666
|
+
return {
|
|
5667
|
+
input: normalized,
|
|
5668
|
+
edits
|
|
5669
|
+
};
|
|
5670
|
+
}
|
|
5619
5671
|
/**
|
|
5620
5672
|
* Team agents and settings, shared by the Help-only code-mode namespace and any settings surface.
|
|
5621
5673
|
* Every path goes through the injected FileSystem, so the edge host runs it unchanged.
|
|
@@ -5679,7 +5731,101 @@ function createTeamConfig(options) {
|
|
|
5679
5731
|
appliesTo: "new sessions"
|
|
5680
5732
|
};
|
|
5681
5733
|
};
|
|
5734
|
+
const previewFs = (filePath, content) => new Proxy(io.fs, { get(fs, key) {
|
|
5735
|
+
if (key === "readTextFile") return (requested, context) => node_path.resolve(requested) === node_path.resolve(filePath) ? Promise.resolve({
|
|
5736
|
+
ok: true,
|
|
5737
|
+
value: content
|
|
5738
|
+
}) : fs.readTextFile(requested, context);
|
|
5739
|
+
const value = Reflect.get(fs, key);
|
|
5740
|
+
return typeof value === "function" ? value.bind(fs) : value;
|
|
5741
|
+
} });
|
|
5682
5742
|
return {
|
|
5743
|
+
async approvalDetails(member, input) {
|
|
5744
|
+
if (member === "saveAgent" || member === "removeAgent") {
|
|
5745
|
+
const ref = parseAgentRef(input);
|
|
5746
|
+
const found = await ownFile(ref.scope, ref.name);
|
|
5747
|
+
const filePath = found?.filePath ?? node_path.join(await agentDir(ref.scope), `${ref.name}.md`);
|
|
5748
|
+
const rows = [
|
|
5749
|
+
{
|
|
5750
|
+
label: "Name",
|
|
5751
|
+
value: ref.name
|
|
5752
|
+
},
|
|
5753
|
+
{
|
|
5754
|
+
label: "Scope",
|
|
5755
|
+
value: ref.scope
|
|
5756
|
+
},
|
|
5757
|
+
{
|
|
5758
|
+
label: "File",
|
|
5759
|
+
value: filePath
|
|
5760
|
+
}
|
|
5761
|
+
];
|
|
5762
|
+
if (member === "saveAgent") rows.push({
|
|
5763
|
+
label: "Replaces existing file",
|
|
5764
|
+
value: await (0, _agimon_ai_po_core_platform.readTextIfExists)(io.fs, filePath, io.context) === void 0 ? "No" : "Yes"
|
|
5765
|
+
});
|
|
5766
|
+
else {
|
|
5767
|
+
if (!found) fail(`No ${ref.scope} agent named '${ref.name}'.`);
|
|
5768
|
+
const next = (await new require_agentDiscovery.AgentDiscoveryService({
|
|
5769
|
+
...io,
|
|
5770
|
+
fs: previewFs(filePath, "")
|
|
5771
|
+
}, { currentOrUndefined: options.effective }).discover(cwd, "both")).agents.find((agent) => agent.name === ref.name);
|
|
5772
|
+
rows.push({
|
|
5773
|
+
label: "Definition afterwards",
|
|
5774
|
+
value: next ? `${next.source}: ${next.filePath}` : "None"
|
|
5775
|
+
});
|
|
5776
|
+
}
|
|
5777
|
+
return rows;
|
|
5778
|
+
}
|
|
5779
|
+
const parsed = parseSettingsEdit(input, member === "setAgentModel");
|
|
5780
|
+
const file = target(parsed.input.scope);
|
|
5781
|
+
const before = await readValues(file.path);
|
|
5782
|
+
const after = structuredClone(before);
|
|
5783
|
+
const agent = parsed.input.agent;
|
|
5784
|
+
const prior = agent ? before.agents?.[agent] ?? {} : before;
|
|
5785
|
+
const changed = agent ? (after.agents ??= {})[agent] ??= {} : after;
|
|
5786
|
+
for (const item of parsed.edits) {
|
|
5787
|
+
const key = item.keyPath.at(-1);
|
|
5788
|
+
if (item.value === void 0) delete changed[key];
|
|
5789
|
+
else changed[key] = item.value;
|
|
5790
|
+
}
|
|
5791
|
+
const fs = previewFs(file.path, (0, yaml.stringify)({ subagents: after }));
|
|
5792
|
+
const inherited = (await (0, _agimon_ai_po_config.readPoConfig)(fs, workspaceRoot ?? io.homeDirectory, io.context, {
|
|
5793
|
+
homeDirectory: io.homeDirectory,
|
|
5794
|
+
environment: io.environment
|
|
5795
|
+
})).subagents;
|
|
5796
|
+
const preview = agent ? new require_agentDiscovery.AgentDiscoveryService({
|
|
5797
|
+
...io,
|
|
5798
|
+
fs
|
|
5799
|
+
}, { currentOrUndefined: async () => ({
|
|
5800
|
+
defaults: inherited,
|
|
5801
|
+
...inherited?.model ? { models: [inherited.model] } : {}
|
|
5802
|
+
}) }) : void 0;
|
|
5803
|
+
const nextAgent = preview ? (await preview.discover(cwd, options.agentScope ?? "both")).agents.find((item) => item.name === agent) : void 0;
|
|
5804
|
+
const show = (value) => value === void 0 ? "not set" : Array.isArray(value) ? value.join(", ") || "(empty list)" : typeof value === "string" ? value : fail("Unexpected setting value.");
|
|
5805
|
+
return [
|
|
5806
|
+
{
|
|
5807
|
+
label: "Scope",
|
|
5808
|
+
value: file.scope
|
|
5809
|
+
},
|
|
5810
|
+
{
|
|
5811
|
+
label: "File",
|
|
5812
|
+
value: file.path
|
|
5813
|
+
},
|
|
5814
|
+
...agent ? [{
|
|
5815
|
+
label: "Agent",
|
|
5816
|
+
value: agent
|
|
5817
|
+
}] : [],
|
|
5818
|
+
...parsed.edits.map((item) => {
|
|
5819
|
+
const key = item.keyPath.at(-1);
|
|
5820
|
+
const fallback = agent ? inherited?.agents?.[agent]?.[key] ?? nextAgent?.[key] : inherited?.[key];
|
|
5821
|
+
const cleared = fallback !== void 0 ? `cleared; inherits ${show(fallback)}` : agent ? "cleared; inherits agent file, then Team defaults or Pi settings" : key === "excludeTools" || key === "fallbackModels" ? "cleared; inherits Team package defaults, if set" : "cleared; inherits Team package defaults or Pi settings, if set";
|
|
5822
|
+
return {
|
|
5823
|
+
label: key,
|
|
5824
|
+
value: `${show(prior[key])} → ${item.value === void 0 ? cleared : show(item.value)}`
|
|
5825
|
+
};
|
|
5826
|
+
})
|
|
5827
|
+
];
|
|
5828
|
+
},
|
|
5683
5829
|
async agents() {
|
|
5684
5830
|
const { agents } = await discovery.discover(cwd, options.agentScope ?? "both");
|
|
5685
5831
|
const models = await options.availableModels?.();
|
|
@@ -5696,16 +5842,7 @@ function createTeamConfig(options) {
|
|
|
5696
5842
|
};
|
|
5697
5843
|
},
|
|
5698
5844
|
async saveAgent(input) {
|
|
5699
|
-
const
|
|
5700
|
-
const scope = agentScope(draft.scope);
|
|
5701
|
-
const name = fileName(draft.name);
|
|
5702
|
-
if (typeof draft.content !== "string" || draft.content.length > MAX_AGENT_FILE_CHARACTERS) fail(`content must be the whole markdown file, at most ${MAX_AGENT_FILE_CHARACTERS} characters.`);
|
|
5703
|
-
const content = draft.content.endsWith("\n") ? draft.content : `${draft.content}\n`;
|
|
5704
|
-
const { frontmatter, body } = require_agentDiscovery.parseFrontmatter(content);
|
|
5705
|
-
if (frontmatter.name !== name) fail(`The frontmatter must start with ---, and say name: ${name}.`);
|
|
5706
|
-
if (!frontmatter.description?.trim()) fail("The frontmatter needs a one-line description.");
|
|
5707
|
-
if (frontmatter.package) fail("Package-qualified agents are hand-authored; remove the package field.");
|
|
5708
|
-
if (!body.trim()) fail("Write the agent prompt below the frontmatter.");
|
|
5845
|
+
const { scope, name, content } = parseAgentSave(input);
|
|
5709
5846
|
const filePath = (await ownFile(scope, name))?.filePath ?? node_path.join(await agentDir(scope), `${name}.md`);
|
|
5710
5847
|
await (0, _agimon_ai_po_core_platform.writeFileAtomic)(io.fs, filePath, content, io.context);
|
|
5711
5848
|
discovery.invalidate();
|
|
@@ -5717,11 +5854,7 @@ function createTeamConfig(options) {
|
|
|
5717
5854
|
};
|
|
5718
5855
|
},
|
|
5719
5856
|
async removeAgent(input) {
|
|
5720
|
-
const
|
|
5721
|
-
const parsed = {
|
|
5722
|
-
scope: agentScope(ref.scope),
|
|
5723
|
-
name: fileName(ref.name)
|
|
5724
|
-
};
|
|
5857
|
+
const parsed = parseAgentRef(input);
|
|
5725
5858
|
const found = await ownFile(parsed.scope, parsed.name);
|
|
5726
5859
|
if (!found) fail(`No ${parsed.scope} agent named '${parsed.name}'. Call teamConfig.agents() for names and sources.`);
|
|
5727
5860
|
await (0, _agimon_ai_po_core_platform.removePath)(io.fs, found.filePath, io.context);
|
|
@@ -5746,28 +5879,12 @@ function createTeamConfig(options) {
|
|
|
5746
5879
|
};
|
|
5747
5880
|
},
|
|
5748
5881
|
async setDefaults(input) {
|
|
5749
|
-
const
|
|
5750
|
-
return write(
|
|
5751
|
-
...edit([SUBAGENTS_KEY, "model"], change.model, modelSpec),
|
|
5752
|
-
...edit([SUBAGENTS_KEY, "thinking"], change.thinking, thinkingLevel),
|
|
5753
|
-
...edit([SUBAGENTS_KEY, "fallbackModels"], change.fallbackModels, nameList),
|
|
5754
|
-
...edit([SUBAGENTS_KEY, "excludeTools"], change.excludeTools, nameList)
|
|
5755
|
-
], "Nothing to change: pass model, thinking, fallbackModels or excludeTools, or null to clear one.");
|
|
5882
|
+
const parsed = parseSettingsEdit(input, false);
|
|
5883
|
+
return write(parsed.input.scope, parsed.edits, "Nothing to change.");
|
|
5756
5884
|
},
|
|
5757
5885
|
async setAgentModel(input) {
|
|
5758
|
-
const
|
|
5759
|
-
|
|
5760
|
-
return write(change.scope, [...edit([
|
|
5761
|
-
SUBAGENTS_KEY,
|
|
5762
|
-
"agents",
|
|
5763
|
-
change.agent,
|
|
5764
|
-
"model"
|
|
5765
|
-
], change.model, modelSpec), ...edit([
|
|
5766
|
-
SUBAGENTS_KEY,
|
|
5767
|
-
"agents",
|
|
5768
|
-
change.agent,
|
|
5769
|
-
"thinking"
|
|
5770
|
-
], change.thinking, thinkingLevel)], "Nothing to change: pass model or thinking, or null to clear one.");
|
|
5886
|
+
const parsed = parseSettingsEdit(input, true);
|
|
5887
|
+
return write(parsed.input.scope, parsed.edits, "Nothing to change.");
|
|
5771
5888
|
}
|
|
5772
5889
|
};
|
|
5773
5890
|
}
|
|
@@ -5866,69 +5983,73 @@ const SETTINGS_REACH = {
|
|
|
5866
5983
|
host: "New sessions on this Po host use it",
|
|
5867
5984
|
workspace: "New sessions in this repository use it"
|
|
5868
5985
|
};
|
|
5869
|
-
const
|
|
5870
|
-
const
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5986
|
+
const reviewFields = (input) => {
|
|
5987
|
+
const rows = field(input, "_teamApprovalDetails") ?? [];
|
|
5988
|
+
const content = rows.filter((row) => row.value.length > 300).map((row) => `${row.label}: ${row.value}`).join("\n");
|
|
5989
|
+
if (content.length > 65536) throw new Error("Team approval content exceeds 65536 characters.");
|
|
5990
|
+
return {
|
|
5991
|
+
details: rows.map((row) => ({
|
|
5992
|
+
...row,
|
|
5993
|
+
value: clip(row.value, 300)
|
|
5994
|
+
})),
|
|
5995
|
+
...content ? { content } : {}
|
|
5996
|
+
};
|
|
5997
|
+
};
|
|
5874
5998
|
/** Every write changes what later sessions run with, so the person approves each one. */
|
|
5875
5999
|
const TEAM_CONFIG_APPROVAL = {
|
|
5876
6000
|
saveAgent: {
|
|
5877
6001
|
requirement: "human",
|
|
6002
|
+
resolve: ([input]) => [parseAgentSave(input)],
|
|
5878
6003
|
describe: (input) => {
|
|
5879
|
-
const scope =
|
|
5880
|
-
const { frontmatter, body } = require_agentDiscovery.parseFrontmatter(text(field(input, "content")));
|
|
6004
|
+
const { scope, name, content } = parseAgentSave(input);
|
|
5881
6005
|
return {
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
value: clip(frontmatter.model ?? "Team default", 300)
|
|
5888
|
-
},
|
|
5889
|
-
{
|
|
5890
|
-
label: "Tools",
|
|
5891
|
-
value: clip(frontmatter.tools ?? "all it inherits", 300)
|
|
5892
|
-
},
|
|
5893
|
-
{
|
|
5894
|
-
label: "Prompt",
|
|
5895
|
-
value: clip(body.trim(), 300)
|
|
5896
|
-
}
|
|
5897
|
-
]
|
|
6006
|
+
source: "Team",
|
|
6007
|
+
title: clip(`Save the ${scope} agent "${name}"`, 120),
|
|
6008
|
+
summary: `${AGENT_REACH[scope]}. Writes the whole agent file below.`,
|
|
6009
|
+
...reviewFields(input),
|
|
6010
|
+
content
|
|
5898
6011
|
};
|
|
5899
6012
|
}
|
|
5900
6013
|
},
|
|
5901
6014
|
removeAgent: {
|
|
5902
6015
|
requirement: "human",
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
6016
|
+
resolve: ([input]) => [parseAgentRef(input)],
|
|
6017
|
+
describe: (input) => {
|
|
6018
|
+
const { scope, name } = parseAgentRef(input);
|
|
6019
|
+
return {
|
|
6020
|
+
source: "Team",
|
|
6021
|
+
title: clip(`Remove the ${scope} agent "${name}"`, 120),
|
|
6022
|
+
summary: "Deletes this agent file. Any definition that answers afterwards is listed below.",
|
|
6023
|
+
...reviewFields(input)
|
|
6024
|
+
};
|
|
6025
|
+
}
|
|
5907
6026
|
},
|
|
5908
6027
|
setDefaults: {
|
|
5909
6028
|
requirement: "human",
|
|
5910
6029
|
applies: (input) => field(input, "scope") !== "global",
|
|
6030
|
+
resolve: ([input]) => [parseSettingsEdit(input, false).input],
|
|
5911
6031
|
describe: (input) => {
|
|
5912
|
-
const scope = text(
|
|
6032
|
+
const scope = text(parseSettingsEdit(input, false).input.scope);
|
|
5913
6033
|
return {
|
|
6034
|
+
source: "Team",
|
|
5914
6035
|
title: clip(`Change Team defaults (${scope})`, 120),
|
|
5915
|
-
summary: clip(`${SETTINGS_REACH[scope] ?? "New sessions use it"}
|
|
5916
|
-
|
|
5917
|
-
"thinking",
|
|
5918
|
-
"fallbackModels",
|
|
5919
|
-
"excludeTools"
|
|
5920
|
-
])}.`, 600)
|
|
6036
|
+
summary: clip(`${SETTINGS_REACH[scope] ?? "New sessions use it"}. Changes the listed Team defaults.`, 600),
|
|
6037
|
+
...reviewFields(input)
|
|
5921
6038
|
};
|
|
5922
6039
|
}
|
|
5923
6040
|
},
|
|
5924
6041
|
setAgentModel: {
|
|
5925
6042
|
requirement: "human",
|
|
5926
6043
|
applies: (input) => field(input, "scope") !== "global",
|
|
6044
|
+
resolve: ([input]) => [parseSettingsEdit(input, true).input],
|
|
5927
6045
|
describe: (input) => {
|
|
5928
|
-
const
|
|
6046
|
+
const parsed = parseSettingsEdit(input, true).input;
|
|
6047
|
+
const scope = text(parsed.scope);
|
|
5929
6048
|
return {
|
|
5930
|
-
|
|
5931
|
-
|
|
6049
|
+
source: "Team",
|
|
6050
|
+
title: clip(`Set the model for "${text(parsed.agent)}" (${scope})`, 120),
|
|
6051
|
+
summary: clip(`${SETTINGS_REACH[scope] ?? "New sessions use it"}, ahead of the agent file and the Team defaults.`, 600),
|
|
6052
|
+
...reviewFields(input)
|
|
5932
6053
|
};
|
|
5933
6054
|
}
|
|
5934
6055
|
}
|
|
@@ -5941,7 +6062,16 @@ function createTeamConfigNamespace(options) {
|
|
|
5941
6062
|
summary: "Help mode only: list, read, save and remove Team agent files, and read or set Team defaults and per-agent models in host or workspace config.yaml, or draft Global YAML. The person approves every write. Load help-how-to-team first.",
|
|
5942
6063
|
portable: true,
|
|
5943
6064
|
declarations: DECLARATIONS$1,
|
|
5944
|
-
approval: TEAM_CONFIG_APPROVAL,
|
|
6065
|
+
approval: Object.fromEntries(Object.entries(TEAM_CONFIG_APPROVAL).map(([member, policy]) => [member, {
|
|
6066
|
+
...policy,
|
|
6067
|
+
async resolve(args) {
|
|
6068
|
+
const [input] = await policy.resolve(args);
|
|
6069
|
+
return [{
|
|
6070
|
+
...input,
|
|
6071
|
+
_teamApprovalDetails: await options.config.approvalDetails(member, input)
|
|
6072
|
+
}];
|
|
6073
|
+
}
|
|
6074
|
+
}])),
|
|
5945
6075
|
bind(run) {
|
|
5946
6076
|
if (run.sessionId !== options.sessionId) throw new Error("teamConfig belongs to another session.");
|
|
5947
6077
|
let disposed = false;
|
|
@@ -5955,7 +6085,15 @@ function createTeamConfigNamespace(options) {
|
|
|
5955
6085
|
if (WRITES.has(member) && run.caller !== "main") throw new Error(`teamConfig.${member} needs the main agent.`);
|
|
5956
6086
|
};
|
|
5957
6087
|
const members = Object.create(null);
|
|
5958
|
-
for (const name of
|
|
6088
|
+
for (const name of [
|
|
6089
|
+
"agents",
|
|
6090
|
+
"agent",
|
|
6091
|
+
"saveAgent",
|
|
6092
|
+
"removeAgent",
|
|
6093
|
+
"settings",
|
|
6094
|
+
"setDefaults",
|
|
6095
|
+
"setAgentModel"
|
|
6096
|
+
]) members[name] = async (input) => {
|
|
5959
6097
|
check(name);
|
|
5960
6098
|
const result = await options.config[name](input);
|
|
5961
6099
|
if (!WRITES.has(name)) check(name);
|