zephyr-agent
Version:
Zephyr plugin agent
133 lines (132 loc) • 6.81 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.d = (exports1, getters, values)=>{
var define = (defs, kind)=>{
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
[kind]: defs[key]
});
};
define(getters, "get");
define(values, "value");
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
readAttributionConfig: ()=>readAttributionConfig,
validateAttributionConfig: ()=>validateAttributionConfig,
writeAttributionConfig: ()=>writeAttributionConfig
});
const external_node_fs_namespaceObject = require("node:fs");
const external_node_crypto_namespaceObject = require("node:crypto");
const external_node_path_namespaceObject = require("node:path");
function object(value) {
return Boolean(value && 'object' == typeof value && !Array.isArray(value));
}
function validateAttributionConfig(value) {
if (!object(value) || Object.keys(value).some((key)=>![
'schemaVersion',
'enabled',
'storage',
'repositoryId',
'content',
'gitAiPath',
'exclude'
].includes(key)) || 1 !== value['schemaVersion'] || 'boolean' != typeof value['enabled'] || void 0 !== value['storage'] && ('string' != typeof value['storage'] || ![
'local',
'remote'
].includes(value['storage'])) || void 0 !== value['repositoryId'] && ('string' != typeof value['repositoryId'] || !/^[a-zA-Z0-9._-]{1,128}$/.test(value['repositoryId'])) || void 0 !== value['gitAiPath'] && 'string' != typeof value['gitAiPath'] || void 0 !== value['exclude'] && (!Array.isArray(value['exclude']) || value['exclude'].some((prefix)=>'string' != typeof prefix || !prefix)) || void 0 !== value['content'] && (!object(value['content']) || Object.entries(value['content']).some(([key, flag])=>![
'patch',
'lines'
].includes(key) || 'boolean' != typeof flag))) throw new Error('Invalid attribution configuration; store only repository preferences, never credentials, URLs, or account tier');
}
function readJson(filename) {
if ((0, external_node_fs_namespaceObject.lstatSync)(filename).isSymbolicLink()) throw new Error('Attribution configuration cannot be a symlink');
try {
return JSON.parse((0, external_node_fs_namespaceObject.readFileSync)(filename, 'utf8'));
} catch {
throw new Error('Invalid attribution configuration JSON');
}
}
function readAttributionConfig(root, gitDir) {
const filename = (0, external_node_path_namespaceObject.join)(root, '.zephyr/attribution.json');
if (!(0, external_node_fs_namespaceObject.existsSync)(filename)) return;
const config = readJson(filename);
validateAttributionConfig(config);
if (!gitDir) return config;
const local = (0, external_node_path_namespaceObject.join)(gitDir, 'zephyr-attribution/config.local.json');
if (!(0, external_node_fs_namespaceObject.existsSync)(local)) return config;
const override = readJson(local);
if (!object(override) || Object.keys(override).some((key)=>![
'storage',
'content'
].includes(key)) || void 0 !== override['storage'] && 'local' !== override['storage'] || void 0 !== override['content'] && (!object(override['content']) || Object.entries(override['content']).some(([key, flag])=>![
'patch',
'lines'
].includes(key) || false !== flag))) throw new Error('Private attribution overrides may only choose local storage or omit content');
return {
...config,
...override['storage'] ? {
storage: 'local'
} : {},
content: {
...config.content,
...override['content']
}
};
}
function writeAttributionConfig(root, gitDir, config, privateOverride = false) {
validateAttributionConfig(config);
if (privateOverride && ('local' !== config.storage || Object.values(config.content ?? {}).some((value)=>false !== value))) throw new Error('Private overrides may only select local storage and omit content');
const filename = privateOverride ? (0, external_node_path_namespaceObject.join)(gitDir, 'zephyr-attribution/config.local.json') : (0, external_node_path_namespaceObject.join)(root, '.zephyr/attribution.json');
const directory = (0, external_node_path_namespaceObject.dirname)(filename);
if ((0, external_node_fs_namespaceObject.existsSync)(directory) && (0, external_node_fs_namespaceObject.lstatSync)(directory).isSymbolicLink()) throw new Error('Attribution configuration directory cannot be a symlink');
(0, external_node_fs_namespaceObject.mkdirSync)(directory, {
recursive: true,
mode: privateOverride ? 448 : 493
});
if ((0, external_node_fs_namespaceObject.existsSync)(filename) && (0, external_node_fs_namespaceObject.lstatSync)(filename).isSymbolicLink()) throw new Error('Attribution configuration cannot be a symlink');
const temporary = (0, external_node_path_namespaceObject.join)(directory, `.config-${(0, external_node_crypto_namespaceObject.randomUUID)()}.tmp`);
try {
const value = privateOverride ? {
storage: config.storage,
content: config.content
} : config;
(0, external_node_fs_namespaceObject.writeFileSync)(temporary, JSON.stringify(value, null, 2) + '\n', {
flag: 'wx',
mode: 384
});
(0, external_node_fs_namespaceObject.renameSync)(temporary, filename);
} finally{
(0, external_node_fs_namespaceObject.rmSync)(temporary, {
force: true
});
}
}
exports.readAttributionConfig = __webpack_exports__.readAttributionConfig;
exports.validateAttributionConfig = __webpack_exports__.validateAttributionConfig;
exports.writeAttributionConfig = __webpack_exports__.writeAttributionConfig;
for(var __rspack_i in __webpack_exports__)if (-1 === [
"readAttributionConfig",
"validateAttributionConfig",
"writeAttributionConfig"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
value: true
});
//# sourceMappingURL=config.js.map