@uselemma/opencode 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -2,7 +2,18 @@
2
2
 
3
3
  `@uselemma/opencode` records one complete Lemma trace for each OpenCode user turn. It uses OpenCode's native plugin hooks and event stream directly. It does not install an MCP server or require an npm-published plugin for local use.
4
4
 
5
- ## Local setup
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm dlx @uselemma/opencode setup
9
+ ```
10
+
11
+ The setup command installs the bundled plugin into
12
+ `~/.config/opencode/plugins/uselemma-opencode.js`, opens project-scoped Lemma
13
+ authorization, and stores the returned credential under
14
+ `~/.config/opencode/lemma`.
15
+
16
+ ## Local development
6
17
 
7
18
  From a Lemma checkout:
8
19
 
@@ -13,7 +24,7 @@ pnpm --filter @uselemma/opencode build
13
24
  node plugins/lemma-opencode/scripts/setup.mjs
14
25
  ```
15
26
 
16
- Setup copies the bundled plugin into `~/.config/opencode/plugins/uselemma-opencode.js`, opens project-scoped Lemma authorization, and stores the resulting credential under `~/.config/opencode/lemma`. OpenCode automatically loads global plugin files at startup.
27
+ OpenCode automatically loads global plugin files at startup.
17
28
 
18
29
  For development:
19
30
 
@@ -34,15 +45,13 @@ Use `--config-dir PATH` and `--data-dir PATH` for isolated verification. Use `--
34
45
 
35
46
  Sensitive keys, authorization values, common provider tokens, credential-bearing URLs, and PEM material are removed before a turn is queued. Failed deliveries remain in a private pending directory and retry on the next plugin startup or completed turn. A turn keeps the API and project scope active when capture started. Rotating credentials for the same project preserves delivery, while switching projects leaves the older trace queued instead of misrouting it.
36
47
 
37
- ## Distribution
38
-
39
- OpenCode supports both local plugin files and npm package configuration. The setup command uses the local-file path so it can be verified from a checkout or packed tarball before any public npm publication. Public npm release and ecosystem listing are separate release steps.
40
-
41
48
  ## Verification
42
49
 
50
+ `runtime/` and `scripts/` are generated by `pnpm --filter @uselemma/opencode build`. They are not committed. CI, `verify:local`, and publish build them before test, pack, and npm publish.
51
+
43
52
  ```bash
44
53
  pnpm --filter @uselemma/opencode type-check
45
- pnpm --filter @uselemma/opencode test
46
54
  pnpm --filter @uselemma/opencode build
55
+ pnpm --filter @uselemma/opencode test
47
56
  pnpm --filter @uselemma/opencode verify:local
48
57
  ```
package/package.json CHANGED
@@ -1,8 +1,18 @@
1
1
  {
2
2
  "name": "@uselemma/opencode",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Lemma SDK tracing for OpenCode coding-agent sessions",
5
5
  "license": "MIT",
6
+ "author": "Lemma",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/uselemma/lemma",
10
+ "directory": "plugins/lemma-opencode"
11
+ },
12
+ "homepage": "https://github.com/uselemma/lemma/tree/main/plugins/lemma-opencode#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/uselemma/lemma/issues"
15
+ },
6
16
  "type": "module",
7
17
  "main": "./runtime/lemma.mjs",
8
18
  "types": "./runtime/lemma.d.ts",
@@ -29,7 +39,7 @@
29
39
  ],
30
40
  "dependencies": {
31
41
  "@opencode-ai/plugin": "1.18.19",
32
- "@uselemma/tracing": "^7.11.0"
42
+ "@uselemma/tracing": "^7.11.1"
33
43
  },
34
44
  "devDependencies": {
35
45
  "@opencode-ai/sdk": "1.18.19",
package/runtime/lemma.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  // @uselemma/opencode managed plugin
2
+ import { createRequire as __lemmaCreateRequire } from "node:module";
3
+ const require = __lemmaCreateRequire(import.meta.url);
2
4
  var __create = Object.create;
3
5
  var __defProp = Object.defineProperty;
4
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1618,31 +1620,57 @@ var require_tool_result = __commonJS({
1618
1620
  const record = asResultRecord(output);
1619
1621
  if (!record)
1620
1622
  return null;
1621
- if (record.isError !== true && record.is_error !== true && record.error !== true) {
1622
- return null;
1623
- }
1624
- const content = record.content;
1625
- if (Array.isArray(content)) {
1626
- const text = content.map((part) => {
1627
- if (!part || typeof part !== "object")
1628
- return "";
1629
- const textValue = part.text;
1630
- return typeof textValue === "string" ? textValue : "";
1631
- }).filter(Boolean).join("\n").trim();
1623
+ if (isFlaggedFailure(record)) {
1624
+ const text = contentText(record.content);
1632
1625
  if (text)
1633
1626
  return text;
1627
+ const flaggedError = nonEmptyString(record.error);
1628
+ if (flaggedError)
1629
+ return flaggedError;
1630
+ const message = nonEmptyString(record.message);
1631
+ if (message)
1632
+ return message;
1633
+ try {
1634
+ return JSON.stringify(record);
1635
+ } catch {
1636
+ return "Tool returned an error result";
1637
+ }
1634
1638
  }
1635
- if (typeof record.error === "string" && record.error.trim()) {
1636
- return record.error;
1637
- }
1638
- if (typeof record.message === "string" && record.message.trim()) {
1639
- return record.message;
1640
- }
1641
- try {
1642
- return JSON.stringify(record);
1643
- } catch {
1644
- return "Tool returned an error result";
1645
- }
1639
+ return encodedPayloadError(record);
1640
+ }
1641
+ function isFlaggedFailure(record) {
1642
+ return record.isError === true || record.is_error === true || record.error === true;
1643
+ }
1644
+ function encodedPayloadError(record) {
1645
+ const direct = nonEmptyString(record.error);
1646
+ if (direct)
1647
+ return direct;
1648
+ const structured = asResultRecord(record.structuredContent);
1649
+ const nested = structured ? nonEmptyString(structured.error) : null;
1650
+ if (nested)
1651
+ return nested;
1652
+ const text = contentText(record.content);
1653
+ if (!text)
1654
+ return null;
1655
+ const parsed = asResultRecord(text);
1656
+ return parsed ? nonEmptyString(parsed.error) : null;
1657
+ }
1658
+ function contentText(content) {
1659
+ if (!Array.isArray(content))
1660
+ return null;
1661
+ const text = content.map((part) => {
1662
+ if (!part || typeof part !== "object")
1663
+ return "";
1664
+ const textValue = part.text;
1665
+ return typeof textValue === "string" ? textValue : "";
1666
+ }).filter(Boolean).join("\n").trim();
1667
+ return text || null;
1668
+ }
1669
+ function nonEmptyString(value) {
1670
+ if (typeof value !== "string")
1671
+ return null;
1672
+ const trimmed = value.trim();
1673
+ return trimmed ? trimmed : null;
1646
1674
  }
1647
1675
  function asResultRecord(output) {
1648
1676
  if (output == null)