opencode-usage-coach 0.11.0 → 0.11.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.
Files changed (2) hide show
  1. package/dist/index.js +12 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -196,6 +196,7 @@ var FRAMEWORK_DOCS = {
196
196
  };
197
197
  var DEFAULT_TIMEOUT_MS = 8e3;
198
198
  var TARGET_RESULT_COUNT = 5;
199
+ var GH_QUERY_MAX = 256;
199
200
  function ghToken() {
200
201
  return process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
201
202
  }
@@ -215,6 +216,9 @@ function truncate(input, max) {
215
216
  const text = (input ?? "").replace(/[\r\n]+/g, " ").trim();
216
217
  return text.length > max ? `${text.slice(0, max)}...` : text;
217
218
  }
219
+ function sanitizeQuery(raw) {
220
+ return raw.replace(/```[\s\S]*?```/g, " ").replace(/`[^`]*`/g, " ").replace(/[#*_[\]()>|]/g, " ").replace(/[\r\n\t]+/g, " ").replace(/\s+/g, " ").trim().slice(0, GH_QUERY_MAX);
221
+ }
218
222
  function effectiveFrameworks(frameworks, keyDeps) {
219
223
  const set = new Set((frameworks || []).filter(Boolean));
220
224
  if (keyDeps) {
@@ -251,7 +255,7 @@ async function tier1OfficialDocs(query, fws, results, docRefs, seen, signal) {
251
255
  if (!entry?.githubOrg) continue;
252
256
  try {
253
257
  const q = `${query} org:${entry.githubOrg}`;
254
- const url = `https://api.github.com/search/issues?q=${encodeURIComponent(q)}&per_page=3`;
258
+ const url = `https://api.github.com/search/issues?q=${encodeURIComponent(sanitizeQuery(q))}&per_page=3`;
255
259
  const data = await ghFetch(url, signal);
256
260
  for (const item of data.items ?? []) {
257
261
  pushResult(results, seen, {
@@ -272,7 +276,7 @@ async function tier1OfficialDocs(query, fws, results, docRefs, seen, signal) {
272
276
  async function tier2GitHubIssues(query, results, seen, signal) {
273
277
  const errors = [];
274
278
  try {
275
- const url = `https://api.github.com/search/issues?q=${encodeURIComponent(query)}&sort=relevance&per_page=5`;
279
+ const url = `https://api.github.com/search/issues?q=${encodeURIComponent(sanitizeQuery(query))}&per_page=5`;
276
280
  const data = await ghFetch(url, signal);
277
281
  for (const item of data.items ?? []) {
278
282
  pushResult(results, seen, {
@@ -293,7 +297,7 @@ async function tier3GitHubCode(query, results, seen, signal) {
293
297
  const errors = [];
294
298
  if (!ghToken()) return errors;
295
299
  try {
296
- const url = `https://api.github.com/search/code?q=${encodeURIComponent(query)}&per_page=3`;
300
+ const url = `https://api.github.com/search/code?q=${encodeURIComponent(sanitizeQuery(query))}&per_page=3`;
297
301
  const data = await ghFetch(url, signal);
298
302
  for (const item of data.items ?? []) {
299
303
  const repo = item.repository?.full_name;
@@ -1678,7 +1682,7 @@ Then: harness_done(). Follow the [usage-coach NEXT] directive each tool returns.
1678
1682
  let webResults = [];
1679
1683
  let docRefs = [];
1680
1684
  try {
1681
- const searchQuery = `${args.prompt} ${tasks.map((t) => t.title).join(" ")}`.slice(0, 500);
1685
+ const searchQuery = `${args.prompt} ${tasks.map((t) => t.title).join(" ")}`.slice(0, 256);
1682
1686
  const webResp = await searchContext(searchQuery, profile.frameworks, profile.keyDeps);
1683
1687
  webResults = webResp.results;
1684
1688
  docRefs = webResp.docRefs;
@@ -1797,6 +1801,10 @@ Then: harness_done(). Follow the [usage-coach NEXT] directive each tool returns.
1797
1801
  model: tool.schema.string().optional()
1798
1802
  },
1799
1803
  async execute(args, ctx) {
1804
+ const VALID_STATUSES = ["generating", "grading", "revising", "completed", "failed", "timed_out", "halted_quota"];
1805
+ if (!args.status || !VALID_STATUSES.includes(args.status)) {
1806
+ return `ERROR: task_update status must be one of: ${VALID_STATUSES.join(", ")}. Got: "${args.status}". Call task_update with a valid status.`;
1807
+ }
1800
1808
  const cfg = readHarnessCfg(ctx.directory);
1801
1809
  const h = readHarness(ctx.sessionID) ?? { name: "batch", total: 0, current: 0, tasks: [], usage: {}, active: true };
1802
1810
  h.tasks = h.tasks.filter((x) => x.id !== args.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-usage-coach",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "opencode closed-loop usage coach — quota SENSE -> coaching DECIDE -> loop ACT + TUI integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",