@goodandready/dsh-goal 0.2.13 → 0.2.14

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.
Files changed (2) hide show
  1. package/lib/index.js +30 -10
  2. package/package.json +6 -1
package/lib/index.js CHANGED
@@ -13,7 +13,7 @@ import { GoalEngine, GoalState } from './goal-engine.js';
13
13
  import { sessionIdOf } from './goal-engine-constants.js';
14
14
 
15
15
  export const name = '@goodandready/dsh-goal';
16
- export const inject = ['webServer', 'settings', 'goals?'];
16
+ export const inject = ['webServer', 'settings'];
17
17
 
18
18
  const NS = 'dsh-goal';
19
19
 
@@ -39,6 +39,24 @@ export const Config = z.object({
39
39
  storagePath: z.string().default('').description('Custom filesystem path for persistent state storage'),
40
40
  });
41
41
 
42
+ /**
43
+ * Safely access a service from Cordis context without throwing if un-injected.
44
+ * @param {any} ctx
45
+ * @param {string} name
46
+ * @returns {any}
47
+ */
48
+ export function safeService(ctx, name) {
49
+ if (!ctx) return null;
50
+ try {
51
+ if (ctx.reflect && typeof ctx.reflect.get === "function") {
52
+ return ctx.reflect.get(name, false) || null;
53
+ }
54
+ return ctx[name] || null;
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+
42
60
  export function apply(ctx, config = {}) {
43
61
  let settingsScope = null;
44
62
  const sseClients = new Map();
@@ -90,8 +108,9 @@ export function apply(ctx, config = {}) {
90
108
 
91
109
  // Attempt migration of legacy state if present
92
110
  try {
93
- const firstAgent = ctx.agents?.get?.(ctx.agents?.keys?.()?.next()?.value);
94
- addonStore.migrateLegacyState(storagePath, ctx.goals, firstAgent);
111
+ const agentsSvc = safeService(ctx, "agents");
112
+ const firstAgent = agentsSvc?.get?.(agentsSvc?.keys?.()?.next()?.value);
113
+ addonStore.migrateLegacyState(storagePath, safeService(ctx, "goals"), firstAgent);
95
114
  } catch (migErr) {
96
115
  logger.warn?.('[dsh-goal] Legacy migration check failed:', migErr.message);
97
116
  }
@@ -99,13 +118,13 @@ export function apply(ctx, config = {}) {
99
118
  // Register addon tools: goal_milestones and goal_checklist
100
119
  registerTools(ctx, {
101
120
  milestoneManager,
102
- goalsService: ctx.goals,
121
+ goalsService: safeService(ctx, "goals"),
103
122
  logger,
104
123
  });
105
124
 
106
125
  // Support fallback engine for tests or non-core environments
107
126
  let fallbackEngine = null;
108
- if (!ctx.goals) {
127
+ if (!safeService(ctx, "goals")) {
109
128
  fallbackEngine = new GoalEngine({
110
129
  storagePath,
111
130
  defaultMaxIterations: currentSettings.maxIterations,
@@ -158,7 +177,7 @@ export function apply(ctx, config = {}) {
158
177
  gitSnapshotManager,
159
178
  tokenBudgetGuard,
160
179
  addonStore,
161
- goalsService: ctx.goals,
180
+ goalsService: safeService(ctx, "goals"),
162
181
  getConfig: () => currentSettings,
163
182
  sseClients,
164
183
  logger,
@@ -202,9 +221,10 @@ export function apply(ctx, config = {}) {
202
221
 
203
222
  // Inject milestone prompts and check budget during agent turns
204
223
  ctx.on('agent/pre-step', async ({ agent, messages, step, signal }, next) => {
205
- if (ctx.goals && typeof ctx.goals.get === 'function' && agent) {
224
+ const goalsSvc = safeService(ctx, "goals");
225
+ if (goalsSvc && typeof goalsSvc.get === "function" && agent) {
206
226
  try {
207
- const currentGoal = ctx.goals.get(agent);
227
+ const currentGoal = goalsSvc.get(agent);
208
228
  if (currentGoal && currentGoal.phase === 'active') {
209
229
  const goalId = currentGoal.id;
210
230
 
@@ -213,8 +233,8 @@ export function apply(ctx, config = {}) {
213
233
  const budgetCheck = tokenBudgetGuard.checkBudget({
214
234
  agent,
215
235
  goal: currentGoal,
216
- tokenMeter: ctx.tokenMeter,
217
- goalsService: ctx.goals,
236
+ tokenMeter: safeService(ctx, "tokenMeter"),
237
+ goalsService: goalsSvc,
218
238
  milestones,
219
239
  });
220
240
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-goal",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Core Goal Addon (Token Budget, Milestones, Git Snapshots & Retrospective Reports) for DeepSeek Harness",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -63,5 +63,10 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@deepseek-ai/schemastery": "^3.18.1"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "@deepseek-ai/dsh-goal": {
69
+ "optional": true
70
+ }
66
71
  }
67
72
  }