@ksm0709/context 0.0.6 → 0.0.7
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/index.js +61 -8
- package/package.json +1 -1
- package/src/version.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -1091,6 +1091,11 @@ function readPromptFile(filePath) {
|
|
|
1091
1091
|
// src/lib/scaffold.ts
|
|
1092
1092
|
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync4, writeFileSync } from "fs";
|
|
1093
1093
|
import { join as join3 } from "path";
|
|
1094
|
+
|
|
1095
|
+
// src/version.ts
|
|
1096
|
+
var PLUGIN_VERSION = "0.0.6";
|
|
1097
|
+
|
|
1098
|
+
// src/lib/scaffold.ts
|
|
1094
1099
|
var DEFAULT_CONFIG = `{
|
|
1095
1100
|
// Context Plugin Configuration
|
|
1096
1101
|
// See: https://github.com/ksm0709/context
|
|
@@ -1405,6 +1410,7 @@ function scaffoldIfNeeded(projectDir) {
|
|
|
1405
1410
|
for (const [filename, content] of Object.entries(TEMPLATE_FILES)) {
|
|
1406
1411
|
writeFileSync(join3(templatesDir, filename), content, "utf-8");
|
|
1407
1412
|
}
|
|
1413
|
+
writeVersion(contextDir, PLUGIN_VERSION);
|
|
1408
1414
|
return true;
|
|
1409
1415
|
} catch {
|
|
1410
1416
|
return false;
|
|
@@ -1432,6 +1438,39 @@ function updateScaffold(projectDir) {
|
|
|
1432
1438
|
writeFileSync(filePath, content, "utf-8");
|
|
1433
1439
|
updated.push(path);
|
|
1434
1440
|
}
|
|
1441
|
+
writeVersion(contextDir, PLUGIN_VERSION);
|
|
1442
|
+
return updated;
|
|
1443
|
+
}
|
|
1444
|
+
function getStoredVersion(projectDir) {
|
|
1445
|
+
try {
|
|
1446
|
+
return readFileSync4(join3(projectDir, ".opencode", "context", ".version"), "utf-8").trim();
|
|
1447
|
+
} catch {
|
|
1448
|
+
return null;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
function writeVersion(contextDir, version) {
|
|
1452
|
+
writeFileSync(join3(contextDir, ".version"), version, "utf-8");
|
|
1453
|
+
}
|
|
1454
|
+
function autoUpdateTemplates(projectDir) {
|
|
1455
|
+
const contextDir = join3(projectDir, ".opencode", "context");
|
|
1456
|
+
if (!existsSync2(contextDir))
|
|
1457
|
+
return [];
|
|
1458
|
+
const stored = getStoredVersion(projectDir);
|
|
1459
|
+
if (stored === PLUGIN_VERSION)
|
|
1460
|
+
return [];
|
|
1461
|
+
mkdirSync(join3(contextDir, "templates"), { recursive: true });
|
|
1462
|
+
const updated = [];
|
|
1463
|
+
for (const [filename, content] of Object.entries(TEMPLATE_FILES)) {
|
|
1464
|
+
const filePath = join3(contextDir, "templates", filename);
|
|
1465
|
+
try {
|
|
1466
|
+
const existing = readFileSync4(filePath, "utf-8");
|
|
1467
|
+
if (existing === content)
|
|
1468
|
+
continue;
|
|
1469
|
+
} catch {}
|
|
1470
|
+
writeFileSync(filePath, content, "utf-8");
|
|
1471
|
+
updated.push(`templates/${filename}`);
|
|
1472
|
+
}
|
|
1473
|
+
writeVersion(contextDir, PLUGIN_VERSION);
|
|
1435
1474
|
return updated;
|
|
1436
1475
|
}
|
|
1437
1476
|
|
|
@@ -1446,6 +1485,17 @@ var plugin = async ({ directory, client }) => {
|
|
|
1446
1485
|
message: "Scaffold created at .opencode/context/"
|
|
1447
1486
|
}
|
|
1448
1487
|
});
|
|
1488
|
+
} else {
|
|
1489
|
+
const autoUpdated = autoUpdateTemplates(directory);
|
|
1490
|
+
if (autoUpdated.length > 0) {
|
|
1491
|
+
await client.app.log({
|
|
1492
|
+
body: {
|
|
1493
|
+
service: "context",
|
|
1494
|
+
level: "info",
|
|
1495
|
+
message: `Auto-updated ${autoUpdated.length} template(s): ${autoUpdated.join(", ")}`
|
|
1496
|
+
}
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1449
1499
|
}
|
|
1450
1500
|
const config = loadConfig(directory);
|
|
1451
1501
|
return {
|
|
@@ -1460,14 +1510,17 @@ var plugin = async ({ directory, client }) => {
|
|
|
1460
1510
|
if (input.command !== "context-update")
|
|
1461
1511
|
return;
|
|
1462
1512
|
const updated = updateScaffold(directory);
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1513
|
+
const text = updated.length === 0 ? "All scaffold files are already up to date." : `Updated ${updated.length} file(s):
|
|
1514
|
+
${updated.map((f) => `- ${f}`).join(`
|
|
1515
|
+
`)}`;
|
|
1516
|
+
const now = Date.now();
|
|
1517
|
+
output.parts.splice(0, output.parts.length, {
|
|
1518
|
+
id: `context-update-${now}`,
|
|
1519
|
+
sessionID: input.sessionID,
|
|
1520
|
+
messageID: `context-update-msg-${now}`,
|
|
1521
|
+
type: "text",
|
|
1522
|
+
text
|
|
1523
|
+
});
|
|
1471
1524
|
},
|
|
1472
1525
|
"experimental.chat.messages.transform": async (_input, output) => {
|
|
1473
1526
|
if (output.messages.length === 0)
|
package/package.json
CHANGED
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PLUGIN_VERSION = '0.0.6';
|