charness 3.3.2 → 3.5.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/CHANGELOG.md +639 -0
- package/DEVELOPMENT.md +76 -0
- package/README.md +78 -7
- package/SETUP.md +65 -19
- package/dist/adapters/claudeCliAdapter.js +2 -2
- package/dist/adapters/claudeCliAdapter.js.map +1 -1
- package/dist/adapters/claudeConfigDir.d.ts +18 -0
- package/dist/adapters/claudeConfigDir.d.ts.map +1 -1
- package/dist/adapters/claudeJsonStreamAdapter.d.ts +8 -1
- package/dist/adapters/claudeJsonStreamAdapter.d.ts.map +1 -1
- package/dist/adapters/claudeJsonStreamAdapter.js +24 -6
- package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
- package/dist/adapters/createAdapter.d.ts +2 -1
- package/dist/adapters/createAdapter.d.ts.map +1 -1
- package/dist/adapters/createAdapter.js +16 -0
- package/dist/adapters/createAdapter.js.map +1 -1
- package/dist/adapters/openCodeAdapter.d.ts +11 -0
- package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
- package/dist/adapters/openCodeAdapter.js +24 -9
- package/dist/adapters/openCodeAdapter.js.map +1 -1
- package/dist/agentLogin/agentLogin.d.ts +19 -1
- package/dist/agentLogin/agentLogin.d.ts.map +1 -1
- package/dist/agentLogin/agentLogin.js +64 -18
- package/dist/agentLogin/agentLogin.js.map +1 -1
- package/dist/apiErrorRetry.d.ts +3 -1
- package/dist/apiErrorRetry.d.ts.map +1 -1
- package/dist/apiErrorRetry.js +11 -1
- package/dist/apiErrorRetry.js.map +1 -1
- package/dist/bot.d.ts +0 -3
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +487 -182
- package/dist/bot.js.map +1 -1
- package/dist/changelogEntries.d.ts +25 -0
- package/dist/changelogEntries.d.ts.map +1 -0
- package/dist/changelogEntries.js +66 -0
- package/dist/changelogEntries.js.map +1 -0
- package/dist/cli/bot.d.ts +6 -2
- package/dist/cli/bot.d.ts.map +1 -1
- package/dist/cli/bot.js +34 -2
- package/dist/cli/bot.js.map +1 -1
- package/dist/cli/claudeProfiles.d.ts +1 -1
- package/dist/cli/claudeProfiles.d.ts.map +1 -1
- package/dist/cli/claudeProfiles.js +11 -6
- package/dist/cli/claudeProfiles.js.map +1 -1
- package/dist/cli/hot.d.ts +7 -0
- package/dist/cli/hot.d.ts.map +1 -1
- package/dist/cli/hot.js +53 -3
- package/dist/cli/hot.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -0
- package/dist/cli.js.map +1 -1
- package/dist/connectors/telegram/bindPicker.d.ts +64 -0
- package/dist/connectors/telegram/bindPicker.d.ts.map +1 -0
- package/dist/connectors/telegram/bindPicker.js +97 -0
- package/dist/connectors/telegram/bindPicker.js.map +1 -0
- package/dist/connectors/telegram/commands/claudeAccounts.d.ts +6 -2
- package/dist/connectors/telegram/commands/claudeAccounts.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/claudeAccounts.js +127 -28
- package/dist/connectors/telegram/commands/claudeAccounts.js.map +1 -1
- package/dist/connectors/telegram/commands/fallbackChain.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/fallbackChain.js +6 -2
- package/dist/connectors/telegram/commands/fallbackChain.js.map +1 -1
- package/dist/connectors/telegram/commands/selfUpdate.d.ts +16 -0
- package/dist/connectors/telegram/commands/selfUpdate.d.ts.map +1 -0
- package/dist/connectors/telegram/commands/selfUpdate.js +210 -0
- package/dist/connectors/telegram/commands/selfUpdate.js.map +1 -0
- package/dist/connectors/telegram/commands/stt.d.ts +1 -0
- package/dist/connectors/telegram/commands/stt.d.ts.map +1 -1
- package/dist/connectors/telegram/commands/stt.js +5 -0
- package/dist/connectors/telegram/commands/stt.js.map +1 -1
- package/dist/connectors/telegram/commands/topicCommand.d.ts +75 -0
- package/dist/connectors/telegram/commands/topicCommand.d.ts.map +1 -0
- package/dist/connectors/telegram/commands/topicCommand.js +391 -0
- package/dist/connectors/telegram/commands/topicCommand.js.map +1 -0
- package/dist/i18n/de.d.ts.map +1 -1
- package/dist/i18n/de.js +136 -3
- package/dist/i18n/de.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +136 -3
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +136 -3
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/fr.d.ts.map +1 -1
- package/dist/i18n/fr.js +136 -3
- package/dist/i18n/fr.js.map +1 -1
- package/dist/i18n/hi.d.ts.map +1 -1
- package/dist/i18n/hi.js +136 -3
- package/dist/i18n/hi.js.map +1 -1
- package/dist/i18n/ja.d.ts.map +1 -1
- package/dist/i18n/ja.js +136 -3
- package/dist/i18n/ja.js.map +1 -1
- package/dist/i18n/ka.d.ts.map +1 -1
- package/dist/i18n/ka.js +136 -3
- package/dist/i18n/ka.js.map +1 -1
- package/dist/i18n/pt.d.ts.map +1 -1
- package/dist/i18n/pt.js +136 -3
- package/dist/i18n/pt.js.map +1 -1
- package/dist/i18n/ru.d.ts.map +1 -1
- package/dist/i18n/ru.js +136 -3
- package/dist/i18n/ru.js.map +1 -1
- package/dist/i18n/uk.d.ts.map +1 -1
- package/dist/i18n/uk.js +136 -3
- package/dist/i18n/uk.js.map +1 -1
- package/dist/i18n/uz.d.ts.map +1 -1
- package/dist/i18n/uz.js +136 -3
- package/dist/i18n/uz.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +136 -3
- package/dist/i18n/zh.js.map +1 -1
- package/dist/instanceSettings.d.ts +12 -1
- package/dist/instanceSettings.d.ts.map +1 -1
- package/dist/instanceSettings.js +40 -4
- package/dist/instanceSettings.js.map +1 -1
- package/dist/scheduler/mcpSurface.d.ts.map +1 -1
- package/dist/scheduler/mcpSurface.js +4 -2
- package/dist/scheduler/mcpSurface.js.map +1 -1
- package/dist/selfUpdate/bootRollback.d.ts +22 -0
- package/dist/selfUpdate/bootRollback.d.ts.map +1 -0
- package/dist/selfUpdate/bootRollback.js +79 -0
- package/dist/selfUpdate/bootRollback.js.map +1 -0
- package/dist/selfUpdate/commandRunner.d.ts +21 -0
- package/dist/selfUpdate/commandRunner.d.ts.map +1 -0
- package/dist/selfUpdate/commandRunner.js +32 -0
- package/dist/selfUpdate/commandRunner.js.map +1 -0
- package/dist/selfUpdate/constants.d.ts +26 -0
- package/dist/selfUpdate/constants.d.ts.map +1 -0
- package/dist/selfUpdate/constants.js +31 -0
- package/dist/selfUpdate/constants.js.map +1 -0
- package/dist/selfUpdate/gitSource.d.ts +58 -0
- package/dist/selfUpdate/gitSource.d.ts.map +1 -0
- package/dist/selfUpdate/gitSource.js +183 -0
- package/dist/selfUpdate/gitSource.js.map +1 -0
- package/dist/selfUpdate/hostLock.d.ts +16 -0
- package/dist/selfUpdate/hostLock.d.ts.map +1 -0
- package/dist/selfUpdate/hostLock.js +101 -0
- package/dist/selfUpdate/hostLock.js.map +1 -0
- package/dist/selfUpdate/hotSupervisor.d.ts +47 -0
- package/dist/selfUpdate/hotSupervisor.d.ts.map +1 -0
- package/dist/selfUpdate/hotSupervisor.js +125 -0
- package/dist/selfUpdate/hotSupervisor.js.map +1 -0
- package/dist/selfUpdate/installKind.d.ts +45 -0
- package/dist/selfUpdate/installKind.d.ts.map +1 -0
- package/dist/selfUpdate/installKind.js +99 -0
- package/dist/selfUpdate/installKind.js.map +1 -0
- package/dist/selfUpdate/launchEnvironment.d.ts +3 -0
- package/dist/selfUpdate/launchEnvironment.d.ts.map +1 -0
- package/dist/selfUpdate/launchEnvironment.js +16 -0
- package/dist/selfUpdate/launchEnvironment.js.map +1 -0
- package/dist/selfUpdate/npmSource.d.ts +34 -0
- package/dist/selfUpdate/npmSource.d.ts.map +1 -0
- package/dist/selfUpdate/npmSource.js +107 -0
- package/dist/selfUpdate/npmSource.js.map +1 -0
- package/dist/selfUpdate/releaseNotes.d.ts +33 -0
- package/dist/selfUpdate/releaseNotes.d.ts.map +1 -0
- package/dist/selfUpdate/releaseNotes.js +115 -0
- package/dist/selfUpdate/releaseNotes.js.map +1 -0
- package/dist/selfUpdate/restart.d.ts +33 -0
- package/dist/selfUpdate/restart.d.ts.map +1 -0
- package/dist/selfUpdate/restart.js +94 -0
- package/dist/selfUpdate/restart.js.map +1 -0
- package/dist/selfUpdate/selfCheck.d.ts +20 -0
- package/dist/selfUpdate/selfCheck.d.ts.map +1 -0
- package/dist/selfUpdate/selfCheck.js +126 -0
- package/dist/selfUpdate/selfCheck.js.map +1 -0
- package/dist/selfUpdate/semver.d.ts +24 -0
- package/dist/selfUpdate/semver.d.ts.map +1 -0
- package/dist/selfUpdate/semver.js +165 -0
- package/dist/selfUpdate/semver.js.map +1 -0
- package/dist/selfUpdate/types.d.ts +51 -0
- package/dist/selfUpdate/types.d.ts.map +1 -0
- package/dist/selfUpdate/types.js +3 -0
- package/dist/selfUpdate/types.js.map +1 -0
- package/dist/selfUpdate/updateEngine.d.ts +110 -0
- package/dist/selfUpdate/updateEngine.d.ts.map +1 -0
- package/dist/selfUpdate/updateEngine.js +727 -0
- package/dist/selfUpdate/updateEngine.js.map +1 -0
- package/dist/selfUpdate/updateMessages.d.ts +84 -0
- package/dist/selfUpdate/updateMessages.d.ts.map +1 -0
- package/dist/selfUpdate/updateMessages.js +115 -0
- package/dist/selfUpdate/updateMessages.js.map +1 -0
- package/dist/selfUpdate/updateModes.d.ts +17 -0
- package/dist/selfUpdate/updateModes.d.ts.map +1 -0
- package/dist/selfUpdate/updateModes.js +14 -0
- package/dist/selfUpdate/updateModes.js.map +1 -0
- package/dist/selfUpdate/updatePending.d.ts +76 -0
- package/dist/selfUpdate/updatePending.d.ts.map +1 -0
- package/dist/selfUpdate/updatePending.js +131 -0
- package/dist/selfUpdate/updatePending.js.map +1 -0
- package/dist/selfUpdate/updatePolicy.d.ts +115 -0
- package/dist/selfUpdate/updatePolicy.d.ts.map +1 -0
- package/dist/selfUpdate/updatePolicy.js +83 -0
- package/dist/selfUpdate/updatePolicy.js.map +1 -0
- package/dist/selfUpdate/updateRuntime.d.ts +22 -0
- package/dist/selfUpdate/updateRuntime.d.ts.map +1 -0
- package/dist/selfUpdate/updateRuntime.js +148 -0
- package/dist/selfUpdate/updateRuntime.js.map +1 -0
- package/dist/startupPromptBuffer.d.ts +2 -0
- package/dist/startupPromptBuffer.d.ts.map +1 -1
- package/dist/startupPromptBuffer.js +4 -0
- package/dist/startupPromptBuffer.js.map +1 -1
- package/dist/state.d.ts +43 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +54 -0
- package/dist/state.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/anthropicApiKeyCheck.d.ts +19 -0
- package/dist/utils/anthropicApiKeyCheck.d.ts.map +1 -0
- package/dist/utils/anthropicApiKeyCheck.js +41 -0
- package/dist/utils/anthropicApiKeyCheck.js.map +1 -0
- package/dist/utils/claudeAccountPickerPlan.d.ts +6 -1
- package/dist/utils/claudeAccountPickerPlan.d.ts.map +1 -1
- package/dist/utils/claudeAccountPickerPlan.js +5 -1
- package/dist/utils/claudeAccountPickerPlan.js.map +1 -1
- package/dist/utils/claudeApiKeyHelper.d.ts +19 -0
- package/dist/utils/claudeApiKeyHelper.d.ts.map +1 -0
- package/dist/utils/claudeApiKeyHelper.js +32 -0
- package/dist/utils/claudeApiKeyHelper.js.map +1 -0
- package/dist/utils/claudeApiSpend.d.ts +73 -0
- package/dist/utils/claudeApiSpend.d.ts.map +1 -0
- package/dist/utils/claudeApiSpend.js +82 -0
- package/dist/utils/claudeApiSpend.js.map +1 -0
- package/dist/utils/claudeCompactHook.d.ts +11 -6
- package/dist/utils/claudeCompactHook.d.ts.map +1 -1
- package/dist/utils/claudeCompactHook.js +28 -11
- package/dist/utils/claudeCompactHook.js.map +1 -1
- package/dist/utils/claudeLimitSwitch.d.ts +2 -1
- package/dist/utils/claudeLimitSwitch.d.ts.map +1 -1
- package/dist/utils/claudeLimitSwitch.js +3 -2
- package/dist/utils/claudeLimitSwitch.js.map +1 -1
- package/dist/utils/claudeProfileUsageLines.d.ts +18 -3
- package/dist/utils/claudeProfileUsageLines.d.ts.map +1 -1
- package/dist/utils/claudeProfileUsageLines.js +23 -2
- package/dist/utils/claudeProfileUsageLines.js.map +1 -1
- package/dist/utils/claudeProfiles.d.ts +57 -2
- package/dist/utils/claudeProfiles.d.ts.map +1 -1
- package/dist/utils/claudeProfiles.js +96 -3
- package/dist/utils/claudeProfiles.js.map +1 -1
- package/dist/utils/claudeStreamJson.d.ts +4 -1
- package/dist/utils/claudeStreamJson.d.ts.map +1 -1
- package/dist/utils/claudeStreamJson.js +6 -0
- package/dist/utils/claudeStreamJson.js.map +1 -1
- package/dist/utils/claudeTranscriptContent.d.ts +8 -0
- package/dist/utils/claudeTranscriptContent.d.ts.map +1 -1
- package/dist/utils/claudeTranscriptContent.js +44 -0
- package/dist/utils/claudeTranscriptContent.js.map +1 -1
- package/dist/utils/claudeUsage.d.ts +22 -6
- package/dist/utils/claudeUsage.d.ts.map +1 -1
- package/dist/utils/claudeUsage.js +12 -5
- package/dist/utils/claudeUsage.js.map +1 -1
- package/dist/utils/claudeUsageRefresher.d.ts +6 -0
- package/dist/utils/claudeUsageRefresher.d.ts.map +1 -1
- package/dist/utils/claudeUsageRefresher.js +2 -2
- package/dist/utils/claudeUsageRefresher.js.map +1 -1
- package/dist/utils/fallbackChain.d.ts +15 -8
- package/dist/utils/fallbackChain.d.ts.map +1 -1
- package/dist/utils/fallbackChain.js +30 -13
- package/dist/utils/fallbackChain.js.map +1 -1
- package/dist/utils/limitsBoardPlan.d.ts +4 -2
- package/dist/utils/limitsBoardPlan.d.ts.map +1 -1
- package/dist/utils/limitsBoardPlan.js +12 -5
- package/dist/utils/limitsBoardPlan.js.map +1 -1
- package/dist/utils/recvPreviewRedaction.d.ts +7 -2
- package/dist/utils/recvPreviewRedaction.d.ts.map +1 -1
- package/dist/utils/recvPreviewRedaction.js +10 -4
- package/dist/utils/recvPreviewRedaction.js.map +1 -1
- package/dist/utils/threadStatusReport.d.ts +12 -1
- package/dist/utils/threadStatusReport.d.ts.map +1 -1
- package/dist/utils/threadStatusReport.js +13 -4
- package/dist/utils/threadStatusReport.js.map +1 -1
- package/dist/utils/updateScreenPlan.d.ts +38 -0
- package/dist/utils/updateScreenPlan.d.ts.map +1 -0
- package/dist/utils/updateScreenPlan.js +143 -0
- package/dist/utils/updateScreenPlan.js.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
exports.checkIsEmittedSource = checkIsEmittedSource;
|
|
37
|
+
exports.checkChangesEmittedSource = checkChangesEmittedSource;
|
|
38
|
+
exports.parseScriptKeys = parseScriptKeys;
|
|
39
|
+
exports.parseGitCheck = parseGitCheck;
|
|
40
|
+
exports.createGitSource = createGitSource;
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const commandRunner_1 = require("./commandRunner");
|
|
44
|
+
const constants_1 = require("./constants");
|
|
45
|
+
const npmSource_1 = require("./npmSource");
|
|
46
|
+
const selfUpdateScriptRelativePath = path.join('scripts', 'self-update.sh');
|
|
47
|
+
const changelogFileName = 'CHANGELOG.md';
|
|
48
|
+
const manifestFileNames = ['yarn.lock', 'package.json'];
|
|
49
|
+
/** What `tsc -w` turns into files under `dist/` — and so into a worker reload by nodemon (which watches nothing else). */
|
|
50
|
+
const emittedSourceRoot = 'src/';
|
|
51
|
+
const unemittedSourcePrefixes = ['src/__tests__/', 'src/release/'];
|
|
52
|
+
const emittedSourceExtension = '.ts';
|
|
53
|
+
const declarationFileExtension = '.d.ts';
|
|
54
|
+
/** The worker's own entry under `dist/`: a file nodemon watches, whose mtime alone makes it replace the worker. */
|
|
55
|
+
const hotWorkerEntryRelativePath = path.join('dist', 'cli', 'botEntry.js');
|
|
56
|
+
/** Enough context lines that the diff of CHANGELOG.md holds the whole file (an entry's `###` heading included). */
|
|
57
|
+
const wholeFileContext = '--unified=100000';
|
|
58
|
+
const heldBreakingExitCode = 3;
|
|
59
|
+
const scriptKeyPattern = /^(status|reason|from|to|behind|migrationGuides)=(.*)$/;
|
|
60
|
+
const gitCheckStatuses = ['upToDate', 'behind', 'skip'];
|
|
61
|
+
const gitSkipReasons = ['dirty', 'diverged', 'noUpstream', 'inProgress', 'fetchFailed'];
|
|
62
|
+
/**
|
|
63
|
+
* @description Whether a change to `filePath` makes `tsc -w` write a file under `dist/` — a TypeScript source it compiles (tests,
|
|
64
|
+
* the release tooling and declaration files excluded). Everything else — docs, the CHANGELOG, scripts, the manifests, a tsconfig
|
|
65
|
+
* edit that changes no output — leaves `dist/` as it is, so nothing would replace a hot worker by itself.
|
|
66
|
+
*/
|
|
67
|
+
function checkIsEmittedSource(filePath) {
|
|
68
|
+
return (filePath.startsWith(emittedSourceRoot) &&
|
|
69
|
+
filePath.endsWith(emittedSourceExtension) &&
|
|
70
|
+
!filePath.endsWith(declarationFileExtension) &&
|
|
71
|
+
!unemittedSourcePrefixes.some((prefix) => filePath.startsWith(prefix)));
|
|
72
|
+
}
|
|
73
|
+
/** @description Whether a pull of these paths is followed by a rebuild — and so by nodemon replacing the hot worker. */
|
|
74
|
+
function checkChangesEmittedSource(changedFiles) {
|
|
75
|
+
return changedFiles.some(checkIsEmittedSource);
|
|
76
|
+
}
|
|
77
|
+
/** @description The `key=value` lines of the script's stdout (its log lines are ignored). */
|
|
78
|
+
function parseScriptKeys(stdout) {
|
|
79
|
+
const keys = {};
|
|
80
|
+
for (const line of stdout.split('\n')) {
|
|
81
|
+
const match = scriptKeyPattern.exec(line);
|
|
82
|
+
if (match)
|
|
83
|
+
keys[match[1]] = match[2];
|
|
84
|
+
}
|
|
85
|
+
return keys;
|
|
86
|
+
}
|
|
87
|
+
function splitGuides(text) {
|
|
88
|
+
return (text ?? '').split(' ').filter((guide) => guide !== '');
|
|
89
|
+
}
|
|
90
|
+
function splitPaths(text) {
|
|
91
|
+
return text.split('\n').filter((line) => line !== '');
|
|
92
|
+
}
|
|
93
|
+
function toSkipReason(text) {
|
|
94
|
+
return gitSkipReasons.find((reason) => reason === text) ?? null;
|
|
95
|
+
}
|
|
96
|
+
/** @description The check a `--check` run printed. */
|
|
97
|
+
function parseGitCheck(stdout) {
|
|
98
|
+
const keys = parseScriptKeys(stdout);
|
|
99
|
+
const status = gitCheckStatuses.find((candidate) => candidate === keys.status);
|
|
100
|
+
if (!status)
|
|
101
|
+
throw new npmSource_1.UpdateSourceError(`self-update.sh --check printed no status: ${stdout.slice(0, 200)}`);
|
|
102
|
+
return {
|
|
103
|
+
status,
|
|
104
|
+
reason: status === 'skip' ? toSkipReason(keys.reason) : null,
|
|
105
|
+
from: keys.from ?? '',
|
|
106
|
+
to: keys.to ?? '',
|
|
107
|
+
behind: Number(keys.behind ?? 0),
|
|
108
|
+
migrationGuides: splitGuides(keys.migrationGuides),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function createGitSource({ runCommand, root, env }) {
|
|
112
|
+
const script = path.join(root, selfUpdateScriptRelativePath);
|
|
113
|
+
async function runGit(args, timeoutMs) {
|
|
114
|
+
const result = await runCommand('git', args, { cwd: root, env, timeoutMs });
|
|
115
|
+
if (!result.ok)
|
|
116
|
+
throw new npmSource_1.UpdateSourceError(`git ${args[0]} failed: ${(0, commandRunner_1.getOutputTail)(result, 2)}`);
|
|
117
|
+
return result.stdout;
|
|
118
|
+
}
|
|
119
|
+
async function getChangedFiles(from, to) {
|
|
120
|
+
return splitPaths(await runGit(['diff', '--name-only', from, to], constants_1.queryTimeoutMs));
|
|
121
|
+
}
|
|
122
|
+
async function reloadHotWorker() {
|
|
123
|
+
const entry = path.join(root, hotWorkerEntryRelativePath);
|
|
124
|
+
const now = new Date();
|
|
125
|
+
try {
|
|
126
|
+
await fs.promises.utimes(entry, now, now);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
throw new npmSource_1.UpdateSourceError(`cannot ask the hot worker to reload (${entry}): ${error instanceof Error ? error.message : String(error)}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
async check() {
|
|
134
|
+
const result = await runCommand('bash', [script, '--check'], { cwd: root, env, timeoutMs: constants_1.queryTimeoutMs });
|
|
135
|
+
if (!result.ok)
|
|
136
|
+
throw new npmSource_1.UpdateSourceError(result.isTimedOut ? 'the remote did not answer in time' : `self-update.sh --check failed: ${(0, commandRunner_1.getOutputTail)(result, 2)}`);
|
|
137
|
+
return parseGitCheck(result.stdout);
|
|
138
|
+
},
|
|
139
|
+
async apply({ holdBreaking }) {
|
|
140
|
+
const result = await runCommand('bash', [script, ...(holdBreaking ? ['--hold-breaking'] : [])], { cwd: root, env, timeoutMs: constants_1.installTimeoutMs });
|
|
141
|
+
const keys = parseScriptKeys(result.stdout);
|
|
142
|
+
if (result.exitCode === heldBreakingExitCode) {
|
|
143
|
+
return { status: 'held', from: keys.from ?? '', to: keys.to ?? '', migrationGuides: splitGuides(keys.migrationGuides) };
|
|
144
|
+
}
|
|
145
|
+
if (!result.ok)
|
|
146
|
+
throw new npmSource_1.UpdateSourceError(result.isTimedOut ? 'the update did not finish in time' : `self-update.sh failed: ${(0, commandRunner_1.getOutputTail)(result)}`);
|
|
147
|
+
if (keys.status === 'updated')
|
|
148
|
+
return { status: 'updated', from: keys.from ?? '', to: keys.to ?? '', migrationGuides: splitGuides(keys.migrationGuides) };
|
|
149
|
+
if (keys.status === 'upToDate')
|
|
150
|
+
return { status: 'upToDate' };
|
|
151
|
+
if (keys.status === 'skip')
|
|
152
|
+
return { status: 'skip', reason: toSkipReason(keys.reason) };
|
|
153
|
+
throw new npmSource_1.UpdateSourceError(`self-update.sh printed no status: ${(0, commandRunner_1.getOutputTail)(result)}`);
|
|
154
|
+
},
|
|
155
|
+
async getChangelogDiff(from, to) {
|
|
156
|
+
return runGit(['diff', wholeFileContext, `${from}..${to}`, '--', changelogFileName], constants_1.queryTimeoutMs);
|
|
157
|
+
},
|
|
158
|
+
getChangedFiles,
|
|
159
|
+
reloadHotWorker,
|
|
160
|
+
async rollback({ from, to, isHot }) {
|
|
161
|
+
const changedFiles = await getChangedFiles(from, to);
|
|
162
|
+
// `--keep`: refuses rather than overwrite a local change the update never touched.
|
|
163
|
+
await runGit(['reset', '--keep', from], constants_1.queryTimeoutMs);
|
|
164
|
+
const isManifestChanged = changedFiles.some((file) => manifestFileNames.includes(file));
|
|
165
|
+
if (isManifestChanged) {
|
|
166
|
+
const install = await runCommand('yarn', ['install', '--immutable'], { cwd: root, env, timeoutMs: constants_1.installTimeoutMs });
|
|
167
|
+
if (!install.ok)
|
|
168
|
+
throw new npmSource_1.UpdateSourceError(`yarn install failed on the way back: ${(0, commandRunner_1.getOutputTail)(install)}`);
|
|
169
|
+
}
|
|
170
|
+
// A hot watcher rebuilds the reset checkout by itself; a second build beside it would race its writes. When the range changed
|
|
171
|
+
// no compiled source there is nothing to rebuild — and nothing that would restart the worker: ask for the reload.
|
|
172
|
+
if (isHot) {
|
|
173
|
+
if (!checkChangesEmittedSource(changedFiles))
|
|
174
|
+
await reloadHotWorker();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const build = await runCommand('yarn', ['build'], { cwd: root, env, timeoutMs: constants_1.installTimeoutMs });
|
|
178
|
+
if (!build.ok)
|
|
179
|
+
throw new npmSource_1.UpdateSourceError(`yarn build failed on the way back: ${(0, commandRunner_1.getOutputTail)(build)}`);
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=gitSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitSource.js","sourceRoot":"","sources":["../../src/selfUpdate/gitSource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,oDAOC;AAGD,8DAEC;AAGD,0CAOC;AAeD,sCAYC;AAED,0CAsEC;AA9KD,uCAAyB;AACzB,2CAA6B;AAC7B,mDAAoE;AACpE,2CAA+D;AAC/D,2CAAgD;AAIhD,MAAM,4BAA4B,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,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|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface HostLockDeps {
|
|
2
|
+
now: () => number;
|
|
3
|
+
/** Whether a process with this pid exists (`kill(pid, 0)`). */
|
|
4
|
+
checkIsProcessAlive: (pid: number) => boolean;
|
|
5
|
+
pid: number;
|
|
6
|
+
}
|
|
7
|
+
export interface HostLock {
|
|
8
|
+
release: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function createDefaultHostLockDeps(): HostLockDeps;
|
|
11
|
+
/**
|
|
12
|
+
* @description Take the lock at `lockPath`, or `null` when another live process holds it. A stale or unreadable lock
|
|
13
|
+
* is taken over; the file is created exclusively, so two takers can never both win.
|
|
14
|
+
*/
|
|
15
|
+
export declare function acquireHostLock(lockPath: string, deps?: HostLockDeps): HostLock | null;
|
|
16
|
+
//# sourceMappingURL=hostLock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostLock.d.ts","sourceRoot":"","sources":["../../src/selfUpdate/hostLock.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,+DAA+D;IAC/D,mBAAmB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAC9C,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAMD,wBAAgB,yBAAyB,IAAI,YAAY,CAcxD;AAgBD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,YAA0C,GAAG,QAAQ,GAAG,IAAI,CAmBnH"}
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
exports.createDefaultHostLockDeps = createDefaultHostLockDeps;
|
|
37
|
+
exports.acquireHostLock = acquireHostLock;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const constants_1 = require("./constants");
|
|
40
|
+
function getErrorCode(error) {
|
|
41
|
+
return error instanceof Error && 'code' in error && typeof error.code === 'string' ? error.code : undefined;
|
|
42
|
+
}
|
|
43
|
+
function createDefaultHostLockDeps() {
|
|
44
|
+
return {
|
|
45
|
+
now: () => Date.now(),
|
|
46
|
+
pid: process.pid,
|
|
47
|
+
checkIsProcessAlive: (pid) => {
|
|
48
|
+
try {
|
|
49
|
+
process.kill(pid, 0);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
// EPERM: it exists but is another user's.
|
|
54
|
+
return getErrorCode(error) === 'EPERM';
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function readLockRecord(lockPath) {
|
|
60
|
+
try {
|
|
61
|
+
const record = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
|
|
62
|
+
return Number.isInteger(record.pid) && Number.isFinite(record.startedAt) ? record : null;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function checkIsLockStale(record, deps) {
|
|
69
|
+
if (record === null)
|
|
70
|
+
return true;
|
|
71
|
+
return !deps.checkIsProcessAlive(record.pid) || deps.now() - record.startedAt > constants_1.hostLockStaleMs;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @description Take the lock at `lockPath`, or `null` when another live process holds it. A stale or unreadable lock
|
|
75
|
+
* is taken over; the file is created exclusively, so two takers can never both win.
|
|
76
|
+
*/
|
|
77
|
+
function acquireHostLock(lockPath, deps = createDefaultHostLockDeps()) {
|
|
78
|
+
const record = { pid: deps.pid, startedAt: deps.now() };
|
|
79
|
+
const maxAttempts = 2;
|
|
80
|
+
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
|
81
|
+
try {
|
|
82
|
+
fs.writeFileSync(lockPath, JSON.stringify(record), { flag: 'wx' });
|
|
83
|
+
return {
|
|
84
|
+
release: () => {
|
|
85
|
+
// Only the owner's own file: a lock taken over meanwhile is not ours to remove.
|
|
86
|
+
if (readLockRecord(lockPath)?.pid === deps.pid)
|
|
87
|
+
fs.rmSync(lockPath, { force: true });
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (getErrorCode(error) !== 'EEXIST')
|
|
93
|
+
throw error;
|
|
94
|
+
if (!checkIsLockStale(readLockRecord(lockPath), deps))
|
|
95
|
+
return null;
|
|
96
|
+
fs.rmSync(lockPath, { force: true });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=hostLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostLock.js","sourceRoot":"","sources":["../../src/selfUpdate/hostLock.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,8DAcC;AAoBD,0CAmBC;AAlFD,uCAAyB;AACzB,2CAA8C;AAwB9C,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9G,CAAC;AAED,SAAgB,yBAAyB;IACvC,OAAO;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;QACrB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;YAC3B,IAAI,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;gBACrB,OAAO,IAAI,CAAC;YACd,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,0CAA0C;gBAC1C,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC;YACzC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,QAAgB;IACtC,IAAI,CAAC;QACH,MAA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,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBACvF,CAAC;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,YAAY,CAAC,KAAK,CAAC,KAAK,QAAQ;gBAAE,MAAM,KAAK,CAAC;YAClD,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;YACnE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The hot supervisor (`charness hot`: `tsc -w` + nodemon) reloads only its WORKER on an update. When a file the SUPERVISOR
|
|
4
|
+
* itself loaded changed, the supervisor must be replaced too: it re-executes itself on `SIGUSR2` — same pid, so a Docker
|
|
5
|
+
* entrypoint `wait`ing on it, `charness-restart-bot` and systemd see nothing. This module is the contract between the two:
|
|
6
|
+
* the supervisor records what it loaded and who it is, the worker compares the record with `dist/` and, at an idle point,
|
|
7
|
+
* signals exactly that supervisor — never a pid that has been reused.
|
|
8
|
+
*/
|
|
9
|
+
export declare const hotSupervisorRecordFileName = "hot-supervisor.json";
|
|
10
|
+
/** Sent by a worker to its supervisor: re-execute yourself. */
|
|
11
|
+
export declare const supervisorReexecSignal: NodeJS.Signals;
|
|
12
|
+
declare const recordSchema: z.ZodObject<{
|
|
13
|
+
pid: z.ZodNumber;
|
|
14
|
+
startToken: z.ZodString;
|
|
15
|
+
canReexec: z.ZodBoolean;
|
|
16
|
+
modules: z.ZodArray<z.ZodObject<{
|
|
17
|
+
path: z.ZodString;
|
|
18
|
+
sha256: z.ZodString;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
/** What a supervisor says about itself: its identity, whether it can re-execute, and the hash of every `dist/` module it loaded. */
|
|
22
|
+
export type HotSupervisorRecord = z.infer<typeof recordSchema>;
|
|
23
|
+
export declare function getHotSupervisorRecordPath(dataDir: string): string;
|
|
24
|
+
export declare function hashFile(filePath: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* @description The modules a process loaded from `<root>/dist`, as paths relative to `dist/` with the hash of the file on
|
|
27
|
+
* disk. Called at the START of the supervisor, before its watcher rebuilds anything, so the hash is the loaded code's.
|
|
28
|
+
*/
|
|
29
|
+
export declare function collectLoadedDistModules(distDirectory: string, loadedModulePaths: readonly string[]): HotSupervisorRecord['modules'];
|
|
30
|
+
export declare function writeHotSupervisorRecord(dataDir: string, record: HotSupervisorRecord): void;
|
|
31
|
+
/** @description The supervisor's record; `null` when there is none (a supervisor that predates re-exec) or it is unreadable. */
|
|
32
|
+
export declare function readHotSupervisorRecord(dataDir: string): HotSupervisorRecord | null;
|
|
33
|
+
/** @description The recorded modules whose file on disk now differs, or is gone: the supervisor runs code that is no longer there. */
|
|
34
|
+
export declare function getStaleSupervisorModules(record: HotSupervisorRecord, distDirectory: string): string[];
|
|
35
|
+
export interface SupervisorSignalDeps {
|
|
36
|
+
/** The start token of the process with this pid now; `null` when no such process exists. */
|
|
37
|
+
getStartToken: (pid: number) => string | null;
|
|
38
|
+
kill: (pid: number, signal: NodeJS.Signals) => void;
|
|
39
|
+
}
|
|
40
|
+
export type SupervisorSignalResult = 'signaled' | 'gone' | 'differentProcess' | 'cannotReexec';
|
|
41
|
+
/**
|
|
42
|
+
* @description Ask the supervisor named by `record` to re-execute — only when that pid is still the SAME process (its start
|
|
43
|
+
* token matches) and the record says it can. A reused pid is a stranger's process: it gets nothing.
|
|
44
|
+
*/
|
|
45
|
+
export declare function requestSupervisorReexec(record: HotSupervisorRecord, deps: SupervisorSignalDeps): SupervisorSignalResult;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=hotSupervisor.d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rD;AAED,MAAM,MAAM,sBAAsB,GAAG,UAAU,GAAG,MAAM,GAAG,kBAAkB,GAAG,cAAc,CAAC;AAE/F;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,mBAAmB,EAAE,IAAI,EAAE,oBAAoB,GAAG,sBAAsB,CAOvH"}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
exports.supervisorReexecSignal = exports.hotSupervisorRecordFileName = void 0;
|
|
37
|
+
exports.getHotSupervisorRecordPath = getHotSupervisorRecordPath;
|
|
38
|
+
exports.hashFile = hashFile;
|
|
39
|
+
exports.collectLoadedDistModules = collectLoadedDistModules;
|
|
40
|
+
exports.writeHotSupervisorRecord = writeHotSupervisorRecord;
|
|
41
|
+
exports.readHotSupervisorRecord = readHotSupervisorRecord;
|
|
42
|
+
exports.getStaleSupervisorModules = getStaleSupervisorModules;
|
|
43
|
+
exports.requestSupervisorReexec = requestSupervisorReexec;
|
|
44
|
+
const crypto = __importStar(require("crypto"));
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const zod_1 = require("zod");
|
|
48
|
+
const configDirFile_1 = require("../configDirFile");
|
|
49
|
+
/**
|
|
50
|
+
* The hot supervisor (`charness hot`: `tsc -w` + nodemon) reloads only its WORKER on an update. When a file the SUPERVISOR
|
|
51
|
+
* itself loaded changed, the supervisor must be replaced too: it re-executes itself on `SIGUSR2` — same pid, so a Docker
|
|
52
|
+
* entrypoint `wait`ing on it, `charness-restart-bot` and systemd see nothing. This module is the contract between the two:
|
|
53
|
+
* the supervisor records what it loaded and who it is, the worker compares the record with `dist/` and, at an idle point,
|
|
54
|
+
* signals exactly that supervisor — never a pid that has been reused.
|
|
55
|
+
*/
|
|
56
|
+
exports.hotSupervisorRecordFileName = 'hot-supervisor.json';
|
|
57
|
+
const recordFileMode = 0o600;
|
|
58
|
+
const sha256Algorithm = 'sha256';
|
|
59
|
+
/** Sent by a worker to its supervisor: re-execute yourself. */
|
|
60
|
+
exports.supervisorReexecSignal = 'SIGUSR2';
|
|
61
|
+
const recordSchema = zod_1.z.object({
|
|
62
|
+
pid: zod_1.z.number().int().positive(),
|
|
63
|
+
startToken: zod_1.z.string().min(1),
|
|
64
|
+
canReexec: zod_1.z.boolean(),
|
|
65
|
+
modules: zod_1.z.array(zod_1.z.object({ path: zod_1.z.string(), sha256: zod_1.z.string() })),
|
|
66
|
+
});
|
|
67
|
+
function getHotSupervisorRecordPath(dataDir) {
|
|
68
|
+
return path.join(dataDir, exports.hotSupervisorRecordFileName);
|
|
69
|
+
}
|
|
70
|
+
function hashFile(filePath) {
|
|
71
|
+
return crypto.createHash(sha256Algorithm).update(fs.readFileSync(filePath)).digest('hex');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @description The modules a process loaded from `<root>/dist`, as paths relative to `dist/` with the hash of the file on
|
|
75
|
+
* disk. Called at the START of the supervisor, before its watcher rebuilds anything, so the hash is the loaded code's.
|
|
76
|
+
*/
|
|
77
|
+
function collectLoadedDistModules(distDirectory, loadedModulePaths) {
|
|
78
|
+
const prefix = `${distDirectory}${path.sep}`;
|
|
79
|
+
return loadedModulePaths
|
|
80
|
+
.filter((modulePath) => modulePath.startsWith(prefix) && modulePath.endsWith('.js'))
|
|
81
|
+
.map((modulePath) => ({ path: path.relative(distDirectory, modulePath).split(path.sep).join('/'), sha256: hashFile(modulePath) }))
|
|
82
|
+
.sort((left, right) => left.path.localeCompare(right.path));
|
|
83
|
+
}
|
|
84
|
+
function writeHotSupervisorRecord(dataDir, record) {
|
|
85
|
+
(0, configDirFile_1.writeJsonFileAtomically)(getHotSupervisorRecordPath(dataDir), record, recordFileMode);
|
|
86
|
+
}
|
|
87
|
+
/** @description The supervisor's record; `null` when there is none (a supervisor that predates re-exec) or it is unreadable. */
|
|
88
|
+
function readHotSupervisorRecord(dataDir) {
|
|
89
|
+
try {
|
|
90
|
+
const parsed = recordSchema.safeParse(JSON.parse(fs.readFileSync(getHotSupervisorRecordPath(dataDir), 'utf8')));
|
|
91
|
+
return parsed.success ? parsed.data : null;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** @description The recorded modules whose file on disk now differs, or is gone: the supervisor runs code that is no longer there. */
|
|
98
|
+
function getStaleSupervisorModules(record, distDirectory) {
|
|
99
|
+
return record.modules
|
|
100
|
+
.filter((module) => {
|
|
101
|
+
try {
|
|
102
|
+
return hashFile(path.join(distDirectory, module.path)) !== module.sha256;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
.map((module) => module.path);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @description Ask the supervisor named by `record` to re-execute — only when that pid is still the SAME process (its start
|
|
112
|
+
* token matches) and the record says it can. A reused pid is a stranger's process: it gets nothing.
|
|
113
|
+
*/
|
|
114
|
+
function requestSupervisorReexec(record, deps) {
|
|
115
|
+
if (!record.canReexec)
|
|
116
|
+
return 'cannotReexec';
|
|
117
|
+
const startToken = deps.getStartToken(record.pid);
|
|
118
|
+
if (startToken === null)
|
|
119
|
+
return 'gone';
|
|
120
|
+
if (startToken !== record.startToken)
|
|
121
|
+
return 'differentProcess';
|
|
122
|
+
deps.kill(record.pid, exports.supervisorReexecSignal);
|
|
123
|
+
return 'signaled';
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=hotSupervisor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotSupervisor.js","sourceRoot":"","sources":["../../src/selfUpdate/hotSupervisor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,gEAEC;AAED,4BAEC;AAMD,4DAMC;AAED,4DAEC;AAGD,0DAOC;AAGD,8DAUC;AAcD,0DAOC;AAhGD,+CAAiC;AACjC,uCAAyB;AACzB,2CAA6B;AAC7B,6BAAwB;AACxB,oDAA2D;AAE3D;;;;;;GAMG;AAEU,QAAA,2BAA2B,GAAG,qBAAqB,CAAC;AACjE,M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C,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAUD;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,MAA2B,EAAE,IAA0B;IAC7F,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAO,cAAc,CAAC;IAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClD,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IACvC,IAAI,UAAU,KAAK,MAAM,CAAC,UAAU;QAAE,OAAO,kBAAkB,CAAC;IAChE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,8BAAsB,CAAC,CAAC;IAC9C,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description How this charness was installed — decided by what the package folder IS and by what the bot may
|
|
3
|
+
* write there, never by "is this a container": a Docker image mounting a git checkout is a checkout.
|
|
4
|
+
*
|
|
5
|
+
* - `npmGlobal`: `npm install -g`, the prefix writable → `npm install -g charness@X` into the SAME prefix.
|
|
6
|
+
* - `checkout`: a git checkout (`npm link` and a mounted checkout included), writable → `scripts/self-update.sh`.
|
|
7
|
+
* - `notifyOnly`: it cannot update itself (no write access, a package manager we do not drive, a Node without
|
|
8
|
+
* `process.execve`): for an npm-style install it says a new version is out and names the command to run by hand; a
|
|
9
|
+
* checkout (`isCheckout`) is not watched at all — `/update` names the reason and the command.
|
|
10
|
+
* - `ephemeral`: `npx` — gone after the run, nothing to update.
|
|
11
|
+
*/
|
|
12
|
+
export type InstallKind = {
|
|
13
|
+
kind: 'npmGlobal';
|
|
14
|
+
prefix: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'checkout';
|
|
17
|
+
root: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'notifyOnly';
|
|
20
|
+
reason: NotifyOnlyReason;
|
|
21
|
+
manualCommand: string;
|
|
22
|
+
isCheckout: boolean;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'ephemeral';
|
|
25
|
+
};
|
|
26
|
+
/** @name NotifyOnlyReason @description Why an install can only notify; the `/update` screen words each one. */
|
|
27
|
+
export type NotifyOnlyReason = 'readOnlyPrefix' | 'readOnlyCheckout' | 'packageManager' | 'localInstall' | 'noExecve';
|
|
28
|
+
/** What the detector needs from the filesystem — injected, so a test needs no real prefix. */
|
|
29
|
+
export interface InstallKindFs {
|
|
30
|
+
checkExists: (target: string) => boolean;
|
|
31
|
+
/** Whether the current process may create and replace entries in the directory. */
|
|
32
|
+
checkIsWritable: (directory: string) => boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface InstallKindInput {
|
|
35
|
+
/** The package's folder, symlinks resolved (`fs.realpathSync`) — the folder `dist/cli.js` sits in. */
|
|
36
|
+
packageRoot: string;
|
|
37
|
+
fs: InstallKindFs;
|
|
38
|
+
platform: NodeJS.Platform;
|
|
39
|
+
/** Whether this Node has `process.execve` (22.15+, POSIX): the plain-mode restart needs it. */
|
|
40
|
+
hasExecve: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare const npmManualCommand = "npm install -g charness@latest";
|
|
43
|
+
/** @description Decide the install kind of a package folder. */
|
|
44
|
+
export declare function detectInstallKind({ packageRoot, fs: filesystem, platform, hasExecve }: InstallKindInput): InstallKind;
|
|
45
|
+
//# sourceMappingURL=installKind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installKind.d.ts","sourceRoot":"","sources":["../../src/selfUpdate/installKind.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GAC5F;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1B,+GAA+G;AAC/G,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,cAAc,GAAG,UAAU,CAAC;AAEtH,8FAA8F;AAC9F,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IACzC,mFAAmF;IACnF,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;CACjD;AAED,MAAM,WAAW,gBAAgB;IAC/B,sGAAsG;IACtG,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,aAAa,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,+FAA+F;IAC/F,SAAS,EAAE,OAAO,CAAC;CACpB;AAgBD,eAAO,MAAM,gBAAgB,mCAAmC,CAAC;AAoBjE,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,gBAAgB,GAAG,WAAW,CA0BrH"}
|