shiva-code 0.3.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{github-R3I7U2DQ.js → api-MT23KCO3.js} +3 -2
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/{chunk-G2G6UUWM.js → chunk-6RAACMKF.js} +1 -1
- package/dist/chunk-PMA6MGQW.js +604 -0
- package/dist/{chunk-MDMZWOX7.js → chunk-TI6Y3VT4.js} +2 -2
- package/dist/{chunk-GHAT2D55.js → chunk-TQ6O4QB6.js} +2 -2
- package/dist/{chunk-66D4NGIK.js → chunk-ZDLLPNCK.js} +2 -2
- package/dist/config-D6M6LI6U.js +83 -0
- package/dist/index.js +12565 -4196
- package/dist/{session-manager-THTEDIUG.js → manager-TQIASXKY.js} +3 -2
- package/dist/{package-manager-OOJUNEKG.js → package-manager-NARG55B5.js} +4 -3
- package/package.json +2 -1
- package/dist/chunk-4GL27U2Z.js +0 -174
- package/dist/chunk-KXYP4OCK.js +0 -236
- package/dist/project-config-GELL5QUH.js +0 -40
- package/dist/tags-P6L3BWO7.js +0 -28
|
@@ -21,8 +21,9 @@ import {
|
|
|
21
21
|
parseGitHubUrl,
|
|
22
22
|
runGh,
|
|
23
23
|
runGhRaw
|
|
24
|
-
} from "./chunk-
|
|
25
|
-
import "./chunk-
|
|
24
|
+
} from "./chunk-ZDLLPNCK.js";
|
|
25
|
+
import "./chunk-6RAACMKF.js";
|
|
26
|
+
import "./chunk-3RG5ZIWI.js";
|
|
26
27
|
export {
|
|
27
28
|
findMentionedIssueNumbers,
|
|
28
29
|
formatContextAsMarkdown,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__require
|
|
10
|
+
};
|
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
// src/services/project/config.ts
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
|
|
5
|
+
// src/types/security.ts
|
|
6
|
+
var SECURITY_PRESETS = {
|
|
7
|
+
beginner: {
|
|
8
|
+
skipPermissions: false,
|
|
9
|
+
approvalStrategy: "manual",
|
|
10
|
+
dockerIsolation: true,
|
|
11
|
+
require2FA: false,
|
|
12
|
+
timeRestrictions: false
|
|
13
|
+
},
|
|
14
|
+
standard: {
|
|
15
|
+
skipPermissions: true,
|
|
16
|
+
approvalStrategy: "hybrid",
|
|
17
|
+
dockerIsolation: false,
|
|
18
|
+
require2FA: false,
|
|
19
|
+
timeRestrictions: false
|
|
20
|
+
},
|
|
21
|
+
strict: {
|
|
22
|
+
skipPermissions: false,
|
|
23
|
+
approvalStrategy: "manual",
|
|
24
|
+
dockerIsolation: true,
|
|
25
|
+
require2FA: true,
|
|
26
|
+
timeRestrictions: true
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var DEFAULT_SESSION_TIME_CONFIG = {
|
|
30
|
+
enabled: false,
|
|
31
|
+
allowedHours: { start: "09:00", end: "18:00" },
|
|
32
|
+
allowedDays: [1, 2, 3, 4, 5],
|
|
33
|
+
// Monday to Friday
|
|
34
|
+
timezone: "Europe/Berlin"
|
|
35
|
+
};
|
|
36
|
+
var DEFAULT_SESSION_LIMITS = {
|
|
37
|
+
maxDurationMinutes: null,
|
|
38
|
+
maxTokens: null,
|
|
39
|
+
warningThreshold: 0.8
|
|
40
|
+
};
|
|
41
|
+
var DEFAULT_SESSION_BUDGET = {
|
|
42
|
+
dailyTokenLimit: null,
|
|
43
|
+
weeklyTokenLimit: null,
|
|
44
|
+
monthlyTokenLimit: null,
|
|
45
|
+
currentUsage: {
|
|
46
|
+
daily: 0,
|
|
47
|
+
weekly: 0,
|
|
48
|
+
monthly: 0,
|
|
49
|
+
lastReset: {
|
|
50
|
+
daily: (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
51
|
+
weekly: (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
52
|
+
monthly: (/* @__PURE__ */ new Date()).toISOString().split("T")[0]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var DEFAULT_PERMISSION_CONFIG = {
|
|
57
|
+
skipPermissions: "inherit",
|
|
58
|
+
allowedTools: "all",
|
|
59
|
+
blockedTools: [],
|
|
60
|
+
allowedPaths: [],
|
|
61
|
+
blockedPaths: [".env", "secrets/"]
|
|
62
|
+
};
|
|
63
|
+
var DEFAULT_APPROVAL_CONFIG = {
|
|
64
|
+
strategy: "hybrid",
|
|
65
|
+
thresholds: {
|
|
66
|
+
autoApproveMaxFiles: 5,
|
|
67
|
+
autoApproveMaxLines: 200,
|
|
68
|
+
requireApprovalPatterns: ["*.secret"],
|
|
69
|
+
skipApprovalPatterns: ["*.test.ts"]
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var DEFAULT_PROJECT_DOCKER_CONFIG = {
|
|
73
|
+
enabled: "inherit",
|
|
74
|
+
image: "default",
|
|
75
|
+
network: "bridge",
|
|
76
|
+
resources: {
|
|
77
|
+
cpuLimit: null,
|
|
78
|
+
memoryLimit: null
|
|
79
|
+
},
|
|
80
|
+
mounts: [],
|
|
81
|
+
environment: {},
|
|
82
|
+
securityOpts: []
|
|
83
|
+
};
|
|
84
|
+
var DEFAULT_ANALYTICS_CONFIG = {
|
|
85
|
+
enabled: true,
|
|
86
|
+
collectTokenUsage: true,
|
|
87
|
+
collectSessionHistory: true,
|
|
88
|
+
retentionDays: 90
|
|
89
|
+
};
|
|
90
|
+
var DEFAULT_SECURITY_CONFIG = {
|
|
91
|
+
tier: "standard",
|
|
92
|
+
permissions: DEFAULT_PERMISSION_CONFIG,
|
|
93
|
+
approval: DEFAULT_APPROVAL_CONFIG,
|
|
94
|
+
require2FA: false
|
|
95
|
+
};
|
|
96
|
+
var DEFAULT_PROJECT_CONFIG_V2 = {
|
|
97
|
+
version: 2,
|
|
98
|
+
autoInjectContext: true,
|
|
99
|
+
branchSessions: {},
|
|
100
|
+
security: DEFAULT_SECURITY_CONFIG,
|
|
101
|
+
session: {
|
|
102
|
+
timeControl: DEFAULT_SESSION_TIME_CONFIG,
|
|
103
|
+
limits: DEFAULT_SESSION_LIMITS,
|
|
104
|
+
budget: DEFAULT_SESSION_BUDGET
|
|
105
|
+
},
|
|
106
|
+
docker: DEFAULT_PROJECT_DOCKER_CONFIG,
|
|
107
|
+
analytics: DEFAULT_ANALYTICS_CONFIG
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/services/project/config.ts
|
|
111
|
+
var SHIVA_DIR = ".shiva";
|
|
112
|
+
var CONFIG_FILE = "config.json";
|
|
113
|
+
var SESSIONS_DIR = "sessions";
|
|
114
|
+
var CONTEXT_DIR = "context";
|
|
115
|
+
var ANALYTICS_DIR = "analytics";
|
|
116
|
+
var GITHUB_CONTEXT_FILE = "github.md";
|
|
117
|
+
var DEFAULT_CONFIG = {
|
|
118
|
+
version: 1,
|
|
119
|
+
autoInjectContext: true,
|
|
120
|
+
branchSessions: {}
|
|
121
|
+
};
|
|
122
|
+
function getShivaDir(projectPath) {
|
|
123
|
+
return path.join(projectPath, SHIVA_DIR);
|
|
124
|
+
}
|
|
125
|
+
function getConfigPath(projectPath) {
|
|
126
|
+
return path.join(getShivaDir(projectPath), CONFIG_FILE);
|
|
127
|
+
}
|
|
128
|
+
function getSessionsDir(projectPath) {
|
|
129
|
+
return path.join(getShivaDir(projectPath), SESSIONS_DIR);
|
|
130
|
+
}
|
|
131
|
+
function getContextDir(projectPath) {
|
|
132
|
+
return path.join(getShivaDir(projectPath), CONTEXT_DIR);
|
|
133
|
+
}
|
|
134
|
+
function hasShivaDir(projectPath) {
|
|
135
|
+
return fs.existsSync(getShivaDir(projectPath));
|
|
136
|
+
}
|
|
137
|
+
function initShivaDir(projectPath) {
|
|
138
|
+
const shivaDir = getShivaDir(projectPath);
|
|
139
|
+
const sessionsDir = getSessionsDir(projectPath);
|
|
140
|
+
const contextDir = getContextDir(projectPath);
|
|
141
|
+
if (!fs.existsSync(shivaDir)) {
|
|
142
|
+
fs.mkdirSync(shivaDir, { recursive: true });
|
|
143
|
+
}
|
|
144
|
+
if (!fs.existsSync(sessionsDir)) {
|
|
145
|
+
fs.mkdirSync(sessionsDir, { recursive: true });
|
|
146
|
+
}
|
|
147
|
+
if (!fs.existsSync(contextDir)) {
|
|
148
|
+
fs.mkdirSync(contextDir, { recursive: true });
|
|
149
|
+
}
|
|
150
|
+
const configPath = getConfigPath(projectPath);
|
|
151
|
+
if (!fs.existsSync(configPath)) {
|
|
152
|
+
fs.writeFileSync(configPath, JSON.stringify(DEFAULT_CONFIG, null, 2), "utf-8");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function addToGitignore(projectPath) {
|
|
156
|
+
const gitignorePath = path.join(projectPath, ".gitignore");
|
|
157
|
+
let content = "";
|
|
158
|
+
if (fs.existsSync(gitignorePath)) {
|
|
159
|
+
content = fs.readFileSync(gitignorePath, "utf-8");
|
|
160
|
+
if (content.includes(".shiva") || content.includes("/.shiva")) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const newEntry = "\n# SHIVA Code local config\n.shiva/\n";
|
|
165
|
+
fs.writeFileSync(gitignorePath, content + newEntry, "utf-8");
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
function removeFromGitignore(projectPath) {
|
|
169
|
+
const gitignorePath = path.join(projectPath, ".gitignore");
|
|
170
|
+
if (!fs.existsSync(gitignorePath)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
let content = fs.readFileSync(gitignorePath, "utf-8");
|
|
174
|
+
const lines = content.split("\n");
|
|
175
|
+
const filtered = lines.filter((line) => {
|
|
176
|
+
const trimmed = line.trim();
|
|
177
|
+
return trimmed !== ".shiva/" && trimmed !== ".shiva" && trimmed !== "/.shiva/";
|
|
178
|
+
});
|
|
179
|
+
const finalLines = filtered.filter((line, i, arr) => {
|
|
180
|
+
return !(line.includes("# SHIVA Code") && arr[i + 1]?.trim() === "");
|
|
181
|
+
});
|
|
182
|
+
const newContent = finalLines.join("\n");
|
|
183
|
+
if (newContent !== content) {
|
|
184
|
+
fs.writeFileSync(gitignorePath, newContent, "utf-8");
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
function getProjectConfig(projectPath) {
|
|
190
|
+
const configPath = getConfigPath(projectPath);
|
|
191
|
+
if (!fs.existsSync(configPath)) {
|
|
192
|
+
return { ...DEFAULT_CONFIG };
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
const content = fs.readFileSync(configPath, "utf-8");
|
|
196
|
+
const config = JSON.parse(content);
|
|
197
|
+
return { ...DEFAULT_CONFIG, ...config };
|
|
198
|
+
} catch {
|
|
199
|
+
return { ...DEFAULT_CONFIG };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function saveProjectConfig(projectPath, config) {
|
|
203
|
+
initShivaDir(projectPath);
|
|
204
|
+
const configPath = getConfigPath(projectPath);
|
|
205
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
206
|
+
}
|
|
207
|
+
function updateProjectConfig(projectPath, updates) {
|
|
208
|
+
const current = getProjectConfig(projectPath);
|
|
209
|
+
const updated = { ...current, ...updates };
|
|
210
|
+
saveProjectConfig(projectPath, updated);
|
|
211
|
+
return updated;
|
|
212
|
+
}
|
|
213
|
+
function sanitizeBranchName(branch) {
|
|
214
|
+
return branch.replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
215
|
+
}
|
|
216
|
+
function mapBranchToSession(projectPath, branch, sessionId, metadata) {
|
|
217
|
+
initShivaDir(projectPath);
|
|
218
|
+
const config = getProjectConfig(projectPath);
|
|
219
|
+
config.branchSessions[branch] = {
|
|
220
|
+
branch,
|
|
221
|
+
sessionId,
|
|
222
|
+
lastAccessed: (/* @__PURE__ */ new Date()).toISOString(),
|
|
223
|
+
...metadata
|
|
224
|
+
};
|
|
225
|
+
saveProjectConfig(projectPath, config);
|
|
226
|
+
const sessionsDir = getSessionsDir(projectPath);
|
|
227
|
+
const sessionFile = path.join(sessionsDir, `${sanitizeBranchName(branch)}.json`);
|
|
228
|
+
fs.writeFileSync(
|
|
229
|
+
sessionFile,
|
|
230
|
+
JSON.stringify(config.branchSessions[branch], null, 2),
|
|
231
|
+
"utf-8"
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
function getSessionForBranch(projectPath, branch) {
|
|
235
|
+
const config = getProjectConfig(projectPath);
|
|
236
|
+
if (config.branchSessions[branch]) {
|
|
237
|
+
return config.branchSessions[branch];
|
|
238
|
+
}
|
|
239
|
+
const sessionsDir = getSessionsDir(projectPath);
|
|
240
|
+
const sessionFile = path.join(sessionsDir, `${sanitizeBranchName(branch)}.json`);
|
|
241
|
+
if (fs.existsSync(sessionFile)) {
|
|
242
|
+
try {
|
|
243
|
+
const content = fs.readFileSync(sessionFile, "utf-8");
|
|
244
|
+
return JSON.parse(content);
|
|
245
|
+
} catch {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
function getAllBranchSessions(projectPath) {
|
|
252
|
+
const config = getProjectConfig(projectPath);
|
|
253
|
+
return config.branchSessions || {};
|
|
254
|
+
}
|
|
255
|
+
function updateBranchSession(projectPath, branch, updates) {
|
|
256
|
+
const existing = getSessionForBranch(projectPath, branch);
|
|
257
|
+
if (!existing) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
mapBranchToSession(projectPath, branch, existing.sessionId, {
|
|
261
|
+
...existing,
|
|
262
|
+
...updates,
|
|
263
|
+
lastAccessed: (/* @__PURE__ */ new Date()).toISOString()
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function removeBranchSession(projectPath, branch) {
|
|
267
|
+
const config = getProjectConfig(projectPath);
|
|
268
|
+
if (config.branchSessions[branch]) {
|
|
269
|
+
delete config.branchSessions[branch];
|
|
270
|
+
saveProjectConfig(projectPath, config);
|
|
271
|
+
}
|
|
272
|
+
const sessionsDir = getSessionsDir(projectPath);
|
|
273
|
+
const sessionFile = path.join(sessionsDir, `${sanitizeBranchName(branch)}.json`);
|
|
274
|
+
if (fs.existsSync(sessionFile)) {
|
|
275
|
+
fs.unlinkSync(sessionFile);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function cacheGitHubContext(projectPath, context) {
|
|
279
|
+
initShivaDir(projectPath);
|
|
280
|
+
const contextDir = getContextDir(projectPath);
|
|
281
|
+
const contextFile = path.join(contextDir, GITHUB_CONTEXT_FILE);
|
|
282
|
+
fs.writeFileSync(contextFile, context, "utf-8");
|
|
283
|
+
return contextFile;
|
|
284
|
+
}
|
|
285
|
+
function getCachedGitHubContext(projectPath) {
|
|
286
|
+
const contextDir = getContextDir(projectPath);
|
|
287
|
+
const contextFile = path.join(contextDir, GITHUB_CONTEXT_FILE);
|
|
288
|
+
if (!fs.existsSync(contextFile)) {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
return fs.readFileSync(contextFile, "utf-8");
|
|
293
|
+
} catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function getContextCacheAge(projectPath) {
|
|
298
|
+
const contextDir = getContextDir(projectPath);
|
|
299
|
+
const contextFile = path.join(contextDir, GITHUB_CONTEXT_FILE);
|
|
300
|
+
if (!fs.existsSync(contextFile)) {
|
|
301
|
+
return Infinity;
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
const stats = fs.statSync(contextFile);
|
|
305
|
+
const ageMs = Date.now() - stats.mtimeMs;
|
|
306
|
+
return Math.floor(ageMs / (1e3 * 60));
|
|
307
|
+
} catch {
|
|
308
|
+
return Infinity;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function clearContextCache(projectPath) {
|
|
312
|
+
const contextDir = getContextDir(projectPath);
|
|
313
|
+
const contextFile = path.join(contextDir, GITHUB_CONTEXT_FILE);
|
|
314
|
+
if (fs.existsSync(contextFile)) {
|
|
315
|
+
fs.unlinkSync(contextFile);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function removeShivaDir(projectPath) {
|
|
319
|
+
const shivaDir = getShivaDir(projectPath);
|
|
320
|
+
if (fs.existsSync(shivaDir)) {
|
|
321
|
+
fs.rmSync(shivaDir, { recursive: true, force: true });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function getAnalyticsDir(projectPath) {
|
|
325
|
+
return path.join(getShivaDir(projectPath), ANALYTICS_DIR);
|
|
326
|
+
}
|
|
327
|
+
function migrateToV2(v1Config) {
|
|
328
|
+
return {
|
|
329
|
+
...DEFAULT_PROJECT_CONFIG_V2,
|
|
330
|
+
version: 2,
|
|
331
|
+
githubRepo: v1Config.githubRepo,
|
|
332
|
+
defaultBranch: v1Config.defaultBranch,
|
|
333
|
+
autoInjectContext: v1Config.autoInjectContext,
|
|
334
|
+
branchSessions: v1Config.branchSessions
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function isV2Config(config) {
|
|
338
|
+
return config.version === 2;
|
|
339
|
+
}
|
|
340
|
+
function getProjectConfigV2(projectPath) {
|
|
341
|
+
const configPath = path.join(getShivaDir(projectPath), CONFIG_FILE);
|
|
342
|
+
if (!fs.existsSync(configPath)) {
|
|
343
|
+
return { ...DEFAULT_PROJECT_CONFIG_V2 };
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
const content = fs.readFileSync(configPath, "utf-8");
|
|
347
|
+
const config = JSON.parse(content);
|
|
348
|
+
if (!config.version || config.version === 1) {
|
|
349
|
+
const v2Config = migrateToV2(config);
|
|
350
|
+
saveProjectConfigV2(projectPath, v2Config);
|
|
351
|
+
return v2Config;
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
...DEFAULT_PROJECT_CONFIG_V2,
|
|
355
|
+
...config,
|
|
356
|
+
security: { ...DEFAULT_SECURITY_CONFIG, ...config.security },
|
|
357
|
+
session: {
|
|
358
|
+
timeControl: { ...DEFAULT_SESSION_TIME_CONFIG, ...config.session?.timeControl },
|
|
359
|
+
limits: { ...DEFAULT_SESSION_LIMITS, ...config.session?.limits },
|
|
360
|
+
budget: { ...DEFAULT_SESSION_BUDGET, ...config.session?.budget }
|
|
361
|
+
},
|
|
362
|
+
docker: { ...DEFAULT_PROJECT_DOCKER_CONFIG, ...config.docker },
|
|
363
|
+
analytics: { ...DEFAULT_ANALYTICS_CONFIG, ...config.analytics }
|
|
364
|
+
};
|
|
365
|
+
} catch {
|
|
366
|
+
return { ...DEFAULT_PROJECT_CONFIG_V2 };
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function saveProjectConfigV2(projectPath, config) {
|
|
370
|
+
initShivaDir(projectPath);
|
|
371
|
+
const analyticsDir = getAnalyticsDir(projectPath);
|
|
372
|
+
if (!fs.existsSync(analyticsDir)) {
|
|
373
|
+
fs.mkdirSync(analyticsDir, { recursive: true });
|
|
374
|
+
}
|
|
375
|
+
const configPath = path.join(getShivaDir(projectPath), CONFIG_FILE);
|
|
376
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
377
|
+
}
|
|
378
|
+
function updateProjectConfigV2(projectPath, updates) {
|
|
379
|
+
const current = getProjectConfigV2(projectPath);
|
|
380
|
+
const updated = { ...current, ...updates };
|
|
381
|
+
saveProjectConfigV2(projectPath, updated);
|
|
382
|
+
return updated;
|
|
383
|
+
}
|
|
384
|
+
function getSessionConfig(projectPath) {
|
|
385
|
+
const config = getProjectConfigV2(projectPath);
|
|
386
|
+
return config.session;
|
|
387
|
+
}
|
|
388
|
+
function updateTimeControl(projectPath, updates) {
|
|
389
|
+
const config = getProjectConfigV2(projectPath);
|
|
390
|
+
const updated = {
|
|
391
|
+
...config.session.timeControl,
|
|
392
|
+
...updates
|
|
393
|
+
};
|
|
394
|
+
saveProjectConfigV2(projectPath, {
|
|
395
|
+
...config,
|
|
396
|
+
session: {
|
|
397
|
+
...config.session,
|
|
398
|
+
timeControl: updated
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
return updated;
|
|
402
|
+
}
|
|
403
|
+
function updateSessionLimits(projectPath, updates) {
|
|
404
|
+
const config = getProjectConfigV2(projectPath);
|
|
405
|
+
const updated = {
|
|
406
|
+
...config.session.limits,
|
|
407
|
+
...updates
|
|
408
|
+
};
|
|
409
|
+
saveProjectConfigV2(projectPath, {
|
|
410
|
+
...config,
|
|
411
|
+
session: {
|
|
412
|
+
...config.session,
|
|
413
|
+
limits: updated
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
return updated;
|
|
417
|
+
}
|
|
418
|
+
function updateSessionBudget(projectPath, updates) {
|
|
419
|
+
const config = getProjectConfigV2(projectPath);
|
|
420
|
+
const updated = {
|
|
421
|
+
...config.session.budget,
|
|
422
|
+
...updates,
|
|
423
|
+
currentUsage: {
|
|
424
|
+
...config.session.budget.currentUsage,
|
|
425
|
+
...updates.currentUsage,
|
|
426
|
+
lastReset: {
|
|
427
|
+
...config.session.budget.currentUsage.lastReset,
|
|
428
|
+
...updates.currentUsage?.lastReset
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
saveProjectConfigV2(projectPath, {
|
|
433
|
+
...config,
|
|
434
|
+
session: {
|
|
435
|
+
...config.session,
|
|
436
|
+
budget: updated
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
return updated;
|
|
440
|
+
}
|
|
441
|
+
function resetSessionBudget(projectPath) {
|
|
442
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
443
|
+
return updateSessionBudget(projectPath, {
|
|
444
|
+
currentUsage: {
|
|
445
|
+
daily: 0,
|
|
446
|
+
weekly: 0,
|
|
447
|
+
monthly: 0,
|
|
448
|
+
lastReset: {
|
|
449
|
+
daily: today,
|
|
450
|
+
weekly: today,
|
|
451
|
+
monthly: today
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function getSecurityConfig(projectPath) {
|
|
457
|
+
const config = getProjectConfigV2(projectPath);
|
|
458
|
+
return config.security;
|
|
459
|
+
}
|
|
460
|
+
function updateSecurityConfig(projectPath, updates) {
|
|
461
|
+
const config = getProjectConfigV2(projectPath);
|
|
462
|
+
const updated = {
|
|
463
|
+
...config.security,
|
|
464
|
+
...updates,
|
|
465
|
+
permissions: {
|
|
466
|
+
...config.security.permissions,
|
|
467
|
+
...updates.permissions
|
|
468
|
+
},
|
|
469
|
+
approval: {
|
|
470
|
+
...config.security.approval,
|
|
471
|
+
...updates.approval,
|
|
472
|
+
thresholds: {
|
|
473
|
+
...config.security.approval.thresholds,
|
|
474
|
+
...updates.approval?.thresholds
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
saveProjectConfigV2(projectPath, {
|
|
479
|
+
...config,
|
|
480
|
+
security: updated
|
|
481
|
+
});
|
|
482
|
+
return updated;
|
|
483
|
+
}
|
|
484
|
+
function updatePermissions(projectPath, updates) {
|
|
485
|
+
const config = getProjectConfigV2(projectPath);
|
|
486
|
+
const updated = {
|
|
487
|
+
...config.security.permissions,
|
|
488
|
+
...updates
|
|
489
|
+
};
|
|
490
|
+
return updateSecurityConfig(projectPath, { permissions: updated }).permissions;
|
|
491
|
+
}
|
|
492
|
+
function updateApproval(projectPath, updates) {
|
|
493
|
+
const config = getProjectConfigV2(projectPath);
|
|
494
|
+
const updated = {
|
|
495
|
+
...config.security.approval,
|
|
496
|
+
...updates,
|
|
497
|
+
thresholds: {
|
|
498
|
+
...config.security.approval.thresholds,
|
|
499
|
+
...updates.thresholds
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
return updateSecurityConfig(projectPath, { approval: updated }).approval;
|
|
503
|
+
}
|
|
504
|
+
function getProjectDockerConfig(projectPath) {
|
|
505
|
+
const config = getProjectConfigV2(projectPath);
|
|
506
|
+
return config.docker;
|
|
507
|
+
}
|
|
508
|
+
function updateProjectDockerConfig(projectPath, updates) {
|
|
509
|
+
const config = getProjectConfigV2(projectPath);
|
|
510
|
+
const updated = {
|
|
511
|
+
...config.docker,
|
|
512
|
+
...updates,
|
|
513
|
+
resources: {
|
|
514
|
+
...config.docker.resources,
|
|
515
|
+
...updates.resources
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
saveProjectConfigV2(projectPath, {
|
|
519
|
+
...config,
|
|
520
|
+
docker: updated
|
|
521
|
+
});
|
|
522
|
+
return updated;
|
|
523
|
+
}
|
|
524
|
+
function addDockerMount(projectPath, host, container, mode = "rw") {
|
|
525
|
+
const config = getProjectConfigV2(projectPath);
|
|
526
|
+
const mounts = [...config.docker.mounts];
|
|
527
|
+
const existingIndex = mounts.findIndex((m) => m.container === container);
|
|
528
|
+
if (existingIndex >= 0) {
|
|
529
|
+
mounts.splice(existingIndex, 1);
|
|
530
|
+
}
|
|
531
|
+
mounts.push({ host, container, mode });
|
|
532
|
+
return updateProjectDockerConfig(projectPath, { mounts });
|
|
533
|
+
}
|
|
534
|
+
function removeDockerMount(projectPath, container) {
|
|
535
|
+
const config = getProjectConfigV2(projectPath);
|
|
536
|
+
const mounts = config.docker.mounts.filter((m) => m.container !== container);
|
|
537
|
+
return updateProjectDockerConfig(projectPath, { mounts });
|
|
538
|
+
}
|
|
539
|
+
function getAnalyticsConfig(projectPath) {
|
|
540
|
+
const config = getProjectConfigV2(projectPath);
|
|
541
|
+
return config.analytics;
|
|
542
|
+
}
|
|
543
|
+
function updateAnalyticsConfig(projectPath, updates) {
|
|
544
|
+
const config = getProjectConfigV2(projectPath);
|
|
545
|
+
const updated = {
|
|
546
|
+
...config.analytics,
|
|
547
|
+
...updates
|
|
548
|
+
};
|
|
549
|
+
saveProjectConfigV2(projectPath, {
|
|
550
|
+
...config,
|
|
551
|
+
analytics: updated
|
|
552
|
+
});
|
|
553
|
+
return updated;
|
|
554
|
+
}
|
|
555
|
+
function getAnalyticsFilePath(projectPath, yearMonth) {
|
|
556
|
+
const month = yearMonth || (/* @__PURE__ */ new Date()).toISOString().slice(0, 7);
|
|
557
|
+
return path.join(getAnalyticsDir(projectPath), `${month}.json`);
|
|
558
|
+
}
|
|
559
|
+
function getAnalyticsSummaryPath(projectPath) {
|
|
560
|
+
return path.join(getAnalyticsDir(projectPath), "summary.json");
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export {
|
|
564
|
+
SECURITY_PRESETS,
|
|
565
|
+
getShivaDir,
|
|
566
|
+
hasShivaDir,
|
|
567
|
+
initShivaDir,
|
|
568
|
+
addToGitignore,
|
|
569
|
+
removeFromGitignore,
|
|
570
|
+
getProjectConfig,
|
|
571
|
+
saveProjectConfig,
|
|
572
|
+
updateProjectConfig,
|
|
573
|
+
mapBranchToSession,
|
|
574
|
+
getSessionForBranch,
|
|
575
|
+
getAllBranchSessions,
|
|
576
|
+
updateBranchSession,
|
|
577
|
+
removeBranchSession,
|
|
578
|
+
cacheGitHubContext,
|
|
579
|
+
getCachedGitHubContext,
|
|
580
|
+
getContextCacheAge,
|
|
581
|
+
clearContextCache,
|
|
582
|
+
removeShivaDir,
|
|
583
|
+
isV2Config,
|
|
584
|
+
getProjectConfigV2,
|
|
585
|
+
saveProjectConfigV2,
|
|
586
|
+
updateProjectConfigV2,
|
|
587
|
+
getSessionConfig,
|
|
588
|
+
updateTimeControl,
|
|
589
|
+
updateSessionLimits,
|
|
590
|
+
updateSessionBudget,
|
|
591
|
+
resetSessionBudget,
|
|
592
|
+
getSecurityConfig,
|
|
593
|
+
updateSecurityConfig,
|
|
594
|
+
updatePermissions,
|
|
595
|
+
updateApproval,
|
|
596
|
+
getProjectDockerConfig,
|
|
597
|
+
updateProjectDockerConfig,
|
|
598
|
+
addDockerMount,
|
|
599
|
+
removeDockerMount,
|
|
600
|
+
getAnalyticsConfig,
|
|
601
|
+
updateAnalyticsConfig,
|
|
602
|
+
getAnalyticsFilePath,
|
|
603
|
+
getAnalyticsSummaryPath
|
|
604
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
findProject,
|
|
3
3
|
getProjectName
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-TI6Y3VT4.js";
|
|
5
5
|
|
|
6
|
-
// src/services/package-manager.ts
|
|
6
|
+
// src/services/data/package-manager.ts
|
|
7
7
|
import Conf from "conf";
|
|
8
8
|
import * as fs from "fs";
|
|
9
9
|
import * as path from "path";
|