@openchamber/web 1.21.0 → 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/bin/cli.test.js +35 -0
- package/bin/lib/DOCUMENTATION.md +12 -0
- package/bin/lib/cli-settings-accessors.js +111 -0
- package/bin/lib/cli-settings-accessors.test.js +189 -0
- package/bin/lib/cli-startup.js +29 -9
- package/bin/lib/commands-connect-url.js +12 -14
- package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
- package/dist/assets/CommitSection-CC5mFzO2.js +1 -0
- 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-osju7J70.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-Dan3mADn.js → PatchDiff-BGPl1s-U.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-Cvz9Z-io.js} +2 -2
- package/dist/assets/PlanView-BFMsnHk3.js +5 -0
- package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
- package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-C1Qa09YO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-DzQlzMF4.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
- package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
- package/dist/assets/de-C3luvSd_.js +9 -0
- package/dist/assets/es-CmU4HLv9.js +15 -0
- package/dist/assets/fr-Bgyni40l.js +13 -0
- package/dist/assets/index-C57jT0Sa.css +1 -0
- package/dist/assets/{index-Brm3X9rs.js → index-CWYs7sMK.js} +1 -1
- package/dist/assets/index-b0zDkWyg.js +7 -0
- package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-BO_q5ezD.js} +1 -1
- package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-D8qPqUAf.js} +1 -1
- package/dist/assets/ja-C1ImKinT.js +15 -0
- package/dist/assets/ko-CP7OdxYH.js +15 -0
- package/dist/assets/main-D4rd8Hy5.js +928 -0
- package/dist/assets/{main-vUCh0VB0.js → main-D7fwjW2z.js} +2 -2
- package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
- package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
- package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-D5rraz-g.js} +2 -2
- package/dist/assets/{mobile-CkX6H-IT.js → mobile-Cg_DE3KL.js} +2 -2
- package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-Bpql0QGw.js} +3 -3
- package/dist/assets/pl-DQYSiGYX.js +15 -0
- package/dist/assets/pt-BR-DytpsW4M.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.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-BgTPSITe.js → shikiHighlight-CFAVs_lu.js} +1 -1
- package/dist/assets/tr-aizaUvft.js +6 -0
- package/dist/assets/uk-DwnRxJZd.js +15 -0
- package/dist/assets/useAppFontEffects-DWXGRUPZ.js +7310 -0
- package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-Cc0OCXr0.js} +2 -2
- package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
- package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
- package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
- package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
- package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
- package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
- package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
- package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
- package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
- package/dist/assets/{web-components-DLnGY4fs.js → web-components-CD-GFayc.js} +4 -4
- package/dist/assets/zh-CN-UDNMxm7r.js +15 -0
- package/dist/assets/zh-TW-BsswdYL-.js +15 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/dist/site.webmanifest +1 -1
- package/dist/sw.js +1 -1
- package/package.json +2 -2
- package/public/site.webmanifest +1 -1
- package/server/index.js +6 -2
- package/server/lib/cloudflare-tunnel.js +1 -1
- 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 +5 -0
- package/server/lib/fs/routes.js +150 -0
- package/server/lib/fs/routes.test.js +308 -3
- package/server/lib/git/DOCUMENTATION.md +4 -3
- package/server/lib/git/service.js +128 -6
- package/server/lib/git/service.test.js +191 -1
- 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/markdown-image-grants/DOCUMENTATION.md +4 -0
- package/server/lib/markdown-image-grants/routes.js +3 -1
- package/server/lib/markdown-image-grants/routes.test.js +14 -0
- package/server/lib/openchamber-sessions/routes.js +4 -1
- package/server/lib/openchamber-sessions/routes.test.js +23 -0
- package/server/lib/opencode/env-runtime.js +17 -1
- package/server/lib/opencode/env-runtime.test.js +56 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/lifecycle.js +48 -9
- package/server/lib/opencode/lifecycle.test.js +125 -1
- package/server/lib/opencode/managed-process-registry.d.ts +13 -0
- package/server/lib/opencode/managed-process-registry.js +213 -163
- package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
- package/server/lib/opencode/project-directory-runtime.js +16 -11
- package/server/lib/opencode/project-directory-runtime.test.js +32 -12
- package/server/lib/opencode/pwa-manifest-routes.js +1 -1
- package/server/lib/opencode/routes-upgrade.test.js +96 -12
- package/server/lib/opencode/routes.js +53 -5
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +10 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/opencode/theme-runtime.js +1 -1
- package/server/lib/opencode/theme-runtime.test.js +129 -0
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/quota/DOCUMENTATION.md +19 -0
- package/server/lib/quota/providers/copilot.js +26 -10
- package/server/lib/quota/providers/copilot.test.js +78 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/small-model/DOCUMENTATION.md +11 -5
- package/server/lib/small-model/call.js +64 -20
- package/server/lib/small-model/call.test.js +184 -2
- 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/server/lib/tunnels/install-help.js +2 -2
- package/server/lib/tunnels/install-help.test.js +9 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
- package/dist/assets/DiffView-D5cvbEPb.js +0 -4
- package/dist/assets/FilesView-DPU8aNPL.js +0 -17
- package/dist/assets/GitView-Ct6xWrVH.js +0 -6
- package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
- package/dist/assets/OnboardingScreen-w2VG4fWY.js +0 -1
- package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
- package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
- package/dist/assets/WalkthroughView-D9Q4lr5x.js +0 -4
- package/dist/assets/de-B_LdJwEM.js +0 -9
- package/dist/assets/es-CubfsAYV.js +0 -15
- package/dist/assets/fr-5qJM0nFS.js +0 -13
- package/dist/assets/index-BW82eK5v.css +0 -1
- package/dist/assets/index-rlLjZUM5.js +0 -7
- package/dist/assets/ja-DJYIBUlH.js +0 -15
- package/dist/assets/ko-DcUBkB7y.js +0 -15
- package/dist/assets/main-DLBxKIoX.js +0 -926
- package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
- package/dist/assets/pl-rB6BLcio.js +0 -15
- package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
- package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
- package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
- package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +0 -1
- package/dist/assets/uk-INZlFD9A.js +0 -15
- package/dist/assets/useAppFontEffects-Cll4gnsh.js +0 -7268
- package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
- package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isPlainObject, readTrimmedString } from './parse.js';
|
|
2
|
+
import { postLinearSessionStatus } from './status.js';
|
|
3
|
+
|
|
4
|
+
function readProperties(payload) {
|
|
5
|
+
if (!isPlainObject(payload)) return {};
|
|
6
|
+
return isPlainObject(payload.properties) ? payload.properties : {};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function readNested(properties, key) {
|
|
10
|
+
return isPlainObject(properties[key]) ? properties[key] : {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function extractSessionId(payload) {
|
|
14
|
+
const properties = readProperties(payload);
|
|
15
|
+
const info = readNested(properties, 'info');
|
|
16
|
+
return readTrimmedString(info.sessionID)
|
|
17
|
+
|| readTrimmedString(info.sessionId)
|
|
18
|
+
|| readTrimmedString(properties.sessionID)
|
|
19
|
+
|| readTrimmedString(properties.sessionId)
|
|
20
|
+
|| readTrimmedString(properties.session);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function extractStatusType(payload) {
|
|
24
|
+
if (!isPlainObject(payload) || payload.type !== 'session.status') return '';
|
|
25
|
+
const properties = readProperties(payload);
|
|
26
|
+
const status = readNested(properties, 'status');
|
|
27
|
+
const info = readNested(properties, 'info');
|
|
28
|
+
return readTrimmedString(status.type) || readTrimmedString(info.type);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function extractErrorName(payload) {
|
|
32
|
+
if (!isPlainObject(payload) || payload.type !== 'session.error') return '';
|
|
33
|
+
const properties = readProperties(payload);
|
|
34
|
+
return readTrimmedString(readNested(properties, 'error').name);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createLinearSessionStatusRuntime() {
|
|
38
|
+
let stopped = false;
|
|
39
|
+
|
|
40
|
+
const processPayload = (payload) => {
|
|
41
|
+
if (stopped) return;
|
|
42
|
+
const sessionId = extractSessionId(payload);
|
|
43
|
+
if (!sessionId) return;
|
|
44
|
+
|
|
45
|
+
if (isPlainObject(payload) && payload.type === 'session.error') {
|
|
46
|
+
if (extractErrorName(payload) === 'MessageAbortedError') return;
|
|
47
|
+
void postLinearSessionStatus({ kind: 'failure', sessionId }).catch((error) => {
|
|
48
|
+
console.warn('[linear] failed to post session failure comment:', error?.message || error);
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (extractStatusType(payload) !== 'idle') return;
|
|
54
|
+
void postLinearSessionStatus({ kind: 'completed', sessionId }).catch((error) => {
|
|
55
|
+
console.warn('[linear] failed to post session completed comment:', error?.message || error);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const stop = () => {
|
|
60
|
+
stopped = true;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return { processPayload, stop };
|
|
64
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { setLinearAuth, clearLinearAuth, setLinearSessionCommentsEnabled } from './auth.js';
|
|
6
|
+
import { createLinearSessionStatusRuntime } from './status-runtime.js';
|
|
7
|
+
|
|
8
|
+
const makeTempDir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-linear-status-runtime-'));
|
|
9
|
+
|
|
10
|
+
const jsonResponse = (payload, status = 200) => new Response(JSON.stringify(payload), {
|
|
11
|
+
status,
|
|
12
|
+
headers: { 'Content-Type': 'application/json' },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const issueNode = {
|
|
16
|
+
id: 'issue-uuid-1',
|
|
17
|
+
identifier: 'ENG-12',
|
|
18
|
+
title: 'Broken login',
|
|
19
|
+
url: 'https://linear.app/openchamber/issue/ENG-12',
|
|
20
|
+
state: { name: 'In Progress', type: 'started' },
|
|
21
|
+
assignee: null,
|
|
22
|
+
team: { id: 'team-eng', key: 'ENG', name: 'Engineering' },
|
|
23
|
+
description: null,
|
|
24
|
+
comments: { nodes: [] },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function stubLinearGraphql({ commentId = 'comment-1' } = {}) {
|
|
28
|
+
return vi.fn(async (_url, options) => {
|
|
29
|
+
const body = JSON.parse(options.body);
|
|
30
|
+
if (body.query.includes('query GetLinearIssue')) {
|
|
31
|
+
return jsonResponse({ data: { issue: issueNode } });
|
|
32
|
+
}
|
|
33
|
+
if (body.query.includes('mutation CommentCreate')) {
|
|
34
|
+
return jsonResponse({
|
|
35
|
+
data: {
|
|
36
|
+
commentCreate: {
|
|
37
|
+
success: true,
|
|
38
|
+
comment: { id: commentId },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`unexpected query: ${body.query}`);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('Linear session status runtime', () => {
|
|
48
|
+
let dataDir;
|
|
49
|
+
let previousDataDir;
|
|
50
|
+
let previousPort;
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
|
|
54
|
+
previousPort = process.env.OPENCHAMBER_PORT;
|
|
55
|
+
dataDir = makeTempDir();
|
|
56
|
+
process.env.OPENCHAMBER_DATA_DIR = dataDir;
|
|
57
|
+
process.env.OPENCHAMBER_PORT = '3001';
|
|
58
|
+
setLinearAuth({
|
|
59
|
+
accessToken: 'access-1',
|
|
60
|
+
refreshToken: 'refresh-1',
|
|
61
|
+
tokenType: 'Bearer',
|
|
62
|
+
expiresAt: Date.now() + 86_400_000,
|
|
63
|
+
scope: 'read,write,comments:create',
|
|
64
|
+
});
|
|
65
|
+
setLinearSessionCommentsEnabled(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
vi.unstubAllGlobals();
|
|
70
|
+
clearLinearAuth();
|
|
71
|
+
if (previousDataDir === undefined) {
|
|
72
|
+
delete process.env.OPENCHAMBER_DATA_DIR;
|
|
73
|
+
} else {
|
|
74
|
+
process.env.OPENCHAMBER_DATA_DIR = previousDataDir;
|
|
75
|
+
}
|
|
76
|
+
if (previousPort === undefined) {
|
|
77
|
+
delete process.env.OPENCHAMBER_PORT;
|
|
78
|
+
} else {
|
|
79
|
+
process.env.OPENCHAMBER_PORT = previousPort;
|
|
80
|
+
}
|
|
81
|
+
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('posts completed on the first idle after started, then ignores later idles', async () => {
|
|
85
|
+
const { postLinearSessionStatus } = await import('./status.js');
|
|
86
|
+
vi.stubGlobal('fetch', stubLinearGraphql({ commentId: 'started' }));
|
|
87
|
+
await postLinearSessionStatus({
|
|
88
|
+
kind: 'started',
|
|
89
|
+
sessionId: 'ses_1',
|
|
90
|
+
issueIdentifier: 'ENG-12',
|
|
91
|
+
sessionOrigin: 'https://app.example.com',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const graphql = stubLinearGraphql({ commentId: 'done' });
|
|
95
|
+
vi.stubGlobal('fetch', graphql);
|
|
96
|
+
const runtime = createLinearSessionStatusRuntime();
|
|
97
|
+
runtime.processPayload({
|
|
98
|
+
type: 'session.status',
|
|
99
|
+
properties: { sessionID: 'ses_1', status: { type: 'idle' } },
|
|
100
|
+
});
|
|
101
|
+
runtime.processPayload({
|
|
102
|
+
type: 'session.status',
|
|
103
|
+
properties: { sessionID: 'ses_1', status: { type: 'idle' } },
|
|
104
|
+
});
|
|
105
|
+
await vi.waitFor(() => {
|
|
106
|
+
const commentCalls = graphql.mock.calls.filter(([, options]) => {
|
|
107
|
+
return JSON.parse(options.body).query.includes('mutation CommentCreate');
|
|
108
|
+
});
|
|
109
|
+
expect(commentCalls).toHaveLength(1);
|
|
110
|
+
});
|
|
111
|
+
runtime.stop();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('posts failure on session.error and skips user abort', async () => {
|
|
115
|
+
const { postLinearSessionStatus } = await import('./status.js');
|
|
116
|
+
vi.stubGlobal('fetch', stubLinearGraphql({ commentId: 'started' }));
|
|
117
|
+
await postLinearSessionStatus({
|
|
118
|
+
kind: 'started',
|
|
119
|
+
sessionId: 'ses_1',
|
|
120
|
+
issueIdentifier: 'ENG-12',
|
|
121
|
+
sessionOrigin: 'https://app.example.com',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const graphql = stubLinearGraphql({ commentId: 'fail' });
|
|
125
|
+
vi.stubGlobal('fetch', graphql);
|
|
126
|
+
const runtime = createLinearSessionStatusRuntime();
|
|
127
|
+
runtime.processPayload({
|
|
128
|
+
type: 'session.error',
|
|
129
|
+
properties: {
|
|
130
|
+
sessionID: 'ses_1',
|
|
131
|
+
error: { name: 'MessageAbortedError', message: 'stopped' },
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
135
|
+
expect(graphql).not.toHaveBeenCalled();
|
|
136
|
+
|
|
137
|
+
runtime.processPayload({
|
|
138
|
+
type: 'session.error',
|
|
139
|
+
properties: {
|
|
140
|
+
sessionID: 'ses_1',
|
|
141
|
+
error: { name: 'ProviderError', message: 'boom' },
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
await vi.waitFor(() => {
|
|
145
|
+
const commentCalls = graphql.mock.calls.filter(([, options]) => {
|
|
146
|
+
return JSON.parse(options.body).query.includes('mutation CommentCreate');
|
|
147
|
+
});
|
|
148
|
+
expect(commentCalls).toHaveLength(1);
|
|
149
|
+
const body = JSON.parse(commentCalls[0][1].body).variables.input.body;
|
|
150
|
+
expect(body).toContain('OpenChamber session failed');
|
|
151
|
+
});
|
|
152
|
+
runtime.stop();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('does not treat busy as completed', async () => {
|
|
156
|
+
const graphql = stubLinearGraphql();
|
|
157
|
+
vi.stubGlobal('fetch', graphql);
|
|
158
|
+
const runtime = createLinearSessionStatusRuntime();
|
|
159
|
+
runtime.processPayload({
|
|
160
|
+
type: 'session.status',
|
|
161
|
+
properties: { sessionID: 'ses_1', status: { type: 'busy' } },
|
|
162
|
+
});
|
|
163
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
164
|
+
expect(graphql).not.toHaveBeenCalled();
|
|
165
|
+
runtime.stop();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getLinearAuth, getLinearAuthFilePath, getLinearSessionCommentsEnabled } from './auth.js';
|
|
4
|
+
import { createLinearIssueComment } from './issues.js';
|
|
5
|
+
import { isPlainObject, readTrimmedString } from './parse.js';
|
|
6
|
+
|
|
7
|
+
const LINEAR_SESSION_STATUS_KINDS = ['started', 'completed', 'failure'];
|
|
8
|
+
const MAX_SESSION_STATUS_RECORDS = 500;
|
|
9
|
+
|
|
10
|
+
export class LinearSessionStatusError extends Error {
|
|
11
|
+
constructor(message, code) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'LinearSessionStatusError';
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const inflight = new Map();
|
|
19
|
+
|
|
20
|
+
function statusFile() {
|
|
21
|
+
return path.join(path.dirname(getLinearAuthFilePath()), 'linear-session-status.json');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function writeJsonFile(filePath, payload) {
|
|
25
|
+
const dir = path.dirname(filePath);
|
|
26
|
+
if (!fs.existsSync(dir)) {
|
|
27
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
const tmpFile = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
30
|
+
fs.writeFileSync(tmpFile, JSON.stringify(payload, null, 2), 'utf8');
|
|
31
|
+
try {
|
|
32
|
+
fs.chmodSync(tmpFile, 0o600);
|
|
33
|
+
} catch {
|
|
34
|
+
// best-effort
|
|
35
|
+
}
|
|
36
|
+
fs.renameSync(tmpFile, filePath);
|
|
37
|
+
try {
|
|
38
|
+
fs.chmodSync(filePath, 0o600);
|
|
39
|
+
} catch {
|
|
40
|
+
// best-effort
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const PRIVATE_HOST_SUFFIXES = ['.local', '.localhost', '.internal', '.lan', '.home.arpa'];
|
|
45
|
+
|
|
46
|
+
function isPrivateIpv4(hostname) {
|
|
47
|
+
const parts = hostname.split('.');
|
|
48
|
+
if (parts.length !== 4) return false;
|
|
49
|
+
const octets = parts.map((part) => (/^\d{1,3}$/.test(part) ? Number(part) : -1));
|
|
50
|
+
if (octets.some((octet) => octet < 0 || octet > 255)) return false;
|
|
51
|
+
const [a, b] = octets;
|
|
52
|
+
if (a === 0 || a === 10 || a === 127) return true;
|
|
53
|
+
if (a === 169 && b === 254) return true;
|
|
54
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
55
|
+
if (a === 192 && b === 168) return true;
|
|
56
|
+
// 100.64.0.0/10 is carrier-grade NAT, which Tailscale and similar overlays use.
|
|
57
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isPrivateIpv6(hostname) {
|
|
62
|
+
const address = hostname.replace(/^\[/, '').replace(/\]$/, '').toLowerCase();
|
|
63
|
+
if (address === '::1' || address === '::') return true;
|
|
64
|
+
// fc00::/7 (unique local) and fe80::/10 (link local).
|
|
65
|
+
return /^f[cd]/.test(address) || /^fe[89ab]/.test(address);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A session link is only worth writing into Linear when somebody other than the
|
|
70
|
+
* person who started the session can open it. Loopback, private LAN and
|
|
71
|
+
* overlay-network addresses reach nobody else, so they do not qualify.
|
|
72
|
+
*/
|
|
73
|
+
export function isPublicSessionOrigin(value) {
|
|
74
|
+
const origin = readSessionOrigin(value);
|
|
75
|
+
if (!origin) return false;
|
|
76
|
+
let hostname;
|
|
77
|
+
try {
|
|
78
|
+
hostname = new URL(origin).hostname.toLowerCase();
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (!hostname || hostname === 'localhost') return false;
|
|
83
|
+
if (PRIVATE_HOST_SUFFIXES.some((suffix) => hostname.endsWith(suffix))) return false;
|
|
84
|
+
if (hostname.includes(':') || hostname.startsWith('[')) return !isPrivateIpv6(hostname);
|
|
85
|
+
if (/^[\d.]+$/.test(hostname)) return !isPrivateIpv4(hostname);
|
|
86
|
+
// A bare single-label host is a LAN machine name, not a routable address.
|
|
87
|
+
return hostname.includes('.');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function readSessionOrigin(value) {
|
|
91
|
+
const trimmed = readTrimmedString(value);
|
|
92
|
+
if (!trimmed) return '';
|
|
93
|
+
try {
|
|
94
|
+
const url = new URL(trimmed);
|
|
95
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return '';
|
|
96
|
+
if (url.username || url.password) return '';
|
|
97
|
+
if (url.search || url.hash) return '';
|
|
98
|
+
if (url.pathname && url.pathname !== '/') return '';
|
|
99
|
+
return url.origin;
|
|
100
|
+
} catch {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function buildLinearSessionOpenUrl(sessionId, sessionOrigin) {
|
|
106
|
+
const id = readTrimmedString(sessionId);
|
|
107
|
+
const origin = readSessionOrigin(sessionOrigin);
|
|
108
|
+
if (!origin) return '';
|
|
109
|
+
return `${origin}/?session=${encodeURIComponent(id)}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function statusWord(kind) {
|
|
113
|
+
if (kind === 'started') return 'started';
|
|
114
|
+
if (kind === 'completed') return 'completed';
|
|
115
|
+
return 'failed';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function buildLinearSessionStatusComment({ kind, sessionUrl }) {
|
|
119
|
+
const url = readTrimmedString(sessionUrl);
|
|
120
|
+
const label = `OpenChamber session ${statusWord(kind)}`;
|
|
121
|
+
if (!url) return label;
|
|
122
|
+
// The comment already lives on the issue, so it says only what happened and
|
|
123
|
+
// links to the session. Issue titles routinely contain brackets ("[Bug] …"),
|
|
124
|
+
// which would break this markdown link if they were repeated in the label.
|
|
125
|
+
return `[${label}](${url})`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function readBooleanFlag(value) {
|
|
129
|
+
return value === true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function readRecord(value) {
|
|
133
|
+
if (!isPlainObject(value)) return null;
|
|
134
|
+
const issueIdentifier = readTrimmedString(value.issueIdentifier);
|
|
135
|
+
if (!issueIdentifier) return null;
|
|
136
|
+
return {
|
|
137
|
+
issueIdentifier,
|
|
138
|
+
sessionOrigin: readSessionOrigin(value.sessionOrigin) || null,
|
|
139
|
+
organizationId: readTrimmedString(value.organizationId) || null,
|
|
140
|
+
started: readBooleanFlag(value.started),
|
|
141
|
+
completed: readBooleanFlag(value.completed),
|
|
142
|
+
failure: readBooleanFlag(value.failure),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function readRecords() {
|
|
147
|
+
const filePath = statusFile();
|
|
148
|
+
if (!fs.existsSync(filePath)) {
|
|
149
|
+
return {};
|
|
150
|
+
}
|
|
151
|
+
let parsed;
|
|
152
|
+
try {
|
|
153
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
154
|
+
const trimmed = raw.trim();
|
|
155
|
+
if (!trimmed) {
|
|
156
|
+
return {};
|
|
157
|
+
}
|
|
158
|
+
parsed = JSON.parse(trimmed);
|
|
159
|
+
} catch {
|
|
160
|
+
throw new LinearSessionStatusError('Linear session status file is malformed', 'MALFORMED');
|
|
161
|
+
}
|
|
162
|
+
if (!isPlainObject(parsed)) {
|
|
163
|
+
throw new LinearSessionStatusError('Linear session status file is malformed', 'MALFORMED');
|
|
164
|
+
}
|
|
165
|
+
const next = {};
|
|
166
|
+
for (const key of Object.keys(parsed)) {
|
|
167
|
+
const sessionId = readTrimmedString(key);
|
|
168
|
+
const record = readRecord(parsed[key]);
|
|
169
|
+
if (sessionId && record) {
|
|
170
|
+
next[sessionId] = record;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return next;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The file only exists to dedupe comments, so it does not need to remember
|
|
178
|
+
* every session ever started. Keep the newest entries and drop the tail.
|
|
179
|
+
*/
|
|
180
|
+
export function pruneSessionStatusRecords(records, limit = MAX_SESSION_STATUS_RECORDS) {
|
|
181
|
+
const keys = Object.keys(records);
|
|
182
|
+
if (keys.length <= limit) {
|
|
183
|
+
return records;
|
|
184
|
+
}
|
|
185
|
+
const kept = {};
|
|
186
|
+
for (const key of keys.slice(keys.length - limit)) {
|
|
187
|
+
kept[key] = records[key];
|
|
188
|
+
}
|
|
189
|
+
return kept;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function writeRecords(records) {
|
|
193
|
+
writeJsonFile(statusFile(), pruneSessionStatusRecords(records));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function postOnce(input) {
|
|
197
|
+
const kind = readTrimmedString(input?.kind);
|
|
198
|
+
const sessionId = readTrimmedString(input?.sessionId);
|
|
199
|
+
if (!LINEAR_SESSION_STATUS_KINDS.includes(kind) || !sessionId) {
|
|
200
|
+
throw new LinearSessionStatusError('kind and sessionId are required', 'INVALID');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Disconnected answers first so the picker and panel keep showing their
|
|
204
|
+
// "connect Linear" state whatever the comment preference says.
|
|
205
|
+
if (!getLinearAuth()) {
|
|
206
|
+
return { connected: false };
|
|
207
|
+
}
|
|
208
|
+
if (!getLinearSessionCommentsEnabled()) {
|
|
209
|
+
return { connected: true, posted: false, skipped: 'disabled' };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const records = readRecords();
|
|
213
|
+
const existing = records[sessionId] || null;
|
|
214
|
+
if (existing?.[kind] === true) {
|
|
215
|
+
return { connected: true, posted: false, skipped: 'already-posted' };
|
|
216
|
+
}
|
|
217
|
+
if (kind !== 'started' && existing?.started !== true) {
|
|
218
|
+
return { connected: true, posted: false, skipped: 'not-started' };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const issueIdentifier = readTrimmedString(input?.issueIdentifier)
|
|
222
|
+
|| readTrimmedString(existing?.issueIdentifier);
|
|
223
|
+
if (!issueIdentifier) {
|
|
224
|
+
throw new LinearSessionStatusError('issueIdentifier is required', 'INVALID');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const sessionOrigin = readSessionOrigin(input?.sessionOrigin)
|
|
228
|
+
|| readTrimmedString(existing?.sessionOrigin);
|
|
229
|
+
// Without an origin other people can reach, the comment would carry a link
|
|
230
|
+
// only its author could open. Say nothing rather than publish a dead link.
|
|
231
|
+
if (!isPublicSessionOrigin(sessionOrigin)) {
|
|
232
|
+
return { connected: true, posted: false, skipped: 'origin-not-public' };
|
|
233
|
+
}
|
|
234
|
+
const sessionUrl = buildLinearSessionOpenUrl(sessionId, sessionOrigin);
|
|
235
|
+
const organizationId = readTrimmedString(input?.organizationId)
|
|
236
|
+
|| readTrimmedString(existing?.organizationId)
|
|
237
|
+
|| readTrimmedString(getLinearAuth()?.workspaceId);
|
|
238
|
+
const body = buildLinearSessionStatusComment({ kind, sessionUrl });
|
|
239
|
+
const commentResult = await createLinearIssueComment({
|
|
240
|
+
issueId: issueIdentifier,
|
|
241
|
+
body,
|
|
242
|
+
organizationId,
|
|
243
|
+
});
|
|
244
|
+
if (commentResult.connected === false) {
|
|
245
|
+
return { connected: false };
|
|
246
|
+
}
|
|
247
|
+
if (!commentResult.comment) {
|
|
248
|
+
return { connected: true, posted: false, skipped: 'issue-not-found' };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
records[sessionId] = {
|
|
252
|
+
issueIdentifier,
|
|
253
|
+
sessionOrigin: sessionOrigin || null,
|
|
254
|
+
organizationId: organizationId || null,
|
|
255
|
+
started: existing?.started === true || kind === 'started',
|
|
256
|
+
completed: existing?.completed === true || kind === 'completed',
|
|
257
|
+
failure: existing?.failure === true || kind === 'failure',
|
|
258
|
+
};
|
|
259
|
+
writeRecords(records);
|
|
260
|
+
return {
|
|
261
|
+
connected: true,
|
|
262
|
+
posted: true,
|
|
263
|
+
commentId: commentResult.comment.id,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export async function postLinearSessionStatus(input) {
|
|
268
|
+
const kind = readTrimmedString(input?.kind);
|
|
269
|
+
const sessionId = readTrimmedString(input?.sessionId);
|
|
270
|
+
const key = `${sessionId}:${kind}`;
|
|
271
|
+
const pending = inflight.get(key);
|
|
272
|
+
if (pending) {
|
|
273
|
+
return pending;
|
|
274
|
+
}
|
|
275
|
+
const promise = postOnce(input).finally(() => {
|
|
276
|
+
inflight.delete(key);
|
|
277
|
+
});
|
|
278
|
+
inflight.set(key, promise);
|
|
279
|
+
return promise;
|
|
280
|
+
}
|