@git-stunts/git-cas 5.3.1 → 6.0.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/ADVANCED_GUIDE.md +1006 -0
- package/ARCHITECTURE.md +514 -0
- package/CHANGELOG.md +401 -4
- package/CODE_OF_CONDUCT.md +33 -0
- package/GUIDE.md +872 -0
- package/README.md +219 -325
- package/SECURITY.md +993 -0
- package/SUPPORT.md +54 -0
- package/UPGRADING.md +299 -0
- package/bin/actions.js +72 -20
- package/bin/agent/cli.js +51 -0
- package/bin/agent/commands/doctor.js +99 -0
- package/bin/agent/commands/index.js +1489 -0
- package/bin/agent/input.js +619 -0
- package/bin/agent/passphrase-source.js +123 -0
- package/bin/agent/protocol.js +193 -0
- package/bin/build-version.js +64 -0
- package/bin/credentials.js +425 -0
- package/bin/git-cas.js +604 -450
- package/bin/io.js +86 -0
- package/bin/passphrase-source.js +266 -0
- package/bin/restore-output-target.js +28 -0
- package/bin/ui/blocks/asset-card.js +109 -0
- package/bin/ui/blocks/health-dashboard.js +149 -0
- package/bin/ui/blocks/heatmap-block.js +67 -0
- package/bin/ui/blocks/merkle-explorer.js +163 -0
- package/bin/ui/blocks/operation-feed.js +176 -0
- package/bin/ui/blocks/wizard-block.js +168 -0
- package/bin/ui/components/short-sha.js +36 -0
- package/bin/ui/context.js +56 -1
- package/bin/ui/dashboard-cmds.js +1578 -13
- package/bin/ui/dashboard-view.js +612 -145
- package/bin/ui/dashboard.js +998 -214
- package/bin/ui/encryption-card.js +69 -26
- package/bin/ui/heatmap.js +26 -54
- package/bin/ui/history-timeline.js +51 -19
- package/bin/ui/manifest-view.js +115 -60
- package/bin/ui/merkle-dag.js +83 -0
- package/bin/ui/progress.js +15 -9
- package/bin/ui/repo-treemap.js +328 -0
- package/bin/ui/shaders/bak-sneppen.js +180 -0
- package/bin/ui/shaders/fractal-zoom.js +99 -0
- package/bin/ui/shaders/merkle-tree.js +142 -0
- package/bin/ui/shaders/organic-flow.js +96 -0
- package/bin/ui/shaders/phase-portrait.js +93 -0
- package/bin/ui/store-wizard.js +296 -0
- package/bin/ui/theme.js +155 -0
- package/bin/ui/vault-report.js +495 -0
- package/build-info.json +4 -0
- package/docs/API.md +2224 -0
- package/docs/ENCRYPTION_MODES.md +33 -0
- package/docs/EXTENDING.md +174 -0
- package/docs/STORE_RESTORE_PIPELINE.md +199 -0
- package/docs/THREAT_MODEL.md +269 -0
- package/docs/VAULT_INTERNALS.md +251 -0
- package/docs/WALKTHROUGH.md +1868 -0
- package/docs/demo.gif +0 -0
- package/docs/releases/v6.0.0.md +104 -0
- package/examples/README.md +260 -0
- package/index.d.ts +208 -65
- package/index.js +163 -54
- package/package.json +35 -6
- package/scripts/migrate-encryption.js +680 -0
- package/src/domain/bytes/ByteLayout.js +96 -0
- package/src/domain/encoding/base64.js +91 -0
- package/src/domain/encoding/hex.js +14 -0
- package/src/domain/encoding/utf8.js +123 -0
- package/src/domain/encryption/schemes.js +132 -0
- package/src/domain/errors/CannotRemoveLastRecipientError.js +10 -0
- package/src/domain/errors/CasError.d.ts +28 -0
- package/src/domain/errors/CasError.js +43 -6
- package/src/domain/errors/Codes.js +54 -0
- package/src/domain/errors/DekUnwrapFailedError.js +10 -0
- package/src/domain/errors/GitError.js +10 -0
- package/src/domain/errors/GitPlumbingInitializationError.js +10 -0
- package/src/domain/errors/IntegrityError.js +10 -0
- package/src/domain/errors/InvalidChunkingStrategyError.js +10 -0
- package/src/domain/errors/InvalidOidError.js +10 -0
- package/src/domain/errors/InvalidOptionsError.js +10 -0
- package/src/domain/errors/ManifestIntegrityError.js +10 -0
- package/src/domain/errors/ManifestNotFoundError.js +10 -0
- package/src/domain/errors/NoMatchingRecipientError.js +10 -0
- package/src/domain/errors/PersistenceCapabilityRequiredError.js +10 -0
- package/src/domain/errors/PortNotImplementedError.js +10 -0
- package/src/domain/errors/RecipientAlreadyExistsError.js +10 -0
- package/src/domain/errors/RecipientNotFoundError.js +10 -0
- package/src/domain/errors/RestoreTooLargeError.js +10 -0
- package/src/domain/errors/RotationNotSupportedError.js +10 -0
- package/src/domain/errors/createCasError.js +68 -0
- package/src/domain/errors/index.js +20 -0
- package/src/domain/helpers/buildKdfMetadata.js +4 -2
- package/src/domain/helpers/codecBytes.js +34 -0
- package/src/domain/helpers/gitRefErrors.js +84 -0
- package/src/domain/helpers/scryptMaxmem.js +22 -0
- package/src/domain/outcomes/RestoreFailure.js +15 -0
- package/src/domain/outcomes/RestoreOutcome.js +11 -0
- package/src/domain/outcomes/RestoreSuccess.js +34 -0
- package/src/domain/outcomes/StoreFailure.js +15 -0
- package/src/domain/outcomes/StoreOutcome.js +11 -0
- package/src/domain/outcomes/StoreSuccess.js +17 -0
- package/src/domain/schemas/ManifestSchema.d.ts +40 -9
- package/src/domain/schemas/ManifestSchema.js +67 -13
- package/src/domain/services/CasService.d.ts +123 -38
- package/src/domain/services/CasService.js +298 -834
- package/src/domain/services/ChunkRepository.js +230 -0
- package/src/domain/services/CompressionStreams.js +72 -0
- package/src/domain/services/ConvergentEncryption.js +128 -0
- package/src/domain/services/GitTreeBuilder.js +86 -0
- package/src/domain/services/IntegrityVerifier.js +199 -0
- package/src/domain/services/KeyResolver.js +49 -42
- package/src/domain/services/ManifestDiff.js +56 -0
- package/src/domain/services/ManifestRepository.js +286 -0
- package/src/domain/services/PrefetchWindow.js +48 -0
- package/src/domain/services/RecipientService.js +157 -0
- package/src/domain/services/RedactingObservability.js +169 -0
- package/src/domain/services/RestorePipeline.js +68 -0
- package/src/domain/services/StorePipeline.js +201 -0
- package/src/domain/services/VaultKeyVerifier.js +101 -0
- package/src/domain/services/VaultMetadataCodec.js +206 -0
- package/src/domain/services/VaultMutationRetryPolicy.js +105 -0
- package/src/domain/services/VaultPersistence.js +410 -0
- package/src/domain/services/VaultPrivacyIndex.js +191 -0
- package/src/domain/services/VaultService.js +749 -251
- package/src/domain/services/VaultStateCache.js +225 -0
- package/src/domain/services/VaultTreeCodec.js +121 -0
- package/src/domain/services/rotateVaultPassphrase.js +37 -20
- package/src/domain/strategies/Aad.js +39 -0
- package/src/domain/strategies/FramedRecordCodec.js +204 -0
- package/src/domain/strategies/RestoreCompressed.js +40 -0
- package/src/domain/strategies/RestoreConvergent.js +44 -0
- package/src/domain/strategies/RestoreFramed.js +55 -0
- package/src/domain/strategies/RestorePlain.js +37 -0
- package/src/domain/strategies/RestoreStrategy.js +35 -0
- package/src/domain/strategies/RestoreWhole.js +135 -0
- package/src/domain/strategies/StoreConvergent.js +28 -0
- package/src/domain/strategies/StoreFramed.js +39 -0
- package/src/domain/strategies/StorePlain.js +20 -0
- package/src/domain/strategies/StoreStrategy.js +61 -0
- package/src/domain/strategies/StoreWhole.js +34 -0
- package/src/domain/value-objects/Chunk.js +1 -2
- package/src/domain/value-objects/EncryptionMetadata.js +87 -0
- package/src/domain/value-objects/Manifest.d.ts +40 -4
- package/src/domain/value-objects/Manifest.js +61 -20
- package/src/domain/value-objects/Oid.js +45 -0
- package/src/domain/value-objects/Slug.js +124 -0
- package/src/domain/value-objects/StoreEncryptionConfig.js +114 -0
- package/src/helpers/aesGcmMeta.js +55 -0
- package/src/helpers/canonicalBase64.js +1 -0
- package/src/helpers/kdfPolicy.js +194 -0
- package/src/infrastructure/adapters/BunCryptoAdapter.js +124 -8
- package/src/infrastructure/adapters/FileIOHelper.js +178 -13
- package/src/infrastructure/adapters/GitPersistenceAdapter.js +235 -42
- package/src/infrastructure/adapters/GitPlumbingFactoryAdapter.js +62 -0
- package/src/infrastructure/adapters/GitRefAdapter.js +19 -6
- package/src/infrastructure/adapters/NodeCompressionAdapter.js +64 -0
- package/src/infrastructure/adapters/NodeCryptoAdapter.js +130 -10
- package/src/infrastructure/adapters/WebCryptoAdapter.js +187 -77
- package/src/infrastructure/chunkers/CdcChunker.js +53 -19
- package/src/infrastructure/chunkers/FixedChunker.js +15 -7
- package/src/infrastructure/chunkers/resolveChunker.js +3 -1
- package/src/infrastructure/codecs/CborCodec.js +3 -3
- package/src/infrastructure/codecs/JsonCodec.js +5 -5
- package/src/infrastructure/createGitPlumbing.js +22 -0
- package/src/package-version.js +1 -0
- package/src/ports/ChunkingPort.js +3 -3
- package/src/ports/CodecPort.js +4 -4
- package/src/ports/CompressionPort.js +57 -0
- package/src/ports/CryptoPort.js +138 -50
- package/src/ports/GitPersistencePort.js +32 -2
- package/src/ports/GitPlumbingFactoryPort.js +16 -0
- package/src/ports/GitRefPort.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/test/CONVENTIONS.md +94 -0
- package/test/cycles/README.md +13 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { resolveOsKeychainPassphrase } from '../passphrase-source.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {{
|
|
5
|
+
* inlineValue?: unknown,
|
|
6
|
+
* fileValue?: string,
|
|
7
|
+
* osKeychainTarget?: string,
|
|
8
|
+
* }} options
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export function hasAgentPassphraseSource({ inlineValue, fileValue, osKeychainTarget }) {
|
|
12
|
+
return inlineValue !== undefined || fileValue !== undefined || osKeychainTarget !== undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {{
|
|
17
|
+
* inlineValue?: unknown,
|
|
18
|
+
* fileValue?: string,
|
|
19
|
+
* osKeychainTarget?: string,
|
|
20
|
+
* osKeychainAccount?: string,
|
|
21
|
+
* inlineFlag: string,
|
|
22
|
+
* fileFlag: string,
|
|
23
|
+
* keychainTargetFlag: string,
|
|
24
|
+
* keychainAccountFlag: string,
|
|
25
|
+
* label: string,
|
|
26
|
+
* errorFactory?: (message: string) => Error,
|
|
27
|
+
* }} options
|
|
28
|
+
*/
|
|
29
|
+
export function validateAgentPassphraseSource({
|
|
30
|
+
inlineValue,
|
|
31
|
+
fileValue,
|
|
32
|
+
osKeychainTarget,
|
|
33
|
+
osKeychainAccount,
|
|
34
|
+
inlineFlag,
|
|
35
|
+
fileFlag,
|
|
36
|
+
keychainTargetFlag,
|
|
37
|
+
keychainAccountFlag,
|
|
38
|
+
label,
|
|
39
|
+
errorFactory = (message) => new Error(message),
|
|
40
|
+
}) {
|
|
41
|
+
const explicitSources = [
|
|
42
|
+
inlineValue !== undefined,
|
|
43
|
+
fileValue !== undefined,
|
|
44
|
+
osKeychainTarget !== undefined,
|
|
45
|
+
].filter(Boolean).length;
|
|
46
|
+
|
|
47
|
+
if (explicitSources > 1) {
|
|
48
|
+
throw errorFactory(
|
|
49
|
+
`Provide exactly one ${label}: ${inlineFlag}, ${fileFlag}, or ${keychainTargetFlag}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (osKeychainAccount !== undefined && osKeychainTarget === undefined) {
|
|
54
|
+
throw errorFactory(`Provide ${keychainTargetFlag} when using ${keychainAccountFlag}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (osKeychainTarget !== undefined && !String(osKeychainTarget).trim()) {
|
|
58
|
+
throw errorFactory('OS keychain target must not be empty');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (osKeychainAccount !== undefined && !String(osKeychainAccount).trim()) {
|
|
62
|
+
throw errorFactory('OS keychain account must not be empty');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {string} value
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
function lowerFirst(value) {
|
|
71
|
+
return value ? value[0].toLowerCase() + value.slice(1) : value;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {{
|
|
76
|
+
* label: string,
|
|
77
|
+
* inlineValue?: unknown,
|
|
78
|
+
* fileValue?: string,
|
|
79
|
+
* osKeychainTarget?: string,
|
|
80
|
+
* osKeychainAccount?: string,
|
|
81
|
+
* requestSource?: string,
|
|
82
|
+
* readPassphraseFile: (filePath: string) => Promise<string>,
|
|
83
|
+
* resolveInlinePassphrase: (label: string, value: unknown) => string | undefined,
|
|
84
|
+
* resolveOsKeychainPassphrase?: (options: { target: string, account?: string }) => Promise<string>,
|
|
85
|
+
* errorFactory?: (message: string) => Error,
|
|
86
|
+
* }} options
|
|
87
|
+
* @returns {Promise<string | undefined>}
|
|
88
|
+
*/
|
|
89
|
+
export async function resolveAgentPassphraseSource({
|
|
90
|
+
label,
|
|
91
|
+
inlineValue,
|
|
92
|
+
fileValue,
|
|
93
|
+
osKeychainTarget,
|
|
94
|
+
osKeychainAccount,
|
|
95
|
+
requestSource,
|
|
96
|
+
readPassphraseFile,
|
|
97
|
+
resolveInlinePassphrase,
|
|
98
|
+
resolveOsKeychainPassphrase: resolveOsKeychainPassphraseFn = resolveOsKeychainPassphrase,
|
|
99
|
+
errorFactory = (message) => new Error(message),
|
|
100
|
+
}) {
|
|
101
|
+
if (fileValue === '-' && requestSource === '-') {
|
|
102
|
+
throw errorFactory(
|
|
103
|
+
`Cannot read both request payload and ${lowerFirst(label)} from stdin`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (fileValue) {
|
|
108
|
+
return await readPassphraseFile(fileValue);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (inlineValue !== undefined) {
|
|
112
|
+
return resolveInlinePassphrase(label, inlineValue);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (osKeychainTarget !== undefined) {
|
|
116
|
+
return await resolveOsKeychainPassphraseFn({
|
|
117
|
+
target: osKeychainTarget,
|
|
118
|
+
account: osKeychainAccount,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { HINTS } from '../actions.js';
|
|
2
|
+
|
|
3
|
+
export const AGENT_PROTOCOL = 'git-cas-agent/v1';
|
|
4
|
+
|
|
5
|
+
export const AGENT_EXIT_CODES = Object.freeze({
|
|
6
|
+
SUCCESS: 0,
|
|
7
|
+
FAILURE: 1,
|
|
8
|
+
INVALID_INPUT: 2,
|
|
9
|
+
VERIFICATION_FAILED: 3,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Map an operational error to an agent exit code.
|
|
14
|
+
*
|
|
15
|
+
* @param {unknown} err
|
|
16
|
+
* @returns {number}
|
|
17
|
+
*/
|
|
18
|
+
export function getAgentExitCode(err) {
|
|
19
|
+
const code = getErrorCode(err);
|
|
20
|
+
|
|
21
|
+
if (code === 'INVALID_INPUT' || code === 'NEEDS_INPUT') {
|
|
22
|
+
return AGENT_EXIT_CODES.INVALID_INPUT;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (code === 'INTEGRITY_ERROR') {
|
|
26
|
+
return AGENT_EXIT_CODES.VERIFICATION_FAILED;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return AGENT_EXIT_CODES.FAILURE;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Normalize an error into the JSONL protocol shape.
|
|
34
|
+
*
|
|
35
|
+
* @param {unknown} err
|
|
36
|
+
* @returns {{ code: string, message: string, retryable: boolean, documentationUrl?: string, hint?: string, meta?: Record<string, any> }}
|
|
37
|
+
*/
|
|
38
|
+
export function normalizeAgentError(err) {
|
|
39
|
+
const code = getErrorCode(err) || 'ERROR';
|
|
40
|
+
const message = getErrorMessage(err);
|
|
41
|
+
const retryable = getErrorRetryable(err);
|
|
42
|
+
|
|
43
|
+
/** @type {{ code: string, message: string, retryable: boolean, documentationUrl?: string, hint?: string, meta?: Record<string, any> }} */
|
|
44
|
+
const data = { code, message, retryable };
|
|
45
|
+
const documentationUrl = getDocumentationUrl(err);
|
|
46
|
+
if (documentationUrl) {
|
|
47
|
+
data.documentationUrl = documentationUrl;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(HINTS, code)) {
|
|
51
|
+
data.hint = HINTS[code];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const meta = getErrorMeta(err);
|
|
55
|
+
if (meta) {
|
|
56
|
+
data.meta = meta;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Normalize a needs-input branch into the JSONL protocol shape.
|
|
64
|
+
*
|
|
65
|
+
* @param {unknown} err
|
|
66
|
+
* @returns {{ code: string, message: string } & Record<string, any>}
|
|
67
|
+
*/
|
|
68
|
+
export function normalizeAgentNeedsInput(err) {
|
|
69
|
+
const code = getErrorCode(err) || 'NEEDS_INPUT';
|
|
70
|
+
const message = getErrorMessage(err);
|
|
71
|
+
const meta = getErrorMeta(err);
|
|
72
|
+
|
|
73
|
+
return meta ? { code, message, ...meta } : { code, message };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {unknown} err
|
|
78
|
+
* @returns {string | undefined}
|
|
79
|
+
*/
|
|
80
|
+
function getErrorCode(err) {
|
|
81
|
+
if (typeof err === 'object' && err && typeof err.code === 'string') {
|
|
82
|
+
return err.code;
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {unknown} err
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
function getErrorMessage(err) {
|
|
92
|
+
return err instanceof Error ? err.message : String(err);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {unknown} err
|
|
97
|
+
* @returns {boolean}
|
|
98
|
+
*/
|
|
99
|
+
function getErrorRetryable(err) {
|
|
100
|
+
if (typeof err === 'object' && err && typeof err.retryable === 'boolean') {
|
|
101
|
+
return err.retryable;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {unknown} err
|
|
108
|
+
* @returns {string | undefined}
|
|
109
|
+
*/
|
|
110
|
+
function getDocumentationUrl(err) {
|
|
111
|
+
if (typeof err === 'object' && err && typeof err.documentationUrl === 'string') {
|
|
112
|
+
return err.documentationUrl;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @param {unknown} err
|
|
119
|
+
* @returns {Record<string, any> | undefined}
|
|
120
|
+
*/
|
|
121
|
+
function getErrorMeta(err) {
|
|
122
|
+
if (
|
|
123
|
+
typeof err === 'object' &&
|
|
124
|
+
err &&
|
|
125
|
+
err.meta &&
|
|
126
|
+
typeof err.meta === 'object' &&
|
|
127
|
+
!Array.isArray(err.meta)
|
|
128
|
+
) {
|
|
129
|
+
return err.meta;
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Create a JSONL session writer for the agent protocol.
|
|
136
|
+
*
|
|
137
|
+
* @param {{
|
|
138
|
+
* command: string,
|
|
139
|
+
* stdout?: Pick<NodeJS.WriteStream, 'write'>,
|
|
140
|
+
* stderr?: Pick<NodeJS.WriteStream, 'write'>,
|
|
141
|
+
* now?: () => Date,
|
|
142
|
+
* }} options
|
|
143
|
+
*/
|
|
144
|
+
export function createAgentSession({
|
|
145
|
+
command,
|
|
146
|
+
stdout = process.stdout,
|
|
147
|
+
stderr = process.stderr,
|
|
148
|
+
now = () => new Date(),
|
|
149
|
+
}) {
|
|
150
|
+
let seq = 0;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @param {Pick<NodeJS.WriteStream, 'write'>} stream
|
|
154
|
+
* @param {string} type
|
|
155
|
+
* @param {Record<string, any>} data
|
|
156
|
+
*/
|
|
157
|
+
function write(stream, type, data) {
|
|
158
|
+
seq += 1;
|
|
159
|
+
const row = {
|
|
160
|
+
protocol: AGENT_PROTOCOL,
|
|
161
|
+
command,
|
|
162
|
+
type,
|
|
163
|
+
seq,
|
|
164
|
+
ts: now().toISOString(),
|
|
165
|
+
data,
|
|
166
|
+
};
|
|
167
|
+
stream.write(`${JSON.stringify(row)}\n`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
writeStart(data = {}) {
|
|
172
|
+
write(stdout, 'start', data);
|
|
173
|
+
},
|
|
174
|
+
writeProgress(data) {
|
|
175
|
+
write(stdout, 'progress', data);
|
|
176
|
+
},
|
|
177
|
+
writeResult(data) {
|
|
178
|
+
write(stdout, 'result', data);
|
|
179
|
+
},
|
|
180
|
+
writeEnd(data) {
|
|
181
|
+
write(stdout, 'end', data);
|
|
182
|
+
},
|
|
183
|
+
writeWarning(data) {
|
|
184
|
+
write(stderr, 'warning', data);
|
|
185
|
+
},
|
|
186
|
+
writeNeedsInput(err) {
|
|
187
|
+
write(stderr, 'needs-input', normalizeAgentNeedsInput(err));
|
|
188
|
+
},
|
|
189
|
+
writeError(err) {
|
|
190
|
+
write(stderr, 'error', normalizeAgentError(err));
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Resolves the full version string: semver + git SHA.
|
|
3
|
+
*
|
|
4
|
+
* In development (git repo present): reads SHA from git at runtime.
|
|
5
|
+
* In published packages: reads SHA from build-info.json (stamped at publish time).
|
|
6
|
+
* Fallback: version only, no SHA.
|
|
7
|
+
*/
|
|
8
|
+
import { execSync } from 'node:child_process';
|
|
9
|
+
import { readFileSync } from 'node:fs';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
|
|
13
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Reads the git SHA from build-info.json (published package).
|
|
17
|
+
* @returns {string|null}
|
|
18
|
+
*/
|
|
19
|
+
export function readStampedSha() {
|
|
20
|
+
try {
|
|
21
|
+
const info = JSON.parse(
|
|
22
|
+
readFileSync(path.resolve(__dirname, '../build-info.json'), 'utf8'),
|
|
23
|
+
);
|
|
24
|
+
return info.sha || null;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Reads the git SHA from the live repo (development).
|
|
32
|
+
* @returns {string|null}
|
|
33
|
+
*/
|
|
34
|
+
export function readGitSha() {
|
|
35
|
+
try {
|
|
36
|
+
return execSync('git rev-parse --short HEAD', {
|
|
37
|
+
encoding: 'utf8',
|
|
38
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
39
|
+
}).trim();
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns the full version string: `<semver>+<sha>` or just `<semver>`.
|
|
47
|
+
* @param {string} semver - The package version from package.json.
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
export function resolveVersionString(
|
|
51
|
+
semver,
|
|
52
|
+
{ readGitSha: readGit = readGitSha, readStampedSha: readStamped = readStampedSha } = {}
|
|
53
|
+
) {
|
|
54
|
+
const sha = normalizeSha(readGit()) || normalizeSha(readStamped());
|
|
55
|
+
return sha ? `${semver}+${sha}` : semver;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {string|null} sha
|
|
60
|
+
* @returns {string|null}
|
|
61
|
+
*/
|
|
62
|
+
function normalizeSha(sha) {
|
|
63
|
+
return sha === 'unknown' ? null : sha;
|
|
64
|
+
}
|