@funfab/cli 0.1.1 → 0.2.0
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 +10 -3
- package/cli/approvals.mjs +29 -18
- package/cli/funfab.mjs +18 -10
- package/cli/tokens.mjs +13 -5
- package/package.json +1 -1
- package/skills/funfab/SKILL.md +6 -0
package/README.md
CHANGED
|
@@ -25,9 +25,16 @@ funfab game stop emote-defense --reason "Balancing pass"
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
Changes ask you in the terminal first. Add --yes to skip
|
|
28
|
-
the question. High-stakes changes, like
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
the question. High-stakes changes, like turning on FunFab
|
|
29
|
+
sign-in for a game, also ask you to confirm it's you in your
|
|
30
|
+
browser, once an hour.
|
|
31
|
+
|
|
32
|
+
## Lifting a hold or creating a token: confirm that one action
|
|
33
|
+
funfab game unhold and funfab token create
|
|
34
|
+
|
|
35
|
+
These two commands need a person at a terminal and a
|
|
36
|
+
browser every time. An agent should ask the person to
|
|
37
|
+
run the command themselves. No token can do either.
|
|
31
38
|
|
|
32
39
|
## Let an agent work for you
|
|
33
40
|
Coming soon.
|
package/cli/approvals.mjs
CHANGED
|
@@ -3,7 +3,8 @@ import {setTimeout as delay} from 'node:timers/promises'
|
|
|
3
3
|
|
|
4
4
|
export const terminalRequired=Object.freeze({error:'terminal_required',nextAction:{kind:'command',command:'funfab token create'}})
|
|
5
5
|
export const terminalMessage='This change needs a person at a terminal. Run the command yourself in a terminal.'
|
|
6
|
-
const
|
|
6
|
+
export const malformedConfirmation=()=>{throw Object.assign(Error('account_unavailable'),{malformedConfirmation:true})}
|
|
7
|
+
export const writePauseStatuses=['activation_needed','sudo_needed','action_confirmation_needed']
|
|
7
8
|
|
|
8
9
|
export function createApprovals({call,output,openBrowser,asJson=false,yes=false,tokenAdvice,input=process.stdin,out=process.stdout,now=Date.now,sleep=delay}) {
|
|
9
10
|
const terminal=Boolean(input.isTTY&&out.isTTY)
|
|
@@ -24,23 +25,30 @@ export function createApprovals({call,output,openBrowser,asJson=false,yes=false,
|
|
|
24
25
|
} catch(error) {if(error.name!=='AbortError')throw error;emit({status:'cancelled'},'Nothing changed.');return false}
|
|
25
26
|
finally {rl.close()}
|
|
26
27
|
}
|
|
27
|
-
async function wait(ticket,pause,{activation=false,opened=false,signIn=false,signal}={}) {
|
|
28
|
+
async function wait(ticket,pause,{activation=false,opened=false,signIn=false,signal,needsAction,pendingOnly=false}={}) {
|
|
28
29
|
const {confirmationUrl:url,requestId,code,interval=5,expiresAt}=pause
|
|
30
|
+
if(typeof url!=='string'||/[\u0000-\u0020\u007f]/u.test(url))return malformedConfirmation()
|
|
29
31
|
let target
|
|
30
|
-
try {target=new URL(url)} catch {return
|
|
31
|
-
if(!(target.protocol==='https:'||(target.protocol==='http:'&&['127.0.0.1','localhost','[::1]'].includes(target.hostname))))return
|
|
32
|
-
if(!/^[A-Za-z0-9_-]{43}$/.test(requestId??'')||!/^[A-Z0-9]{4}$/.test(code??'')||!Number.isInteger(interval)||interval<5||!Number.isFinite(Date.parse(expiresAt)))return
|
|
33
|
-
const
|
|
34
|
-
|
|
32
|
+
try {target=new URL(url)} catch {return malformedConfirmation()}
|
|
33
|
+
if(!(target.protocol==='https:'||(target.protocol==='http:'&&['127.0.0.1','localhost','[::1]'].includes(target.hostname))))return malformedConfirmation()
|
|
34
|
+
if(!/^[A-Za-z0-9_-]{43}$/.test(requestId??'')||!/^[A-Z0-9]{4}$/.test(code??'')||!Number.isInteger(interval)||interval<5||!Number.isFinite(Date.parse(expiresAt)))return malformedConfirmation()
|
|
35
|
+
const action=pause.status==='action_confirmation_needed'
|
|
36
|
+
const safe={status:action?pause.status:activation?'activation_needed':'sudo_needed',confirmationUrl:url,requestId,code,interval,expiresAt,nextAction:next(url)}
|
|
37
|
+
if(asJson||!terminal||pendingOnly) {
|
|
38
|
+
output(pendingOnly&&!asJson&&terminal?{...safe,message:url}:safe)
|
|
39
|
+
process.exitCode=3;return false
|
|
40
|
+
}
|
|
41
|
+
if(action&&needsAction)emit({status:safe.status},needsAction)
|
|
42
|
+
const matchCode=`Check the code matches: ${code}`
|
|
35
43
|
const browserOpened=opened||await openBrowser(url)
|
|
36
|
-
emit(safe,browserOpened?`Opening your browser${signIn?' to sign in':''}.
|
|
44
|
+
emit(safe,browserOpened?`Opening your browser${signIn?' to sign in':''}. ${matchCode}`:`Open this address in your browser. ${matchCode}`)
|
|
37
45
|
if(!browserOpened)emit(safe,url)
|
|
38
|
-
emit({status:safe.status},'Waiting for you to confirm… (Ctrl-C to stop)')
|
|
39
46
|
const controller=new AbortController(),cancel=()=>controller.abort()
|
|
40
47
|
process.once('SIGINT',cancel)
|
|
41
48
|
const combined=signal?AbortSignal.any([signal,controller.signal]):controller.signal
|
|
42
49
|
const localDeadline=now()+600000,deadline=Math.min(localDeadline,Date.parse(expiresAt));let seconds=interval,expired=false
|
|
43
50
|
try {
|
|
51
|
+
emit({status:safe.status},'Waiting for you to confirm… (Ctrl-C to stop)')
|
|
44
52
|
while(now()<deadline&&!combined.aborted) {
|
|
45
53
|
await sleep(Math.min(seconds*1000,Math.max(0,deadline-now())),undefined,{signal:combined})
|
|
46
54
|
if(now()>=deadline||combined.aborted)break
|
|
@@ -53,20 +61,20 @@ export function createApprovals({call,output,openBrowser,asJson=false,yes=false,
|
|
|
53
61
|
throw error
|
|
54
62
|
}
|
|
55
63
|
if(combined.aborted||now()>=deadline)break
|
|
56
|
-
if(!state||!['pending','confirmed','cancelled','expired'].includes(state.status)||state.code!==code||!Number.isInteger(state.interval??5)||(state.interval??5)<5||!Number.isFinite(Date.parse(state.expiresAt)))return
|
|
57
|
-
if(state.status==='confirmed') {emit({status:'confirmed'},activation?'Confirmed.':"Confirmed. High-stakes commands won't ask again for an hour.");return true}
|
|
58
|
-
if(state.status==='cancelled') {emit({status:'cancelled'},'You chose "No, this isn\'t me" in your browser. Nothing changed.');process.exitCode=1;return false}
|
|
64
|
+
if(!state||!['pending','confirmed','cancelled','expired'].includes(state.status)||state.code!==code||!Number.isInteger(state.interval??5)||(state.interval??5)<5||!Number.isFinite(Date.parse(state.expiresAt)))return malformedConfirmation()
|
|
65
|
+
if(state.status==='confirmed') {if(!action)emit({status:'confirmed'},activation?'Confirmed.':"Confirmed. High-stakes commands won't ask again for an hour.");return true}
|
|
66
|
+
if(state.status==='cancelled') {emit({status:'cancelled'},action?'Cancelled. Nothing changed.':'You chose "No, this isn\'t me" in your browser. Nothing changed.');process.exitCode=1;return false}
|
|
59
67
|
if(state.status==='expired'){expired=true;break}
|
|
60
68
|
seconds=Math.max(seconds,state.interval??5)
|
|
61
69
|
}
|
|
62
70
|
} catch(error) {if(!combined.aborted)throw error}
|
|
63
71
|
finally {process.removeListener('SIGINT',cancel)}
|
|
64
72
|
if(combined.aborted) {emit({status:'cancelled',nextAction:{kind:'command',command:'funfab '+process.argv.slice(2).map(arg=>"'"+arg.replaceAll("'", "'\\''")+"'").join(' ')}},'Stopped waiting. Nothing changed. The browser request expires on its own.');process.exitCode=3;return false}
|
|
65
|
-
if(!expired&&localDeadline<Date.parse(expiresAt)&&now()>=localDeadline) {emit(safe
|
|
73
|
+
if(!expired&&localDeadline<Date.parse(expiresAt)&&now()>=localDeadline) {emit(safe,`${matchCode}\n${url}`);process.exitCode=3;return false}
|
|
66
74
|
emit({error:'confirmation_expired',nextAction:{kind:'command',command:'funfab '+process.argv.slice(2).map(arg=>"'"+arg.replaceAll("'", "'\\''")+"'").join(' ')}},"You didn't confirm in your browser in time. Nothing changed. Run the command again to try again.")
|
|
67
75
|
process.exitCode=1;return false
|
|
68
76
|
}
|
|
69
|
-
async function write(path,body,saved,{prompt,destructive,needs}={}) {
|
|
77
|
+
async function write(path,body,saved,{prompt,destructive,needs,needsAction}={}) {
|
|
70
78
|
requireTerminal()
|
|
71
79
|
if(!await question(prompt,destructive))return null
|
|
72
80
|
const approvedIn=yes?'yes':'terminal',input={...body,approvedIn}
|
|
@@ -75,13 +83,16 @@ export function createApprovals({call,output,openBrowser,asJson=false,yes=false,
|
|
|
75
83
|
if(!await wait(saved.ticket,result,{activation:true}))return null
|
|
76
84
|
result=await call(path,input,saved.ticket)
|
|
77
85
|
}
|
|
78
|
-
if(result.status==='sudo_needed') {
|
|
79
|
-
if(needs&&!asJson)emit({status:'sudo_needed'},needs)
|
|
80
|
-
if(!await wait(saved.ticket,result))return null
|
|
86
|
+
if(result.status==='sudo_needed'||result.status==='action_confirmation_needed') {
|
|
87
|
+
if(result.status==='sudo_needed'&&needs&&!asJson)emit({status:'sudo_needed'},needs)
|
|
88
|
+
if(!await wait(saved.ticket,result,{needsAction}))return null
|
|
81
89
|
// The pause proves that no write ran. This is the one first execution, not a
|
|
82
90
|
// transport retry. A thrown/uncertain sent write is never retried here.
|
|
83
91
|
result=await call(path,input,saved.ticket)
|
|
84
|
-
if(
|
|
92
|
+
if(writePauseStatuses.includes(result.status)) {
|
|
93
|
+
await wait(saved.ticket,result,{activation:result.status==='activation_needed',pendingOnly:true})
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
85
96
|
}
|
|
86
97
|
return result
|
|
87
98
|
}
|
package/cli/funfab.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {submitInput,submitCopy} from '../validation/submit.mjs'
|
|
|
12
12
|
import {probeSubmitGate} from './submit-probe.mjs'
|
|
13
13
|
import {CALLBACKS,createAttempt,authorizationURL} from './attempt.mjs'
|
|
14
14
|
import {tokenCommands,tokenIntent,runToken} from './tokens.mjs'
|
|
15
|
-
import {createApprovals,terminalMessage,alignedRows} from './approvals.mjs'
|
|
15
|
+
import {createApprovals,terminalMessage,alignedRows,malformedConfirmation,writePauseStatuses} from './approvals.mjs'
|
|
16
16
|
|
|
17
17
|
if(Number(process.versions.node.split('.')[0])<22) {
|
|
18
18
|
console.error('FunFab needs Node.js 22 or newer. Upgrade Node.js, then run funfab again.')
|
|
@@ -37,6 +37,7 @@ const commands=[
|
|
|
37
37
|
{command:'login',arguments:'',description:'Sign in to the FunFab Developer CLI',example:'funfab login',next:'Confirm your sign-in in the browser.',run:login,count:1},
|
|
38
38
|
...['list','status','check','requests'].map(read=>({command:`game ${read}`,arguments:read==='list'?'':read==='requests'?'GAME [--before REQUEST] | GAME --answer REQUEST --approve|--decline --reason TEXT [--expires TIME|never]':'GAME',description:{list:'List games you can inspect',status:'Show game status and real access',check:'Show recorded setup steps',requests:'Show pending requests, or answer one; decisions stay in history; remove an allow-list entry separately'}[read],example:`funfab game ${read}${read==='list'?'':' my-game'}`,run:gameRead,count:read==='list'?2:3})),
|
|
39
39
|
...['set-status','stop','start','allow','block'].map(action=>({command:`game ${action}`,arguments:`GAME${action==='set-status'?' internal|playtest':['allow','block'].includes(action)?' ACCOUNT':''} --reason TEXT${['allow','block'].includes(action)?' [--expires TIME|never] [--remove]':''}`,description:{'set-status':'Move to Internal, or to Playtest on Production; listing stays a separate fact',stop:'Stop game; rooms already running end within 5 minutes',start:'Start game; ended rooms do not come back',allow:'Add to the allow list; daily room limits stay unchanged; undo with --remove',block:'Add to the block list; undo with --remove; removing creates no allow-list entry'}[action],example:`funfab game ${action} my-game${action==='set-status'?' internal':['allow','block'].includes(action)?' ACCOUNT':''} --reason 'Reason'`,next:'Answer the question in your terminal.',run:gameWrite})),
|
|
40
|
+
...['hold','unhold'].map(action=>({command:`game ${action}`,arguments:`GAME ${action==='hold'?'[--reason TEXT]':'--reason TEXT'}`,description:action==='hold'?'Place a hold; nobody can start the game until a person lifts it':'Lift the hold; the game stays stopped',example:`funfab game ${action} my-game --reason 'Reason'`,next:'Answer the question in your terminal.',run:gameWrite})),
|
|
40
41
|
...['show','hide'].map(action=>({command:`title ${action}`,arguments:'TITLE --reason TEXT',description:action==='hide'?'Hide title from the list; launching through the game is unchanged; undo with show':'Show title with its stored declaration; undo with hide',example:`funfab title ${action} my-title --reason 'Reason'`,next:'Answer the question in your terminal.',run:gameWrite})),
|
|
41
42
|
{command:'game init' ,arguments:'FILE',description:'Write a new submission file offline, without signing in',example:'funfab game init submission.json',next:'Fill in the fields, then run funfab game submit FILE.',run:init,count:3},
|
|
42
43
|
{command:'game submit',arguments:'FILE',description:'Submit a caller-owned stream game on Preview',example:'funfab game submit submission.json',next:'Connect the shown address, install the sign-in key, then confirm the checks in the same file.',run:submit,count:3},
|
|
@@ -98,8 +99,12 @@ const load=async()=>{
|
|
|
98
99
|
try {const saved=JSON.parse(raw);if(!saved||typeof saved.ticket!=='string'||!saved.ticket)throw Error();return saved} catch {throw problem('cli_state_corrupt','The saved sign-in is damaged. Run funfab login to replace it.',commandAction('funfab login'))}
|
|
99
100
|
}
|
|
100
101
|
async function call(path,body,ticket,signal) {
|
|
101
|
-
const
|
|
102
|
-
const
|
|
102
|
+
const actionConfirmation=path==='token/create'||path==='game/action'&&body?.operation?.action==='unhold'
|
|
103
|
+
const response=await fetch(`${api}/api/cli/${path}`,{method:body===undefined?'GET':'POST',headers:{...(body===undefined?{}:{'Content-Type':'application/json'}),...(actionConfirmation?{'FunFab-CLI-Action-Confirmation':'1'}:{}),...(ticket?{Authorization:`Bearer ${ticket}`}:{})},...(body===undefined?{}:{body:JSON.stringify(body)}),signal:signal?AbortSignal.any([signal,AbortSignal.timeout(10000)]):AbortSignal.timeout(path==='submit'?180000:10000)})
|
|
104
|
+
const data=await response.json()
|
|
105
|
+
if(data?.status==='action_confirmation_needed'&&(!actionConfirmation||response.status!==202))return malformedConfirmation()
|
|
106
|
+
if(actionConfirmation&&response.status===202&&!writePauseStatuses.includes(data?.status))return malformedConfirmation()
|
|
107
|
+
if(!response.ok) throw Object.assign(Error(data.error??'account_unavailable'),(path.startsWith('game/')||path.startsWith('token/')||path==='confirm-request')&&['game_request_invalid','game_request_conflict'].includes(data.error)&&['input_invalid','cursor_invalid','expiry_elapsed','consumed','answered','invalidated'].includes(data.reason)?{reason:data.reason}:{});return data
|
|
103
108
|
}
|
|
104
109
|
const terminal=Boolean(process.stdin.isTTY&&process.stdout.isTTY&&!asJson)
|
|
105
110
|
const personWrite=isWrite||['game submit','game admit','token create','token revoke','token kill-switch'].includes(command?.command)
|
|
@@ -196,10 +201,11 @@ async function whoami() {
|
|
|
196
201
|
output({...result,message:`${result.displayName??'FunFab account'}\n${result.confirmed?'Confirmed':'Waiting for your confirmation. Run funfab login to start a new confirmation.'}\nSession expires: ${expiry}\nInactivity limit: ${inactivity}`,...(!result.confirmed?{nextAction:commandAction('funfab login')}:{})})
|
|
197
202
|
}
|
|
198
203
|
async function logout() {
|
|
199
|
-
let saved,exists=true,ended=false
|
|
204
|
+
let saved,malformed,exists=true,ended=false
|
|
200
205
|
try {saved=await load()} catch(error) {if(error.message==='authorization_required')exists=false}
|
|
201
|
-
if(saved)try {ended=(await call('logout',{},saved.ticket)).ended===true} catch {}
|
|
206
|
+
if(saved)try {ended=(await call('logout',{},saved.ticket)).ended===true} catch(error) {if(error.malformedConfirmation)malformed=error}
|
|
202
207
|
try {await unlink(file)} catch(error) {if(error.code!=='ENOENT')throw problem('cli_state_unwritable','The saved sign-in could not be removed. Make the CLI state folder writable, then run funfab logout.',person('Make the CLI state folder writable, then run funfab logout.'))}
|
|
208
|
+
if(malformed)throw malformed
|
|
203
209
|
output({ended,message:!exists?"You're not signed in":ended?'Signed out':"Signed out on this computer; the server session couldn't be confirmed as ended"})
|
|
204
210
|
}
|
|
205
211
|
function starter() {
|
|
@@ -307,7 +313,7 @@ async function gameRead() {
|
|
|
307
313
|
function writeIntent() {
|
|
308
314
|
const title=args[0]==='title', answer=args[1]==='requests'
|
|
309
315
|
const base=title||answer?3:['set-status','allow','block'].includes(args[1])?4:3
|
|
310
|
-
const intent={action:title?`title-${args[1]}`:answer?'request-decide':args[1]==='set-status'?(args[3]==='internal'?'dev':args[3]==='playtest'?'live':undefined):({stop:'off',start:'on',allow:'grant',block:'block'}[args[1]]),selector:args[2]}
|
|
316
|
+
const intent={action:title?`title-${args[1]}`:answer?'request-decide':args[1]==='set-status'?(args[3]==='internal'?'dev':args[3]==='playtest'?'live':undefined):({stop:'off',start:'on',allow:'grant',block:'block',hold:'hold',unhold:'unhold'}[args[1]]),selector:args[2]}
|
|
311
317
|
if(!intent.action||!intent.selector||(!title&&['allow','block'].includes(args[1])&&!args[3]))throw Error('usage')
|
|
312
318
|
if(!title&&['allow','block'].includes(args[1]))intent.accountId=args[3]
|
|
313
319
|
const flags=new Map()
|
|
@@ -317,7 +323,7 @@ function writeIntent() {
|
|
|
317
323
|
if(!boolean&&(!args[i+1]||args[i+1].startsWith('--')))throw Error('usage')
|
|
318
324
|
flags.set(flag,boolean?true:args[++i])
|
|
319
325
|
}
|
|
320
|
-
intent.reason=flags.get('--reason')
|
|
326
|
+
intent.reason=flags.get('--reason')??(intent.action==='hold'?'Person placed a switch-off hold':undefined)
|
|
321
327
|
if(!intent.reason?.trim()||intent.reason.trim().length>1000)throw Error('usage')
|
|
322
328
|
if(flags.has('--remove')&&!['allow','block'].includes(args[1])||['--answer','--approve','--decline'].some(f=>flags.has(f))&&!answer)throw Error('usage')
|
|
323
329
|
if(intent.accountId&&!/^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(intent.accountId))throw Error('usage')
|
|
@@ -365,13 +371,15 @@ async function gameWrite() {
|
|
|
365
371
|
}
|
|
366
372
|
const name=account?.displayName??'this FunFab account',g=game.name
|
|
367
373
|
const variant=intent.action==='grant'?(intent.active?'grant':'revoke'):intent.action==='block'?(intent.active?'block':'lift'):intent.action==='request-decide'?'request-'+intent.decision:intent.action
|
|
368
|
-
const questions={off:`Stop ${g}? Players can't start or join rooms.\nRooms already running end within 5 minutes.`,on:`Start ${g}? ${g} can be played again within 5 minutes. Rooms that ended don't come back.`,live:`Move ${g} to Playtest? After: Playtest, people on the allow list.`,dev:`Move ${g} to Internal? After: Internal, team only. The allow list is kept, but it won't do anything until the game moves back to Playtest.`,grant:`Add ${name} to ${g}'s allow list? Their daily room limits don't change.`,revoke:`Remove ${name} from ${g}'s allow list? If ${g} isn't open to everyone, ${name} won't be able to host it any more.`,block:`Add ${name} to ${g}'s block list? A room they're already running ends within 5 minutes.`,lift:`Remove ${name} from ${g}'s block list? Whether ${name} can host now depends on the game's access and its allow list.`,'request-grant':`Approve ${name}'s request to host ${g}? Their daily room limits don't change.`,'request-decline':`Decline ${name}'s request to host ${g}? They can ask again after 7 days.`,'title-show':`Show ${selected?.name} in the games list? Game access still decides who can host ${g}.`,'title-hide':`Hide ${selected?.name} from the games list? This doesn't stop people launching it through ${g}.`}
|
|
374
|
+
const questions={hold:`Place a hold on ${g}? While it's held, nobody can start it until a person lifts the hold.`,unhold:`Lift the hold on ${g}? It stays stopped until someone starts it.`,off:`Stop ${g}? Players can't start or join rooms.\nRooms already running end within 5 minutes.`,on:`Start ${g}? ${g} can be played again within 5 minutes. Rooms that ended don't come back.`,live:`Move ${g} to Playtest? After: Playtest, people on the allow list.`,dev:`Move ${g} to Internal? After: Internal, team only. The allow list is kept, but it won't do anything until the game moves back to Playtest.`,grant:`Add ${name} to ${g}'s allow list? Their daily room limits don't change.`,revoke:`Remove ${name} from ${g}'s allow list? If ${g} isn't open to everyone, ${name} won't be able to host it any more.`,block:`Add ${name} to ${g}'s block list? A room they're already running ends within 5 minutes.`,lift:`Remove ${name} from ${g}'s block list? Whether ${name} can host now depends on the game's access and its allow list.`,'request-grant':`Approve ${name}'s request to host ${g}? Their daily room limits don't change.`,'request-decline':`Decline ${name}'s request to host ${g}? They can ask again after 7 days.`,'title-show':`Show ${selected?.name} in the games list? Game access still decides who can host ${g}.`,'title-hide':`Hide ${selected?.name} from the games list? This doesn't stop people launching it through ${g}.`}
|
|
369
375
|
if(!asJson)output({message:`${game.environment==='preview'?'Preview':'Production'} · ${g}`})
|
|
370
|
-
|
|
376
|
+
let response
|
|
377
|
+
try {response=await approvals.write('game/action',{operation},saved,{prompt:questions[variant]+' [y/N]',needsAction:variant==='unhold'?'Lifting a hold needs your confirmation in the browser.':undefined,needs:variant==='unhold'?`Lifting the hold on ${g} needs you to confirm it's you.`:undefined,destructive:game.environment==='production'&&['off','block','revoke','title-hide','request-decline'].includes(variant)?game.gameId:undefined})}
|
|
378
|
+
catch(error) {if(error.message==='game_switch_off_held')throw problem(error.message,`${g} is on hold. A person has to lift the hold first: funfab game unhold ${game.gameId} --reason "…"`,commandAction(`funfab game unhold ${game.gameId} --reason "…"`));throw error}
|
|
371
379
|
if(!response)return
|
|
372
380
|
const result=response.result
|
|
373
381
|
const undo={off:`funfab game start ${game.gameId} --reason "…"`,on:`funfab game stop ${game.gameId} --reason "…"`,live:`funfab game set-status ${game.gameId} internal --reason TEXT`,dev:game.environment==='production'?`funfab game set-status ${game.gameId} playtest --reason TEXT`:null,grant:`funfab game allow ${game.gameId} ${intent.accountId} --remove --reason TEXT`,revoke:`funfab game allow ${game.gameId} ${intent.accountId} --reason TEXT [--expires TIME|never]`,block:`funfab game block ${game.gameId} ${intent.accountId} --remove --reason TEXT`,lift:`funfab game block ${game.gameId} ${intent.accountId} --reason TEXT [--expires TIME|never]`,'title-show':`funfab title hide ${selected?.titleId} --reason TEXT`,'title-hide':`funfab title show ${selected?.titleId} --reason TEXT`}[variant]
|
|
374
|
-
const messages={off:'Stopped.',on:'Started.',live:'Moved to Playtest.',dev:'Moved to Internal.',grant:'Added to the allow list.',revoke:'Removed from the allow list.',block:'Added to the block list.',lift:'Removed from the block list.','request-grant':'Request approved.','request-decline':'Request declined.','title-show':'Shown on the Games page.','title-hide':'Hidden from the Games page.'}
|
|
382
|
+
const messages={hold:'Hold placed.',unhold:`Hold lifted. ${g} is still stopped.\nTo start it: funfab game start ${game.gameId} --reason "…"`,off:'Stopped.',on:'Started.',live:'Moved to Playtest.',dev:'Moved to Internal.',grant:'Added to the allow list.',revoke:'Removed from the allow list.',block:'Added to the block list.',lift:'Removed from the block list.','request-grant':'Request approved.','request-decline':'Request declined.','title-show':'Shown on the Games page.','title-hide':'Hidden from the Games page.'}
|
|
375
383
|
output({...result,...(!asJson?{message:messages[variant]+(undo?'\nTo undo: '+undo:'')}:{}),nextAction:commandAction(`funfab game status ${game.gameId}`)})
|
|
376
384
|
}
|
|
377
385
|
|
package/cli/tokens.mjs
CHANGED
|
@@ -144,12 +144,19 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
|
|
|
144
144
|
}
|
|
145
145
|
async function list(result) {
|
|
146
146
|
const own=await read('whoami',{});if(!own)return
|
|
147
|
-
const
|
|
147
|
+
const active=result.tokens.filter(activeToken)
|
|
148
|
+
const rows=active.map(t=>{
|
|
148
149
|
const powers=powerLabels(t.ticks).join(', ')
|
|
149
150
|
const age=t.lastUsedAt?Math.max(0,Math.floor((Date.now()-Date.parse(t.lastUsedAt))/60000)):null
|
|
150
151
|
return [t.name,t.authorizerAccountId===own.accountId?'you':'a staff member',`can ${powers||'see only'}`,t.expiresAt?`ends ${date(t.expiresAt)}`:'until revoked',age===null?'never used':`last used ${age} min ago`]
|
|
151
152
|
})
|
|
152
|
-
|
|
153
|
+
const table=alignedRows(asJson?null:['Name','Created by','Permissions','Ends','Last used'],rows).split('\n')
|
|
154
|
+
const powers={status:'change the status of',switchOff:'stop and start',access:'change access to'}
|
|
155
|
+
const lines=asJson?table:[table[0],...active.flatMap((token,index)=>[
|
|
156
|
+
table[index+1],
|
|
157
|
+
...(token.pausedPowers??[]).map(p=>` Paused: ${p.authorizerDisplayName??'The person who made this token'} can't ${powers[p.power]} ${p.gameName} now, so this token can't either.`)
|
|
158
|
+
])]
|
|
159
|
+
output({environment:result.environment,tokens:result.tokens,message:lines.join('\n')||(!asJson?'No tokens.':'')})
|
|
153
160
|
}
|
|
154
161
|
if(intent.action==='list') {const result=await read('token/list',{scope:intent.scope});if(result)await list(result);return}
|
|
155
162
|
if(intent.action!=='create') {
|
|
@@ -179,13 +186,13 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
|
|
|
179
186
|
const powers=powerLabels(intent.ticks)
|
|
180
187
|
const prompt=`Create "${intent.name}" for ${scopeName}? It can ${powers.length===1&&intent.ticks.switchOff?'stop and start the game':powers.length?powers.join(', '):'see only'}. [y/N]`
|
|
181
188
|
let response
|
|
182
|
-
try {response=await approvals.write('token/create',{operation},saved,{prompt,needs:"Creating an agent token needs you to confirm it's you."})}
|
|
189
|
+
try {response=await approvals.write('token/create',{operation},saved,{prompt,needs:"Creating an agent token needs you to confirm it's you.",needsAction:'Creating an agent token needs your confirmation in the browser.'})}
|
|
183
190
|
catch(error) {
|
|
184
191
|
if(error.message==='delegate_tokens_disabled')throw Object.assign(error,{display:`Agent tokens are switched off on ${environmentLabel(environment)} right now. Ask staff.`,nextAction:{kind:'person',instruction:'Ask staff.'}})
|
|
185
192
|
if(error.message==='game_revision_conflict')throw Object.assign(error,{display:'This approval is no longer valid. No token was made. Run the same command again for a new approval.',nextAction:{kind:'command',command:listCommand(intent)}})
|
|
186
193
|
if(error.message==='game_request_conflict')throw failure(error.message,uncertain(intent),listCommand(intent))
|
|
187
194
|
if(error.message==='game_request_invalid'&&error.reason==='expiry_elapsed')throw Object.assign(error,{display:'The requested end date has passed. Choose a later --expires time and run the command again.',nextAction:{kind:'command',command:listCommand(intent)}})
|
|
188
|
-
if(['authorization_required','game_request_invalid','game_request_conflict','game_revision_conflict','delegate_tokens_disabled','game_permission_denied','game_action_unavailable','game_environment_mismatch'].includes(error.message))throw error
|
|
195
|
+
if(error.malformedConfirmation||['authorization_required','game_request_invalid','game_request_conflict','game_revision_conflict','delegate_tokens_disabled','game_permission_denied','game_action_unavailable','game_environment_mismatch'].includes(error.message))throw error
|
|
189
196
|
throw failure('token_delivery_unknown',uncertain(intent),listCommand(intent))
|
|
190
197
|
}
|
|
191
198
|
if(!response)return
|
|
@@ -195,7 +202,8 @@ export async function runToken(intent,{call,load,output,approvals,asJson=false})
|
|
|
195
202
|
try {path=await saveToken(response.tokenValue,environment,intent.scope,intent.name,mutationId)}
|
|
196
203
|
catch {throw failure('token_delivery_lost',madeButNotSaved(intent),revokeCommand(intent))}
|
|
197
204
|
const shown=displayPath(path)
|
|
198
|
-
const
|
|
205
|
+
const paidLine=response.paidGameName?`\n${response.paidGameName} costs money each time it's played. Starting it and letting players in will spend money.`:''
|
|
206
|
+
const message=`Token created: ${intent.name} (${scopeName}, ${environmentLabel(environment)})\nSaved to ${shown}\n (readable only by you; shown nowhere else)\nCan: ${powers.length?['see',...powers].join(', '):'see only'}${paidLine}\n${intent.expiresAt?`Ends: ${date(intent.expiresAt,true)} UTC`:'Lasts until revoked'}\n\nTo use it: export FUNFAB_TOKEN_FILE=${shellPath(path)}\nTo revoke: ${revokeCommand(intent)}`
|
|
199
207
|
output({environment,name:intent.name,path,message})
|
|
200
208
|
if(intent.print)process.stdout.write(response.tokenValue+'\n')
|
|
201
209
|
}
|
package/package.json
CHANGED
package/skills/funfab/SKILL.md
CHANGED
|
@@ -29,3 +29,9 @@ description: Check and change FunFab games with the funfab
|
|
|
29
29
|
Creating or revoking tokens, the kill switch, turning
|
|
30
30
|
FunFab sign-in on or off, editors, holds and submitting a
|
|
31
31
|
game need a person. Say so, and show the command they'd run.
|
|
32
|
+
|
|
33
|
+
funfab game unhold and funfab token create
|
|
34
|
+
|
|
35
|
+
These two commands need a person at a terminal and a
|
|
36
|
+
browser every time. An agent should ask the person to
|
|
37
|
+
run the command themselves. No token can do either.
|