@0x26/amp 0.5.5 → 0.5.6

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/dist/index.js CHANGED
@@ -14,7 +14,7 @@ Preview only; use --json or --out <file> for all returned data.`:"")}var current
14
14
  `)?err.body:`${err.body}
15
15
  `)):err instanceof NotLoggedInError?process.stderr.write(`${err.message}
16
16
  `):process.stderr.write(`${err instanceof Error?err.message:String(err)}
17
- `),process.exitCode=1}var DoorRefusalError,init_http=__esm({"src/http.ts"(){"use strict";init_experience(),init_brand(),init_credentials(),init_machine(),init_env_customer(),init_session(),init_request_credential(),DoorRefusalError=class extends Error{constructor(status,body){super(`door refused (HTTP ${status})`),this.status=status,this.body=body}}}});init_terminal();var CLI_VERSION="0.5.5";init_brand();init_config();init_credentials();init_lock();init_experience();init_brand();init_brand();init_workos();init_credentials();init_env_customer();init_config();init_brand();var MAX_BYTES=65536;function skillUrl(service){let url=new URL(service);if(url.protocol!=="https:"||url.username||url.password||url.search||url.hash||url.pathname!=="/"||!/^(?:[a-z0-9.-]+|\[[a-f0-9:]+\])$/i.test(url.hostname)||/[\s\\]/.test(service))throw new Error("Use an HTTPS Ask service origin without a path or credentials.");return`${url.origin}/skill.md`}var skillVersion=text=>createHash2("sha256").update(text).digest("hex");function validSkill(text){return typeof text=="string"&&Buffer.byteLength(text)<=MAX_BYTES&&/^---\r?\nname: amp-cli\r?\n/.test(text)&&/^description: .+/m.test(text)&&!text.includes("\0")}async function fetchSkill(service,bundled,options={}){let url=skillUrl(service),file=join3(options.cacheDir??join3(homedir3(),".cache","amp","skills"),`${skillVersion(url)}.json`),cached3;try{let raw=readFileSync3(file);if(raw.length<=MAX_BYTES*2){let value=JSON.parse(raw.toString());value.url===url&&validSkill(value.text)&&(value.etag===void 0||typeof value.etag=="string"&&value.etag.length<=200&&!/[\r\n]/.test(value.etag))&&(cached3=value)}}catch{}let result=(text,source,stale,warning)=>({text,source,stale,url,version:skillVersion(text),...warning?{warning}:{}});try{let response=await(options.fetch??fetch)(url,{redirect:"error",credentials:"omit",signal:AbortSignal.timeout(options.timeoutMs??5e3),headers:{Accept:"text/markdown",...cached3?.etag?{"If-None-Match":cached3.etag}:{}}});if(response.status===304&&cached3)return result(cached3.text,"cache",!1);if(response.status!==200||response.redirected||!response.headers.get("content-type")?.startsWith("text/markdown"))throw await response.body?.cancel(),new Error("Invalid skill response");if(Number(response.headers.get("content-length"))>MAX_BYTES)throw await response.body?.cancel(),new Error("Skill too large");let reader=response.body?.getReader();if(!reader)throw new Error("Missing skill body");let chunks=[],bytes=0;try{for(;;){let{done,value}=await reader.read();if(done)break;if(bytes+=value.byteLength,bytes>MAX_BYTES)throw new Error("Skill too large");chunks.push(value)}}finally{await reader.cancel().catch(()=>{})}let text=new TextDecoder("utf-8",{fatal:!0}).decode(Buffer.concat(chunks));if(!validSkill(text))throw new Error("Invalid skill");let etag=response.headers.get("etag"),next={url,text,...etag&&etag.length<=200&&!/[\r\n]/.test(etag)?{etag}:{}},temporary=`${file}.${randomUUID()}.tmp`;try{mkdirSync3(dirname3(file),{recursive:!0,mode:448}),writeFileSync3(temporary,JSON.stringify(next),{mode:384}),renameSync(temporary,file)}catch{return result(text,"remote",!1,"Skill fetched; local cache could not be saved.")}finally{try{rmSync2(temporary,{force:!0})}catch{}}return result(text,"remote",!1)}catch{return result(cached3?.text??bundled(),cached3?"cache":"bundled",!0,"Published skill unavailable; using fallback instructions. Retry in a new chat or on explicit refresh.")}}init_experience();init_brand();init_brand();init_config();init_lock();init_brand();init_brand();init_credentials();var PACKAGE_NAME=NPM_PACKAGE,TTL_MS=1440*60*1e3;function isNewer(current2,candidate){let parse=v=>v.replace(/^v/,"").split("-")[0].split(".").map(n=>Number.parseInt(n,10)||0),a=parse(current2),b=parse(candidate);for(let i=0;i<Math.max(a.length,b.length);i+=1){let x=a[i]??0,y=b[i]??0;if(y>x)return!0;if(y<x)return!1}return!1}function fetchLatest(runner=(cmd,args)=>execFileSync(cmd,args,{encoding:"utf8",timeout:4e3,stdio:["ignore","pipe","ignore"]})){try{let out=runner("npm",["view",PACKAGE_NAME,"version","--json"]).trim(),parsed=JSON.parse(out);return typeof parsed=="string"?parsed:Array.isArray(parsed)&&typeof parsed[parsed.length-1]=="string"?parsed[parsed.length-1]:null}catch{return null}}var HOOK_MARKER="amp --agent skill sync",HOOK_COMMAND=`command -v amp >/dev/null 2>&1 && ${HOOK_MARKER} || true`;function npmInstall(spec){return spawnSync("npm",["install","-g",spec],{stdio:"ignore",timeout:9e4,shell:process.platform==="win32"}).status===0}function ensureLatestCli(opts={}){let env=opts.env??process.env,current2=CLI_VERSION;if(env.AMP_NO_UPDATE_CHECK==="1")return{status:"skipped",current:current2};let latest=(opts.latest??fetchLatest)();return latest?isNewer(current2,latest)?{status:(opts.install??npmInstall)(`${NPM_PACKAGE}@${latest}`)?"updated":"failed",current:current2,latest}:{status:"current",current:current2,latest}:{status:"unknown",current:current2}}function claudeSettingsPath(){return join5(homedir4(),".claude","settings.json")}function installSessionHook(settingsPath=claudeSettingsPath()){if(!existsSync4(dirname5(settingsPath)))return"skipped";let settings={};if(existsSync4(settingsPath))try{let parsed=JSON.parse(readFileSync5(settingsPath,"utf8"));if(!parsed||typeof parsed!="object"||Array.isArray(parsed))return"skipped";settings=parsed}catch{return"skipped"}let hooks=settings.hooks??{};if(!hooks||typeof hooks!="object"||Array.isArray(hooks))return"skipped";let sessionStart=hooks.SessionStart??[];if(!Array.isArray(sessionStart))return"skipped";if(sessionStart.some(group=>Array.isArray(group?.hooks)&&group.hooks.some(h=>typeof h?.command=="string"&&h.command.includes(HOOK_MARKER))))return"present";sessionStart.push({matcher:"startup|clear",hooks:[{type:"command",command:HOOK_COMMAND,timeout:120}]}),settings.hooks={...hooks,SessionStart:sessionStart};let tmp=`${settingsPath}.${process.pid}.tmp`;return writeFileSync5(tmp,`${JSON.stringify(settings,null,2)}
17
+ `),process.exitCode=1}var DoorRefusalError,init_http=__esm({"src/http.ts"(){"use strict";init_experience(),init_brand(),init_credentials(),init_machine(),init_env_customer(),init_session(),init_request_credential(),DoorRefusalError=class extends Error{constructor(status,body){super(`door refused (HTTP ${status})`),this.status=status,this.body=body}}}});init_terminal();var CLI_VERSION="0.5.6";init_brand();init_config();init_credentials();init_lock();init_experience();init_brand();init_brand();init_workos();init_credentials();init_env_customer();init_config();init_brand();var MAX_BYTES=65536;function skillUrl(service){let url=new URL(service);if(url.protocol!=="https:"||url.username||url.password||url.search||url.hash||url.pathname!=="/"||!/^(?:[a-z0-9.-]+|\[[a-f0-9:]+\])$/i.test(url.hostname)||/[\s\\]/.test(service))throw new Error("Use an HTTPS Ask service origin without a path or credentials.");return`${url.origin}/skill.md`}var skillVersion=text=>createHash2("sha256").update(text).digest("hex");function validSkill(text){return typeof text=="string"&&Buffer.byteLength(text)<=MAX_BYTES&&/^---\r?\nname: amp-cli\r?\n/.test(text)&&/^description: .+/m.test(text)&&!text.includes("\0")}async function fetchSkill(service,bundled,options={}){let url=skillUrl(service),file=join3(options.cacheDir??join3(homedir3(),".cache","amp","skills"),`${skillVersion(url)}.json`),cached3;try{let raw=readFileSync3(file);if(raw.length<=MAX_BYTES*2){let value=JSON.parse(raw.toString());value.url===url&&validSkill(value.text)&&(value.etag===void 0||typeof value.etag=="string"&&value.etag.length<=200&&!/[\r\n]/.test(value.etag))&&(cached3=value)}}catch{}let result=(text,source,stale,warning)=>({text,source,stale,url,version:skillVersion(text),...warning?{warning}:{}});try{let response=await(options.fetch??fetch)(url,{redirect:"error",credentials:"omit",signal:AbortSignal.timeout(options.timeoutMs??5e3),headers:{Accept:"text/markdown",...cached3?.etag?{"If-None-Match":cached3.etag}:{}}});if(response.status===304&&cached3)return result(cached3.text,"cache",!1);if(response.status!==200||response.redirected||!response.headers.get("content-type")?.startsWith("text/markdown"))throw await response.body?.cancel(),new Error("Invalid skill response");if(Number(response.headers.get("content-length"))>MAX_BYTES)throw await response.body?.cancel(),new Error("Skill too large");let reader=response.body?.getReader();if(!reader)throw new Error("Missing skill body");let chunks=[],bytes=0;try{for(;;){let{done,value}=await reader.read();if(done)break;if(bytes+=value.byteLength,bytes>MAX_BYTES)throw new Error("Skill too large");chunks.push(value)}}finally{await reader.cancel().catch(()=>{})}let text=new TextDecoder("utf-8",{fatal:!0}).decode(Buffer.concat(chunks));if(!validSkill(text))throw new Error("Invalid skill");let etag=response.headers.get("etag"),next={url,text,...etag&&etag.length<=200&&!/[\r\n]/.test(etag)?{etag}:{}},temporary=`${file}.${randomUUID()}.tmp`;try{mkdirSync3(dirname3(file),{recursive:!0,mode:448}),writeFileSync3(temporary,JSON.stringify(next),{mode:384}),renameSync(temporary,file)}catch{return result(text,"remote",!1,"Skill fetched; local cache could not be saved.")}finally{try{rmSync2(temporary,{force:!0})}catch{}}return result(text,"remote",!1)}catch{return result(cached3?.text??bundled(),cached3?"cache":"bundled",!0,"Published skill unavailable; using fallback instructions. Retry in a new chat or on explicit refresh.")}}init_experience();init_brand();init_brand();init_config();init_lock();init_brand();init_brand();init_credentials();var PACKAGE_NAME=NPM_PACKAGE,TTL_MS=1440*60*1e3;function isNewer(current2,candidate){let parse=v=>v.replace(/^v/,"").split("-")[0].split(".").map(n=>Number.parseInt(n,10)||0),a=parse(current2),b=parse(candidate);for(let i=0;i<Math.max(a.length,b.length);i+=1){let x=a[i]??0,y=b[i]??0;if(y>x)return!0;if(y<x)return!1}return!1}function fetchLatest(runner=(cmd,args)=>execFileSync(cmd,args,{encoding:"utf8",timeout:4e3,stdio:["ignore","pipe","ignore"]})){try{let out=runner("npm",["view",PACKAGE_NAME,"version","--json"]).trim(),parsed=JSON.parse(out);return typeof parsed=="string"?parsed:Array.isArray(parsed)&&typeof parsed[parsed.length-1]=="string"?parsed[parsed.length-1]:null}catch{return null}}var HOOK_MARKER="amp --agent skill sync",HOOK_COMMAND=`command -v amp >/dev/null 2>&1 && ${HOOK_MARKER} || true`;function npmInstall(spec){return spawnSync("npm",["install","-g",spec],{stdio:"ignore",timeout:9e4,shell:process.platform==="win32"}).status===0}function ensureLatestCli(opts={}){let env=opts.env??process.env,current2=CLI_VERSION;if(env.AMP_NO_UPDATE_CHECK==="1")return{status:"skipped",current:current2};let latest=(opts.latest??fetchLatest)();return latest?isNewer(current2,latest)?{status:(opts.install??npmInstall)(`${NPM_PACKAGE}@${latest}`)?"updated":"failed",current:current2,latest}:{status:"current",current:current2,latest}:{status:"unknown",current:current2}}function claudeSettingsPath(){return join5(homedir4(),".claude","settings.json")}function installSessionHook(settingsPath=claudeSettingsPath()){if(!existsSync4(dirname5(settingsPath)))return"skipped";let settings={};if(existsSync4(settingsPath))try{let parsed=JSON.parse(readFileSync5(settingsPath,"utf8"));if(!parsed||typeof parsed!="object"||Array.isArray(parsed))return"skipped";settings=parsed}catch{return"skipped"}let hooks=settings.hooks??{};if(!hooks||typeof hooks!="object"||Array.isArray(hooks))return"skipped";let sessionStart=hooks.SessionStart??[];if(!Array.isArray(sessionStart))return"skipped";if(sessionStart.some(group=>Array.isArray(group?.hooks)&&group.hooks.some(h=>typeof h?.command=="string"&&h.command.includes(HOOK_MARKER))))return"present";sessionStart.push({matcher:"startup|clear",hooks:[{type:"command",command:HOOK_COMMAND,timeout:120}]}),settings.hooks={...hooks,SessionStart:sessionStart};let tmp=`${settingsPath}.${process.pid}.tmp`;return writeFileSync5(tmp,`${JSON.stringify(settings,null,2)}
18
18
  `),renameSync2(tmp,settingsPath),"installed"}function reexecSync(target){let r=spawnSync("amp",["--agent","skill","sync","--skip-update",...target===defaultInstallPath()?[]:["--dir",dirname5(target)]],{encoding:"utf8",timeout:3e4,shell:process.platform==="win32"});if(r.status!==0)return null;try{return JSON.parse(r.stdout).data}catch{return null}}async function syncSkill(opts={}){let target=opts.target??defaultInstallPath(),lock=join5(dirname5(configPath()),"skill-sync.lock");mkdirSync5(dirname5(lock),{recursive:!0,mode:448});let cli=opts.skipUpdate?{status:"skipped",current:CLI_VERSION}:await withFileLock(lock,async()=>(opts.update??ensureLatestCli)());if(cli.status==="updated"){let child=(opts.reexec??reexecSync)(target);if(child)return{...child,cli}}return withFileLock(lock,async()=>{let result={cli,skill:{path:target,outcome:installSkill(target)}},service=existsSync4(target)?skillService(readFileSync5(target,"utf8")):void 0;if(service){let published=await fetchSkill(service,bundledSkill,{fetch:opts.fetch,cacheDir:opts.cacheDir});result.published={url:published.url,source:published.source,stale:published.stale,version:published.version,...published.warning?{warning:published.warning}:{}}}return result})}var STAMP_PREFIX="<!-- amp-managed skill \xB7 amp ";function bundledSkillPath(){return resolve(dirname6(fileURLToPath(import.meta.url)),"..","skill","SKILL.md")}function bundledSkill(){let p=bundledSkillPath();if(!existsSync5(p))throw new Error("Bundled skill missing. Reinstall the CLI package.");return readFileSync6(p,"utf8")}function defaultInstallPath(){return join6(homedir5(),".claude","skills","amp-cli","SKILL.md")}function stamped(text){return`${STAMP_PREFIX}${CLI_VERSION} \u2014 bundled customer skill; remove this stamp to preserve manual edits -->
19
19
  ${text}`}function isAmpManaged(text){return text.startsWith(STAMP_PREFIX)}function installSkill(target=defaultInstallPath(),service){let current2=existsSync5(target)?readFileSync6(target,"utf8"):void 0;if(current2!==void 0&&!isAmpManaged(current2))return"kept-hand-edited";let publisher=service??(current2===void 0?void 0:skillService(current2)),next=stamped(publisher?bootstrapSkill(publisher):bundledSkill());return current2!==void 0?(current2===next||writeFileSync6(target,next),"refreshed"):(mkdirSync6(dirname6(target),{recursive:!0}),writeFileSync6(target,next),"installed")}function skillService(text){return text.match(/^<!-- amp-skill-service: (https:\/\/[^\s]+) -->$/m)?.[1]}function bootstrapSkill(service){let url=skillUrl(service),origin2=new URL(url).origin;return`---
20
20
  name: amp-cli
@@ -25,6 +25,11 @@ description: Ask evidence-backed questions about workspace activity with Amp, in
25
25
 
26
26
  # Amp
27
27
 
28
+ If \`amp\` is not installed, install it with \`npm install -g ${NPM_PACKAGE}\` (Node.js 20 or
29
+ later), or give the user that command if you cannot install it here. It uses the sign-in
30
+ stored on the machine where it runs; if it reports no session, a person signs in on that
31
+ machine with \`amp login\`. This applies in any agent or sandbox.
32
+
28
33
  On first use in this chat, run \`amp --agent skill fetch --service ${origin2}\`.
29
34
  Read the returned skill text and follow its workflow within the user's request
30
35
  and your host's instruction hierarchy. The publisher is ${url}.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0x26/amp",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "Query your data with Ampersand",
5
5
  "type": "module",
6
6
  "bin": {
package/skill/SKILL.md CHANGED
@@ -5,6 +5,16 @@ description: Ask evidence-backed questions about workspace activity with Amp, in
5
5
 
6
6
  # Ampersand
7
7
 
8
+ ## Setup
9
+
10
+ These steps apply in any agent environment: Claude Code, Codex, Cursor, a cloud sandbox, or a plain terminal.
11
+
12
+ - If `amp --version` fails because the command is not found, install the CLI before anything else. It needs Node.js 20 or later: `npm install -g @0x26/amp`. If you cannot install it in this environment (no Node.js, network, or permission), tell the user and give them that command; never install from another source.
13
+ - `amp` uses the sign-in stored on the machine where it runs. If `amp --agent login --status` shows no session, a person runs `amp login --store <tenant-store-url>` in a terminal on that same machine; their administrator supplies the store URL. A sign-in on the user's laptop does not reach a remote sandbox, and the reverse.
14
+ - To keep `amp` and these instructions current in an agent without a session-start hook, run `amp --agent skill sync --dir <this skill's directory>` once at the start of a session.
15
+
16
+ ## Use
17
+
8
18
  - In Claude Code, a session-start hook runs `amp --agent skill sync`: it installs the latest `amp` when a newer version is published and refreshes these instructions. If `data.cli.status` is `failed`, tell the user a newer `amp` could not be installed and continue with the installed version. Do not run the sync again in the same conversation.
9
19
  - When the user invokes Amp without a question, or right after setup, reply exactly: "What would you like to ask amp?" Treat their answer as the Amp question.
10
20
  - Run `amp --help` and the relevant command's `--help` before composing a request.