@voltade/volty 0.1.20 → 0.1.22
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/volty.js +464 -17
- package/package.json +1 -1
package/dist/volty.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// bin/volty.ts
|
|
4
|
-
import { existsSync as
|
|
4
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync5, readFileSync as readFileSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
5
5
|
import { homedir as homedir3 } from "node:os";
|
|
6
|
-
import { join as
|
|
6
|
+
import { join as join5 } from "node:path";
|
|
7
7
|
|
|
8
8
|
// src/api.ts
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
@@ -646,16 +646,422 @@ function decideProposal(ctx, proposalId, decision, reason) {
|
|
|
646
646
|
});
|
|
647
647
|
}
|
|
648
648
|
|
|
649
|
+
// src/pull.ts
|
|
650
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
651
|
+
import { chmodSync, existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync4, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
652
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
653
|
+
async function call(ctx, name, input = {}) {
|
|
654
|
+
const res = await runOp(ctx, { name }, input);
|
|
655
|
+
if (!res.ok)
|
|
656
|
+
throw new Error(`${name}: ${res.body?.error?.message ?? `HTTP ${res.status}`}`);
|
|
657
|
+
const structured = res.body.structuredContent;
|
|
658
|
+
if (structured?.refused)
|
|
659
|
+
return { refused: res.body.content?.[0]?.text ?? `${name} refused` };
|
|
660
|
+
return { value: structured };
|
|
661
|
+
}
|
|
662
|
+
async function read(ctx, name, input = {}) {
|
|
663
|
+
const out = await call(ctx, name, input);
|
|
664
|
+
if ("refused" in out)
|
|
665
|
+
throw new Error(`${name}: ${out.refused}`);
|
|
666
|
+
return out.value;
|
|
667
|
+
}
|
|
668
|
+
function slugBase(name) {
|
|
669
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60).replace(/^-+|-+$/g, "");
|
|
670
|
+
return slug || "source";
|
|
671
|
+
}
|
|
672
|
+
function tsLiteral(value, indent = "") {
|
|
673
|
+
if (value === null || typeof value !== "object")
|
|
674
|
+
return JSON.stringify(value) ?? "undefined";
|
|
675
|
+
const next = `${indent} `;
|
|
676
|
+
if (Array.isArray(value)) {
|
|
677
|
+
if (value.length === 0)
|
|
678
|
+
return "[]";
|
|
679
|
+
return `[
|
|
680
|
+
${value.map((v) => `${next}${tsLiteral(v, next)}`).join(`,
|
|
681
|
+
`)},
|
|
682
|
+
${indent}]`;
|
|
683
|
+
}
|
|
684
|
+
const entries = Object.entries(value).filter(([, v]) => v !== undefined);
|
|
685
|
+
if (entries.length === 0)
|
|
686
|
+
return "{}";
|
|
687
|
+
const key = (k) => /^[A-Za-z_$][\w$]*$/.test(k) ? k : JSON.stringify(k);
|
|
688
|
+
return `{
|
|
689
|
+
${entries.map(([k, v]) => `${next}${key(k)}: ${tsLiteral(v, next)}`).join(`,
|
|
690
|
+
`)},
|
|
691
|
+
${indent}}`;
|
|
692
|
+
}
|
|
693
|
+
function tsFile(header, value) {
|
|
694
|
+
return `// ${header[0]}
|
|
695
|
+
// ${header[1]}
|
|
696
|
+
export default ${tsLiteral(value)}
|
|
697
|
+
`;
|
|
698
|
+
}
|
|
699
|
+
var sha256 = (text) => createHash2("sha256").update(text).digest("hex");
|
|
700
|
+
|
|
701
|
+
class Observed {
|
|
702
|
+
sections = new Map;
|
|
703
|
+
add(heading, line) {
|
|
704
|
+
let lines = this.sections.get(heading);
|
|
705
|
+
if (!lines) {
|
|
706
|
+
lines = [];
|
|
707
|
+
this.sections.set(heading, lines);
|
|
708
|
+
}
|
|
709
|
+
lines.push(line);
|
|
710
|
+
}
|
|
711
|
+
render() {
|
|
712
|
+
const blocks = [...this.sections].map(([heading, lines]) => `${heading}
|
|
713
|
+
${lines.map((l) => `- ${l}`).join(`
|
|
714
|
+
`)}`);
|
|
715
|
+
return `${[OBSERVED_HEAD, ...blocks].join(`
|
|
716
|
+
|
|
717
|
+
`)}
|
|
718
|
+
`;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
var OBSERVED_HEAD = "Read-only. What this workspace holds outside the project as of the last volty pull: data Volty and staff write in the app, and what has no project file yet. Editing this file changes nothing, and volty pull rewrites it.";
|
|
722
|
+
var WAITING_HEADING = "Versions waiting for approval (the files hold the running version)";
|
|
723
|
+
var DRIVE_HEADING = "Drive files (the workspace Drive, which the project does not hold)";
|
|
724
|
+
var part = () => ({ files: new Map, observed: new Observed });
|
|
725
|
+
async function pooled(items, fn, size = 6) {
|
|
726
|
+
const out = new Array(items.length);
|
|
727
|
+
let next = 0;
|
|
728
|
+
const worker = async () => {
|
|
729
|
+
while (next < items.length) {
|
|
730
|
+
const i = next++;
|
|
731
|
+
out[i] = await fn(items[i]);
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
await Promise.all(Array.from({ length: Math.min(size, items.length) }, worker));
|
|
735
|
+
return out;
|
|
736
|
+
}
|
|
737
|
+
function ruleOut(rule) {
|
|
738
|
+
const { teamId, userId, userIds, ...action } = rule.action;
|
|
739
|
+
return {
|
|
740
|
+
enabled: rule.enabled,
|
|
741
|
+
condition: rule.condition,
|
|
742
|
+
action: {
|
|
743
|
+
...action,
|
|
744
|
+
...teamId ? { team: rule.teamSlug } : {},
|
|
745
|
+
...userId ? { member: rule.memberEmails[0] ?? null } : {},
|
|
746
|
+
...userIds ? { members: rule.memberEmails } : {}
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
async function pullInboxes(ctx) {
|
|
751
|
+
const out = { ...part(), slugById: new Map };
|
|
752
|
+
const { inboxes } = await read(ctx, "inboxes list");
|
|
753
|
+
const rows = inboxes.filter((i) => i.type === "shared").sort((a, b) => a.id.localeCompare(b.id));
|
|
754
|
+
const got = await pooled(rows, async (row) => {
|
|
755
|
+
if (row.role === null)
|
|
756
|
+
return null;
|
|
757
|
+
const inbox = await read(ctx, "inboxes get", { inboxId: row.id });
|
|
758
|
+
const flow = inbox.webChat ? await read(ctx, "chat-flow get", { inboxId: row.id, part: "source" }) : null;
|
|
759
|
+
return { inbox, flow };
|
|
760
|
+
});
|
|
761
|
+
rows.forEach((row, i) => {
|
|
762
|
+
const one = got[i];
|
|
763
|
+
if (!one) {
|
|
764
|
+
out.observed.add("Inboxes not pulled", `${row.name}: you are not on this inbox, so its settings are not readable`);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
const { inbox, flow } = one;
|
|
768
|
+
out.slugById.set(row.id, inbox.slug);
|
|
769
|
+
const dir = `inboxes/${inbox.slug}`;
|
|
770
|
+
if (flow?.published)
|
|
771
|
+
out.files.set(`${dir}/quick-paths.ts`, flow.published.source);
|
|
772
|
+
if (flow && flow.revision > 0 && flow.source !== flow.published?.source) {
|
|
773
|
+
out.observed.add("Quick paths with unpublished changes (the file holds the published version)", `${dir}/quick-paths.ts: the draft at revision ${flow.revision} is not published`);
|
|
774
|
+
}
|
|
775
|
+
const { volty, webChat, routing } = inbox;
|
|
776
|
+
const { agentId: _agentId, agentName, ...seat } = volty ?? { agentId: "", agentName: "" };
|
|
777
|
+
const { handoffWhatsappInstanceId: _wa, handoffEmailInstanceId: _email, ...chat } = webChat?.settings ?? {};
|
|
778
|
+
out.files.set(`${dir}/inbox.ts`, tsFile([
|
|
779
|
+
`The ${inbox.name} inbox: hours, reply targets, hand-off, priority guide, routing, Volty's reply mode and its web chat.`,
|
|
780
|
+
"Written by volty pull from the live inbox. Who works the inbox, team members and channels stay in the app."
|
|
781
|
+
], {
|
|
782
|
+
name: inbox.name,
|
|
783
|
+
icon: inbox.icon,
|
|
784
|
+
autoEnrollOrgMembers: inbox.autoEnrollOrgMembers,
|
|
785
|
+
businessHours: inbox.businessHours,
|
|
786
|
+
idleClose: inbox.idleClose,
|
|
787
|
+
firstResponseMinutes: inbox.firstResponseMinutes,
|
|
788
|
+
handoff: inbox.handoff,
|
|
789
|
+
priority: inbox.priority,
|
|
790
|
+
routing: { ...routing, rules: routing.rules.map(ruleOut) },
|
|
791
|
+
volty: volty ? { agent: agentName, ...seat } : null,
|
|
792
|
+
webChat: webChat ? {
|
|
793
|
+
...chat,
|
|
794
|
+
handoffWhatsappNumber: webChat.handoffAddresses.whatsapp,
|
|
795
|
+
handoffEmailAddress: webChat.handoffAddresses.email
|
|
796
|
+
} : null,
|
|
797
|
+
quickPaths: flow ? { enabled: flow.enabled } : undefined
|
|
798
|
+
}));
|
|
799
|
+
});
|
|
800
|
+
return out;
|
|
801
|
+
}
|
|
802
|
+
async function pullInstructions(ctx, inboxes) {
|
|
803
|
+
const out = part();
|
|
804
|
+
const [got, { slugById }] = await Promise.all([read(ctx, "instructions get"), inboxes]);
|
|
805
|
+
if (got.org.text)
|
|
806
|
+
out.files.set("instructions/org.md", got.org.text);
|
|
807
|
+
if (got.team.text)
|
|
808
|
+
out.files.set("instructions/team.md", got.team.text);
|
|
809
|
+
for (const row of got.inboxes) {
|
|
810
|
+
const slug = slugById.get(row.inboxId);
|
|
811
|
+
if (slug && row.text)
|
|
812
|
+
out.files.set(`inboxes/${slug}/instructions.md`, row.text);
|
|
813
|
+
}
|
|
814
|
+
return out;
|
|
815
|
+
}
|
|
816
|
+
async function pullSources(ctx) {
|
|
817
|
+
const { sources } = await read(ctx, "sources list");
|
|
818
|
+
const out = { ...part(), sources };
|
|
819
|
+
const rows = [...sources].sort((a, b) => a.id.localeCompare(b.id));
|
|
820
|
+
const got = await pooled(rows, (row) => call(ctx, "sources get", { source: row.id, export: true }));
|
|
821
|
+
const taken = new Set;
|
|
822
|
+
rows.forEach((row, i) => {
|
|
823
|
+
const one = got[i];
|
|
824
|
+
if (!one || "refused" in one) {
|
|
825
|
+
out.observed.add("Sources with no file yet (website, API and sync sources)", `${row.name} (${row.kind})`);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const base = slugBase(row.name);
|
|
829
|
+
let slug = base;
|
|
830
|
+
for (let n = 2;taken.has(slug); n++)
|
|
831
|
+
slug = `${base}-${n}`;
|
|
832
|
+
taken.add(slug);
|
|
833
|
+
const { id: _id, scope, automation, ...rest } = one.value.file;
|
|
834
|
+
out.files.set(`sources/${slug}.ts`, tsFile([
|
|
835
|
+
`The ${row.name} source: its settings, the names of its secrets (never a value), lanes, scope and tool modes.`,
|
|
836
|
+
"Written by volty pull. Secret values, sign-ins and which tools an admin approved stay in the app."
|
|
837
|
+
], {
|
|
838
|
+
...rest,
|
|
839
|
+
scope: { mode: scope.mode, inboxes: scope.inboxes.map((i) => i.slug), privateInboxes: scope.privateInboxes },
|
|
840
|
+
automation: automation?.slug ?? null
|
|
841
|
+
}));
|
|
842
|
+
});
|
|
843
|
+
return out;
|
|
844
|
+
}
|
|
845
|
+
var notDeployed = (row) => `${row.slug}: ${row.pendingApproval ? "its first version waits for approval" : "no version is running"}`;
|
|
846
|
+
async function pullAutomations(ctx) {
|
|
847
|
+
const out = part();
|
|
848
|
+
const { automations } = await read(ctx, "automations list");
|
|
849
|
+
const got = await pooled(automations, async (row) => {
|
|
850
|
+
if (!row.deployed)
|
|
851
|
+
return null;
|
|
852
|
+
const first = await read(ctx, "automations get", { id: row.id });
|
|
853
|
+
if (first.sourceLabel !== "pending" || !first.active?.version)
|
|
854
|
+
return { got: first, waiting: false };
|
|
855
|
+
return {
|
|
856
|
+
got: await read(ctx, "automations get", { id: row.id, version: first.active.version }),
|
|
857
|
+
waiting: true
|
|
858
|
+
};
|
|
859
|
+
});
|
|
860
|
+
automations.forEach((row, i) => {
|
|
861
|
+
const one = got[i];
|
|
862
|
+
if (!one) {
|
|
863
|
+
out.observed.add("Automations not deployed", notDeployed(row));
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
if (one.waiting)
|
|
867
|
+
out.observed.add(WAITING_HEADING, `automations/${row.slug}.ts`);
|
|
868
|
+
if (one.got.source !== null)
|
|
869
|
+
out.files.set(`automations/${row.slug}.ts`, one.got.source);
|
|
870
|
+
});
|
|
871
|
+
return out;
|
|
872
|
+
}
|
|
873
|
+
async function pullPages(ctx) {
|
|
874
|
+
const out = part();
|
|
875
|
+
const { miniApps } = await read(ctx, "mini-apps list");
|
|
876
|
+
const got = await pooled(miniApps, async (row) => {
|
|
877
|
+
if (!row.deployed)
|
|
878
|
+
return null;
|
|
879
|
+
const first = await read(ctx, "mini-apps get", { id: row.id });
|
|
880
|
+
if (!first.pending)
|
|
881
|
+
return { got: first, waiting: false };
|
|
882
|
+
const active = first.deploys.find((d) => d.status === "active");
|
|
883
|
+
return {
|
|
884
|
+
got: active?.version ? await read(ctx, "mini-apps get", { id: row.id, version: active.version }) : first,
|
|
885
|
+
waiting: true
|
|
886
|
+
};
|
|
887
|
+
});
|
|
888
|
+
miniApps.forEach((row, i) => {
|
|
889
|
+
const one = got[i];
|
|
890
|
+
if (!one) {
|
|
891
|
+
out.observed.add("Pages not deployed", notDeployed(row));
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
if (one.waiting)
|
|
895
|
+
out.observed.add(WAITING_HEADING, `pages/${row.slug}/`);
|
|
896
|
+
if (one.got.entrySource !== null)
|
|
897
|
+
out.files.set(`pages/${row.slug}/entry.tsx`, one.got.entrySource);
|
|
898
|
+
if (one.got.bffSource !== null)
|
|
899
|
+
out.files.set(`pages/${row.slug}/bff.ts`, one.got.bffSource);
|
|
900
|
+
});
|
|
901
|
+
return out;
|
|
902
|
+
}
|
|
903
|
+
var DRIVE_FOLDER_CAP = 100;
|
|
904
|
+
async function walkDrive(ctx) {
|
|
905
|
+
const files = [];
|
|
906
|
+
let queue = ["/"];
|
|
907
|
+
let walked = 0;
|
|
908
|
+
while (queue.length > 0 && walked < DRIVE_FOLDER_CAP) {
|
|
909
|
+
const level = queue.slice(0, DRIVE_FOLDER_CAP - walked);
|
|
910
|
+
walked += level.length;
|
|
911
|
+
const listed = await pooled(level, (path) => read(ctx, "drive list-folder", { scope: "organization", path }));
|
|
912
|
+
const children = [];
|
|
913
|
+
for (const { entries } of listed) {
|
|
914
|
+
for (const entry of entries) {
|
|
915
|
+
if (entry.kind === "folder")
|
|
916
|
+
children.push(entry.path);
|
|
917
|
+
else
|
|
918
|
+
files.push(entry.path);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
queue = [...queue.slice(level.length), ...children];
|
|
922
|
+
}
|
|
923
|
+
return { files, unread: queue.length };
|
|
924
|
+
}
|
|
925
|
+
async function observeData(ctx) {
|
|
926
|
+
const out = part();
|
|
927
|
+
const [learned, drive, { tables }] = await Promise.all([
|
|
928
|
+
read(ctx, "learned list"),
|
|
929
|
+
walkDrive(ctx),
|
|
930
|
+
read(ctx, "tables list")
|
|
931
|
+
]);
|
|
932
|
+
for (const rule of learned.rules)
|
|
933
|
+
out.observed.add("Learned rules (Volty writes them; a push never touches them)", rule.text);
|
|
934
|
+
for (const path of drive.files)
|
|
935
|
+
out.observed.add(DRIVE_HEADING, path);
|
|
936
|
+
if (drive.unread > 0)
|
|
937
|
+
out.observed.add(DRIVE_HEADING, `${drive.unread} more folders not listed`);
|
|
938
|
+
for (const table of tables)
|
|
939
|
+
out.observed.add("Tables (their rows stay in the workspace)", table.name);
|
|
940
|
+
return out;
|
|
941
|
+
}
|
|
942
|
+
function agentsMd(workspaceId, sources) {
|
|
943
|
+
const systems = [...sources].sort((a, b) => a.name.localeCompare(b.name)).map((s) => `- ${s.name} (${s.kind})`);
|
|
944
|
+
return `# Volty project
|
|
945
|
+
|
|
946
|
+
This folder is one Volty workspace's setup as files, written by \`volty pull\` from the live workspace \`${workspaceId}\`.
|
|
947
|
+
|
|
948
|
+
- \`instructions/org.md\`: the instructions Volty reads everywhere. \`instructions/team.md\`: how Volty works with staff, read only when it talks to staff.
|
|
949
|
+
- \`inboxes/<slug>/inbox.ts\`: one inbox's settings. Beside it, \`instructions.md\` is that inbox's own instructions and \`quick-paths.ts\` its web chat's quick paths.
|
|
950
|
+
- \`sources/<slug>.ts\`: a connected source's settings, the names of its secrets (never a value), lanes and tool modes.
|
|
951
|
+
- \`automations/<slug>.ts\`: an automation's running source.
|
|
952
|
+
- \`pages/<slug>/\`: a page's \`entry.tsx\` and \`bff.ts\`.
|
|
953
|
+
- \`volty.config.ts\`: the workspace this project deploys to.
|
|
954
|
+
- \`.volty/targets\`: the version this folder was pulled from. \`.volty/observed\`: what the workspace holds outside the project (Learned rules, Drive files, tables, sources with no file yet), read-only.
|
|
955
|
+
|
|
956
|
+
Systems connected to this workspace:
|
|
957
|
+
${systems.length > 0 ? systems.join(`
|
|
958
|
+
`) : "- none"}
|
|
959
|
+
|
|
960
|
+
Pushing the folder back is not built yet. Run \`volty pull\` again to bring the folder up to date, and \`volty docs\` for every operation.
|
|
961
|
+
`;
|
|
962
|
+
}
|
|
963
|
+
function configFile(target, workspaceId) {
|
|
964
|
+
return tsFile([
|
|
965
|
+
"Where this project deploys: each target names one workspace by id.",
|
|
966
|
+
"Written by volty pull; the version each target was pulled from is in .volty/targets."
|
|
967
|
+
], { targets: { [target]: { workspace: workspaceId } } });
|
|
968
|
+
}
|
|
969
|
+
function readTargets(dir) {
|
|
970
|
+
const path = join3(dir, ".volty", "targets");
|
|
971
|
+
if (!existsSync4(path))
|
|
972
|
+
return null;
|
|
973
|
+
return JSON.parse(readFileSync4(path, "utf8"));
|
|
974
|
+
}
|
|
975
|
+
async function pull(ctx, opts) {
|
|
976
|
+
const { dir, workspaceId, target } = opts;
|
|
977
|
+
const targets = readTargets(dir);
|
|
978
|
+
if (targets) {
|
|
979
|
+
const other = Object.entries(targets).find(([, t]) => t.workspace !== workspaceId);
|
|
980
|
+
if (other) {
|
|
981
|
+
throw new Error(`${dir} holds the project of workspace ${other[1].workspace}: pull ${workspaceId} into its own folder.`);
|
|
982
|
+
}
|
|
983
|
+
} else if (existsSync4(dir) && readdirSync(dir).some((name) => !name.startsWith("."))) {
|
|
984
|
+
throw new Error(`${dir} is not empty and no volty pull wrote it: pull into an empty folder.`);
|
|
985
|
+
}
|
|
986
|
+
const inboxes = pullInboxes(ctx);
|
|
987
|
+
const parts = await Promise.all([
|
|
988
|
+
inboxes,
|
|
989
|
+
pullInstructions(ctx, inboxes),
|
|
990
|
+
pullSources(ctx),
|
|
991
|
+
pullAutomations(ctx),
|
|
992
|
+
pullPages(ctx),
|
|
993
|
+
observeData(ctx)
|
|
994
|
+
]);
|
|
995
|
+
const files = new Map;
|
|
996
|
+
const observed = new Observed;
|
|
997
|
+
for (const one of parts) {
|
|
998
|
+
for (const [rel, text] of one.files)
|
|
999
|
+
files.set(rel, text);
|
|
1000
|
+
for (const [heading, lines] of one.observed.sections)
|
|
1001
|
+
for (const line of lines)
|
|
1002
|
+
observed.add(heading, line);
|
|
1003
|
+
}
|
|
1004
|
+
files.set("AGENTS.md", agentsMd(workspaceId, parts[2].sources));
|
|
1005
|
+
files.set("volty.config.ts", configFile(target, workspaceId));
|
|
1006
|
+
const base = targets?.[target]?.version;
|
|
1007
|
+
const { baseFiles, ...recorded } = await read(ctx, "project record-pull", {
|
|
1008
|
+
workspace: workspaceId,
|
|
1009
|
+
files: Object.fromEntries(files),
|
|
1010
|
+
...base ? { base } : {}
|
|
1011
|
+
});
|
|
1012
|
+
const written = [];
|
|
1013
|
+
const deleted = [];
|
|
1014
|
+
const kept = [];
|
|
1015
|
+
const edited = (rel, local) => base !== undefined && sha256(local) !== baseFiles[rel];
|
|
1016
|
+
for (const [rel, text] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1017
|
+
const path = join3(dir, rel);
|
|
1018
|
+
const local = existsSync4(path) ? readFileSync4(path, "utf8") : null;
|
|
1019
|
+
if (local === text)
|
|
1020
|
+
continue;
|
|
1021
|
+
if (local !== null && edited(rel, local)) {
|
|
1022
|
+
kept.push({ path: rel, workspace: sha256(text) === baseFiles[rel] ? "unchanged" : "changed" });
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
mkdirSync3(dirname2(path), { recursive: true });
|
|
1026
|
+
writeFileSync4(path, text);
|
|
1027
|
+
written.push(rel);
|
|
1028
|
+
}
|
|
1029
|
+
for (const rel of Object.keys(baseFiles).sort()) {
|
|
1030
|
+
const path = join3(dir, rel);
|
|
1031
|
+
if (files.has(rel) || !existsSync4(path))
|
|
1032
|
+
continue;
|
|
1033
|
+
if (edited(rel, readFileSync4(path, "utf8"))) {
|
|
1034
|
+
kept.push({ path: rel, workspace: "removed" });
|
|
1035
|
+
} else {
|
|
1036
|
+
unlinkSync(path);
|
|
1037
|
+
deleted.push(rel);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
mkdirSync3(join3(dir, ".volty"), { recursive: true });
|
|
1041
|
+
const nextTargets = {
|
|
1042
|
+
...targets,
|
|
1043
|
+
[target]: { workspace: recorded.workspaceId, version: recorded.versionId }
|
|
1044
|
+
};
|
|
1045
|
+
writeFileSync4(join3(dir, ".volty", "targets"), `${JSON.stringify(nextTargets, null, 2)}
|
|
1046
|
+
`);
|
|
1047
|
+
const observedPath = join3(dir, ".volty", "observed");
|
|
1048
|
+
if (existsSync4(observedPath))
|
|
1049
|
+
chmodSync(observedPath, 420);
|
|
1050
|
+
writeFileSync4(observedPath, observed.render());
|
|
1051
|
+
chmodSync(observedPath, 292);
|
|
1052
|
+
return { ...recorded, written, deleted, kept };
|
|
1053
|
+
}
|
|
1054
|
+
|
|
649
1055
|
// src/update.ts
|
|
650
|
-
import { mkdirSync as
|
|
1056
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
651
1057
|
import { homedir as homedir2 } from "node:os";
|
|
652
|
-
import { dirname as
|
|
653
|
-
var CACHE_PATH =
|
|
1058
|
+
import { dirname as dirname3, join as join4 } from "node:path";
|
|
1059
|
+
var CACHE_PATH = join4(homedir2(), ".config", "volty", "update-check.json");
|
|
654
1060
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
655
1061
|
var REGISTRY_LATEST = "https://registry.npmjs.org/@voltade/volty/latest";
|
|
656
1062
|
function currentVersion() {
|
|
657
1063
|
try {
|
|
658
|
-
const pkg = JSON.parse(
|
|
1064
|
+
const pkg = JSON.parse(readFileSync5(join4(import.meta.dirname, "..", "package.json"), "utf8"));
|
|
659
1065
|
return pkg.version ?? null;
|
|
660
1066
|
} catch {
|
|
661
1067
|
return null;
|
|
@@ -673,15 +1079,15 @@ function cmpVersion(a, b) {
|
|
|
673
1079
|
}
|
|
674
1080
|
function readCache() {
|
|
675
1081
|
try {
|
|
676
|
-
return JSON.parse(
|
|
1082
|
+
return JSON.parse(readFileSync5(CACHE_PATH, "utf8"));
|
|
677
1083
|
} catch {
|
|
678
1084
|
return null;
|
|
679
1085
|
}
|
|
680
1086
|
}
|
|
681
1087
|
function writeCache(cache) {
|
|
682
1088
|
try {
|
|
683
|
-
|
|
684
|
-
|
|
1089
|
+
mkdirSync4(dirname3(CACHE_PATH), { recursive: true });
|
|
1090
|
+
writeFileSync5(CACHE_PATH, `${JSON.stringify(cache)}
|
|
685
1091
|
`);
|
|
686
1092
|
} catch {}
|
|
687
1093
|
}
|
|
@@ -903,6 +1309,41 @@ async function handleChanges(rest, ctx) {
|
|
|
903
1309
|
process.stdout.write(`${dec.value === "approve" ? "Approved" : "Rejected"} proposal ${res.body.proposal?.id ?? pid.value} → ${res.body.proposal?.status ?? "decided"}
|
|
904
1310
|
`);
|
|
905
1311
|
}
|
|
1312
|
+
var KEPT_NOTE = {
|
|
1313
|
+
unchanged: "",
|
|
1314
|
+
changed: ", and the workspace changed it too: delete it and pull again for the workspace copy",
|
|
1315
|
+
removed: ", and the workspace no longer has it"
|
|
1316
|
+
};
|
|
1317
|
+
async function handlePull(rest, ctx, env) {
|
|
1318
|
+
const [dir = ".", ...extra] = rest;
|
|
1319
|
+
if (extra.length > 0 || dir.startsWith("--"))
|
|
1320
|
+
fail("usage: volty pull [dir] [--workspace <id>]");
|
|
1321
|
+
let workspaceId = ctx.organizationId;
|
|
1322
|
+
if (!workspaceId) {
|
|
1323
|
+
const res = await whoami(ctx);
|
|
1324
|
+
if ("error" in res)
|
|
1325
|
+
fail(res.error);
|
|
1326
|
+
workspaceId = res.who.organizationId;
|
|
1327
|
+
}
|
|
1328
|
+
if (!workspaceId)
|
|
1329
|
+
fail("this key names no workspace: run `volty auth login`");
|
|
1330
|
+
const out = await pull(ctx, { dir, workspaceId, target: env });
|
|
1331
|
+
if (out.unchanged && out.written.length + out.deleted.length + out.kept.length === 0) {
|
|
1332
|
+
process.stdout.write(`${dir} is up to date with version ${out.versionId} of workspace ${out.workspaceId}.
|
|
1333
|
+
`);
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
const lines = [
|
|
1337
|
+
`Pulled workspace ${out.workspaceId} into ${dir}: version ${out.versionId}${out.unchanged ? " (unchanged)" : ""}.`,
|
|
1338
|
+
...out.written.map((f) => ` wrote ${f}`),
|
|
1339
|
+
...out.deleted.map((f) => ` deleted ${f}, which the workspace no longer has`),
|
|
1340
|
+
...out.kept.map((f) => ` kept ${f.path}: edited here${KEPT_NOTE[f.workspace]}`),
|
|
1341
|
+
"What the project does not hold is listed in .volty/observed."
|
|
1342
|
+
];
|
|
1343
|
+
process.stdout.write(`${lines.join(`
|
|
1344
|
+
`)}
|
|
1345
|
+
`);
|
|
1346
|
+
}
|
|
906
1347
|
async function handleDocs(config, env) {
|
|
907
1348
|
const ctx = ensureContext(config, env);
|
|
908
1349
|
if (!ctx.baseUrl)
|
|
@@ -916,16 +1357,16 @@ function handleSkill(rest) {
|
|
|
916
1357
|
if (rest[0] !== "install")
|
|
917
1358
|
fail("usage: volty skill install");
|
|
918
1359
|
const candidates = [
|
|
919
|
-
|
|
920
|
-
|
|
1360
|
+
join5(import.meta.dirname, "..", "skill", "volty-cli-ops", "SKILL.md"),
|
|
1361
|
+
join5(import.meta.dirname, "..", "..", ".claude", "skills", "volty-cli-ops", "SKILL.md")
|
|
921
1362
|
];
|
|
922
|
-
const source = candidates.find((p) =>
|
|
1363
|
+
const source = candidates.find((p) => existsSync5(p));
|
|
923
1364
|
if (!source)
|
|
924
1365
|
fail("bundled SKILL.md not found — reinstall the @voltade/volty package");
|
|
925
|
-
const destDir =
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
process.stdout.write(`Installed the volty-cli-ops skill → ${
|
|
1366
|
+
const destDir = join5(homedir3(), ".claude", "skills", "volty-cli-ops");
|
|
1367
|
+
mkdirSync5(destDir, { recursive: true });
|
|
1368
|
+
writeFileSync6(join5(destDir, "SKILL.md"), readFileSync6(source, "utf8"));
|
|
1369
|
+
process.stdout.write(`Installed the volty-cli-ops skill → ${join5(destDir, "SKILL.md")}
|
|
929
1370
|
`);
|
|
930
1371
|
}
|
|
931
1372
|
async function main() {
|
|
@@ -936,6 +1377,8 @@ async function main() {
|
|
|
936
1377
|
argv = orgExtract.rest;
|
|
937
1378
|
const cacheFlag = takeBool(argv, "--no-cache");
|
|
938
1379
|
argv = cacheFlag.rest;
|
|
1380
|
+
const workspaceExtract = argv[0] === "pull" ? takeValue(argv, "--workspace") : { value: undefined, rest: argv };
|
|
1381
|
+
argv = workspaceExtract.rest;
|
|
939
1382
|
const config = loadConfig();
|
|
940
1383
|
const env = activeEnv(config, envExtract.value ?? (process.env.VOLTY_ENV || undefined));
|
|
941
1384
|
const peek = config.contexts[env];
|
|
@@ -943,7 +1386,7 @@ async function main() {
|
|
|
943
1386
|
const target = resolveTargetOrg({
|
|
944
1387
|
env,
|
|
945
1388
|
baseUrl: peek?.baseUrl,
|
|
946
|
-
override: orgExtract.value ?? (process.env.VOLTY_ORG || undefined),
|
|
1389
|
+
override: workspaceExtract.value ?? orgExtract.value ?? (process.env.VOLTY_ORG || undefined),
|
|
947
1390
|
sticky: peek?.activeOrg,
|
|
948
1391
|
command: argv
|
|
949
1392
|
});
|
|
@@ -984,10 +1427,14 @@ async function main() {
|
|
|
984
1427
|
process.stderr.write(`→ ${env} · ${res.who.organizationName} (${res.who.organizationId}) · ${res.who.role}
|
|
985
1428
|
`);
|
|
986
1429
|
}
|
|
1430
|
+
if (cmd === "pull")
|
|
1431
|
+
return handlePull(rest, ctx, env);
|
|
987
1432
|
if (cmd === "changes" && rest[0] === "decide")
|
|
988
1433
|
return handleChanges(rest, ctx);
|
|
989
1434
|
if (cmd === "keys")
|
|
990
1435
|
argv = keysArgv(argv);
|
|
1436
|
+
if (cmd === "changes" && (rest[0] === undefined || rest[0].startsWith("--")))
|
|
1437
|
+
argv = ["changes", "list-mine", ...rest];
|
|
991
1438
|
const catalog = await fetchCatalog(ctx, env, !cacheFlag.present);
|
|
992
1439
|
if (!cmd || cmd === "help" || cmd === "--help") {
|
|
993
1440
|
process.stdout.write(`${renderCatalog(catalog.ops, rest.length ? rest.join(" ") : undefined)}
|
package/package.json
CHANGED