@blxzer/cursor-trellis 0.1.0 → 0.1.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.
- package/README.md +124 -5
- package/README.zh-CN.md +170 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1 -33
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/init.d.ts +0 -13
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +7 -14
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/uninstall.d.ts.map +1 -1
- package/dist/commands/uninstall.js +3 -32
- package/dist/commands/uninstall.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +7 -84
- package/dist/commands/update.js.map +1 -1
- package/dist/configurators/index.d.ts +7 -8
- package/dist/configurators/index.d.ts.map +1 -1
- package/dist/configurators/index.js +11 -236
- package/dist/configurators/index.js.map +1 -1
- package/dist/configurators/workflow.d.ts.map +1 -1
- package/dist/configurators/workflow.js +5 -1
- package/dist/configurators/workflow.js.map +1 -1
- package/dist/templates/common/bundled-skills/smart-search-cli/SKILL.md +3 -3
- package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +4 -2
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +8 -15
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +7 -7
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-skills-or-commands.md +18 -21
- package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/overview.md +2 -2
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +10 -7
- package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +4 -4
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +20 -31
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +20 -31
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +24 -40
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +28 -59
- package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +12 -28
- package/dist/templates/common/bundled-skills/trellis-skill-creator/references/trellis-skill-locations.md +2 -2
- package/dist/templates/cursor/hooks.json +6 -0
- package/dist/templates/cursor/rules/retrieval-routing.mdc +57 -0
- package/dist/templates/extract.d.ts +0 -14
- package/dist/templates/extract.d.ts.map +1 -1
- package/dist/templates/extract.js +0 -34
- package/dist/templates/extract.js.map +1 -1
- package/dist/templates/markdown/agents.md +2 -6
- package/dist/templates/markdown/index.d.ts +1 -0
- package/dist/templates/markdown/index.d.ts.map +1 -1
- package/dist/templates/markdown/index.js +1 -0
- package/dist/templates/markdown/index.js.map +1 -1
- package/dist/templates/markdown/prompts/run-semantic-slice-12.md.txt +41 -0
- package/dist/templates/markdown/spec/guides/code-reuse-thinking-guide.md.txt +14 -14
- package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +8 -20
- package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +15 -14
- package/dist/templates/markdown/spec/guides/cursor-context-injection-guide.md.txt +2 -1
- package/dist/templates/markdown/spec/guides/cursor-semantic-compliance.md.txt +49 -0
- package/dist/templates/markdown/spec/guides/cursor-subagent-policy.md.txt +2 -2
- package/dist/templates/markdown/spec/guides/retrieval-daily-guide.md.txt +68 -20
- package/dist/templates/shared-hooks/index.d.ts +1 -1
- package/dist/templates/shared-hooks/index.d.ts.map +1 -1
- package/dist/templates/shared-hooks/index.js +1 -0
- package/dist/templates/shared-hooks/index.js.map +1 -1
- package/dist/templates/shared-hooks/inject-retrieval-plan.py +163 -0
- package/dist/templates/shared-hooks/research-end-retrieval-pack.py +2 -11
- package/dist/templates/trellis/index.d.ts +11 -0
- package/dist/templates/trellis/index.d.ts.map +1 -1
- package/dist/templates/trellis/index.js +22 -0
- package/dist/templates/trellis/index.js.map +1 -1
- package/dist/templates/trellis/scripts/aggregate_retrieval_telemetry.py +342 -0
- package/dist/templates/trellis/scripts/batch_plan_envelope.py +105 -0
- package/dist/templates/trellis/scripts/codegraph_session_smoke.py +76 -0
- package/dist/templates/trellis/scripts/common/active_task.py +116 -147
- package/dist/templates/trellis/scripts/common/cli_adapter.py +34 -710
- package/dist/templates/trellis/scripts/common/codebase_retrieval_router.py +49 -106
- package/dist/templates/trellis/scripts/common/git_context.py +17 -2
- package/dist/templates/trellis/scripts/common/project_file_stats.py +91 -0
- package/dist/templates/trellis/scripts/common/retrieval_adapter_metadata.py +9 -11
- package/dist/templates/trellis/scripts/common/retrieval_agent_instructions.py +313 -0
- package/dist/templates/trellis/scripts/common/retrieval_pack.py +0 -6
- package/dist/templates/trellis/scripts/common/retrieval_pack_context.py +0 -4
- package/dist/templates/trellis/scripts/common/retrieval_plan_gate.py +76 -0
- package/dist/templates/trellis/scripts/common/retrieval_result_ranking.py +253 -0
- package/dist/templates/trellis/scripts/common/retrieval_tool_classification.py +157 -0
- package/dist/templates/trellis/scripts/common/semantic_plan_gate.py +52 -0
- package/dist/templates/trellis/scripts/common/workflow_phase.py +3 -24
- package/dist/templates/trellis/scripts/rank_retrieval_candidates.py +80 -0
- package/dist/templates/trellis/scripts/route_codebase_retrieval.py +38 -11
- package/dist/templates/trellis/scripts/score_evidence.py +112 -0
- package/dist/templates/trellis/workflow.md +861 -960
- package/dist/types/ai-tools.d.ts +13 -16
- package/dist/types/ai-tools.d.ts.map +1 -1
- package/dist/types/ai-tools.js +5 -238
- package/dist/types/ai-tools.js.map +1 -1
- package/dist/utils/codebase-retrieval-router.d.ts +1 -8
- package/dist/utils/codebase-retrieval-router.d.ts.map +1 -1
- package/dist/utils/codebase-retrieval-router.js +39 -180
- package/dist/utils/codebase-retrieval-router.js.map +1 -1
- package/dist/utils/project-capabilities.d.ts.map +1 -1
- package/dist/utils/project-capabilities.js +10 -24
- package/dist/utils/project-capabilities.js.map +1 -1
- package/dist/utils/retrieval-agent-instructions.d.ts +14 -0
- package/dist/utils/retrieval-agent-instructions.d.ts.map +1 -0
- package/dist/utils/retrieval-agent-instructions.js +221 -0
- package/dist/utils/retrieval-agent-instructions.js.map +1 -0
- package/dist/utils/retrieval-execution-telemetry.d.ts +43 -85
- package/dist/utils/retrieval-execution-telemetry.d.ts.map +1 -1
- package/dist/utils/retrieval-execution-telemetry.js +289 -22
- package/dist/utils/retrieval-execution-telemetry.js.map +1 -1
- package/dist/utils/retrieval-result-ranking.js +1 -1
- package/dist/utils/retrieval-result-ranking.js.map +1 -1
- package/dist/utils/retrieval-tool-classification.d.ts +32 -0
- package/dist/utils/retrieval-tool-classification.d.ts.map +1 -0
- package/dist/utils/retrieval-tool-classification.js +113 -0
- package/dist/utils/retrieval-tool-classification.js.map +1 -0
- package/dist/utils/uninstall-scrubbers.d.ts +0 -36
- package/dist/utils/uninstall-scrubbers.d.ts.map +1 -1
- package/dist/utils/uninstall-scrubbers.js +0 -184
- package/dist/utils/uninstall-scrubbers.js.map +1 -1
- package/package.json +4 -2
- package/dist/commands/mem.d.ts +0 -30
- package/dist/commands/mem.d.ts.map +0 -1
- package/dist/commands/mem.js +0 -424
- package/dist/commands/mem.js.map +0 -1
- package/dist/configurators/antigravity.d.ts +0 -7
- package/dist/configurators/antigravity.d.ts.map +0 -1
- package/dist/configurators/antigravity.js +0 -19
- package/dist/configurators/antigravity.js.map +0 -1
- package/dist/configurators/claude.d.ts +0 -9
- package/dist/configurators/claude.d.ts.map +0 -1
- package/dist/configurators/claude.js +0 -72
- package/dist/configurators/claude.js.map +0 -1
- package/dist/configurators/codebuddy.d.ts +0 -10
- package/dist/configurators/codebuddy.d.ts.map +0 -1
- package/dist/configurators/codebuddy.js +0 -30
- package/dist/configurators/codebuddy.js.map +0 -1
- package/dist/configurators/codex.d.ts +0 -8
- package/dist/configurators/codex.d.ts.map +0 -1
- package/dist/configurators/codex.js +0 -87
- package/dist/configurators/codex.js.map +0 -1
- package/dist/configurators/copilot.d.ts +0 -10
- package/dist/configurators/copilot.d.ts.map +0 -1
- package/dist/configurators/copilot.js +0 -51
- package/dist/configurators/copilot.js.map +0 -1
- package/dist/configurators/droid.d.ts +0 -10
- package/dist/configurators/droid.d.ts.map +0 -1
- package/dist/configurators/droid.js +0 -30
- package/dist/configurators/droid.js.map +0 -1
- package/dist/configurators/gemini.d.ts +0 -16
- package/dist/configurators/gemini.d.ts.map +0 -1
- package/dist/configurators/gemini.js +0 -38
- package/dist/configurators/gemini.js.map +0 -1
- package/dist/configurators/kilo.d.ts +0 -7
- package/dist/configurators/kilo.d.ts.map +0 -1
- package/dist/configurators/kilo.js +0 -19
- package/dist/configurators/kilo.js.map +0 -1
- package/dist/configurators/kiro.d.ts +0 -8
- package/dist/configurators/kiro.d.ts.map +0 -1
- package/dist/configurators/kiro.js +0 -24
- package/dist/configurators/kiro.js.map +0 -1
- package/dist/configurators/opencode.d.ts +0 -14
- package/dist/configurators/opencode.d.ts.map +0 -1
- package/dist/configurators/opencode.js +0 -96
- package/dist/configurators/opencode.js.map +0 -1
- package/dist/configurators/pi.d.ts +0 -3
- package/dist/configurators/pi.d.ts.map +0 -1
- package/dist/configurators/pi.js +0 -45
- package/dist/configurators/pi.js.map +0 -1
- package/dist/configurators/qoder.d.ts +0 -11
- package/dist/configurators/qoder.d.ts.map +0 -1
- package/dist/configurators/qoder.js +0 -31
- package/dist/configurators/qoder.js.map +0 -1
- package/dist/configurators/windsurf.d.ts +0 -7
- package/dist/configurators/windsurf.d.ts.map +0 -1
- package/dist/configurators/windsurf.js +0 -19
- package/dist/configurators/windsurf.js.map +0 -1
- package/dist/templates/claude/agents/trellis-check.md +0 -124
- package/dist/templates/claude/agents/trellis-implement.md +0 -110
- package/dist/templates/claude/agents/trellis-research.md +0 -137
- package/dist/templates/claude/index.d.ts +0 -22
- package/dist/templates/claude/index.d.ts.map +0 -1
- package/dist/templates/claude/index.js +0 -46
- package/dist/templates/claude/index.js.map +0 -1
- package/dist/templates/claude/settings.json +0 -84
- package/dist/templates/codebuddy/agents/trellis-check.md +0 -115
- package/dist/templates/codebuddy/agents/trellis-implement.md +0 -110
- package/dist/templates/codebuddy/agents/trellis-research.md +0 -137
- package/dist/templates/codebuddy/index.d.ts +0 -15
- package/dist/templates/codebuddy/index.d.ts.map +0 -1
- package/dist/templates/codebuddy/index.js +0 -15
- package/dist/templates/codebuddy/index.js.map +0 -1
- package/dist/templates/codebuddy/settings.json +0 -70
- package/dist/templates/codex/agents/trellis-check.toml +0 -67
- package/dist/templates/codex/agents/trellis-implement.toml +0 -40
- package/dist/templates/codex/agents/trellis-research.toml +0 -73
- package/dist/templates/codex/config.toml +0 -28
- package/dist/templates/codex/hooks/session-start.py +0 -575
- package/dist/templates/codex/hooks.json +0 -15
- package/dist/templates/codex/index.d.ts +0 -39
- package/dist/templates/codex/index.d.ts.map +0 -1
- package/dist/templates/codex/index.js +0 -85
- package/dist/templates/codex/index.js.map +0 -1
- package/dist/templates/codex/skills/before-dev/SKILL.md +0 -40
- package/dist/templates/codex/skills/brainstorm/SKILL.md +0 -112
- package/dist/templates/codex/skills/break-loop/SKILL.md +0 -130
- package/dist/templates/codex/skills/check/SKILL.md +0 -98
- package/dist/templates/codex/skills/check-cross-layer/SKILL.md +0 -158
- package/dist/templates/codex/skills/create-command/SKILL.md +0 -101
- package/dist/templates/codex/skills/finish-work/SKILL.md +0 -90
- package/dist/templates/codex/skills/improve-ut/SKILL.md +0 -69
- package/dist/templates/codex/skills/integrate-skill/SKILL.md +0 -221
- package/dist/templates/codex/skills/onboard/SKILL.md +0 -363
- package/dist/templates/codex/skills/record-session/SKILL.md +0 -67
- package/dist/templates/codex/skills/start/SKILL.md +0 -66
- package/dist/templates/codex/skills/update-spec/SKILL.md +0 -335
- package/dist/templates/copilot/hooks/session-start.py +0 -557
- package/dist/templates/copilot/hooks.json +0 -19
- package/dist/templates/copilot/index.d.ts +0 -23
- package/dist/templates/copilot/index.d.ts.map +0 -1
- package/dist/templates/copilot/index.js +0 -54
- package/dist/templates/copilot/index.js.map +0 -1
- package/dist/templates/copilot/prompts/before-dev.prompt.md +0 -39
- package/dist/templates/copilot/prompts/brainstorm.prompt.md +0 -111
- package/dist/templates/copilot/prompts/break-loop.prompt.md +0 -129
- package/dist/templates/copilot/prompts/check-cross-layer.prompt.md +0 -157
- package/dist/templates/copilot/prompts/check.prompt.md +0 -97
- package/dist/templates/copilot/prompts/create-command.prompt.md +0 -116
- package/dist/templates/copilot/prompts/finish-work.prompt.md +0 -99
- package/dist/templates/copilot/prompts/integrate-skill.prompt.md +0 -223
- package/dist/templates/copilot/prompts/onboard.prompt.md +0 -362
- package/dist/templates/copilot/prompts/parallel.prompt.md +0 -204
- package/dist/templates/copilot/prompts/record-session.prompt.md +0 -66
- package/dist/templates/copilot/prompts/start.prompt.md +0 -63
- package/dist/templates/copilot/prompts/update-spec.prompt.md +0 -358
- package/dist/templates/droid/droids/trellis-check.md +0 -107
- package/dist/templates/droid/droids/trellis-implement.md +0 -102
- package/dist/templates/droid/droids/trellis-research.md +0 -137
- package/dist/templates/droid/index.d.ts +0 -15
- package/dist/templates/droid/index.d.ts.map +0 -1
- package/dist/templates/droid/index.js +0 -15
- package/dist/templates/droid/index.js.map +0 -1
- package/dist/templates/droid/settings.json +0 -70
- package/dist/templates/gemini/agents/trellis-check.md +0 -107
- package/dist/templates/gemini/agents/trellis-implement.md +0 -102
- package/dist/templates/gemini/agents/trellis-research.md +0 -136
- package/dist/templates/gemini/index.d.ts +0 -13
- package/dist/templates/gemini/index.d.ts.map +0 -1
- package/dist/templates/gemini/index.js +0 -13
- package/dist/templates/gemini/index.js.map +0 -1
- package/dist/templates/gemini/settings.json +0 -28
- package/dist/templates/kiro/agents/trellis-check.json +0 -26
- package/dist/templates/kiro/agents/trellis-implement.json +0 -26
- package/dist/templates/kiro/agents/trellis-research.json +0 -30
- package/dist/templates/kiro/index.d.ts +0 -18
- package/dist/templates/kiro/index.d.ts.map +0 -1
- package/dist/templates/kiro/index.js +0 -18
- package/dist/templates/kiro/index.js.map +0 -1
- package/dist/templates/opencode/agents/trellis-check.md +0 -122
- package/dist/templates/opencode/agents/trellis-implement.md +0 -118
- package/dist/templates/opencode/agents/trellis-research.md +0 -145
- package/dist/templates/opencode/lib/session-utils.js +0 -667
- package/dist/templates/opencode/lib/trellis-context.js +0 -336
- package/dist/templates/opencode/package.json +0 -5
- package/dist/templates/opencode/plugins/inject-subagent-context.js +0 -495
- package/dist/templates/opencode/plugins/inject-workflow-state.js +0 -159
- package/dist/templates/opencode/plugins/session-start.js +0 -101
- package/dist/templates/pi/agents/trellis-check.md +0 -37
- package/dist/templates/pi/agents/trellis-implement.md +0 -42
- package/dist/templates/pi/agents/trellis-research.md +0 -25
- package/dist/templates/pi/extensions/trellis/index.ts.txt +0 -1600
- package/dist/templates/pi/index.d.ts +0 -5
- package/dist/templates/pi/index.d.ts.map +0 -1
- package/dist/templates/pi/index.js +0 -12
- package/dist/templates/pi/index.js.map +0 -1
- package/dist/templates/pi/settings.json +0 -12
- package/dist/templates/qoder/agents/trellis-check.md +0 -108
- package/dist/templates/qoder/agents/trellis-implement.md +0 -103
- package/dist/templates/qoder/agents/trellis-research.md +0 -137
- package/dist/templates/qoder/index.d.ts +0 -15
- package/dist/templates/qoder/index.d.ts.map +0 -1
- package/dist/templates/qoder/index.js +0 -15
- package/dist/templates/qoder/index.js.map +0 -1
- package/dist/templates/qoder/settings.json +0 -47
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Trellis Context Manager
|
|
3
|
-
*
|
|
4
|
-
* Utility class for OpenCode plugins providing file reading,
|
|
5
|
-
* JSONL parsing, and context building capabilities.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { existsSync, readFileSync, appendFileSync, readdirSync } from "fs"
|
|
9
|
-
import { isAbsolute, join } from "path"
|
|
10
|
-
import { platform } from "os"
|
|
11
|
-
import { execSync } from "child_process"
|
|
12
|
-
import { createHash } from "crypto"
|
|
13
|
-
import process from "process"
|
|
14
|
-
|
|
15
|
-
const PYTHON_CMD = platform() === "win32" ? "python" : "python3"
|
|
16
|
-
// Debug logging
|
|
17
|
-
const DEBUG_LOG = "/tmp/trellis-plugin-debug.log"
|
|
18
|
-
|
|
19
|
-
function debugLog(prefix, ...args) {
|
|
20
|
-
const timestamp = new Date().toISOString()
|
|
21
|
-
const msg = `[${timestamp}] [${prefix}] ${args.map(a => typeof a === "object" ? JSON.stringify(a) : a).join(" ")}\n`
|
|
22
|
-
try {
|
|
23
|
-
appendFileSync(DEBUG_LOG, msg)
|
|
24
|
-
} catch {
|
|
25
|
-
// ignore
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function stringValue(value) {
|
|
30
|
-
return typeof value === "string" && value.trim() ? value.trim() : null
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function sanitizeKey(raw) {
|
|
34
|
-
const safe = raw.trim().replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^[._-]+|[._-]+$/g, "")
|
|
35
|
-
return safe ? safe.slice(0, 160) : ""
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function hashValue(raw) {
|
|
39
|
-
return createHash("sha256").update(raw).digest("hex").slice(0, 24)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function lookupString(data, keys) {
|
|
43
|
-
if (!data || typeof data !== "object") return null
|
|
44
|
-
for (const key of keys) {
|
|
45
|
-
const value = stringValue(data[key])
|
|
46
|
-
if (value) return value
|
|
47
|
-
}
|
|
48
|
-
for (const nestedKey of ["input", "properties", "event", "hook_input", "hookInput"]) {
|
|
49
|
-
const nested = data[nestedKey]
|
|
50
|
-
if (nested && typeof nested === "object") {
|
|
51
|
-
const value = lookupString(nested, keys)
|
|
52
|
-
if (value) return value
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return null
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function buildContextKey(platformName, kind, value) {
|
|
59
|
-
if (kind === "transcript") {
|
|
60
|
-
return `${platformName}_transcript_${hashValue(value)}`
|
|
61
|
-
}
|
|
62
|
-
const safeValue = sanitizeKey(value)
|
|
63
|
-
return safeValue ? `${platformName}_${safeValue}` : `${platformName}_${hashValue(value)}`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Matches `trellis-implement`, `trellis-check`, `trellis-research` exactly.
|
|
67
|
-
// Used by chat.message plugins to skip injection inside Trellis sub-agent turns.
|
|
68
|
-
const TRELLIS_SUBAGENT_RE = /^trellis-(implement|check|research)$/
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Return true when the OpenCode `chat.message` input represents a Trellis
|
|
72
|
-
* sub-agent turn. `input.agent` is set by OpenCode when a Task tool spawns a
|
|
73
|
-
* child session with a custom agent (see `packages/opencode/src/tool/task.ts`).
|
|
74
|
-
*/
|
|
75
|
-
export function isTrellisSubagent(input) {
|
|
76
|
-
if (!input || typeof input !== "object") return false
|
|
77
|
-
const agent = typeof input.agent === "string" ? input.agent.trim() : ""
|
|
78
|
-
return TRELLIS_SUBAGENT_RE.test(agent)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Trellis Context Manager
|
|
83
|
-
*/
|
|
84
|
-
export class TrellisContext {
|
|
85
|
-
constructor(directory) {
|
|
86
|
-
this.directory = directory
|
|
87
|
-
debugLog("context", "TrellisContext initialized", { directory })
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ============================================================
|
|
91
|
-
// Trellis Project Detection
|
|
92
|
-
// ============================================================
|
|
93
|
-
|
|
94
|
-
isTrellisProject() {
|
|
95
|
-
return existsSync(join(this.directory, ".trellis"))
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
getContextKey(platformInput = null) {
|
|
99
|
-
const override = stringValue(process.env.TRELLIS_CONTEXT_ID)
|
|
100
|
-
if (override) {
|
|
101
|
-
return sanitizeKey(override) || hashValue(override)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const runID = stringValue(process.env.OPENCODE_RUN_ID)
|
|
105
|
-
if (runID) return buildContextKey("opencode", "session", runID)
|
|
106
|
-
|
|
107
|
-
const input = platformInput && typeof platformInput === "object" ? platformInput : null
|
|
108
|
-
if (!input) return null
|
|
109
|
-
|
|
110
|
-
const sessionID = lookupString(input, ["session_id", "sessionId", "sessionID"])
|
|
111
|
-
if (sessionID) return buildContextKey("opencode", "session", sessionID)
|
|
112
|
-
|
|
113
|
-
const conversationID = lookupString(input, ["conversation_id", "conversationId", "conversationID"])
|
|
114
|
-
if (conversationID) return buildContextKey("opencode", "conversation", conversationID)
|
|
115
|
-
|
|
116
|
-
const transcriptPath = lookupString(input, ["transcript_path", "transcriptPath", "transcript"])
|
|
117
|
-
if (transcriptPath) return buildContextKey("opencode", "transcript", transcriptPath)
|
|
118
|
-
|
|
119
|
-
return null
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
readContext(contextKey) {
|
|
123
|
-
try {
|
|
124
|
-
const contextPath = join(this.directory, ".trellis", ".runtime", "sessions", `${contextKey}.json`)
|
|
125
|
-
if (!existsSync(contextPath)) return null
|
|
126
|
-
return JSON.parse(readFileSync(contextPath, "utf-8"))
|
|
127
|
-
} catch {
|
|
128
|
-
return null
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Get selected task from explicit session runtime context.
|
|
134
|
-
*
|
|
135
|
-
* Resolution mirrors Python `active_task.resolve_selected_task`: lookup only
|
|
136
|
-
* the runtime file for the input-derived context key. A new live session must
|
|
137
|
-
* not infer selection from existing runtime files.
|
|
138
|
-
*/
|
|
139
|
-
getActiveTask(platformInput = null) {
|
|
140
|
-
const contextKey = this.getContextKey(platformInput)
|
|
141
|
-
if (contextKey) {
|
|
142
|
-
const context = this.readContext(contextKey)
|
|
143
|
-
const taskRef = this.normalizeTaskRef(context?.selected_task || "")
|
|
144
|
-
if (taskRef) {
|
|
145
|
-
const taskDir = this.resolveTaskDir(taskRef)
|
|
146
|
-
return {
|
|
147
|
-
taskPath: taskRef,
|
|
148
|
-
source: `session:${contextKey}`,
|
|
149
|
-
stale: !taskDir || !existsSync(taskDir),
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return { taskPath: null, source: "none", stale: false }
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
getCurrentTask(platformInput = null) {
|
|
158
|
-
return this.getActiveTask(platformInput).taskPath
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
normalizeTaskRef(taskRef) {
|
|
162
|
-
if (!taskRef) {
|
|
163
|
-
return ""
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (isAbsolute(taskRef)) {
|
|
167
|
-
return taskRef.trim()
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
let normalized = taskRef.trim().replace(/\\/g, "/")
|
|
171
|
-
while (normalized.startsWith("./")) {
|
|
172
|
-
normalized = normalized.slice(2)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (normalized.startsWith("tasks/")) {
|
|
176
|
-
return `.trellis/${normalized}`
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return normalized
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
resolveTaskDir(taskRef) {
|
|
183
|
-
const normalized = this.normalizeTaskRef(taskRef)
|
|
184
|
-
if (!normalized) {
|
|
185
|
-
return null
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (isAbsolute(normalized)) {
|
|
189
|
-
return normalized
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (normalized.startsWith(".trellis/")) {
|
|
193
|
-
return join(this.directory, normalized)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return join(this.directory, ".trellis", "tasks", normalized)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// ============================================================
|
|
200
|
-
// File Reading Utilities
|
|
201
|
-
// ============================================================
|
|
202
|
-
|
|
203
|
-
readFile(filePath) {
|
|
204
|
-
try {
|
|
205
|
-
if (existsSync(filePath)) {
|
|
206
|
-
return readFileSync(filePath, "utf-8")
|
|
207
|
-
}
|
|
208
|
-
} catch {
|
|
209
|
-
// Ignore read errors
|
|
210
|
-
}
|
|
211
|
-
return null
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
readProjectFile(relativePath) {
|
|
215
|
-
return this.readFile(join(this.directory, relativePath))
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
runScript(scriptPath, cwd = null, contextKey = null) {
|
|
219
|
-
try {
|
|
220
|
-
const result = execSync(`${PYTHON_CMD} "${scriptPath}"`, {
|
|
221
|
-
cwd: cwd || this.directory,
|
|
222
|
-
timeout: 10000,
|
|
223
|
-
encoding: "utf-8",
|
|
224
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
225
|
-
env: {
|
|
226
|
-
...process.env,
|
|
227
|
-
...(contextKey ? { TRELLIS_CONTEXT_ID: contextKey } : {}),
|
|
228
|
-
},
|
|
229
|
-
})
|
|
230
|
-
return result || ""
|
|
231
|
-
} catch {
|
|
232
|
-
return ""
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// ============================================================
|
|
237
|
-
// JSONL Reading
|
|
238
|
-
// ============================================================
|
|
239
|
-
|
|
240
|
-
readDirectoryMdFiles(dirPath, maxFiles = 20) {
|
|
241
|
-
const results = []
|
|
242
|
-
const fullPath = join(this.directory, dirPath)
|
|
243
|
-
|
|
244
|
-
if (!existsSync(fullPath)) {
|
|
245
|
-
return results
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
try {
|
|
249
|
-
const files = readdirSync(fullPath)
|
|
250
|
-
.filter(f => f.endsWith(".md"))
|
|
251
|
-
.sort()
|
|
252
|
-
.slice(0, maxFiles)
|
|
253
|
-
|
|
254
|
-
for (const filename of files) {
|
|
255
|
-
const filePath = join(dirPath, filename)
|
|
256
|
-
const content = this.readProjectFile(filePath)
|
|
257
|
-
if (content) {
|
|
258
|
-
results.push({ path: filePath, content })
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
} catch {
|
|
262
|
-
// Ignore directory read errors
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return results
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Read a JSONL file and load referenced files/directories
|
|
270
|
-
* Supports:
|
|
271
|
-
* {"file": "path/to/file.md", "reason": "..."}
|
|
272
|
-
* {"file": "path/to/dir/", "type": "directory", "reason": "..."}
|
|
273
|
-
*/
|
|
274
|
-
readJsonlWithFiles(jsonlPath) {
|
|
275
|
-
const results = []
|
|
276
|
-
const content = this.readFile(jsonlPath)
|
|
277
|
-
if (!content) return results
|
|
278
|
-
|
|
279
|
-
for (const line of content.split("\n")) {
|
|
280
|
-
if (!line.trim()) continue
|
|
281
|
-
try {
|
|
282
|
-
const item = JSON.parse(line)
|
|
283
|
-
const file = item.file || item.path
|
|
284
|
-
const entryType = item.type || "file"
|
|
285
|
-
|
|
286
|
-
if (!file) continue
|
|
287
|
-
|
|
288
|
-
if (entryType === "directory") {
|
|
289
|
-
const dirEntries = this.readDirectoryMdFiles(file)
|
|
290
|
-
results.push(...dirEntries)
|
|
291
|
-
} else {
|
|
292
|
-
const fullPath = join(this.directory, file)
|
|
293
|
-
const fileContent = this.readFile(fullPath)
|
|
294
|
-
if (fileContent) {
|
|
295
|
-
results.push({ path: file, content: fileContent })
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
} catch {
|
|
299
|
-
// Ignore parse errors for individual lines
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
return results
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
buildContextFromEntries(entries) {
|
|
306
|
-
return entries.map(e => `=== ${e.path} ===\n${e.content}`).join("\n\n")
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// ============================================================
|
|
311
|
-
// Context Collector (for session deduplication)
|
|
312
|
-
// ============================================================
|
|
313
|
-
|
|
314
|
-
class ContextCollector {
|
|
315
|
-
constructor() {
|
|
316
|
-
this.processed = new Set()
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
markProcessed(sessionID) {
|
|
320
|
-
this.processed.add(sessionID)
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
isProcessed(sessionID) {
|
|
324
|
-
return this.processed.has(sessionID)
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
clear(sessionID) {
|
|
328
|
-
this.processed.delete(sessionID)
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Singleton instance
|
|
333
|
-
export const contextCollector = new ContextCollector()
|
|
334
|
-
|
|
335
|
-
// Export debug log for plugins
|
|
336
|
-
export { debugLog }
|