Files
hyperframes/packages/cli/src/timeline/a2Mutations.ts
T
Miguel Ángel 4e9059ad59 feat(cli): add agent timeline workflows (#4241)
* feat(cli): add timeline agent mutation commands

* fix(cli): type timeline a2 mutations

* style(cli): format timeline a2 commands

* test(cli): cover timeline a2 verbs

* test(cli): assert ids keep named refs

* refactor: centralize timeline duplicate mutation

* fix(cli): narrow set assignment field

* style(cli): format timeline mutation exports

* refactor(cli): split apply plan decisions

* fix(cli): tag apply plan refusals

* refactor(cli): move A2 runners beside timeline helpers

* fix(cli): remove stale A2 imports

* style(cli): format A2 command module

* fix(cli): avoid A2 command import cycle

* refactor(cli): isolate shared timeline mutation logic

* fix(cli): restore timeline mutation command factory

* fix(cli): remove stale command-surface remnants

* fix(cli): complete shared timeline support extraction

* fix(cli): close shared conflict helper

* fix(cli): import shared timeline formatter

* style(cli): format shared mutation runner

* refactor(cli): split mutation command orchestration

* fix(cli): keep shared mutation primitives in support module

* fix(cli): use shared mutation support helpers

* refactor(cli): centralize A2 refusals

* style(cli): format A2 refusal helpers

* fix(cli): clean shared A2 imports

* fix(cli): make A2 runner imports explicit

* refactor(cli): isolate apply plan target validation

* fix(cli): tag prepared plan edits

* style(cli): format plan target helper

* fix(cli): validate sequential plans and duplicate ids

* test(cli): account for stamped composition id

* fix(studio): stamp ids on patched html

* fix(studio): preserve no-op patch bytes

* test(studio): expect stamped patch markup

* fix(studio-server): duplicate elements in nested templates

* refactor(cli): share timeline mutation receipts

* fix(studio-server): harden duplicate and no-op mutations

* fix(studio-server): reduce duplicate helper complexity
2026-09-21 17:14:47 -04:00

55 lines
1.6 KiB
TypeScript

export type SetField = "volume" | "rate" | "track";
export interface SetAssignment {
field: SetField;
value: string;
}
export function parseSetAssignments(
values: readonly string[],
): { ok: true; assignments: SetAssignment[] } | { ok: false; reason: string; fix: string } {
const assignments: SetAssignment[] = [];
for (const value of values) {
const match = /^(volume|rate|track)=(.+)$/.exec(value);
if (!match) {
return {
ok: false,
reason: `unsupported set assignment ${value}`,
fix: "use volume=<number>, rate=<number>, or track=<number>",
};
}
const fieldValue = match[1];
if (!fieldValue) {
return {
ok: false,
reason: `unsupported set assignment ${value}`,
fix: "use volume=<number>, rate=<number>, or track=<number>",
};
}
const field = parseSetField(fieldValue);
const number = Number(match[2]);
if (!Number.isFinite(number) || (field === "track" && !Number.isInteger(number))) {
return {
ok: false,
reason: `${field} must be a valid ${field === "track" ? "integer" : "number"}`,
fix: `pass ${field}=<number>`,
};
}
if (field === "rate" && number <= 0) {
return { ok: false, reason: "rate must be positive", fix: "pass rate=<positive number>" };
}
assignments.push({ field, value: String(number) });
}
return { ok: true, assignments };
}
function parseSetField(value: string): SetField {
switch (value) {
case "volume":
case "rate":
case "track":
return value;
}
throw new Error(`unsupported set field ${value}`);
}