webctx 0.2.2 → 0.2.3

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/AGENTS.md CHANGED
@@ -74,7 +74,7 @@ Behavioral expectations:
74
74
 
75
75
  Release pipeline triggers on `v*` tags and expects:
76
76
 
77
- - `NPM_TOKEN` GitHub secret present.
77
+ - The `NPM_TOKEN` GitHub Actions secret must contain a valid npm access token with publish rights for `webctx`; publishing uses `NODE_AUTH_TOKEN` (not OIDC trusted publishing).
78
78
  - npm package name in `package.json` is publishable under your account/org.
79
79
  - repository URL matches the release origin used by `scripts/postinstall.js`.
80
80
 
package/CONTRIBUTORS.md CHANGED
@@ -80,27 +80,16 @@ make release-tag VERSION=x.y.z
80
80
  - GitHub release publish
81
81
  - npm publish
82
82
 
83
- ## Required GitHub secret
83
+ ## Automatic npm access-token publishing
84
84
 
85
- - `NPM_TOKEN`: npm automation token with publish rights for your package.
85
+ This project publishes npm releases using the repository's GitHub Actions secret `NPM_TOKEN`. Set it to a valid npm access token with publish access to the `webctx` package and appropriate npm two-factor-authentication settings for automated publishing. GitHub Actions supplies it as `NODE_AUTH_TOKEN` during the `release.yml` workflow's npm step.
86
86
 
87
- Set via GitHub CLI:
87
+ If a token expires, rotate it in npm and update `NPM_TOKEN` using `gh secret set NPM_TOKEN --repo amxv/webctx`. Never commit tokens or print them in job logs. Trusted publishing is not used.
88
88
 
89
- ```bash
90
- gh secret set NPM_TOKEN --repo amxv/webctx
91
- ```
92
-
93
- ## npm token setup
94
-
95
- Create token at npm:
96
-
97
- - Profile -> Access Tokens -> Create New Token
98
- - Use an automation/granular token scoped to required package/org
99
-
100
- Validate auth locally:
89
+ If a release's GitHub binaries were successfully published while npm authentication failed, dispatch `npm-publish-retry.yml` with the existing version. Do not create or move the release tag just to retry npm publishing:
101
90
 
102
91
  ```bash
103
- npm whoami
92
+ gh workflow run npm-publish-retry.yml --repo amxv/webctx --ref main -f version=0.2.2
104
93
  ```
105
94
 
106
95
  ## Project layout
package/README.md CHANGED
@@ -10,14 +10,21 @@ webctx read-link <url>
10
10
  webctx map-site <url>
11
11
  ```
12
12
 
13
- The output is plain text or markdown, so it is easy to hand to ChatGPT, Codex, Claude Code, a shell script, or another tool.
13
+ The output is plain text or markdown, so it is easy to hand to ChatGPT, Codex, Claude Code, a shell script, or another tool. Search now retrieves relevant source excerpts automatically instead of returning only URLs. For a specific URL, add an optional question to explore related documentation and surface exact code and API details.
14
+
15
+ ```bash
16
+ webctx search "Go MCP SDK read-only tool annotations"
17
+ webctx read-link https://docs.example.com/api --question "How do authentication and pagination work?"
18
+ ```
14
19
 
15
20
  ## Origo: hosted MCP access
16
21
 
17
- **Origo** is the MCP transport over the same WebCTX retrieval engine. Connect an MCP client to `https://api.origo.ashray.xyz/mcp?key=<your-private-key>` to access exactly two tools: `read_link` and `map_site`. Origo does not expose `search`; the CLI continues to provide all three commands.
22
+ **Origo** is the MCP transport over the same WebCTX retrieval engine. Connect an MCP client to `https://api.origo.ashray.xyz/mcp?key=<your-private-key>` to access exactly two tools: `read_link` and `map_site`. Origo does not expose `search`; the CLI continues to provide all three commands. `read_link` accepts an optional `question` to retrieve focused source context while keeping ordinary URL-only reads intact.
18
23
 
19
24
  Both surfaces share native GitHub/Markdown readers and Firecrawl fallback behavior. Firecrawl's built-in cache is limited to **30 minutes**. Difficult pages automatically escalate through Firecrawl's proxy fallback and, if necessary, a temporary Browser Sandbox session. There is no Redis or additional cache database.
20
25
 
26
+ Source-aware reading also prefers raw JSON, YAML, and OpenAPI files when the URL identifies one; question-focused reads can follow up to two relevant pages on the same host, including links found in `llms.txt`, and inspect embedded structured JSON. Firecrawl Alexandria tool matching and search discovery are automatic when supported, but **no paid Alexandria provider tools are executed**. The original source URLs remain explicit so an agent can verify facts.
27
+
21
28
  Origo deploys independently through the `origo-api` Vercel project on pushes to `main`. CLI releases and npm publishing are unchanged. See the [Origo MCP guide](https://webctx.ashray.xyz/docs/origo) for architecture, setup, and security notes.
22
29
 
23
30
  ## Install
@@ -71,7 +78,7 @@ Recognized native GitHub auth, private/not-found, and rate-limit failures stay a
71
78
 
72
79
  ## Search
73
80
 
74
- Normal search asks Brave, Tavily, and Exa, removes duplicate URLs, and returns one useful list.
81
+ Normal search asks Brave, Tavily, and Exa, removes duplicate URLs, automatically reads three promising sources, follows up to two relevant links, and returns excerpts plus the ranked list. Alexandria tool discovery is included when available, without paid execution.
75
82
 
76
83
  ```bash
77
84
  webctx search "next.js server components"
@@ -0,0 +1,102 @@
1
+ package app
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "fmt"
7
+ "net/http"
8
+ "os"
9
+ "strings"
10
+ "time"
11
+ )
12
+
13
+ // formatAlexandriaTools describes discovered capabilities, not their data.
14
+ // Discovery is free but actual provider execution is not, and is never
15
+ // silently authorized by reading a link or searching the web.
16
+ func formatAlexandriaTools(raw any) string {
17
+ items, ok := raw.([]any)
18
+ if !ok || len(items) == 0 {
19
+ return ""
20
+ }
21
+ parts := []string{"**Available structured-data capabilities (not executed):**"}
22
+ count := 0
23
+ for _, item := range items {
24
+ tool, ok := item.(map[string]any)
25
+ if !ok {
26
+ continue
27
+ }
28
+ provider := safeToolField(tool["provider"], 80)
29
+ capability := safeToolField(tool["capability"], 160)
30
+ if provider == "" || capability == "" {
31
+ continue
32
+ }
33
+ description := safeToolField(tool["description"], 180)
34
+ if description == "" {
35
+ description = safeToolField(tool["name"], 180)
36
+ }
37
+ line := fmt.Sprintf("- `%s/%s`", provider, capability)
38
+ if description != "" {
39
+ line += ": " + description
40
+ }
41
+ parts = append(parts, line)
42
+ count++
43
+ if count >= 3 {
44
+ break
45
+ }
46
+ }
47
+ if count == 0 {
48
+ return ""
49
+ }
50
+ return strings.Join(parts, "\n")
51
+ }
52
+
53
+ func safeToolField(value any, limit int) string {
54
+ s, ok := value.(string)
55
+ if !ok {
56
+ return ""
57
+ }
58
+ s = strings.Join(strings.Fields(s), " ")
59
+ s = strings.ReplaceAll(s, "`", "'")
60
+ if len(s) > limit {
61
+ s = s[:limit] + "…"
62
+ }
63
+ return s
64
+ }
65
+
66
+ func withSourceTools(markdown, toolSummary string) string {
67
+ if toolSummary == "" {
68
+ return markdown
69
+ }
70
+ return markdown + "\n\n---\n\n" + toolSummary + "\n\n*Matched through Firecrawl Alexandria. Discovery does not verify, license, or execute these providers.*"
71
+ }
72
+
73
+ func discoverAlexandria(query string) string {
74
+ apiKey := strings.TrimSpace(os.Getenv("FIRECRAWL_API_KEY"))
75
+ if apiKey == "" {
76
+ return ""
77
+ }
78
+ ctx, cancel := context.WithTimeout(context.Background(), 12*time.Second)
79
+ defer cancel()
80
+ response, err := doJSONRequest(ctx, http.MethodPost, "https://api.firecrawl.dev/v2/search", map[string]string{
81
+ "Authorization": "Bearer " + apiKey,
82
+ "Content-Type": "application/json",
83
+ }, map[string]any{
84
+ "query": query,
85
+ "sources": []string{"alexandria"},
86
+ "limit": 3,
87
+ "toolDetail": "compact",
88
+ })
89
+ if err != nil {
90
+ return "" // unavailable Alexandria is never a search failure
91
+ }
92
+ var result struct {
93
+ Success bool `json:"success"`
94
+ Data struct {
95
+ Tools []any `json:"tools"`
96
+ } `json:"data"`
97
+ }
98
+ if json.Unmarshal(response, &result) != nil || !result.Success {
99
+ return ""
100
+ }
101
+ return formatAlexandriaTools(result.Data.Tools)
102
+ }
@@ -51,10 +51,10 @@ func Run(args []string, stdout, stderr io.Writer) int {
51
51
  case "read-link":
52
52
  if strings.TrimSpace(input) == "" {
53
53
  _, _ = fmt.Fprintln(stderr, "Error: read-link requires a URL")
54
- _, _ = fmt.Fprintln(stdout, "Usage: webctx read-link <url>")
54
+ _, _ = fmt.Fprintln(stdout, "Usage: webctx read-link <url> [--question 'what to find']")
55
55
  return 1
56
56
  }
57
- text, err := ReadLink(input)
57
+ text, err := ReadLinkFocused(input, flags["question"])
58
58
  if err != nil {
59
59
  _, _ = fmt.Fprintln(stderr, err.Error())
60
60
  return 1
@@ -86,7 +86,7 @@ func usageText() string {
86
86
 
87
87
  Usage:
88
88
  webctx search <query> [--exclude domain1,domain2] [--keyword phrase]
89
- webctx read-link <url>
89
+ webctx read-link <url> [--question 'what to find']
90
90
  webctx map-site <url>
91
91
 
92
92
  Examples:
@@ -94,6 +94,7 @@ Examples:
94
94
  webctx search "react hooks" --exclude youtube.com,vimeo.com
95
95
  webctx search "drizzle orm" --keyword "migration guide"
96
96
  webctx read-link https://docs.example.com/guide
97
+ webctx read-link https://docs.example.com/api --question "How do auth and pagination work?"
97
98
  webctx map-site https://example.com`, version)
98
99
  }
99
100
 
@@ -12,8 +12,9 @@ import (
12
12
  )
13
13
 
14
14
  type scrapedPage struct {
15
- Title string
16
- Markdown string
15
+ Title string
16
+ Markdown string
17
+ ToolSummary string
17
18
  }
18
19
 
19
20
  func usableScrapedMarkdown(markdown string) bool {
@@ -37,6 +38,7 @@ func firecrawlScrape(rawURL, apiKey, proxy string) (scrapedPage, error) {
37
38
  requestBody := map[string]any{
38
39
  "url": rawURL,
39
40
  "formats": []string{"markdown"},
41
+ "domainTools": true, // Alexandria discovery, not paid execution.
40
42
  "onlyMainContent": true,
41
43
  "blockAds": true,
42
44
  "removeBase64Images": true,
@@ -58,6 +60,16 @@ func firecrawlScrape(rawURL, apiKey, proxy string) (scrapedPage, error) {
58
60
  "Authorization": "Bearer " + apiKey,
59
61
  "Content-Type": "application/json",
60
62
  }, requestBody)
63
+ // Alexandria is a separately enabled Firecrawl capability. A 403 from
64
+ // domain matching must never break ordinary page extraction for users that
65
+ // haven't enabled Alexandria or have zero-data-retention configured.
66
+ if err != nil && strings.Contains(err.Error(), "403") {
67
+ requestBody["domainTools"] = false
68
+ body, err = doJSONRequest(ctx, http.MethodPost, "https://api.firecrawl.dev/v2/scrape", map[string]string{
69
+ "Authorization": "Bearer " + apiKey,
70
+ "Content-Type": "application/json",
71
+ }, requestBody)
72
+ }
61
73
  if err != nil {
62
74
  return nil, err
63
75
  }
@@ -76,8 +88,9 @@ func firecrawlScrape(rawURL, apiKey, proxy string) (scrapedPage, error) {
76
88
  pageData, _ := data["data"].(map[string]any)
77
89
  metadata, _ := pageData["metadata"].(map[string]any)
78
90
  page := scrapedPage{
79
- Title: stringValue(metadata["title"]),
80
- Markdown: stringValue(pageData["markdown"]),
91
+ Title: stringValue(metadata["title"]),
92
+ Markdown: stringValue(pageData["markdown"]),
93
+ ToolSummary: formatAlexandriaTools(pageData["tools"]),
81
94
  }
82
95
  if status, ok := metadata["statusCode"].(float64); ok && status >= 400 {
83
96
  return page, fmt.Errorf("source responded with HTTP %d", int(status))