opencode-writer-swarm 1.2.0 → 1.2.1

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.
@@ -35,6 +35,7 @@ export type GuardrailsConfig = z.infer<typeof GuardrailsConfigSchema>;
35
35
  export declare const HooksConfigSchema: z.ZodObject<{
36
36
  pre_agent: z.ZodOptional<z.ZodString>;
37
37
  post_agent: z.ZodOptional<z.ZodString>;
38
+ compaction: z.ZodDefault<z.ZodBoolean>;
38
39
  }, z.core.$strip>;
39
40
  export type HooksConfig = z.infer<typeof HooksConfigSchema>;
40
41
  export declare const PluginConfigSchema: z.ZodObject<{
@@ -70,6 +71,7 @@ export declare const PluginConfigSchema: z.ZodObject<{
70
71
  hooks: z.ZodOptional<z.ZodObject<{
71
72
  pre_agent: z.ZodOptional<z.ZodString>;
72
73
  post_agent: z.ZodOptional<z.ZodString>;
74
+ compaction: z.ZodDefault<z.ZodBoolean>;
73
75
  }, z.core.$strip>>;
74
76
  qa_retry_limit: z.ZodDefault<z.ZodNumber>;
75
77
  file_retry_enabled: z.ZodDefault<z.ZodBoolean>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Compaction Customizer Hook
3
+ *
4
+ * Enhances session compaction by injecting swarm context from plan.md and context.md.
5
+ * Adds current phase information and key decisions to the compaction context.
6
+ */
7
+ import type { PluginConfig } from '../config';
8
+ /**
9
+ * Creates the experimental.session.compacting hook for compaction customization.
10
+ */
11
+ export declare function createCompactionCustomizerHook(config: PluginConfig, directory: string): Record<string, unknown>;
@@ -18,6 +18,10 @@ export declare function extractCurrentPhase(planContent: string): string | null;
18
18
  * Extracts incomplete tasks (phases) from plan content.
19
19
  */
20
20
  export declare function extractIncompleteTasks(planContent: string, maxChars?: number): string | null;
21
+ /**
22
+ * Extracts patterns section from context content.
23
+ */
24
+ export declare function extractPatterns(contextContent: string, maxChars?: number): string | null;
21
25
  /**
22
26
  * Extracts decisions section from context content.
23
27
  */
@@ -2,4 +2,5 @@ import { safeHook, composeHandlers } from './utils';
2
2
  import { createSystemEnhancerHook } from './system-enhancer';
3
3
  import { createDelegationTrackerHook } from './delegation-tracker';
4
4
  import { createContextBudgetHook } from './context-budget';
5
- export { safeHook, composeHandlers, createSystemEnhancerHook, createDelegationTrackerHook, createContextBudgetHook, };
5
+ import { createCompactionCustomizerHook } from './compaction-customizer';
6
+ export { safeHook, composeHandlers, createSystemEnhancerHook, createDelegationTrackerHook, createContextBudgetHook, createCompactionCustomizerHook, };
package/dist/index.js CHANGED
@@ -14238,7 +14238,8 @@ var GuardrailsConfigSchema = exports_external.object({
14238
14238
  });
14239
14239
  var HooksConfigSchema = exports_external.object({
14240
14240
  pre_agent: exports_external.string().optional(),
14241
- post_agent: exports_external.string().optional()
14241
+ post_agent: exports_external.string().optional(),
14242
+ compaction: exports_external.boolean().default(true)
14242
14243
  });
14243
14244
  var PluginConfigSchema = exports_external.object({
14244
14245
  agents: exports_external.record(exports_external.string(), AgentOverrideConfigSchema).optional(),
@@ -14339,7 +14340,9 @@ function getGuardrailsDefaults() {
14339
14340
  };
14340
14341
  }
14341
14342
  function getHooksDefaults() {
14342
- return {};
14343
+ return {
14344
+ compaction: true
14345
+ };
14343
14346
  }
14344
14347
 
14345
14348
  // src/utils/logger.ts
@@ -23946,6 +23949,48 @@ function extractIncompleteTasks(planContent, maxChars = 500) {
23946
23949
  }
23947
23950
  return `${trimmed.slice(0, maxChars)}...`;
23948
23951
  }
23952
+ function extractPatterns(contextContent, maxChars = 500) {
23953
+ if (!contextContent) {
23954
+ return null;
23955
+ }
23956
+ const tree = parseMarkdownWithCache(contextContent);
23957
+ const patternsText = [];
23958
+ let inPatternsSection = false;
23959
+ visit(tree, (node2) => {
23960
+ if (node2.type === "heading") {
23961
+ const heading = node2;
23962
+ const text4 = heading.children.map((child) => child.type === "text" ? child.value : "").join("");
23963
+ const normalizedText = text4.toLowerCase();
23964
+ if (normalizedText === "patterns") {
23965
+ inPatternsSection = true;
23966
+ } else if (inPatternsSection && heading.depth === 2) {
23967
+ inPatternsSection = false;
23968
+ }
23969
+ }
23970
+ if (inPatternsSection && node2.type === "listItem") {
23971
+ const listItem = node2;
23972
+ const text4 = listItem.children.map((child) => {
23973
+ if (child.type === "paragraph") {
23974
+ return child.children.map((c) => c.type === "text" ? c.value : "").join("");
23975
+ }
23976
+ return "";
23977
+ }).join(" ").trim();
23978
+ if (text4) {
23979
+ patternsText.push(text4);
23980
+ }
23981
+ }
23982
+ });
23983
+ if (patternsText.length === 0) {
23984
+ return null;
23985
+ }
23986
+ const joined = patternsText.join(`
23987
+ `);
23988
+ const trimmed = joined.trim();
23989
+ if (trimmed.length <= maxChars) {
23990
+ return trimmed;
23991
+ }
23992
+ return `${trimmed.slice(0, maxChars)}...`;
23993
+ }
23949
23994
  function extractDecisions(contextContent, maxChars = 500) {
23950
23995
  if (!contextContent) {
23951
23996
  return null;
@@ -24161,6 +24206,44 @@ function createContextBudgetHook(config2, directory) {
24161
24206
  };
24162
24207
  }
24163
24208
 
24209
+ // src/hooks/compaction-customizer.ts
24210
+ function createCompactionCustomizerHook(config2, directory) {
24211
+ const enabled = config2.hooks?.compaction !== false;
24212
+ if (!enabled) {
24213
+ return {};
24214
+ }
24215
+ return {
24216
+ "experimental.session.compacting": safeHook(async (_input, output) => {
24217
+ const planContent = await readSwarmFileAsync(directory, "plan.md");
24218
+ const contextContent = await readSwarmFileAsync(directory, "context.md");
24219
+ if (planContent) {
24220
+ const currentPhase = extractCurrentPhase(planContent);
24221
+ if (currentPhase) {
24222
+ output.context.push(`[SWARM PLAN] ${currentPhase}`);
24223
+ }
24224
+ }
24225
+ if (contextContent) {
24226
+ const decisionsSummary = extractDecisions(contextContent);
24227
+ if (decisionsSummary) {
24228
+ output.context.push(`[SWARM DECISIONS] ${decisionsSummary}`);
24229
+ }
24230
+ }
24231
+ if (planContent) {
24232
+ const incompleteTasks = extractIncompleteTasks(planContent);
24233
+ if (incompleteTasks) {
24234
+ output.context.push(`[SWARM TASKS] ${incompleteTasks}`);
24235
+ }
24236
+ }
24237
+ if (contextContent) {
24238
+ const patterns = extractPatterns(contextContent);
24239
+ if (patterns) {
24240
+ output.context.push(`[SWARM PATTERNS] ${patterns}`);
24241
+ }
24242
+ }
24243
+ })
24244
+ };
24245
+ }
24246
+
24164
24247
  // src/hooks/guardrails.ts
24165
24248
  function isToolRepetition(currentTool, lastTool) {
24166
24249
  if (!currentTool || !lastTool)
@@ -37452,6 +37535,7 @@ var WriterSwarmPlugin = async ({ client, project, directory }) => {
37452
37535
  const delegationHandler = createDelegationTrackerHook(config3);
37453
37536
  const commandHandler = createSwarmCommandHandler(directory);
37454
37537
  const guardrailsHook = createGuardrailsHook(config3.guardrails ?? getGuardrailsDefaults());
37538
+ const compactionHook = createCompactionCustomizerHook(config3, directory);
37455
37539
  const startupMessage = formatStartupLog(agentCount, safeConfigKeys, directory);
37456
37540
  console.log(startupMessage);
37457
37541
  const verboseInit = process.env.VERBOSE_INIT === "1" || process.env.LOG_LEVEL === "debug";
@@ -37493,10 +37577,11 @@ var WriterSwarmPlugin = async ({ client, project, directory }) => {
37493
37577
  });
37494
37578
  },
37495
37579
  "experimental.chat.system.transform": systemTransform,
37580
+ "experimental.session.compacting": compactionHook["experimental.session.compacting"],
37496
37581
  "chat.message": safeHook(delegationHandler),
37497
37582
  "command.execute.before": safeHook(commandHandler),
37498
- "tool.execute.before": guardrailsHook.toolBefore,
37499
- "tool.execute.after": guardrailsHook.toolAfter
37583
+ "tool.execute.before": safeHook(guardrailsHook.toolBefore),
37584
+ "tool.execute.after": safeHook(guardrailsHook.toolAfter)
37500
37585
  };
37501
37586
  };
37502
37587
  var src_default = WriterSwarmPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "opencode-writer-swarm",
3
- "version": "1.2.0",
2
+ "name": "opencode-writer-swarm",
3
+ "version": "1.2.1",
4
4
  "description": "Editorial swarm plugin for OpenCode - professional writing workflow with editor-in-chief, writers, and reviewers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",