@beyondwork/wb-cli 0.1.26 → 0.1.27
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/CHANGELOG.md +6 -0
- package/out/cli.js +32 -8
- package/out/cli.js.map +1 -1
- package/out/cli.test.js +195 -0
- package/out/cli.test.js.map +1 -0
- package/out/client.js.map +1 -1
- package/out/extension.js +175 -136
- package/out/extension.js.map +1 -1
- package/out/lib/branches.js +138 -0
- package/out/lib/branches.js.map +1 -0
- package/out/lib/branches.test.js +185 -0
- package/out/lib/branches.test.js.map +1 -0
- package/out/lib/cli-security.test.js +146 -0
- package/out/lib/cli-security.test.js.map +1 -0
- package/out/lib/index.js +2 -0
- package/out/lib/index.js.map +1 -1
- package/out/lib/workspace.js +282 -0
- package/out/lib/workspace.js.map +1 -0
- package/out/lib/workspace.test.js +666 -0
- package/out/lib/workspace.test.js.map +1 -0
- package/out/lib/ws-client.test.js +188 -0
- package/out/lib/ws-client.test.js.map +1 -0
- package/out/tree_data_provider.js +22 -37
- package/out/tree_data_provider.js.map +1 -1
- package/out/types.js +3 -1
- package/out/types.js.map +1 -1
- package/out/ws-client.js +89 -21
- package/out/ws-client.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BranchAction = void 0;
|
|
4
|
+
exports.isUserBranch = isUserBranch;
|
|
5
|
+
exports.filterVisibleBranches = filterVisibleBranches;
|
|
6
|
+
exports.branchOwnerId = branchOwnerId;
|
|
7
|
+
exports.userBranchesFor = userBranchesFor;
|
|
8
|
+
exports.neuiUserBranchesFor = neuiUserBranchesFor;
|
|
9
|
+
exports.filterBranchesForUser = filterBranchesForUser;
|
|
10
|
+
exports.conversationsByWorkblock = conversationsByWorkblock;
|
|
11
|
+
exports.visibleBranchRows = visibleBranchRows;
|
|
12
|
+
exports.directoryActionLabel = directoryActionLabel;
|
|
13
|
+
exports.branchActionOptions = branchActionOptions;
|
|
14
|
+
const workspace_1 = require("./workspace");
|
|
15
|
+
const NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
16
|
+
function isUserBranch(branchName) {
|
|
17
|
+
return branchName.replace(/^features\//, "").includes("@users/");
|
|
18
|
+
}
|
|
19
|
+
function filterVisibleBranches(branches) {
|
|
20
|
+
const featureBranches = new Set(branches
|
|
21
|
+
.filter((branch) => branch.name.startsWith("features/"))
|
|
22
|
+
.filter((branch) => !branch.name.includes("@thread/"))
|
|
23
|
+
.filter((branch) => !branch.name.includes("@stream/"))
|
|
24
|
+
.filter((branch) => !isUserBranch(branch.name))
|
|
25
|
+
.map((branch) => (0, workspace_1.getFeatureName)(branch.name)));
|
|
26
|
+
return branches.filter((branch) => {
|
|
27
|
+
if (branch.name === "main") {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (!branch.name.startsWith("features/") ||
|
|
31
|
+
branch.name.includes("@thread/")) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (branch.name.includes("@stream/")) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (!isUserBranch(branch.name)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return featureBranches.has((0, workspace_1.getFeatureName)(branch.name));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function getFeatureRef(branchName) {
|
|
44
|
+
const withoutThread = (0, workspace_1.stripThreadSuffix)(branchName);
|
|
45
|
+
const userBranchIdx = withoutThread.lastIndexOf("@users/");
|
|
46
|
+
if (userBranchIdx !== -1) {
|
|
47
|
+
return withoutThread.slice(0, userBranchIdx);
|
|
48
|
+
}
|
|
49
|
+
return withoutThread;
|
|
50
|
+
}
|
|
51
|
+
function branchOwnerId(branch) {
|
|
52
|
+
const withoutThread = (0, workspace_1.stripThreadSuffix)(branch.name);
|
|
53
|
+
const userBranchIdx = withoutThread.lastIndexOf("@users/");
|
|
54
|
+
if (userBranchIdx !== -1) {
|
|
55
|
+
return withoutThread.slice(userBranchIdx + "@users/".length);
|
|
56
|
+
}
|
|
57
|
+
if (withoutThread.startsWith("users/")) {
|
|
58
|
+
return withoutThread.slice("users/".length);
|
|
59
|
+
}
|
|
60
|
+
if (branch.owner_id && branch.owner_id !== NIL_UUID) {
|
|
61
|
+
return branch.owner_id;
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
function userBranchesFor(branches, currentUserId) {
|
|
66
|
+
return branches
|
|
67
|
+
.filter((branch) => branch.name.startsWith("features/") || branch.name.startsWith("users/"))
|
|
68
|
+
.filter((branch) => !branch.name.includes("@thread/"))
|
|
69
|
+
.filter((branch) => branchOwnerId(branch) === currentUserId);
|
|
70
|
+
}
|
|
71
|
+
function neuiUserBranchesFor(branches, currentUserId) {
|
|
72
|
+
const featureBranches = new Set(branches
|
|
73
|
+
.filter((branch) => branch.name.startsWith("features/"))
|
|
74
|
+
.filter((branch) => !branch.name.includes("@thread/"))
|
|
75
|
+
.filter((branch) => !branchOwnerId(branch))
|
|
76
|
+
.map((branch) => getFeatureRef(branch.name)));
|
|
77
|
+
return branches
|
|
78
|
+
.filter((branch) => branch.name.startsWith("features/"))
|
|
79
|
+
.filter((branch) => !branch.name.includes("@thread/"))
|
|
80
|
+
.filter((branch) => branchOwnerId(branch) === currentUserId)
|
|
81
|
+
.filter((branch) => featureBranches.has(getFeatureRef(branch.name)));
|
|
82
|
+
}
|
|
83
|
+
function filterBranchesForUser(branches, currentUserId, ownsWorkblock) {
|
|
84
|
+
const visibleBranches = filterVisibleBranches(branches);
|
|
85
|
+
const userBranches = neuiUserBranchesFor(branches, currentUserId);
|
|
86
|
+
if (userBranches.length > 0) {
|
|
87
|
+
return userBranches;
|
|
88
|
+
}
|
|
89
|
+
return ownsWorkblock
|
|
90
|
+
? visibleBranches.filter((branch) => branch.name === "main")
|
|
91
|
+
: [];
|
|
92
|
+
}
|
|
93
|
+
/** Live conversation workspaces grouped by the workblock they belong to. */
|
|
94
|
+
function conversationsByWorkblock(workspaces) {
|
|
95
|
+
const byWorkblock = {};
|
|
96
|
+
for (const workspace of workspaces) {
|
|
97
|
+
if (workspace.archived || !(0, workspace_1.isConversationBranch)(workspace.branch)) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
(byWorkblock[workspace.workblock_id] ??= []).push(workspace);
|
|
101
|
+
}
|
|
102
|
+
return byWorkblock;
|
|
103
|
+
}
|
|
104
|
+
/** The branch rows the tree shows for one workblock. */
|
|
105
|
+
function visibleBranchRows(allBranches, conversations, currentUserId, ownsWorkblock) {
|
|
106
|
+
return (0, workspace_1.mergeActiveConversationBranches)(filterBranchesForUser(allBranches, currentUserId, ownsWorkblock), allBranches, conversations);
|
|
107
|
+
}
|
|
108
|
+
exports.BranchAction = {
|
|
109
|
+
ChooseDirectory: "Choose a directory for the branch",
|
|
110
|
+
NewConversation: "New conversation",
|
|
111
|
+
RemoveDirectoryBinding: "Remove directory binding",
|
|
112
|
+
GetBranch: "Get workblock branch",
|
|
113
|
+
StoreBranch: "Store workblock branch",
|
|
114
|
+
EnableSync: "Enable sync",
|
|
115
|
+
DisableSync: "Disable sync",
|
|
116
|
+
CompareChanges: "Compare changes",
|
|
117
|
+
};
|
|
118
|
+
function directoryActionLabel(dir) {
|
|
119
|
+
return dir ? `Change directory from ${dir}` : exports.BranchAction.ChooseDirectory;
|
|
120
|
+
}
|
|
121
|
+
/** The action menu shown for a branch row, in display order. */
|
|
122
|
+
function branchActionOptions(state) {
|
|
123
|
+
const options = [directoryActionLabel(state.dir)];
|
|
124
|
+
if ((0, workspace_1.conversationForkTarget)(state.branch)) {
|
|
125
|
+
options.push(exports.BranchAction.NewConversation);
|
|
126
|
+
}
|
|
127
|
+
if (state.dir) {
|
|
128
|
+
options.push(exports.BranchAction.RemoveDirectoryBinding);
|
|
129
|
+
options.push(exports.BranchAction.GetBranch);
|
|
130
|
+
options.push(exports.BranchAction.StoreBranch);
|
|
131
|
+
options.push(state.syncEnabled ? exports.BranchAction.DisableSync : exports.BranchAction.EnableSync);
|
|
132
|
+
if (state.modified) {
|
|
133
|
+
options.push(exports.BranchAction.CompareChanges);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return options;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=branches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branches.js","sourceRoot":"","sources":["../../src/lib/branches.ts"],"names":[],"mappings":";;;AAYA,oCAEC;AAED,sDA4BC;AAWD,sCAaC;AAED,0CAWC;AAED,kDAiBC;AAED,sDAaC;AAGD,4DASC;AAGD,8CAWC;AAaD,oDAEC;AAUD,kDAiBC;AAtLD,2CAOqB;AAErB,MAAM,QAAQ,GAAG,sCAAsC,CAAC;AAExD,SAAgB,YAAY,CAAC,UAAkB;IAC7C,OAAO,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACnE,CAAC;AAED,SAAgB,qBAAqB,CAAC,QAA+B;IACnE,MAAM,eAAe,GAAG,IAAI,GAAG,CAC7B,QAAQ;SACL,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;SACvD,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACrD,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACrD,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SAC9C,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,0BAAc,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C,SAAS,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,oBAAY,CAAC,WAAW,CAAC,CAAC;QACvC,OAAO,CAAC,IAAI,CACV,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAY,CAAC,WAAW,CAAC,CAAC,CAAC,oBAAY,CAAC,UAAU,CACvE,CAAC;QACF,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,oBAAY,CAAC,cAAc,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const assert = __importStar(require("node:assert/strict"));
|
|
37
|
+
const branches_1 = require("./branches");
|
|
38
|
+
const workspace_1 = require("./workspace");
|
|
39
|
+
const STREAM_ID = "42b99b44-8e41-46b5-aaf4-f45656505950";
|
|
40
|
+
const OTHER_STREAM_ID = "6a4ee779-4848-49c7-8eb1-48ce288da35c";
|
|
41
|
+
const THREAD_ID = "92186d93-607a-4f27-a5fd-0a2646fd97c6";
|
|
42
|
+
const USER_ID = "8d52f62c-818d-4c97-968d-e7e4cd3ab58c";
|
|
43
|
+
const OTHER_USER_ID = "1f0f0d0a-2b4c-4a1d-9c3e-9a5f6b7c8d9e";
|
|
44
|
+
const WORKBLOCK_ID = "d7bd49ad-3584-41e5-9279-b1b505862c74";
|
|
45
|
+
function branch(name) {
|
|
46
|
+
return {
|
|
47
|
+
head_commit: `${name}-head`,
|
|
48
|
+
last_changed: "2026-07-29T00:00:00Z",
|
|
49
|
+
name,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function workspace(overrides = {}) {
|
|
53
|
+
return {
|
|
54
|
+
branch: `features/my-feature@stream/${STREAM_ID}`,
|
|
55
|
+
created_at: "2026-07-29T01:00:00Z",
|
|
56
|
+
id: STREAM_ID,
|
|
57
|
+
thread_id: THREAD_ID,
|
|
58
|
+
title: "Investigate the import",
|
|
59
|
+
updated_at: "2026-07-29T02:00:00Z",
|
|
60
|
+
user_id: USER_ID,
|
|
61
|
+
workblock_id: WORKBLOCK_ID,
|
|
62
|
+
...overrides,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const mainBranch = branch("main");
|
|
66
|
+
const versionBranch = branch("features/my-feature");
|
|
67
|
+
const myUserBranch = branch(`features/my-feature@users/${USER_ID}`);
|
|
68
|
+
const theirUserBranch = branch(`features/my-feature@users/${OTHER_USER_ID}`);
|
|
69
|
+
const myConversationBranch = branch(`features/my-feature@stream/${STREAM_ID}`);
|
|
70
|
+
const threadBranch = branch(`features/my-feature@stream/${STREAM_ID}@thread/${THREAD_ID}`);
|
|
71
|
+
describe("filterVisibleBranches", () => {
|
|
72
|
+
it("keeps main, versions and user branches with a version", () => {
|
|
73
|
+
const result = (0, branches_1.filterVisibleBranches)([
|
|
74
|
+
mainBranch,
|
|
75
|
+
versionBranch,
|
|
76
|
+
myUserBranch,
|
|
77
|
+
theirUserBranch,
|
|
78
|
+
myConversationBranch,
|
|
79
|
+
threadBranch,
|
|
80
|
+
branch(`features/orphan@users/${USER_ID}`),
|
|
81
|
+
]);
|
|
82
|
+
assert.deepEqual(result.map((row) => row.name), [
|
|
83
|
+
mainBranch.name,
|
|
84
|
+
versionBranch.name,
|
|
85
|
+
myUserBranch.name,
|
|
86
|
+
theirUserBranch.name,
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe("conversationsByWorkblock", () => {
|
|
91
|
+
it("groups live conversation rows and drops everything else", () => {
|
|
92
|
+
const grouped = (0, branches_1.conversationsByWorkblock)([
|
|
93
|
+
workspace(),
|
|
94
|
+
workspace({ id: "archived", archived: true }),
|
|
95
|
+
workspace({ id: "on-main", branch: "main" }),
|
|
96
|
+
workspace({ id: "on-user-branch", branch: myUserBranch.name }),
|
|
97
|
+
workspace({
|
|
98
|
+
id: "other-workblock",
|
|
99
|
+
workblock_id: "other",
|
|
100
|
+
branch: `features/x@stream/${OTHER_STREAM_ID}`,
|
|
101
|
+
}),
|
|
102
|
+
]);
|
|
103
|
+
assert.deepEqual(grouped[WORKBLOCK_ID].map((row) => row.id), [STREAM_ID]);
|
|
104
|
+
assert.deepEqual(grouped["other"].map((row) => row.id), ["other-workblock"]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe("visibleBranchRows", () => {
|
|
108
|
+
it("shows the user's work branch and conversations, never the version itself", () => {
|
|
109
|
+
const rows = (0, branches_1.visibleBranchRows)([
|
|
110
|
+
mainBranch,
|
|
111
|
+
versionBranch,
|
|
112
|
+
myUserBranch,
|
|
113
|
+
theirUserBranch,
|
|
114
|
+
myConversationBranch,
|
|
115
|
+
], [workspace()], USER_ID, true);
|
|
116
|
+
assert.deepEqual(rows.map((row) => row.name), [myUserBranch.name, myConversationBranch.name]);
|
|
117
|
+
assert.deepEqual(rows.filter((row) => (0, workspace_1.isFeatureBranch)(row.name)), []);
|
|
118
|
+
});
|
|
119
|
+
it("shows only conversations when the user has no work branch", () => {
|
|
120
|
+
const rows = (0, branches_1.visibleBranchRows)([mainBranch, versionBranch, myConversationBranch], [workspace()], USER_ID, false);
|
|
121
|
+
assert.deepEqual(rows.map((row) => row.name), [myConversationBranch.name]);
|
|
122
|
+
assert.deepEqual(rows.filter((row) => (0, workspace_1.isFeatureBranch)(row.name)), []);
|
|
123
|
+
});
|
|
124
|
+
it("falls back to main for an owner with no version branches", () => {
|
|
125
|
+
const rows = (0, branches_1.visibleBranchRows)([mainBranch], [], USER_ID, true);
|
|
126
|
+
assert.deepEqual(rows.map((row) => row.name), [mainBranch.name]);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
describe("branchActionOptions", () => {
|
|
130
|
+
it("offers a new conversation on every row that belongs to a version", () => {
|
|
131
|
+
const rows = (0, branches_1.visibleBranchRows)([
|
|
132
|
+
mainBranch,
|
|
133
|
+
versionBranch,
|
|
134
|
+
myUserBranch,
|
|
135
|
+
theirUserBranch,
|
|
136
|
+
myConversationBranch,
|
|
137
|
+
], [workspace()], USER_ID, true);
|
|
138
|
+
for (const row of rows) {
|
|
139
|
+
assert.ok((0, branches_1.branchActionOptions)({
|
|
140
|
+
branch: row.name,
|
|
141
|
+
syncEnabled: false,
|
|
142
|
+
modified: false,
|
|
143
|
+
}).includes(branches_1.BranchAction.NewConversation), `${row.name} offers no new conversation`);
|
|
144
|
+
assert.equal((0, workspace_1.conversationForkTarget)(row.name), versionBranch.name);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
it("offers no new conversation on a main-only tree", () => {
|
|
148
|
+
const rows = (0, branches_1.visibleBranchRows)([mainBranch], [], USER_ID, true);
|
|
149
|
+
assert.deepEqual(rows.map((row) => (0, branches_1.branchActionOptions)({
|
|
150
|
+
branch: row.name,
|
|
151
|
+
syncEnabled: false,
|
|
152
|
+
modified: false,
|
|
153
|
+
})), [[branches_1.BranchAction.ChooseDirectory]]);
|
|
154
|
+
});
|
|
155
|
+
it("lists the directory actions only for a bound row", () => {
|
|
156
|
+
assert.deepEqual((0, branches_1.branchActionOptions)({
|
|
157
|
+
branch: myConversationBranch.name,
|
|
158
|
+
dir: "/work/wb",
|
|
159
|
+
syncEnabled: false,
|
|
160
|
+
modified: true,
|
|
161
|
+
}), [
|
|
162
|
+
(0, branches_1.directoryActionLabel)("/work/wb"),
|
|
163
|
+
branches_1.BranchAction.NewConversation,
|
|
164
|
+
branches_1.BranchAction.RemoveDirectoryBinding,
|
|
165
|
+
branches_1.BranchAction.GetBranch,
|
|
166
|
+
branches_1.BranchAction.StoreBranch,
|
|
167
|
+
branches_1.BranchAction.EnableSync,
|
|
168
|
+
branches_1.BranchAction.CompareChanges,
|
|
169
|
+
]);
|
|
170
|
+
assert.deepEqual((0, branches_1.branchActionOptions)({
|
|
171
|
+
branch: myConversationBranch.name,
|
|
172
|
+
dir: "/work/wb",
|
|
173
|
+
syncEnabled: true,
|
|
174
|
+
modified: false,
|
|
175
|
+
}), [
|
|
176
|
+
(0, branches_1.directoryActionLabel)("/work/wb"),
|
|
177
|
+
branches_1.BranchAction.NewConversation,
|
|
178
|
+
branches_1.BranchAction.RemoveDirectoryBinding,
|
|
179
|
+
branches_1.BranchAction.GetBranch,
|
|
180
|
+
branches_1.BranchAction.StoreBranch,
|
|
181
|
+
branches_1.BranchAction.DisableSync,
|
|
182
|
+
]);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
//# sourceMappingURL=branches.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branches.test.js","sourceRoot":"","sources":["../../src/lib/branches.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA6C;AAE7C,yCAOoB;AACpB,2CAIqB;AAErB,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,eAAe,GAAG,sCAAsC,CAAC;AAC/D,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,OAAO,GAAG,sCAAsC,CAAC;AACvD,MAAM,aAAa,GAAG,sCAAsC,CAAC;AAC7D,MAAM,YAAY,GAAG,sCAAsC,CAAC;AAE5D,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO;QACL,WAAW,EAAE,GAAG,IAAI,OAAO;QAC3B,YAAY,EAAE,sBAAsB;QACpC,IAAI;KACL,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAChB,YAA0C,EAAE;IAE5C,OAAO;QACL,MAAM,EAAE,8BAA8B,SAAS,EAAE;QACjD,UAAU,EAAE,sBAAsB;QAClC,EAAE,EAAE,SAAS;QACb,SAAS,EAAE,SAAS;QACpB,KAAK,EAAE,wBAAwB;QAC/B,UAAU,EAAE,sBAAsB;QAClC,OAAO,EAAE,OAAO;QAChB,YAAY,EAAE,YAAY;QAC1B,GAAG,SAAS;KACb,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAClC,MAAM,aAAa,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,MAAM,YAAY,GAAG,MAAM,CAAC,6BAA6B,OAAO,EAAE,CAAC,C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AQ,EAAE,KAAK;SAChB,CAAC,EACF;YACE,IAAA,+BAAoB,EAAC,UAAU,CAAC;YAChC,uBAAY,CAAC,eAAe;YAC5B,uBAAY,CAAC,sBAAsB;YACnC,uBAAY,CAAC,SAAS;YACtB,uBAAY,CAAC,WAAW;YACxB,uBAAY,CAAC,WAAW;SACzB,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const assert = __importStar(require("assert"));
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const os = __importStar(require("os"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
/**
|
|
41
|
+
* Tests for path traversal vulnerability mitigation in CLI
|
|
42
|
+
*
|
|
43
|
+
* These tests verify that the path validation logic correctly prevents:
|
|
44
|
+
* - Directory traversal using ../
|
|
45
|
+
* - Absolute path access outside the base directory
|
|
46
|
+
* - Path traversal in output file paths
|
|
47
|
+
*/
|
|
48
|
+
function makeTmpDir() {
|
|
49
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), "cli-test-"));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Core path validation function extracted from the CLI
|
|
53
|
+
* This is the security-critical logic that prevents path traversal
|
|
54
|
+
*/
|
|
55
|
+
function isPathSafe(baseDir, filePath) {
|
|
56
|
+
const resolvedBase = path.resolve(baseDir);
|
|
57
|
+
const absolutePath = path.resolve(resolvedBase, filePath);
|
|
58
|
+
const relativePath = path.relative(resolvedBase, absolutePath);
|
|
59
|
+
// Reject if path escapes the base directory or is absolute
|
|
60
|
+
if (relativePath.startsWith('..') || path.isAbsolute(relativePath)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
describe("CLI path traversal security", () => {
|
|
66
|
+
describe("workblock path validation", () => {
|
|
67
|
+
it("should reject simple parent directory traversal", () => {
|
|
68
|
+
const baseDir = makeTmpDir();
|
|
69
|
+
try {
|
|
70
|
+
const result = isPathSafe(baseDir, "../etc/passwd");
|
|
71
|
+
assert.strictEqual(result, false);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
it("should reject multiple parent directory traversal", () => {
|
|
78
|
+
const baseDir = makeTmpDir();
|
|
79
|
+
try {
|
|
80
|
+
const result = isPathSafe(baseDir, "../../../../../../etc/passwd");
|
|
81
|
+
assert.strictEqual(result, false);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
it("should reject mixed path traversal", () => {
|
|
88
|
+
const baseDir = makeTmpDir();
|
|
89
|
+
try {
|
|
90
|
+
const result = isPathSafe(baseDir, "subdir/../../etc/passwd");
|
|
91
|
+
assert.strictEqual(result, false);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
it("should reject absolute path access", () => {
|
|
98
|
+
const baseDir = makeTmpDir();
|
|
99
|
+
try {
|
|
100
|
+
const result = isPathSafe(baseDir, "/etc/passwd");
|
|
101
|
+
assert.strictEqual(result, false);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
it("should allow legitimate relative paths", () => {
|
|
108
|
+
const baseDir = makeTmpDir();
|
|
109
|
+
try {
|
|
110
|
+
const result = isPathSafe(baseDir, "workblocks/my-workblock");
|
|
111
|
+
assert.strictEqual(result, true);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("output path validation", () => {
|
|
119
|
+
it("should reject output path with parent directory traversal", () => {
|
|
120
|
+
const baseDir = process.cwd();
|
|
121
|
+
const result = isPathSafe(baseDir, "../../../etc/passwd");
|
|
122
|
+
assert.strictEqual(result, false);
|
|
123
|
+
});
|
|
124
|
+
it("should reject absolute output paths outside base", () => {
|
|
125
|
+
const baseDir = makeTmpDir();
|
|
126
|
+
try {
|
|
127
|
+
const result = isPathSafe(baseDir, "/tmp/output.json");
|
|
128
|
+
assert.strictEqual(result, false);
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
it("should allow legitimate output paths", () => {
|
|
135
|
+
const baseDir = makeTmpDir();
|
|
136
|
+
try {
|
|
137
|
+
const result = isPathSafe(baseDir, "output/workblock.json");
|
|
138
|
+
assert.strictEqual(result, true);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
fs.rmSync(baseDir, { recursive: true, force: true });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=cli-security.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-security.test.js","sourceRoot":"","sources":["../../src/lib/cli-security.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,uCAAyB;AACzB,uCAAyB;AACzB,2CAA6B;AAE7B;;;;;;;GAOG;AAEH,SAAS,UAAU;IACjB,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CAAC,OAAe,EAAE,QAAgB;IACnD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAC1D,M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A2D,EAAE,GAAG,EAAE;YACnE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;YAC9B,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;YAC1D,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;YAC1D,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;gBACvD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACpC,CAAC;oBAAS,CAAC;gBACT,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACvD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;YAC9C,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;gBAC5D,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;oBAAS,CAAC;gBACT,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACvD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/out/lib/index.js
CHANGED
|
@@ -21,7 +21,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
// Re-export utility functions
|
|
24
|
+
__exportStar(require("./branches"), exports);
|
|
24
25
|
__exportStar(require("./workblock"), exports);
|
|
26
|
+
__exportStar(require("./workspace"), exports);
|
|
25
27
|
// Re-export logger interfaces and implementations
|
|
26
28
|
__exportStar(require("./logger"), exports);
|
|
27
29
|
//# sourceMappingURL=index.js.map
|
package/out/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,8BAA8B;AAC9B,8CAA4B;AAE5B,kDAAkD;AAClD,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,8BAA8B;AAC9B,6CAA2B;AAC3B,8CAA4B;AAC5B,8CAA4B;AAE5B,kDAAkD;AAClD,2CAAyB"}
|