@openchamber/web 1.21.1 → 1.22.0
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/assets/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
- package/dist/assets/{CommitSection-DwGiXyjf.js → CommitSection-CC5mFzO2.js} +1 -1
- package/dist/assets/DiffView-6xGdyI0n.js +4 -0
- package/dist/assets/FilesView-Bm3vT63N.js +17 -0
- package/dist/assets/GitView-B6y1Y69c.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-rwHz84MX.js} +1 -1
- package/dist/assets/LinearIssuesView-B0UM_Rkx.js +1 -0
- package/dist/assets/MarkdownImageGallery-sGilV9Hs.js +1 -0
- package/dist/assets/MarkdownRendererImpl--4sRsKBn.js +12 -0
- package/dist/assets/OnboardingScreen-CECL_Cms.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BGPl1s-U.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-Cvz9Z-io.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-BFMsnHk3.js} +4 -4
- package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-C1Qa09YO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-DzQlzMF4.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-C7kBQNAA.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
- package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-C3luvSd_.js} +4 -4
- package/dist/assets/{es-DwyXCqaL.js → es-CmU4HLv9.js} +3 -3
- package/dist/assets/{fr-CS7Csln9.js → fr-Bgyni40l.js} +4 -4
- package/dist/assets/index-C57jT0Sa.css +1 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-CWYs7sMK.js} +1 -1
- package/dist/assets/index-b0zDkWyg.js +7 -0
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-BO_q5ezD.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-D8qPqUAf.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-C1ImKinT.js} +4 -4
- package/dist/assets/{ko-CXuSfZv5.js → ko-CP7OdxYH.js} +4 -4
- package/dist/assets/main-D4rd8Hy5.js +928 -0
- package/dist/assets/{main-D5RWr6sJ.js → main-D7fwjW2z.js} +2 -2
- package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-D5rraz-g.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-Cg_DE3KL.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Bpql0QGw.js} +3 -3
- package/dist/assets/{pl-BJxry0Mi.js → pl-DQYSiGYX.js} +4 -4
- package/dist/assets/{pt-BR-DxLmkhdv.js → pt-BR-DytpsW4M.js} +3 -3
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-B_Bn7BbN.js} +2 -2
- package/dist/assets/renderMobileApp-DLfxMzGJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-HlRmXFGW.js +16 -0
- package/dist/assets/scheduledTasksApi-BPvxrynl.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CFAVs_lu.js} +1 -1
- package/dist/assets/tr-aizaUvft.js +6 -0
- package/dist/assets/{uk-ClgQjmlw.js → uk-DwnRxJZd.js} +3 -3
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-DWXGRUPZ.js} +191 -151
- package/dist/assets/useInlineCommentController-Cc0OCXr0.js +2 -0
- package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-CD-GFayc.js} +4 -4
- package/dist/assets/{zh-CN-Ba6y8H-i.js → zh-CN-UDNMxm7r.js} +3 -3
- package/dist/assets/zh-TW-BsswdYL-.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +4 -0
- package/server/lib/dictation/DOCUMENTATION.md +19 -6
- package/server/lib/dictation/local/model-catalog.js +220 -0
- package/server/lib/dictation/local/model-catalog.test.js +42 -0
- package/server/lib/dictation/local/sherpa-tts.js +41 -20
- package/server/lib/dictation/local/worker-process.js +2 -0
- package/server/lib/dictation/runtime.js +4 -0
- package/server/lib/dictation/service.js +27 -4
- package/server/lib/fs/DOCUMENTATION.md +4 -0
- package/server/lib/fs/routes.js +129 -0
- package/server/lib/fs/routes.test.js +219 -0
- package/server/lib/linear/DOCUMENTATION.md +97 -0
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
- package/server/lib/linear/auth.js +436 -0
- package/server/lib/linear/auth.test.js +242 -0
- package/server/lib/linear/client.js +191 -0
- package/server/lib/linear/index.js +61 -0
- package/server/lib/linear/issues.js +499 -0
- package/server/lib/linear/issues.test.js +512 -0
- package/server/lib/linear/mapping.js +188 -0
- package/server/lib/linear/mapping.test.js +147 -0
- package/server/lib/linear/oauth.js +345 -0
- package/server/lib/linear/oauth.test.js +166 -0
- package/server/lib/linear/parse.js +23 -0
- package/server/lib/linear/routes.js +432 -0
- package/server/lib/linear/routes.test.js +661 -0
- package/server/lib/linear/status-runtime.js +64 -0
- package/server/lib/linear/status-runtime.test.js +167 -0
- package/server/lib/linear/status.js +280 -0
- package/server/lib/linear/status.test.js +271 -0
- package/server/lib/linear/teams.js +72 -0
- package/server/lib/linear/teams.test.js +94 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/tts/DOCUMENTATION.md +1 -0
- package/server/lib/tts/language-detect.js +210 -0
- package/server/lib/tts/language-detect.test.js +76 -0
- package/server/lib/tts/routes.js +23 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/dist/assets/DiffView-Db6bjVv1.js +0 -4
- package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
- package/dist/assets/GitView-CHzJxTi0.js +0 -6
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
- package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
- package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
- package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
- package/dist/assets/index-CUKcHnUA.css +0 -1
- package/dist/assets/index-DIvDEKE-.js +0 -7
- package/dist/assets/main-DLlfDjQ_.js +0 -926
- package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
- package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/zh-TW-Dv8yyhN1.js +0 -15
package/server/lib/fs/routes.js
CHANGED
|
@@ -297,6 +297,79 @@ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProject
|
|
|
297
297
|
});
|
|
298
298
|
};
|
|
299
299
|
|
|
300
|
+
// Nested repository discovery bounds: only shallow walks are useful for the
|
|
301
|
+
// Git tab's "pick a repository" picker, and deep/monorepo trees can explode
|
|
302
|
+
// otherwise. Directories deeper than maxDepth or beyond the visit cap are
|
|
303
|
+
// silently not searched.
|
|
304
|
+
const GIT_DIRS_MAX_DEPTH = 3;
|
|
305
|
+
const GIT_DIRS_MAX_DIRS = 100;
|
|
306
|
+
const GIT_DIRS_SKIP_LIST = new Set(['node_modules', 'dist', 'build', '.venv', 'target', '.next']);
|
|
307
|
+
|
|
308
|
+
// Walks rootPath and returns every nested git repository path (a directory
|
|
309
|
+
// containing a `.git` entry — a directory, a worktree pointer file, or a
|
|
310
|
+
// symlink). A repository boundary stops descent: nested repos inside repos
|
|
311
|
+
// are not reported. The root itself, when it is a repo, yields no results.
|
|
312
|
+
const findGitDirectories = async ({ rootPath, fsPromises, path: pathModule, maxDepth, maxDirs }) => {
|
|
313
|
+
const results = [];
|
|
314
|
+
let visited = 0;
|
|
315
|
+
|
|
316
|
+
const walk = async (dir, depth) => {
|
|
317
|
+
if (visited >= maxDirs) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
let dirents;
|
|
322
|
+
try {
|
|
323
|
+
dirents = await fsPromises.readdir(dir, { withFileTypes: true });
|
|
324
|
+
} catch (error) {
|
|
325
|
+
// Unreadable subtree — skip it unless it is the root itself, which the
|
|
326
|
+
// route maps to 403/404/500 through the shared error handling.
|
|
327
|
+
if (dir === rootPath) {
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
visited += 1;
|
|
333
|
+
|
|
334
|
+
let isRepoBoundary = false;
|
|
335
|
+
const subdirectories = [];
|
|
336
|
+
for (const dirent of dirents) {
|
|
337
|
+
if (dirent.name === '.git') {
|
|
338
|
+
isRepoBoundary = true;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (!dirent.isDirectory() || dirent.isSymbolicLink()) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (GIT_DIRS_SKIP_LIST.has(dirent.name)) {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (depth >= maxDepth) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
subdirectories.push(dirent.name);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (isRepoBoundary) {
|
|
354
|
+
if (dir !== rootPath) {
|
|
355
|
+
results.push(dir);
|
|
356
|
+
}
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
subdirectories.sort();
|
|
361
|
+
for (const name of subdirectories) {
|
|
362
|
+
if (visited >= maxDirs) {
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
await walk(pathModule.join(dir, name), depth + 1);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
await walk(rootPath, 0);
|
|
370
|
+
return results;
|
|
371
|
+
};
|
|
372
|
+
|
|
300
373
|
const deriveCloneDirectoryName = (remoteUrl) => {
|
|
301
374
|
const remote = typeof remoteUrl === 'string' ? remoteUrl.trim() : '';
|
|
302
375
|
if (!remote) return '';
|
|
@@ -1599,4 +1672,60 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1599
1672
|
return res.status(500).json({ error: (error && error.message) || 'Failed to list directory' });
|
|
1600
1673
|
}
|
|
1601
1674
|
});
|
|
1675
|
+
|
|
1676
|
+
app.get('/api/fs/git-dirs', async (req, res) => {
|
|
1677
|
+
const rawPath = typeof req.query.path === 'string' && req.query.path.trim().length > 0
|
|
1678
|
+
? req.query.path.trim()
|
|
1679
|
+
: '';
|
|
1680
|
+
if (!rawPath) {
|
|
1681
|
+
return res.status(400).json({ error: 'Path is required' });
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
try {
|
|
1685
|
+
const resolved = await resolveWorkspacePathFromContext({
|
|
1686
|
+
req,
|
|
1687
|
+
targetPath: rawPath,
|
|
1688
|
+
resolveProjectDirectory,
|
|
1689
|
+
path,
|
|
1690
|
+
os,
|
|
1691
|
+
normalizeDirectoryPath,
|
|
1692
|
+
openchamberUserConfigRoot,
|
|
1693
|
+
});
|
|
1694
|
+
if (!resolved.ok) {
|
|
1695
|
+
return res.status(400).json({ error: resolved.error });
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
const stats = await fsPromises.stat(resolved.resolved);
|
|
1699
|
+
if (!stats.isDirectory()) {
|
|
1700
|
+
return res.status(400).json({ error: 'Specified path is not a directory', reason: 'not-directory' });
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
const repositories = await findGitDirectories({
|
|
1704
|
+
rootPath: resolved.resolved,
|
|
1705
|
+
fsPromises,
|
|
1706
|
+
path,
|
|
1707
|
+
maxDepth: GIT_DIRS_MAX_DEPTH,
|
|
1708
|
+
maxDirs: GIT_DIRS_MAX_DIRS,
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1711
|
+
return res.json({
|
|
1712
|
+
path: resolved.resolved,
|
|
1713
|
+
repositories: repositories.map((repoPath) => ({
|
|
1714
|
+
path: repoPath,
|
|
1715
|
+
name: path.basename(repoPath),
|
|
1716
|
+
})),
|
|
1717
|
+
});
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
const err = error;
|
|
1720
|
+
const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
|
|
1721
|
+
if (code === 'ENOENT') {
|
|
1722
|
+
return res.status(404).json({ error: 'Directory not found', reason: 'not-found' });
|
|
1723
|
+
}
|
|
1724
|
+
if (isOsPermissionError(err)) {
|
|
1725
|
+
return sendOsPermissionDenied(res, 'Access to directory denied');
|
|
1726
|
+
}
|
|
1727
|
+
console.error('Failed to find git directories:', error);
|
|
1728
|
+
return res.status(500).json({ error: (error && error.message) || 'Failed to find git directories' });
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1602
1731
|
};
|
|
@@ -1136,6 +1136,225 @@ describe('fs list symlink path space (issue 2627)', () => {
|
|
|
1136
1136
|
}
|
|
1137
1137
|
});
|
|
1138
1138
|
|
|
1139
|
+
describe('fs git-dirs', () => {
|
|
1140
|
+
const createDirent = (name, type) => ({
|
|
1141
|
+
name,
|
|
1142
|
+
isDirectory: () => type === 'dir',
|
|
1143
|
+
isFile: () => type === 'file',
|
|
1144
|
+
isSymbolicLink: () => type === 'symlink',
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
// tree maps directory path -> [[name, type], ...]
|
|
1148
|
+
const registerGitDirs = (tree, { stat, readdir: readdirOverride } = {}) => {
|
|
1149
|
+
const { app, getRoute } = createRouteRegistry();
|
|
1150
|
+
const readdir = readdirOverride ?? vi.fn(async (dirPath) => (tree[dirPath] ?? []).map(([name, type]) => createDirent(name, type)));
|
|
1151
|
+
registerFsRoutes(app, {
|
|
1152
|
+
os: { homedir: () => '/home/user' },
|
|
1153
|
+
path: path.posix,
|
|
1154
|
+
fsPromises: {
|
|
1155
|
+
realpath: async (targetPath) => targetPath,
|
|
1156
|
+
stat: stat ?? vi.fn(async (targetPath) => ({ isDirectory: () => Boolean(tree[targetPath]) })),
|
|
1157
|
+
readdir,
|
|
1158
|
+
},
|
|
1159
|
+
spawn: vi.fn(),
|
|
1160
|
+
crypto: { randomUUID: () => 'job-0' },
|
|
1161
|
+
normalizeDirectoryPath: (p) => p,
|
|
1162
|
+
resolveProjectDirectory: async () => ({ directory: '/workspace' }),
|
|
1163
|
+
buildAugmentedPath: () => '/usr/bin',
|
|
1164
|
+
resolveGitBinaryForSpawn: () => 'git',
|
|
1165
|
+
openchamberUserConfigRoot: '/home/user/.config',
|
|
1166
|
+
});
|
|
1167
|
+
return { handler: getRoute('GET', '/api/fs/git-dirs'), readdir };
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
const callGitDirs = async (handler, query) => {
|
|
1171
|
+
const res = createMockResponse();
|
|
1172
|
+
await handler({ query: query ?? {} }, res);
|
|
1173
|
+
return res;
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
it('returns an empty list when the root itself is a repository', async () => {
|
|
1177
|
+
const { handler, readdir } = registerGitDirs({
|
|
1178
|
+
'/workspace': [['.git', 'dir'], ['proj-a', 'dir']],
|
|
1179
|
+
'/workspace/proj-a': [['.git', 'dir']],
|
|
1180
|
+
});
|
|
1181
|
+
|
|
1182
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1183
|
+
|
|
1184
|
+
expect(res.statusCode).toBe(200);
|
|
1185
|
+
expect(res.body).toEqual({ path: '/workspace', repositories: [] });
|
|
1186
|
+
expect(readdir).toHaveBeenCalledTimes(1);
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1189
|
+
it('finds nested repositories with a .git directory', async () => {
|
|
1190
|
+
const { handler } = registerGitDirs({
|
|
1191
|
+
'/workspace': [['proj-a', 'dir'], ['proj-b', 'dir']],
|
|
1192
|
+
'/workspace/proj-a': [['.git', 'dir'], ['src', 'dir']],
|
|
1193
|
+
'/workspace/proj-a/src': [['index.ts', 'file']],
|
|
1194
|
+
'/workspace/proj-b': [['.git', 'dir']],
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1198
|
+
|
|
1199
|
+
expect(res.statusCode).toBe(200);
|
|
1200
|
+
expect(res.body.repositories).toEqual([
|
|
1201
|
+
{ path: '/workspace/proj-a', name: 'proj-a' },
|
|
1202
|
+
{ path: '/workspace/proj-b', name: 'proj-b' },
|
|
1203
|
+
]);
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
it('treats a .git file (linked worktree) as a repository boundary', async () => {
|
|
1207
|
+
const { handler } = registerGitDirs({
|
|
1208
|
+
'/workspace': [['worktree', 'dir']],
|
|
1209
|
+
'/workspace/worktree': [['.git', 'file']],
|
|
1210
|
+
});
|
|
1211
|
+
|
|
1212
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1213
|
+
|
|
1214
|
+
expect(res.statusCode).toBe(200);
|
|
1215
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/worktree', name: 'worktree' }]);
|
|
1216
|
+
});
|
|
1217
|
+
|
|
1218
|
+
it('stops descending at repository boundaries', async () => {
|
|
1219
|
+
const { handler, readdir } = registerGitDirs({
|
|
1220
|
+
'/workspace': [['outer', 'dir']],
|
|
1221
|
+
'/workspace/outer': [['.git', 'dir'], ['inner', 'dir']],
|
|
1222
|
+
'/workspace/outer/inner': [['.git', 'dir']],
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1226
|
+
|
|
1227
|
+
expect(res.statusCode).toBe(200);
|
|
1228
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/outer', name: 'outer' }]);
|
|
1229
|
+
expect(readdir).not.toHaveBeenCalledWith('/workspace/outer/inner', { withFileTypes: true });
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
it('does not descend past the depth cap', async () => {
|
|
1233
|
+
const { handler } = registerGitDirs({
|
|
1234
|
+
'/workspace': [['a', 'dir']],
|
|
1235
|
+
'/workspace/a': [['b', 'dir']],
|
|
1236
|
+
'/workspace/a/b': [['c', 'dir']],
|
|
1237
|
+
'/workspace/a/b/c': [['.git', 'dir'], ['d', 'dir']],
|
|
1238
|
+
'/workspace/a/b/c/d': [['.git', 'dir']],
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1242
|
+
|
|
1243
|
+
expect(res.statusCode).toBe(200);
|
|
1244
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/a/b/c', name: 'c' }]);
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
it('skips junk directories', async () => {
|
|
1248
|
+
const { handler, readdir } = registerGitDirs({
|
|
1249
|
+
'/workspace': [['node_modules', 'dir'], ['dist', 'dir'], ['real', 'dir']],
|
|
1250
|
+
'/workspace/node_modules': [['dep', 'dir']],
|
|
1251
|
+
'/workspace/node_modules/dep': [['.git', 'dir']],
|
|
1252
|
+
'/workspace/dist': [['.git', 'dir']],
|
|
1253
|
+
'/workspace/real': [['.git', 'dir']],
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1257
|
+
|
|
1258
|
+
expect(res.statusCode).toBe(200);
|
|
1259
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/real', name: 'real' }]);
|
|
1260
|
+
expect(readdir).not.toHaveBeenCalledWith('/workspace/node_modules', { withFileTypes: true });
|
|
1261
|
+
});
|
|
1262
|
+
|
|
1263
|
+
it('never descends into symbolic links', async () => {
|
|
1264
|
+
const { handler } = registerGitDirs({
|
|
1265
|
+
'/workspace': [['link', 'symlink'], ['real', 'dir']],
|
|
1266
|
+
'/workspace/real': [['.git', 'dir']],
|
|
1267
|
+
});
|
|
1268
|
+
|
|
1269
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1270
|
+
|
|
1271
|
+
expect(res.statusCode).toBe(200);
|
|
1272
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/real', name: 'real' }]);
|
|
1273
|
+
});
|
|
1274
|
+
|
|
1275
|
+
it('returns repositories in deterministic order', async () => {
|
|
1276
|
+
const { handler } = registerGitDirs({
|
|
1277
|
+
'/workspace': [['zebra', 'dir'], ['alpha', 'dir']],
|
|
1278
|
+
'/workspace/zebra': [['.git', 'dir']],
|
|
1279
|
+
'/workspace/alpha': [['.git', 'dir']],
|
|
1280
|
+
});
|
|
1281
|
+
|
|
1282
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1283
|
+
|
|
1284
|
+
expect(res.body.repositories.map((repo) => repo.name)).toEqual(['alpha', 'zebra']);
|
|
1285
|
+
});
|
|
1286
|
+
|
|
1287
|
+
it('returns 400 when path is missing', async () => {
|
|
1288
|
+
const { handler } = registerGitDirs({});
|
|
1289
|
+
|
|
1290
|
+
const res = await callGitDirs(handler, {});
|
|
1291
|
+
|
|
1292
|
+
expect(res.statusCode).toBe(400);
|
|
1293
|
+
expect(res.body.error).toBe('Path is required');
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
it('returns 400 when the path is not a directory', async () => {
|
|
1297
|
+
const { handler } = registerGitDirs({
|
|
1298
|
+
'/workspace': [['file.txt', 'file']],
|
|
1299
|
+
}, {
|
|
1300
|
+
stat: vi.fn(async (targetPath) => ({ isDirectory: () => targetPath !== '/workspace/file.txt' })),
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
const res = await callGitDirs(handler, { path: '/workspace/file.txt' });
|
|
1304
|
+
|
|
1305
|
+
expect(res.statusCode).toBe(400);
|
|
1306
|
+
expect(res.body).toEqual({ error: 'Specified path is not a directory', reason: 'not-directory' });
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
it('returns 404 when the directory does not exist', async () => {
|
|
1310
|
+
const error = Object.assign(new Error('missing'), { code: 'ENOENT' });
|
|
1311
|
+
const { handler } = registerGitDirs({}, {
|
|
1312
|
+
stat: vi.fn(async () => { throw error; }),
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1315
|
+
const res = await callGitDirs(handler, { path: '/workspace/missing' });
|
|
1316
|
+
|
|
1317
|
+
expect(res.statusCode).toBe(404);
|
|
1318
|
+
expect(res.body).toEqual({ error: 'Directory not found', reason: 'not-found' });
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
for (const code of ['EACCES', 'EPERM']) {
|
|
1322
|
+
it(`maps root ${code} to the os-permission contract`, async () => {
|
|
1323
|
+
const error = Object.assign(new Error('denied'), { code });
|
|
1324
|
+
const { handler } = registerGitDirs({}, {
|
|
1325
|
+
stat: vi.fn(async () => ({ isDirectory: () => true })),
|
|
1326
|
+
readdir: vi.fn(async () => { throw error; }),
|
|
1327
|
+
});
|
|
1328
|
+
|
|
1329
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1330
|
+
|
|
1331
|
+
expect(res.statusCode).toBe(403);
|
|
1332
|
+
expect(res.body).toEqual({ error: 'Access to directory denied', reason: 'os-permission' });
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
it('skips unreadable subtrees without failing the scan', async () => {
|
|
1337
|
+
const tree = {
|
|
1338
|
+
'/workspace': [['blocked', 'dir'], ['open', 'dir']],
|
|
1339
|
+
'/workspace/open': [['.git', 'dir']],
|
|
1340
|
+
};
|
|
1341
|
+
const blockedError = Object.assign(new Error('denied'), { code: 'EACCES' });
|
|
1342
|
+
const { handler } = registerGitDirs(tree, {
|
|
1343
|
+
readdir: vi.fn(async (dirPath) => {
|
|
1344
|
+
if (dirPath === '/workspace/blocked') {
|
|
1345
|
+
throw blockedError;
|
|
1346
|
+
}
|
|
1347
|
+
return (tree[dirPath] ?? []).map(([name, type]) => createDirent(name, type));
|
|
1348
|
+
}),
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
const res = await callGitDirs(handler, { path: '/workspace' });
|
|
1352
|
+
|
|
1353
|
+
expect(res.statusCode).toBe(200);
|
|
1354
|
+
expect(res.body.repositories).toEqual([{ path: '/workspace/open', name: 'open' }]);
|
|
1355
|
+
});
|
|
1356
|
+
});
|
|
1357
|
+
|
|
1139
1358
|
describe('fs stat directory scope (issue 3019)', () => {
|
|
1140
1359
|
// Wires the real project-directory runtime so the stat route resolves the
|
|
1141
1360
|
// workspace exactly as the server does: explicit x-opencode-directory header
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Linear Module Documentation
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
This module owns Linear OAuth, issue lookup, Linear-team-to-project mapping, issue status updates, and session status comments on Linear issues. Credentials live on the OpenChamber server, so web, desktop, and a phone paired to that host share them. You can store more than one Linear workspace; exactly one is current. Issue list, mapping, and new OAuth default to the current workspace. Session status comments use the workspace that started the session. The right-hand context panel lists issues for the current workspace, can switch workspace, filters the list, shows a read-only card, changes status or closes the issue, and starts a session or worktree. Start session stays visible in a footer while the issue card scrolls. The chat picker lists issues and attaches them to a message. New Worktree can also start from a Linear issue in the currently active project. A session started from a Linear issue can post started/completed/failure comments, each with an OpenChamber session link. Those comments are opt-in and only appear when this server has a publicly reachable address.
|
|
6
|
+
|
|
7
|
+
VS Code omits Linear (`RuntimeAPIs.linear` is optional). Hide Linear UI when the API is missing.
|
|
8
|
+
|
|
9
|
+
## Entrypoints and structure
|
|
10
|
+
|
|
11
|
+
- `packages/web/server/lib/linear/index.js`: public server entrypoint. `routes.js` loads it lazily with `await import('./index.js')`.
|
|
12
|
+
- `packages/web/server/lib/linear/routes.js`: Express registration for the public callback, `/api/linear/auth/*`, `/api/linear/issues/*`, `/api/linear/mapping`, and `/api/linear/session-status`.
|
|
13
|
+
- `packages/web/server/lib/linear/auth.js`: auth file, client id, scopes, redirect URI.
|
|
14
|
+
- `packages/web/server/lib/linear/oauth.js`: authorization-code + PKCE S256, public callback broker handoff, refresh, revoke.
|
|
15
|
+
- `packages/web/server/lib/linear/client.js`: GraphQL helper, viewer/organization lookup, and access-token refresh. GraphQL errors prefer `extensions.userPresentableMessage` / validation constraints over the generic `Argument Validation Error` label. User-facing Linear errors set `LinearApiError.userError`. Requests send `public-file-urls-expire-in: 3600` so file URLs in issue descriptions and comments are temporarily readable in the panel.
|
|
16
|
+
- `packages/web/server/lib/linear/issues.js`: list/search/get issues, team workflow states, `issueUpdate`, and `commentCreate`. Parses identifiers and Linear URLs. `issueUpdate` resolves identifiers to UUIDs first because Linear's mutation does not accept `ENG-12`. List/get include `state.id`, `priority` (0–4), and labels (`id`, `name`, sanitized hex `color`) so the panel can show them and update status.
|
|
17
|
+
- `packages/web/server/lib/linear/teams.js`: list Linear teams for mapping UI.
|
|
18
|
+
- `packages/web/server/lib/linear/mapping.js`: persist default and per-team OpenChamber project paths. Separate from the auth file so disconnect does not wipe maps.
|
|
19
|
+
- `packages/web/server/lib/linear/status.js`: persist per-session started/completed/failure flags and post the matching Linear comment with an open-session URL. Posts nothing unless the user opted in and the session origin is public; `isPublicSessionOrigin` rejects loopback, private LAN, carrier-grade NAT, link-local and single-label hosts. The dedupe file keeps the newest 500 sessions.
|
|
20
|
+
- `packages/web/server/lib/linear/status-runtime.js`: on the OpenCode event hub, first `session.status` idle after started posts completed once; `session.error` (except abort) posts failure once.
|
|
21
|
+
- `packages/web/src/api/linear.ts`: web client wrapper. Electron and hosted/Capacitor mobile reuse it. VS Code omits `linear`.
|
|
22
|
+
|
|
23
|
+
## Public routes
|
|
24
|
+
|
|
25
|
+
- `GET /linear/oauth/callback`: public fallback for an explicitly configured direct redirect URI. The built-in flow uses the stable callback broker instead, because desktop and self-hosted instances may have private or dynamic addresses.
|
|
26
|
+
- `GET /api/linear/auth/status`: connected flag, current user/organization/scope, and `workspaces` (id, name, current, user, authorizedAt). Never returns tokens. A 401 on the current workspace drops that workspace only; if another remains, status returns that one instead of disconnected. Identity refresh does not bump `authorizedAt`.
|
|
27
|
+
- `POST /api/linear/auth/start`: returns `{ authorizationUrl, expiresIn, scope }`. Body may include `origin: "desktop"` so the callback page can raise the desktop window. The authorize URL uses `prompt=consent` so Add workspace can pick a different Linear org. Completing OAuth stores or replaces that org and makes it current.
|
|
28
|
+
- `POST /api/linear/auth/activate`: body `{ organizationId }`. Makes that stored workspace current. 400 if the id is missing, 404 if it is not stored.
|
|
29
|
+
- `DELETE /api/linear/auth`: revokes the current workspace refresh token when present, then drops that workspace only. Other stored workspaces stay. Mapping is kept.
|
|
30
|
+
- `GET /api/linear/issues/list?query=&cursor=&status=&assignee=&teamId=&priority=`: issues from the current workspace. Omitted `status` is incomplete states (same as the chat picker). The panel sends `all`, `backlog`, `todo` (Linear `unstarted`), `started` (In Progress, excluding the In Review name), `inReview` (state name In Review), `completed` (Done), `canceled` (excluding the Duplicate name), or `duplicate` (state type or name Duplicate). `assignee` is `any` (default) or `me`. `teamId` limits the list to that Linear team. `priority` is `all` (default), `none`, `urgent`, `high`, `medium`, or `low`. An identifier or Linear URL returns that issue even if it is completed and ignores the other filters. Each issue includes `state.id` when Linear sends it, plus `priority` (0 none through 4 low) and `labels`. Never returns tokens.
|
|
31
|
+
- `GET /api/linear/issues/get?id=`: one issue by UUID or identifier, including description, comments, team, `state.id`, priority, and labels.
|
|
32
|
+
- `GET /api/linear/issues/states?teamId=`: workflow states for that Linear team (`id`, `name`, `type`, `position`), ordered like Linear's workflow: type (backlog, unstarted, started, completed, canceled) then position. Missing `teamId` is 400. Linear not-found or validation errors are 400 with Linear's presentable message. Disconnected is `{ connected: false }` with HTTP 200.
|
|
33
|
+
- `POST /api/linear/issues/update`: body `{ id, stateId }`. `id` may be a UUID, identifier, or Linear URL; identifiers are resolved before `issueUpdate` because Linear's mutation requires a UUID. Returns the updated issue. Closing an issue is this same call with the team's first `type: completed` state. Missing `id` or `stateId` is 400. Linear validation (for example a non-UUID `stateId`) is 400 with Linear's presentable message. A GraphQL 401 clears that workspace only. Disconnected is `{ connected: false }` with HTTP 200.
|
|
34
|
+
- `GET /api/linear/mapping`: stored default project plus live Linear teams with their mapped paths. Missing file is empty mapping. Malformed file is 500, not empty success. Disconnected is `{ connected: false }` with HTTP 200.
|
|
35
|
+
- `PUT /api/linear/mapping`: replace default project and per-team paths. Body `{ defaultProjectPath, teamProjectPaths }`. Failed write does not touch tokens. Disconnected is `{ connected: false }` and does not save.
|
|
36
|
+
- `GET /api/linear/preferences`: `{ sessionComments }`. `PUT /api/linear/preferences` with body `{ sessionComments: boolean }` replaces it and returns the stored value. A non-boolean body is 400. The preference is server-side because the event hub posts completed/failure without going through the interface.
|
|
37
|
+
- `POST /api/linear/session-status`: post a started/completed/failure comment on the linked Linear issue. Body `{ kind, sessionId, issueIdentifier?, sessionOrigin? }`. `started` requires `issueIdentifier`. `completed` and `failure` reuse the stored issue and open URL from `started`. Each kind posts at most once per session. Answers in this order: disconnected is `{ connected: false }` with HTTP 200; comments turned off is `skipped: 'disabled'`; a `sessionOrigin` nobody else can reach is `skipped: 'origin-not-public'`. `sessionOrigin` must be `http` or `https` with no path, and must resolve to a public host — loopback, private LAN and desktop deep links post no comment at all rather than a link only its author can open. Comment bodies are one markdown link: `[OpenChamber session started](url)` so Linear keeps the `?session=` query. The comment carries no issue or session title: it already sits on the issue, and titles routinely contain brackets that would break the link. Invalid body is 400.
|
|
38
|
+
|
|
39
|
+
`POST /api/linear/auth/start`, `PUT /api/linear/mapping`, `POST /api/linear/issues/update`, and `POST /api/linear/session-status` parse JSON on the route (`16kb`). They are not on the `/api` 50mb allowlist.
|
|
40
|
+
|
|
41
|
+
Disconnected list/get/states/update/mapping/session-status return `{ connected: false }` with HTTP 200 so the picker and panel can show an empty state. Missing `id` on get is 400. Missing `teamId` on states is 400.
|
|
42
|
+
|
|
43
|
+
## Auth storage and config
|
|
44
|
+
|
|
45
|
+
- Auth storage: `~/.config/openchamber/linear-auth.json` (or `$OPENCHAMBER_DATA_DIR/linear-auth.json`). Shape is `{ workspaces: [ { accessToken, refreshToken, user, organization, workspaceId, current, authorizedAt, ... } ] }`. `workspaceId` is the Linear organization id, or `user:<id>` when there is no org, or `legacy` for a migrated token with neither. A legacy single-object file is rewritten to this list on read. Reconnecting the same org replaces that slot.
|
|
46
|
+
- Mapping storage: `~/.config/openchamber/linear-mapping.json` (same data dir). Shape is `{ workspaces: { [workspaceId]: { defaultProjectPath, teamProjectPaths } } }`. Reads and writes use the current workspace slice. A legacy flat file is wrapped under the current workspace id on read. Disconnect does not wipe maps. Writes are atomic and file mode is `0o600`.
|
|
47
|
+
- Session status storage: `~/.config/openchamber/linear-session-status.json` (same data dir). Writes are atomic and file mode is `0o600`. Dedupes started/completed/failure per OpenChamber session id.
|
|
48
|
+
- Writes are atomic and file mode is `0o600`.
|
|
49
|
+
- Client ID: `OPENCHAMBER_LINEAR_CLIENT_ID` -> `settings.json` `linearClientId` -> baked-in public default.
|
|
50
|
+
- Client secret: `OPENCHAMBER_LINEAR_CLIENT_SECRET` -> `settings.json` `linearClientSecret`. Optional with PKCE. Do not commit a secret.
|
|
51
|
+
- Scopes: `OPENCHAMBER_LINEAR_SCOPES` -> `settings.json` `linearScopes` -> `read,write,comments:create`.
|
|
52
|
+
- Session comments: `settings.json` `linearSessionComments`, boolean, absent means off. Written only through `PUT /api/linear/preferences`.
|
|
53
|
+
- Broker URL: `OPENCHAMBER_LINEAR_BROKER_URL` -> `settings.json` `linearBrokerUrl` -> `https://api.openchamber.dev/v1/oauth/linear`.
|
|
54
|
+
- Redirect URI: `OPENCHAMBER_LINEAR_REDIRECT_URI` -> `settings.json` `linearRedirectUri` -> `<broker-url>/callback`. Setting an explicit redirect URI bypasses the broker for custom/self-hosted OAuth applications.
|
|
55
|
+
|
|
56
|
+
Linear requires an exact callback match. The built-in application registers `https://api.openchamber.dev/v1/oauth/linear/callback`; the broker holds only the short-lived authorization code. The local OpenChamber server keeps the claim secret and PKCE verifier, exchanges the code for tokens locally, then acknowledges the handoff. Custom brokers must expose `/start`, `/callback`, `/poll`, and `/complete` with the same contract.
|
|
57
|
+
|
|
58
|
+
## OAuth contract
|
|
59
|
+
|
|
60
|
+
- Authorization code + PKCE S256. Linear has no device flow.
|
|
61
|
+
- The broker stores hashes of OAuth state and a separate claim secret for ten minutes. It never receives the PKCE verifier or Linear tokens. The local status polling path claims a completed broker result and persists tokens on the OpenChamber server.
|
|
62
|
+
- Access tokens expire in 24 hours. Refresh tokens rotate; persist the new refresh token from every successful refresh. Concurrent refreshes share one in-flight promise per workspace.
|
|
63
|
+
- `invalid_grant` / 401 on refresh clears that workspace only so a dead token cannot loop. If it was the last workspace, status becomes disconnected.
|
|
64
|
+
- A GraphQL 401 after a valid-looking token also clears that workspace. A network failure while a token is stored does not: status stays connected with the last known user.
|
|
65
|
+
|
|
66
|
+
## Project mapping
|
|
67
|
+
|
|
68
|
+
OpenChamber has projects (directories), not accounts or organizations. Mapping is how create-session (picker and the right-hand panel) picks a directory:
|
|
69
|
+
|
|
70
|
+
1. If the issue's Linear team has a project path, use that.
|
|
71
|
+
2. Otherwise use the default project path.
|
|
72
|
+
3. If neither is set, the UI tells the user to map the team in Settings → Integrations. It does not fall back to the currently active project.
|
|
73
|
+
|
|
74
|
+
A worktree started from the panel or picker is created in that mapped project. New Worktree from Git is different: it stays in the currently active project.
|
|
75
|
+
|
|
76
|
+
## Shared UI
|
|
77
|
+
|
|
78
|
+
- `RuntimeAPIs.linear` is optional. Hide Linear settings, the chat picker, and the panel when it is missing (VS Code).
|
|
79
|
+
- Store: `packages/ui/src/stores/useLinearAuthStore.ts`. App start refreshes it from `App.tsx` and `MobileApp.tsx`, not `VSCodeApp`.
|
|
80
|
+
- Settings: first-party section on the Integrations page. Connect opens the authorization URL and polls status until the workspace list or current `authorizedAt` changes, so Add workspace is not treated as done just because a workspace was already connected. When connected, map a default project and optional per-team projects for the current workspace. Other stored workspaces appear in a list with Switch to. Disconnect removes the current workspace only. The panel can also switch the current workspace when more than one is stored.
|
|
81
|
+
- Context panel: desktop/web right-hand rail surface `linear` (`packages/ui/src/components/views/LinearIssuesView.tsx`). Singleton like git/pr. The rail icon is hidden until a Linear workspace is connected; disconnecting while the panel is open closes it. List/search defaults to all issues; the status filter is All, Backlog, To Do, In Progress, In Review, Done, Canceled, and Duplicate, matching the card status order. Identifier/URL still finds completed. Status, assignee, team, and priority filters persist in `useUIStore` so they survive rail switches. Non-default list filters and search tint the filter icon `text-primary`, same as the context rail; one control clears them, not the workspace switch. Changing those filters keeps the previous list until the next page arrives and does not disable the filter row. On a narrow panel search and the filters other than status drop to icons; status keeps its label. The card shows priority and labels. Comments render as an avatar timeline matching the pull request panel, so both context surfaces read alike; comment authors carry `avatarUrl`. The card is read-only except status (`issueUpdate`) and Close (first completed workflow state). Start session stays in a footer while the description and comments scroll. Start session / worktree share `startLinearIssueSession` with the picker. No create-issue, no writing comments, no polling. VS Code and the mobile workspace drawer omit this rail.
|
|
82
|
+
- Chat: composer attach menu "Link Linear Issue" attaches body and comments as `linear-issue` context on the next send. Exclusive with a linked GitHub issue or PR. The attached issue is stored on session metadata (`kind: 'linear'`) so work status can show it. Clicking that work-status row opens the Linear rail when Linear is connected on desktop/web; otherwise the Linear URL. Managed Chats do not offer start-from-issue; those sessions have no project directory.
|
|
83
|
+
- Worktree: New Worktree can start from a Linear issue. It uses the currently active project and does not consult team-to-project mapping. GitHub issue/PR and Linear issue are exclusive on that form.
|
|
84
|
+
- Status comments: off until the user turns them on in Settings -> Integrations -> Linear (`LinearSessionComments.tsx`). When on, create-session and worktree-from-Linear post `started` after the session exists. The event hub posts `completed` on the first idle after that, and `failure` on `session.error` except `MessageAbortedError`. Failed comments must not fail session create. Comment bodies are English (they live on Linear) and are one markdown link named `OpenChamber session started` (or completed/failed). Web uses `/?session=<id>` on the current origin; desktop reports the loopback origin its own server listens on, not `openchamber-ui://`. A Linear comment is read by the whole team, so the server posts nothing when that origin is not publicly reachable rather than publishing a link only its author could open. Opening `/?session=` selects that session after the global session list can resolve its directory.
|
|
85
|
+
- Magic prompts: `linear.issue.review.visible` / `.instructions`. Do not reuse the GitHub issue-review templates for Linear.
|
|
86
|
+
|
|
87
|
+
## Notes for contributors
|
|
88
|
+
|
|
89
|
+
The implementation and deployment hand-off for the stable callback broker is
|
|
90
|
+
in [`OAUTH-BROKER-HANDOFF.md`](./OAUTH-BROKER-HANDOFF.md). It records the exact
|
|
91
|
+
Linear redirect URI that must be registered and why the original loopback
|
|
92
|
+
callback could not support packaged desktop or arbitrary self-hosted servers.
|
|
93
|
+
|
|
94
|
+
- Do not log tokens, codes, verifiers, or the client secret.
|
|
95
|
+
- Do not add Linear under Git or as a third-party plugin row.
|
|
96
|
+
- Actor is `user`. Do not enable Linear client-credentials tokens for this flow.
|
|
97
|
+
- One OAuth grant is still one Linear organization. The server stores many grants and keeps one current. Webhooks and inbound Linear issue actions are out of scope until a later change.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Linear OAuth broker hand-off
|
|
2
|
+
|
|
3
|
+
## Required Linear application change
|
|
4
|
+
|
|
5
|
+
Register this exact redirect URI in the Linear OAuth application used by the
|
|
6
|
+
baked-in client ID:
|
|
7
|
+
|
|
8
|
+
`https://api.openchamber.dev/v1/oauth/linear/callback`
|
|
9
|
+
|
|
10
|
+
Linear compares the full redirect URI, including scheme, host, path, and port.
|
|
11
|
+
Deploy the API broker and apply its D1 migration before testing this branch.
|
|
12
|
+
|
|
13
|
+
## Why the original callback failed
|
|
14
|
+
|
|
15
|
+
The first implementation redirected Linear back to the OpenChamber server:
|
|
16
|
+
|
|
17
|
+
`http://127.0.0.1:<listen-port>/linear/oauth/callback`
|
|
18
|
+
|
|
19
|
+
That address is not stable across OpenChamber runtimes:
|
|
20
|
+
|
|
21
|
+
- packaged desktop prefers its stored local port and can select another free
|
|
22
|
+
port when needed;
|
|
23
|
+
- local development and the CLI use different ports;
|
|
24
|
+
- self-hosted servers may sit behind a reverse proxy or have no public inbound
|
|
25
|
+
address at all.
|
|
26
|
+
|
|
27
|
+
Linear requires an exact pre-registered callback. Registering every possible
|
|
28
|
+
desktop or self-hosted address is impossible, and forcing desktop onto one port
|
|
29
|
+
would make startup fail whenever another process owns that port.
|
|
30
|
+
|
|
31
|
+
## New flow
|
|
32
|
+
|
|
33
|
+
The built-in Linear client now uses the stable callback broker in
|
|
34
|
+
`openchamber-website/apps/api`:
|
|
35
|
+
|
|
36
|
+
1. The OpenChamber server generates OAuth state, a PKCE verifier, and a separate
|
|
37
|
+
claim secret.
|
|
38
|
+
2. The broker stores only hashes of state and the claim secret for ten minutes.
|
|
39
|
+
3. Linear sends its authorization code to the stable public callback.
|
|
40
|
+
4. The OpenChamber server polls the broker with state and the claim secret.
|
|
41
|
+
5. The OpenChamber server exchanges the code using the PKCE verifier and stores
|
|
42
|
+
the Linear tokens locally.
|
|
43
|
+
6. After persistence succeeds, OpenChamber acknowledges the hand-off and the
|
|
44
|
+
broker marks it consumed.
|
|
45
|
+
|
|
46
|
+
The broker never receives the PKCE verifier, access token, or refresh token.
|
|
47
|
+
Private Relay is not involved; the local server only needs outbound HTTPS.
|
|
48
|
+
|
|
49
|
+
## Compatibility and configuration
|
|
50
|
+
|
|
51
|
+
- `OPENCHAMBER_LINEAR_BROKER_URL` or `settings.json` `linearBrokerUrl` selects a
|
|
52
|
+
self-hosted broker. The default is
|
|
53
|
+
`https://api.openchamber.dev/v1/oauth/linear`.
|
|
54
|
+
- `OPENCHAMBER_LINEAR_REDIRECT_URI` or `settings.json` `linearRedirectUri`
|
|
55
|
+
bypasses the broker and preserves the direct callback flow for a custom
|
|
56
|
+
Linear OAuth application.
|
|
57
|
+
|
|
58
|
+
## Owning files
|
|
59
|
+
|
|
60
|
+
OpenChamber:
|
|
61
|
+
|
|
62
|
+
- `auth.js`: broker and redirect configuration.
|
|
63
|
+
- `oauth.js`: PKCE, broker registration/poll/acknowledgement, token exchange.
|
|
64
|
+
- `routes.js`: starts authorization and completes broker results during status
|
|
65
|
+
polling.
|
|
66
|
+
|
|
67
|
+
Hosted API, in the `openchamber-website` repository:
|
|
68
|
+
|
|
69
|
+
- `apps/api/src/routes/linear-oauth.ts`
|
|
70
|
+
- `apps/api/migrations/0010_linear_oauth_transactions.sql`
|
|
71
|
+
- `apps/api/LINEAR-OAUTH.md`
|
|
72
|
+
|
|
73
|
+
## Validation
|
|
74
|
+
|
|
75
|
+
OpenChamber focused tests:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
bunx vitest run \
|
|
79
|
+
packages/web/server/lib/linear/oauth.test.js \
|
|
80
|
+
packages/web/server/lib/linear/auth.test.js \
|
|
81
|
+
packages/web/server/lib/linear/routes.test.js
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Hosted API checks:
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
cd apps/api
|
|
88
|
+
bun test src/routes/linear-oauth.test.ts
|
|
89
|
+
bun run check
|
|
90
|
+
bun run build
|
|
91
|
+
```
|